[BUG BOUNTY 2] 10 Steem Reward - Debug my Python Code!steemCreated with Sketch.

in #programming7 years ago (edited)


py.png


I have continued my work and research on my trading indicator, but as the code get's more complex the probability of some bug appearing is likely, and I dont have time to simulate every variable, so I just thought if some people would help me verify my code, then together we can find the bugs and fix them. I am offering 10 Steem Reward for anyone who helps me debug my code.


So this is the new code, partial credit to @hendrikcrause for helping me rewrite the code. It's in Python 3.5+


The code is simple, I have a proprietary indicator, that I'll keep secret for now, and this is the trading simulator code for this indicator, to sort of "backtest" the indicator on historical data, obtained via the Poloniex API, in JSON format. In this example we have "moneroday" which is a JSON formatted file containing the daily historica data of XMR/BTC.

The code loads in the JSON data, processes it, by putting the Close price and the Volume column into their own separate arrays. Then the simulate_trade() script runs which basically calculates the indicator, buys when the indicator is > than the TRIGGER, and closes the trade when it's <= than the TRIGGER. Then the profits, the duration of the trade and the number of trades is calculated.

Then we run through an interator function that loops through all values of the TRIGGER variable. The profit, the number of trades, and the average duration time is then printed out to the screen. So we will know at what trigger point we have the biggest profit basically.

This is the full code (note that the profitindicator is replaced with a dummy, since I won't reveal the real one):


import math
import datetime
import json
import statistics

def PROFITINDICATORv2(price):  ## dummy
 return 0


#-----------------------load data-----------------------------------------------

a = datetime.datetime.now()

with open('moneroday') as data_file:
    data = json.load(data_file)

close     = [item['close'] for item in data]
btcvolume = [item['volume'] for item in data]
total     = len(close)

#-----------------------trade simulator-----------------------------------------------

def simulate_trade():
 opentrade   =False
 buyprice    =0.0
 profit      =0.0
 avg_duration=0.0
 trades      =0
 duration    =0
 buy_time    =0

 for current_time in range(2,total-1):
     current_price  = close    [current_time-1]
     current_volume = btcvolume[current_time-1]
    
     priceset  =  close    [0:current_time]
     #volumeset =  btcvolume[0:current_time]
     indicator = PROFITINDICATORv2(priceset)

     if(not opentrade and indicator > TRIGGER):
      # print(indicator)
        buyprice = current_price
        buy_time = current_time
        opentrade = True 

     if((opentrade and indicator <= TRIGGER) or current_time==total):
        profit   += (current_price - buyprice)
        duration += (current_time  - buy_time)
        trades   += 1
        opentrade = False

 if(trades!=0):
  avg_duration=duration/trades

 return profit,trades,avg_duration

#-----------------------iterator-----------------------------------------------

def frange(x, y, jump):
  while x < y:
    yield x
    x += jump

print("Trigger | Profit | Trades | Avg Duration")

for TRIGGER in frange (1,5,0.01):
 output=simulate_trade()
 print(str('{0:.2f}'.format(TRIGGER))+"  |  "+str('{0:.4f}'.format(output[0]))+"  |  "+str(output[1])+"  |  "+str('{0:.4f}'.format(output[2])))


#-----------------------end-----------------------------------------------

b = datetime.datetime.now()
print("Time Elapsed: "  +str(b-a))




Sort:  

I upvoted & resteemed your post and also followed you :)

Coin Marketplace

STEEM 0.20
TRX 0.12
JST 0.028
BTC 64268.35
ETH 3499.18
USDT 1.00
SBD 2.51