Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1.  
  2. if int(optSwitch) == 0:
  3. opt = n
  4. elif int(optSwitch) == 1:
  5. #from scipy.optimize import brute
  6. #if iOpt == 1: #Optimize returns
  7. from scipy.optimize import brute
  8. # The following fix has been introduced because brute is not accounting for the value n_max when optimizing
  9. n_max_new = n_max + n_incr
  10. opt = brute(returns_in_Fxn, ((n_min, n_max_new, n_incr),), finish=None)
  11.  
  12.  
  13. #opt = brute(returns_in_Fxn, ((n_min, n_max, n_incr),), finish=None)
  14. #opt = brute(returns_in_Fxn, ((n_min, n_max, n_incr),), full_output=True, finish=None)
  15. # The following fix has been introduced because brute is not accounting for the value n_max when optimizing
  16. #n_max_new = n_max + n_incr
  17. #opt = brute(returns_in_Fxn, ((n_min, n_max, n_incr),), full_output=True, finish=None)
  18. import xlwt
  19.  
  20.  
  21.  
  22. wb = xlwt.Workbook()
  23. ws = wb.add_sheet('A Opt Sheet')
  24. ws.write(0,0,'optSwitch')
  25. ws.write(0,1, optSwitch)
  26. ws.write(1,0,'n_min')
  27. ws.write(1,1, n_min)
  28. ws.write(2,0,'n_max')
  29. ws.write(2,1, n_max)
  30. ws.write(3,0,'n_incr')
  31. ws.write(3,1, n_incr)
  32.  
  33.  
  34.  
  35. #ws.write(4,0,'opt')
  36. #row = 5
  37. #for col, data in enumerate(opt):
  38. # ws.write(row, col, data)
  39. #ws.write(4,1, opt)
  40. #n_min = df_param.ix['n']['Min']
  41. #n_max = df_param.ix['n']['Max']
  42. #n_incr = df_param.ix['n']['increment']
  43. wb.save('/var/www/html/finpoc/public/xlsx/exampleOpt_'+fn_append+'.xls')
  44. #elif iOpt == 2: #Optimize PnL
  45. # opt = brute
  46.  
  47.  
  48.  
  49.  
  50.  
  51. sys.stderr.write("======================= DEBUG ===================")
  52. sys.stdout = sys.stderr
  53. pprint(MA_array)
  54.  
  55.  
  56. return_vals = {"in": returns_in_Fxn_1(opt, True), "all": returns_all_Fxn((opt), True), "out": returns_out_Fxn((opt), True), "back_test": 1, "optimization_n": opt}
  57.  
  58.  
  59. return return_vals
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement