Background
You are all traders for a slightly less than reputable stock firm. You all are part of a group of traders who focus only on one specific stock.
Each hour each trader has a chance to Buy X stocks or Sell X stocks. There are 50 hours per round and 3 rounds per competition. At the end of all of the rounds the trader with the highest average value wins a trip to Jamaica!
Gameplay
There are 3 rounds of 50 turns each.
Each trader begins the round with $5000 and A random number of shares between 20 and 30 shares. The price of the shares starts at a random number between 10 and 150.
Each turn each trader can Buy any number of shares they can afford or Sell any number of shares they currently hold, each for the current price per share.
The price per share increases by a random number between 1 and 5 for each share bought and decreases by a random value between 2 and 6 for each share sold. The minimum price is $1.
It is important to note that all traders process their transactions at the same time, meaning that any trader buying/selling shares will not affect the price until the next turn.
The player with the highest average value at the end of the 3 rounds wins. Value is determined by taking the amount of money left over at the end of the round and adding the number of shares owned by the trader * closing market price.
Arguments
Your program will be rerun at the start of each turn receiving the current market price, the trader's current amount of money and the number of shares owned by that trader.
Ex:
120 5000 0
Output
Your trader program must output a letter corresponding to the action it would like to take followed by the quantity.
Ex:
B10 //Buy 10 shares
or
S3 //Sell 3 shares
The trader also has the option to not do anything that turn. That can be accomplished by outputting a W or any other command that is not 'B>amnt<' or 'S>amnt<'
Submissions
Your program will be inside a 'players/>your program name<' directory:
+-- players
| +-- BotNameFolder
| +-- BotProgram
Please provide your code along with a command line argument to run it from inside the 'players' directory.
For example the Test1 trader could be run with java -cp "Test1" Test1
Additional Rules
Go ahead, shoot yourself EmoWolf, Idc.
No messing with anything outside of your BotNameFolder directory, feel free to create files in there though for persistent info throughout rounds / turns.
Do not intentionally create programs to crash the simulation.
I will accept multiple entries per user, as long as the entries act as seperate entities (No insider trading).
Leaderboard
[java&-cp&"TestPlayer"&Test1]:$10027395221
[python&daydreamer/daydreamer.py]:$5000
[java&-cp&"DayTrader"&DayTrader]:$4713199930331196453
I will try to update the leaderboard at least once a day
Controller
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
public class Controller {
public static BigInteger marketValue = BigInteger.valueOf(100);
public static BigInteger newValue = BigInteger.valueOf(100);
public static final char BUY = 'B';
public static final char SELL = 'S';
public static final int MARKET_INDEX = 1;
public static final int MONEY_INDEX = 2;
public static final int SHARE_INDEX = 3;
public static int numRunning = 0;
public static final int MAX_RUNNING = 10;
public static void main(String[] args){
try {
BufferedReader br1 = new BufferedReader(new InputStreamReader(new FileInputStream("resources/config")));
int numRounds = Integer.parseInt(br1.readLine());
int turnsPerRound = Integer.parseInt(br1.readLine());
//Create the array of players
List<String> players = new LinkedList<String>();
String line1 = null;
while((line1 = br1.readLine()) != null){
players.add(line1);
}
BigInteger[] totalVals = new BigInteger[players.size()];
for(int i = 0; i < totalVals.length; i++){
totalVals[i] = BigInteger.valueOf(0);
}
br1.close();
//Begin processing
for(int round = 0; round < numRounds; round++){
//Create players' shares and currency array
Map<String,BigInteger[]> vals = new HashMap<String, BigInteger[]>();
for(int i = 0; i < players.size(); i++){
vals.put(players.get(i), new BigInteger[]{BigInteger.valueOf(5000), BigInteger.valueOf(getRandInt(20,30))});
}
marketValue = BigInteger.valueOf(getRandInt(10,150));
newValue = marketValue;
for(int turn = 0; turn < turnsPerRound; turn++){
marketValue = newValue;
Queue<Object[]> processQueue = new LinkedList<Object[]>();
for(String playerKey : vals.keySet()){
BigInteger[] valSet = vals.get(playerKey);
String[] pkParts = playerKey.split("&");
String[] parts = new String[pkParts.length + 3];
for(int i = 0; i < pkParts.length; i++){
parts[i] = pkParts[i];
}
parts[pkParts.length] = marketValue + "";
parts[pkParts.length + 1] = valSet[0] + "";
parts[pkParts.length + 2] = valSet[1] + "";
processQueue.add(new Object[]{playerKey, parts});
}
while(!processQueue.isEmpty() || numRunning > 0){
if(numRunning < MAX_RUNNING && !processQueue.isEmpty()){
numRunning++;
Object[] o = processQueue.poll();
String pKey = (String)(o[0]);
String[] p = (String[])(o[1]);
try {
Process proc = new ProcessBuilder(p).directory(new File("resources/players").getAbsoluteFile()).start();
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = br.readLine();
br.close();
switch(line.charAt(0)){
case BUY :
BigInteger numShares = new BigInteger(line.substring(1).trim());
if(numShares.multiply(marketValue).compareTo(vals.get(pKey)[0]) <= 0){
BigInteger[] tempVals = vals.get(pKey);
tempVals[0] = tempVals[0].subtract(numShares.multiply(marketValue));
tempVals[1] = tempVals[1].add(numShares);
vals.put(pKey, tempVals);
newValue = newValue.add(numShares.multiply(BigInteger.valueOf(getRandInt(0,2))));
if(newValue.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) >= 1){
newValue = BigInteger.valueOf(Integer.MAX_VALUE - 1);
}
}
break;
case SELL:
BigInteger shares = new BigInteger(line.substring(1).trim());
if(shares.compareTo(vals.get(pKey)[1]) <= 0){
BigInteger[] tempVals = vals.get(pKey);
tempVals[0] = tempVals[0].add(shares.multiply(marketValue));
tempVals[1] = tempVals[1].subtract(shares);
vals.put(pKey, tempVals);
newValue = newValue.subtract(shares.multiply(BigInteger.valueOf(getRandInt(5,10))));
if(newValue.compareTo(BigInteger.valueOf(1)) <= -1){
newValue = BigInteger.valueOf(1);
}
}
break;
}
} catch (Exception e) {
System.err.println("[" + pKey + "] threw error:");
e.printStackTrace();
} finally{
numRunning--;
}
}else{
try{
Thread.sleep(50);
continue;
}catch(InterruptedException e){
continue;
}
}
}
System.out.println("Turn " + turn + " over: " + marketValue);
}
System.out.println("End of round market value is: " + marketValue);
int count = 0;
for(String player : vals.keySet()){
totalVals[count] = totalVals[count].add(vals.get(player)[0].add(vals.get(player)[1].multiply(marketValue)));
count++;
}
newValue = BigInteger.valueOf(100);
}
for(int i = 0; i < players.size(); i++){
System.out.println("[" + players.get(i) + "]:$" + (totalVals[i].divide(BigInteger.valueOf(numRounds))));
}
} catch (Exception e) {
System.err.println("An exception occured while running the controller.");
e.printStackTrace();
}
}
public static Random r = new Random(new Date().getTime());
public static int getRandInt(int min, int max){
return r.nextInt(max - min) + min;
}
}
Compile this with java Controller.java
and run from a directory containing a directory like below:
+-- resources
| +-- config
| +-- players
| +-- Player1Folder
| +-- Player1Program
| +-- Player2Folder
| +-- Player2Program
The file config
should look something like this:
3
50
java&-cp&"TestPlayer"&Test1
python&daydreamer/daydreamer.py
java&-cp&"DayTrader"&DayTrader
First number is number of rounds, second number is turns per round, followed by the commands to run each player.
Replace spaces with ampersands! ('&')
~Let me know if I can improve the wording of this post at all, and happy trading!