#Percentage Trader Python3 (maybe works in python2)
import sys
args=sys.argv
price=int(args[1])
held=int(args[2])
money=int(args[3])
roundNum=int(args[4])
prevPrice=0
if roundNum==1:
print("b"+str((money+1000)//price))
else:
if roundNum==1000:
print("s"+str(held))
else:
with open("percentageTrader.dat","r") as f:
prevPrice=int(f.read())
if(price>prevPrice):
toSell=int(held*floatheld*int(1000000*(price-prevPrice))/float(price))//1000000
print("s"+str(toSell))
if(price<prevPrice):
toBuy=int(((money+1000)//price)*float*int(1000000*(prevPrice-price))/float/(prevPrice))//1000000
print("b"+str(toBuy))
if(price==prevPrice):
print("b0")
with open("percentageTrader.dat","w") as f:
f.write(str(price))
###Instructions on running
- Save as filename.py
- Run with python filename.py price #shares balance round#
###How it works
- First round the bot purchases as many shares as it can afford.
- If the price increases, the bot sells a percentage of shares equal to the percentage increase in price(calculated from new value)
- If the price decreases, the bot buys a percentage of the maximum shares it could buy equal to the percentage decrease in price(calculated from previous value)
- Sells off everything at round 1000
Changes should hopefully remove the problems caused by floating point division