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 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 decimal number of shares.
After 5 rounds, at the end of each round, all players will 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.
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
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
Will be added after the first game
Related but the gameplay and winning criterion are very different to this challenge.