# short when test short_res > roll.mean+sd_coef*roll.sd elif self.short_roll.test_sigma(short_res, self.sd_coef): # only short when position is 0 or 1 if pos >= 0: self.short_y(y_qty=1) self.last_short_res = short_res else: pass # update rolling self.long_roll.add(long_res) self.short_roll.add(short_res) pair = ['a1505', 'a1509'] date_list = get_trade_day(pair) algo = {'class': TestAlgo} algo['param'] = { 'x': pair[0], 'y': pair[1], 'a': 1, 'b': 0, 'rolling': 4000, 'sd_coef': 3, 'block': 100, 'stop_win': 200, } settings = { 'date': date_list, 'path': DATA_PATH, 'tickset': 'top',
# short when test short_res > roll.mean+sd_coef*roll.sd elif self.short_roll.test_sigma(short_res, self.sd_coef): # only short when position is 0 or 1 if pos >= 0: self.short_y(y_qty=1) else: pass # update rolling self.long_roll.add(long_res) self.short_roll.add(short_res) pair = ['a1505', 'a1509'] sd_coef = np.arange(2.0, 6.1, 0.5) rolling = np.arange(1000, 9000, 1000) Date_list = get_trade_day(pair) pars = list(itertools.product(rolling, sd_coef)) def run_simulation(p,runner): runner.run(algo_param={'alpha': p[0], 'stop_win': p[1]}) account = runner.account orders = account.orders.to_dataframe() history = account.history.to_dataframe(account.items) return float(history.pnl.tail(1)), len(orders) def best_param(date_list): score = [] num_trades = [] algo = { 'class': TestAlgo } algo['param'] = {'x': pair[0], 'y': pair[1],