NOTICE: This challenge is now closed: I will no longer be updating the leaderboard and will not change the accepted answer. However, you are free to run the controller and update the leaderboard yourself, if you wish.
Join the chat!
Introduction
Good evening, traders! You are all traders for the golfing company PPCG. Your task is to make as much money as possible.
Challenge
Write a program that buys and sells shares on the Stack Exchange Stock Exchange with the aim of making as much money as possible.
Gameplay
All players will start with 5 shares and $100 in their bank. The game always starts with a share price of $10.
Each game will have 1000 rounds where the first round is round 1
. In each round, your program will be supplied four arguments as input: the current share price, the number of shares you hold, the amount of money you own and the round number (1-indexed).
For example, if my program is test1.py
, the share price is 100
, the number of shares I hold is 3
, the amount of money I have is 1200
, and the round number is 576
, my program will be run like so:
python test1.py 100 3 1200 576
In a round, the share price given to each player will be the same. This doesn't change until the end of the round.
In response, the player must print their command. There are two options:
- Buy shares: This command is given as
bn
wheren
is the number of shares you wish to buy. For example, if you want to buy 100 shares, you would output:
b100
When buying shares, you are allowed an overdraft of up to $1000. If you try to buy enough shares that exceed this overdraft (your bank balance goes below $-1000), you will be declared bankrupt. This means that you will lose all of your shares and your balance will be set to $50.
The share price will be unaffected by your command if you go bankrupt.
(If your balance is $-1000, you are not bankrupt. However if your balance is $-1001, you are bankrupt)
- Sell shares: This command is given as
sn
wheren
is the number of shares you wish to sell. For example, if you want to sell 100 shares, you would output:
s100
You may not sell more shares than you own. If you try to do this, your request will be denied, and you will skip the round.
If you want to skip the round and do nothing, output either b0
or s0
.
Your request will be denied if you try to buy or sell a negative number of shares and/or a non-integer number of shares.
After 5 rounds, at the end of each round, all players will be payed a dividend, the value of which is 5% of the mean average share price of the last 5 rounds.
How does it work?
Initially the share price will be $10. At the end of each round, it will be recalculated using the formula:
$$\text{New Share Price} = \text{Old Share Price} + (\text{Number of shares bought}-\text{Number of shares sold})$$
The share price will be limited so that it never falls below $1.
To prevent overly rapid change, the change in share price is limited to a maximum of \$\pm$200\$.
Rules
- Your program must have a name
- Your program is allowed a single text file for data storage. It must be stored in the same folder as your program
- Include in your answer details of how to run your program
- This KotH is open to all programming languages that are free-to-use and can be run on Windows 10
- Your score is based solely on the contents of your balance. Any money locked up in shares will not be counted
- You may edit your program at any time. Before each game, the latest code will be saved and compiled
- You should not write code which specifically targets another bot.
Controller
The controller is written in Python and can be found here: https://gist.github.com/beta-decay/a6abe40fc9f4ff6cac443395377ec31f
At the end it will print a leaderboard and display a graph of how the share price changed throughout the game.
For example, when two random bots were playing
Winning
The player with the highest amount of money in their balance at the end of the last game wins.
Leaderboard
Game 4: 16:14 10/08/2018
Name Balance
Experienced Greedy Idiot $14802860126910608746226775271608441476740220190868405578697473058787503167301288688412912141064764060957801420415934984247914753474481204843420999117641289792179203440895025689047561483400211597324662824868794009792985857917296068788434607950379253177065699908166901854516163240207641611196996217004494096517064741782361827125867827455285639964058498121173062045074772914323311612234964464095317202678432969866099864014974786854889944224928268964434751475446606732939913688961295787813863551384458839364617299883106342420461998689419913505735314365685264187374513996061826694192786379011458348988554845036604940421113739997490412464158065355335378462589602228039730
Equalizer $763185511031294813246284506179317396432985772155750823910419030867990447973211564091988995290789610193513321528772412563772470011147066425321453744308521967943712734185479563642323459564466177543928912648398244481744861744565800383179966018254551412512770699653538211331184147038781605464336206279313836606330
Percentage Trader $448397954167281544772103458977846133762031629256561243713673243996259286459758487106045850187688160858986472490834559645508673466589151486119551222357206708156491069820990603783876340193236064700332082781080188011584263709364962735827741094223755467455209136453381715027369221484319039100339776026752813930
OYAIB $8935960891618546760585096898089377896156886097652629690033599419878768424984255852521421137695754769495085398921618469764914237729576710889307470954692315601571866328742408488796145771039574397444873926883379666840494456194839899502761180282430561362538663182006432392949099112239702124912922930
Chimps on a Typewriter $176504338999287847159247017725770908273849738720252130115528568718490320252556133502528055177870
Greedy B*****d $17689013777381240
Illiterate Dividend Investor $2367418699671980
Lucky Number 6 $4382725536910
Lone Accountant $90954970320
Buy/Reinvest $127330
Technical Analysis Robot $126930
Dollar Cost Averager $106130
Fibonacci $69930
Novice Broker $28130
Buy Low $6130
Naive Statistician $6130
Fallacious Gambler $6130
Passive Trader $4980
Half More or Nothing $4920
Monkeys on a Typewriter $66
View graphs of each contestant
Related but the gameplay and winning criterion are very different to this challenge.