本文整理汇总了Python中mewp.simulate.runner.PairRunner类的典型用法代码示例。如果您正苦于以下问题:Python PairRunner类的具体用法?Python PairRunner怎么用?Python PairRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PairRunner类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: back_test
def back_test(pair, date, param):
algo = { 'class': StopWinAlgo }
algo['param'] = {'x': pair[0],
'y': pair[1],
'a': 1,
'b': 0,
'rolling': param[0],
'alpha': -1,
'bollinger': param[1],
'stop_win': param[2],
'block': 100,
'if_stop_win': True,
'if_ema': False,
'if_consider_spread': True,
}
settings = { 'date': date,
'path': DATA_PATH,
'tickset': 'top',
'algo': algo}
runner = PairRunner(settings)
runner.run()
account = runner.account
history = account.history.to_dataframe(account.items)
score = float(history[['pnl']].iloc[-1])
return score
示例2: back_test
def back_test(pair, date, param):
tracker = TradeAnalysis(Contract(pair[0]))
algo = { 'class': ConstantAlgo }
algo['param'] = {'x': pair[0],
'y': pair[1],
'a': 1,
'b': 0,
'rolling': param[0],
'bollinger': param[1],
'const': param[2],
'block': 100,
'tracker': tracker
}
settings = { 'date': date,
'path': DATA_PATH,
'tickset': 'top',
'algo': algo,
'singletick': True}
runner = PairRunner(settings)
runner.run()
account = runner.account
history = account.history.to_dataframe(account.items)
score = float(history[['pnl']].iloc[-1])
order_win = tracker.order_winning_ratio()
order_profit = tracker.analyze_all_profit()[0]
num_rounds = tracker.analyze_all_profit()[2]
return score, order_win, order_profit, num_rounds, runner
示例3: run_simulation
def run_simulation(param, date_list):
algo = { 'class': ConstStopWinGuardAlgo }
algo['param'] = {'x': 'ni1609',
'y': 'ni1701',
'a': 1,
'b': 0,
'rolling': param[0],
'bollinger': 2,
'const': param[1],
'stop_win':param[2],
'block': 100,
'tracker': None
}
settings = { 'date': date_list,
'path': DATA_PATH,
'tickset': 'top',
'algo': algo,
'singletick': False}
settings['exe'] = PairExePlusTick(2)
runner = PairRunner(settings)
runner.run()
report = Report(runner)
temp = report.get_daily_pnl()
pnl_list = list(temp.daily_pnl)
return pnl_list
示例4: back_test
def back_test(pair, date, param, tracker):
algo = {"class": StopWinSpreadGuardAlgo}
algo["param"] = {
"x": pair[0],
"y": pair[1],
"a": 1,
"b": 0,
"rolling": param[0],
"bollinger": param[1],
"stop_win": param[2],
"block": 100,
"tracker": tracker,
}
settings = {"date": date, "path": DATA_PATH, "tickset": "top", "algo": algo, "singletick": True}
runner = PairRunner(settings)
runner.run()
return runner, algo
示例5: back_test
def back_test(pair, date):
algo = { 'class': TestAlgo }
algo['param'] = {'x': pair[0],
'y': pair[1],
'a': 1,
'b': 0,
'rolling': 4000,
'sd_coef': 3,
'block': 100,
}
settings = { 'date': date,
'path': DATA_PATH,
'tickset': 'top',
'algo': algo}
runner = PairRunner(settings)
runner.run()
return runner
示例6: back_test
def back_test(pair, date, param, tracker):
algo = { 'class': SpreadGuardAlgo }
algo['param'] = {'x': pair[0],
'y': pair[1],
'a': 1,
'b': 0,
'rolling': param[0],
'bollinger': param[1],
'block': 100,
'tracker': tracker,
}
settings = { 'date': date,
'path': DATA_PATH,
'tickset': 'top',
'algo': algo,
'singletick': True}
runner = PairRunner(settings)
runner.run()
return runner, algo
示例7: run_based_on_pre
def run_based_on_pre(date_list):
temp = best_param(date_list[:-1])
algo = { 'class': TestAlgo }
algo['param'] = {'x': pair[0],
'y': pair[1],
'a': 1,
'b': 0,
'rolling': float(temp.rolling),
'sd_coef': float(temp.sd_coef),
'block': 100}
settings = { 'date': date_list[-1],
'path': DATA_PATH,
'tickset': 'top',
'algo': algo}
runner = PairRunner(settings)
runner.run()
account = runner.account
orders = account.orders.to_dataframe()
history = account.history.to_dataframe(account.items)
return float(history.pnl.tail(1)), len(orders)
示例8: back_test
def back_test(pair, date, param):
algo = {"class": StopWinAlgo}
algo["param"] = {
"x": pair[0],
"y": pair[1],
"a": 1,
"b": 0,
"rolling": param[0],
"alpha": -1,
"bollinger": param[1],
"stop_win": param[2],
"block": 100,
"if_stop_win": True,
"if_ema": False,
"if_consider_spread": True,
}
settings = {"date": date, "path": DATA_PATH, "tickset": "top", "algo": algo}
runner = PairRunner(settings)
runner.run()
return runner
示例9: back_test
def back_test(pair, date, param):
algo = { 'class': TestAlgo }
algo['param'] = {'x': pair[0],
'y': pair[1],
'a': 1,
'b': 0,
'rolling': param[0],
'sd_coef': param[1],
'block': 100,
}
settings = { 'date': date,
'path': DATA_PATH,
'tickset': 'top',
'algo': algo}
runner = PairRunner(settings)
runner.run()
account = runner.account
history = account.history.to_dataframe(account.items)
orders = account.orders.to_dataframe()
pnl = np.asarray(history.pnl)[-1]
return pnl, len(orders)
示例10: back_test
def back_test(pair, date, param, if_param):
algo = { 'class': StopWinAlgo }
algo['param'] = {'x': pair[0],
'y': pair[1],
'a': 1,
'b': 0,
'rolling': param[0],
'alpha': param[1],
'bollinger': param[2],
'stop_win': param[3],
'block': 100,
'if_stop_win': if_param[0],
'if_ema': if_param[1],
'if_consider_spread': if_param[2],
}
settings = { 'date': date,
'path': DATA_PATH,
'tickset': 'top',
'algo': algo}
runner = PairRunner(settings)
runner.run()
return runner
示例11: back_test
def back_test(pair, date, param):
tracker = TradeAnalysis(Contract(pair[0]))
algo = {"class": OUAlgo}
algo["param"] = {
"x": pair[0],
"y": pair[1],
"a": 1,
"b": 0,
"rolling": param[0],
"bollinger": param[1],
"block": 100,
"tracker": tracker,
}
settings = {"date": date, "path": DATA_PATH, "tickset": "top", "algo": algo, "singletick": True}
runner = PairRunner(settings)
runner.run()
account = runner.account
history = account.history.to_dataframe(account.items)
score = float(history[["pnl"]].iloc[-1])
order_win = tracker.order_winning_ratio()
order_profit = tracker.analyze_all_profit()[0]
num_rounds = tracker.analyze_all_profit()[2]
return score, order_win, order_profit, num_rounds
示例12: PairRunner
date_list = [str(x).split(' ')[0] for x in pd.date_range('2016-03-01','2016-03-31').tolist()]
algo = { 'class': TestAlgo }
algo['param'] = {'x': pair[0],
'y': pair[1],
'a': 1,
'b': 0,
'rolling': 1000,
'rolling_sigma': 1000,
'sd_coef': 3,
'block': 100,
}
settings = { 'date': date_list,
'path': DATA_PATH,
'tickset': 'top',
'algo': algo}
runner = PairRunner(settings)
rolling_list = range(500,5000,500)
rolling_sigma_list = range(500,5000,500)
sd_coef_list = np.arange(1, 5, 0.5)
final_profit = []
for r in rolling_list :
for rs in rolling_sigma_list:
for sd in sd_coef_list :
start_time = time.time()
runner.run(algo_param={'rolling': r,'rolling_sigma': rs, 'sd_coef': sd})
account = runner.account
history = account.history.to_dataframe(account.items)
score = float(history[['pnl']].iloc[-1])
final_profit.append(score)
print("rolling {}, rolling sigma {}, sd_coef {}, backtest took {:.3f}s, score is {:.3f}".format(r, rs, sd, time.time() - start_time, score))
pars = list(itertools.product(rolling_list, rolling_sigma_list, sd_coef_list))
示例13: PairRunner
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',
'algo': algo}
runner = PairRunner(settings)
price_diff = get_price_diff(pair)
price_diff_std = np.nanstd(price_diff)
rolling_list = range(1000,10000,2000)
sd_coef_list = np.arange(2,8)
stop_win_list = price_diff_std * np.arange(0.5, 3.5, 0.5)
final_profit = []
for r in rolling_list :
for sd in sd_coef_list :
for sw in stop_win_list:
start_time = time.time()
runner.run(algo_param={'rolling': r, 'sd_coef': sd, 'stop_win': sw })
account = runner.account
history = account.history.to_dataframe(account.items)
score = float(history[['pnl']].iloc[-1])
final_profit.append(score)
示例14: get_trade_day
pair = ["m1505", "m1509"]
date_list = get_trade_day(pair)
algo = {"class": MyAlgo}
algo["param"] = {
"x": pair[0],
"y": pair[1],
"a": 1,
"b": 0,
"rolling": 4000,
"rolling_sigma": 4000,
"sd_coef": 3,
"block": 100,
"stop_win": 200,
}
settings = {"date": date_list, "path": DATA_PATH, "tickset": "top", "algo": algo}
runner = PairRunner(settings)
price_diff = get_price_diff(pair)
price_diff_std = np.nanstd(price_diff)
rolling_list = range(1000, 10000, 2000)
rolling_sigma_list = range(1000, 10000, 2000)
sd_coef_list = np.arange(2, 8)
stop_win_list = price_diff_std * np.arange(0.3, 3, 0.3)
final_profit = []
for r in rolling_list:
for rs in rolling_sigma_list:
for sd in sd_coef_list:
for sw in stop_win_list:
start_time = time.time()
runner.run(algo_param={"rolling": r, "rolling_sigma": rs, "sd_coef": sd, "stop_win": sw})
account = runner.account
history = account.history.to_dataframe(account.items)