Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. def pnl_classic(model_infos):
  2.  
  3. BUY_COL = 4
  4. SELL_COL = 5
  5.  
  6. filename = model_infos[0]
  7. period = model_infos[1]
  8. ohlcbs = model_infos[2]
  9. signals = model_infos[3]
  10. calc_dd = model_infos[4]
  11.  
  12.  
  13. #print(len(ohlcbs),len(signals))
  14. #exit()
  15. #print(ohlcbs)
  16.  
  17. trades = 0
  18. pnl = 0
  19. max_dd_percent = 0
  20.  
  21. dt_pnl = []
  22.  
  23. for r in range(1,len(ohlcbs),1): # signal on line N has to be traded on line N+1, thus no PnL on line 0
  24. signal = signals[r-1] # TODO: Are the signals themselves rigth? Check it out at some point!
  25. dpips = 0 # It's really importtant to get this one nulled for rows that have 0 signal
  26. if ( signal != 0): # it was a valid signal and we execute it
  27. trades += 1
  28. if (signal>0):
  29. dpips = ohlcbs[r][BUY_COL]
  30. else:
  31. dpips = ohlcbs[r][SELL_COL]
  32. pnl += dpips # dpips was nulled, so it's OK to add it
  33.  
  34. # DEBUG - TEST THIS NEXT TODO!
  35. #if (filename=="54_16055-19155_3000_0.9_USDCAD_240 1075_export1.csv" and period ==8):
  36. # # maybe add DATE/time for the signals and prices columns to make sure we can see precisely the right rows
  37. # print("DEBUG:", ohlcbs[r][0],ohlcbs[r][1],ohlcbs[r][2],ohlcbs[r][3], ohlcbs[r][4], ohlcbs[r][5], signals[r], dpips, pnl )
  38.  
  39.  
  40. dt_pnl.append(pnl)
  41.  
  42. if (calc_dd == True):
  43. max_dd_percent = drawdowns(np.array(dt_pnl))
  44. else:
  45. max_dd_percent = 0 # initially we don't use that fot the sake of CPU resources
  46.  
  47. if pnl > 0:
  48. #print(filename, period, trades, pnl, max_dd_percent)
  49. return [ filename, period, trades, pnl, max_dd_percent ]
  50. else:
  51. return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement