Skip to main content
added 106 characters in body
Source Link
fəˈnɛtɪk
  • 4.2k
  • 2
  • 14
  • 40

#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

#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*float(price-prevPrice)/float(price))
            print("s"+str(toSell))
        if(price<prevPrice):
            toBuy=int(((money+1000)/price)*float(prevPrice-price)/float(prevPrice))
            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

#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*int(1000000*(price-prevPrice))/(price))//1000000
            print("s"+str(toSell))
        if(price<prevPrice):
            toBuy=int(((money+1000)//price)*int(1000000*(prevPrice-price))//(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

added 152 characters in body
Source Link
fəˈnɛtɪk
  • 4.2k
  • 2
  • 14
  • 40

#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*float(price-prevPrice)/float(price))
            print("s"+str(toSell))
        if(price<prevPrice):
            toBuy=int(((money+1000)/price)*float(prevPrice-price)/float(prevPrice))
            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 sellsbuys 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

#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:
    with open("percentageTrader.dat","r") as f:
        prevPrice=int(f.read())
    if(price>prevPrice):
        toSell=int(held*float(price-prevPrice)/float(price))
        print("s"+str(toSell))
    if(price<prevPrice):
        toBuy=int(((money+1000)/price)*float(prevPrice-price)/float(prevPrice))
        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 sells a percentage of shares equal to the percentage decrease in price(calculated from previous value)

#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*float(price-prevPrice)/float(price))
            print("s"+str(toSell))
        if(price<prevPrice):
            toBuy=int(((money+1000)/price)*float(prevPrice-price)/float(prevPrice))
            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
Source Link
fəˈnɛtɪk
  • 4.2k
  • 2
  • 14
  • 40

#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:
    with open("percentageTrader.dat","r") as f:
        prevPrice=int(f.read())
    if(price>prevPrice):
        toSell=int(held*float(price-prevPrice)/float(price))
        print("s"+str(toSell))
    if(price<prevPrice):
        toBuy=int(((money+1000)/price)*float(prevPrice-price)/float(prevPrice))
        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 sells a percentage of shares equal to the percentage decrease in price(calculated from previous value)