Realistic Stock Market
This is based off of this other challenge, but with a whole lot of added realism. I'm trying to add as much realism as possible. It is a king-of-the-hill challenge.
You are an entrepreneur in the stock market, having created your own hedge fund (correct term?). Your company buys and sells shares in other companies, but also sells shares in itself.
At the very end of the game, the money is redistributed: All the money you've earned* is split up amongst your shareholders. Likewise, you gain money from the companies in which you've invested. By selling shares in yourself, there is a trade-off between long- and short-term gains.
There is a finite amount of each stock in the game, and there is one type of stock per company (so one per entrant). Your bot will start out with
100 shares of each other company, along with
100*N shares of itself, where
N is the number of entrants. Each bot will have an initial bankroll of
10000 * N. (This helps to ensure a sufficiently large initial stock price).
Buying and Selling
Buying and selling stock is done by placing buy and sell orders. Each time a buy/sell order is placed, it is matched with the existing buy/sells orders to complete the trade.
Here is an example of how the orders are matched with each other for one stock:
19 @ $20 - Bot A
11 @ $21 - Bot B
06 @ $19 - Bot S #oldest is given preference
06 @ $19 - Bot Q
13 @ $18 - Bot T
22 @ $16 - Bot R
Sell 26 @ $17 - Bot C
Trades [06 @ $19 - Bot S] with a surplus of 20
Trades [06 @ $19 - Bot Q] with a surplus of 14
Trades [13 @ $18 - Bot T] with a surplus of 01
No more matches
01 @ $17 - Bot C #the remainder of the sell order
19 @ $20 - Bot A
11 @ $21 - Bot B
22 @ $16 - Bot R
In this particular example, Bot C will manage to sell 26 shares for
12*19+13*18+1*17 = $479, assuming that someone will eventually buy that one remaining share. The bot receives $462 at the end of his turn, and would receive the $17 at the end of the buyer's turn. If the share is not bought in the time between one turn and the next, the bot would receive that remaining share back.
The Tournament Setup
The tournament will be composed of 10 games, with each game consisting of 365 trading rounds. Each trading round will consist of one turn for each bot, with the bots in a randomized order.
There is nothing special that happens between any particular round. This helps to smooth out game flow so that each bot will have equal opportunity on their turn.
At the end of each game, the money of each competitor is redistributed to its stock holders (how much of the money?).
The winner of the tournament will be the bot with the highest average amount of money at the end of each game.
A Single Turn
For each stock, the bot will receive the buy and sell orders available.
At the start of every bot's turn, that bot's previous unfulfilled sell/buy orders will be canceled. (Is this a good idea?). Any unsold stock or unspent money is returned to the player.
Then, the bot will output the list of buy/sell orders it would like to place. The bot will be able to place one buy/sell order per stock. The bot must be able to immediately set aside the shares/money to support the order.
The controller program will look through your sell and buy orders sequentially and will remove the assets from you that are required for the transaction. If you have insufficient funds, that order will be ignored completely.
Then, the orders will be processed. Orders that match the already-existing orders will allow the transaction to occur after the bot's turn. Orders that are unmatched will remain on the market until the start of the bot's next turn.
Recording the past
Your bot is allow to create 1 text file to maintain a history of stock prices.
Input will consist of 3 arguments in this order:
Current round number, which is a number 1-365
Which stock ticker is for your company
A list of the data for each stock
The data for the stocks will be formatted like this:
"[stock ticker #1],[quantity 1],[price 1],[quantity 2],[price 2] [stock ticker #2],[quantity 1],[price 1],[quantity 2],[price 2]"
Each quantity/price pair represents one buy or sell order. Sell orders have positive quantity, while buy orders have negative quantity.
The order of the stocks will be randomized, but the stock tickers will remain consistent for the whole game.
(I was also think of including some more data in here, what else might be needed? Data on the assets of all the other competitors?)
Output will consist of many lines, each line formatted like so:
[stock number 1-N] [action] [quantity] [price]
The stock number is a number 1-N representing which stock to buy or sell. The action can be either
b for buy or
s for sell. The quantity and price can be any positive integer.
I want price to have 2 decimal digits, but I don't know if that would exclude anything or make it unnecessarily complicated. Right now, the prices are limited to integers. There is approximately $50 for each stock in the game, in an attempt to increase smoothness.
We need to balance the number of actions allowed per turn with the number of rounds in a game. Right now, the player can make 1 order per stock in a single round, which may make the time flow too roughly. The more rounds played, and the fewer actions allowed per turn, the smoother the game will be.
*We need to determine exactly how the money is redistributed. I initially had the idea that all the money will be redistributed equally to each stock, so a player who sells all the shares in himself keeps none of the money he earned in game and only gets the money from the other stocks. I think it might make more sense to only distribute profits, but we would have to determine how much of the profits are redistributed to shareholders.
Is it a good idea to have orders cancel after a period of time? Currently, a bot's orders are cancelled upon that bot's next turn. If we reduce the number of moves per turn, then we would want to increase the longevity of the orders. Alternatively, we could make orders permanent and irrevocable, only being cancelled at the end of the game.