def run_simulation(param, date_list, product): pnl_list = [] order_win_list = [] order_profit_list = [] num_rounds_list = [] master = MasterReport() for date in date_list: date_pair = get_best_pair(date, market, product) if type(date_pair) != tuple: continue else: result = back_test(date_pair, date, param) pnl_list.append(result[0]) order_win_list.append(result[1]) order_profit_list.append(result[2]) num_rounds_list.append(result[3]) runner = result[4] try: report = Report(runner) except IndexError: print 'WTF? {} has IndexError'.format(date) continue report.print_report(to_file=False, to_screen=False, to_master=master) return pnl_list, order_win_list, order_profit_list, num_rounds_list, master
def run_simulation(param, date_list): total_pnl = 0 total_order = 0 for date in date_list: date_pair = get_best_pair(date,'ic') if type(date_pair) != tuple: continue else: tpnl, torder = back_test(date_pair, date, param) total_pnl += tpnl total_order += torder return total_pnl, total_order
def run_simulation(param, date_list): total_pnl = 0 total_order = 0 for date in date_list: date_pair = get_best_pair(date,'if') if type(date_pair) != tuple: continue else: tpnl, torder = back_test(date_pair, date, param) total_pnl += tpnl total_order += torder return total_pnl, total_order
def run_simulation(param, date_list, product): pnl_list = [] order_win_list = [] order_profit_list = [] num_rounds_list = [] master = MasterReport() for date in date_list: date_pair = get_best_pair(date,market, product) if type(date_pair) != tuple: continue else: result = back_test(date_pair, date, param) pnl_list.append(result[0]) order_win_list.append(result[1]) order_profit_list.append(result[2]) num_rounds_list.append(result[3]) runner = result[4] try: report = Report(runner) except IndexError: print 'WTF? {} has IndexError'.format(date) continue report.print_report(to_file=False, to_screen=False, to_master=master) return pnl_list, order_win_list, order_profit_list, num_rounds_list, master
print 'WTF? {} has IndexError'.format(date) continue report.print_report(to_file=False, to_screen=False, to_master=master) return pnl_list, order_win_list, order_profit_list, num_rounds_list, master date_list = [str(x).split(' ')[0] for x in pd.date_range('2015-01-01','2016-03-31').tolist()] roll_list = np.concatenate((np.arange(200,500,100), np.arange(500, 3500, 500),[5000, 8000])) #11 params sd_list = np.concatenate((np.arange(0, 2.1, 0.25),[3,4,5]))#11 params spread_list = np.concatenate((np.arange(0, 2.1, 0.25),[3,4,5]))#11 params pars = list(itertools.product(roll_list, sd_list, spread_list)) num_cores = 20 product = 'pb' trade_day_list = [] for date in date_list: date_pair = get_best_pair(date, market, product) if type(date_pair) != tuple: continue else: trade_day_list.append(date) results = Parallel(n_jobs=num_cores)(delayed(run_simulation)(param,\ date_list, product) for param in pars) keys = ['roll:{}_sd:{}_spreadcoef:{}'.format(*p) for p in pars] pnl = [i[0] for i in results] order_win = [i[1] for i in results] order_profit = [i[2] for i in results] num_rounds = [i[3] for i in results] master = [i[4] for i in results] pnl_dict = dict(zip(keys, pnl)) pnl_result = pd.DataFrame(pnl_dict)
date_list = [ str(x).split(' ')[0] for x in pd.date_range('2015-01-01', '2016-03-31').tolist() ] roll_list = np.concatenate( (np.arange(200, 500, 100), np.arange(500, 3500, 500), [5000, 8000])) #11 params sd_list = np.concatenate((np.arange(0, 2.1, 0.25), [3, 4, 5])) #11 params spread_list = np.concatenate((np.arange(0, 2.1, 0.25), [3, 4, 5])) #11 params pars = list(itertools.product(roll_list, sd_list, spread_list)) num_cores = 20 product = 'pb' trade_day_list = [] for date in date_list: date_pair = get_best_pair(date, market, product) if type(date_pair) != tuple: continue else: trade_day_list.append(date) results = Parallel(n_jobs=num_cores)(delayed(run_simulation)(param,\ date_list, product) for param in pars) keys = ['roll:{}_sd:{}_spreadcoef:{}'.format(*p) for p in pars] pnl = [i[0] for i in results] order_win = [i[1] for i in results] order_profit = [i[2] for i in results] num_rounds = [i[3] for i in results] master = [i[4] for i in results] pnl_dict = dict(zip(keys, pnl)) pnl_result = pd.DataFrame(pnl_dict)
} settings = { 'date': date, 'path': DATA_PATH, 'tickset': 'top', 'algo': algo} runner = PairRunner(settings) runner.run() account = runner.account return account date_list = [str(x).split(' ')[0] for x in pd.date_range('2015-05-01','2016-03-31').tolist()] result = {} account_history = {} pnl = np.zeros(1) for date in date_list: date_pair = get_best_pair(date,'ic') if type(date_pair) != tuple: continue else: pair = date_pair pre = pair account = back_test(pair,date) history = account.history.to_dataframe(account.items) temp = np.asarray(history.pnl) pnl = np.concatenate([pnl,pnl[-1] + temp]) account_history[date] = account result[date] = temp[-1] print 'final result' print pnl[-1] pickle.dump(pnl, open( "/work/rqiao/backtest_result/ic_pnl.p", "wb" )) pickle.dump(result, open( "/work/rqiao/backtest_result/ic_result.p", "wb" ))