def run_strategy(start_date, end_date): try: changeConfig(start_date, end_date, config) run_file(strategy_file_path, config) pass except Exception as e: pass return "Done!"
def run_backtrace(self, config, strategy_file_path): self._config = config for contract in self._valify_list: self._init_contract(contract) self.update_config(contract) print("strategy_params: %s" % str(self._config)) res = run_file(strategy_file_path, self._config) self.parse_backtrace_trade_log(backtrace_filter) self.parse_ctplive_trade_log(ctplive_filter) self.valify()
# s_date = "2016-02-08" s_date = "2017-01-01" e_date = "2018-01-01" # e_date = "2019-01-01" benchmark = "000300.XSHG" strategy_path = "../src/other_po.py" config = { "base": { "start_date": s_date, "end_date": e_date, "benchmark": benchmark, "accounts": { "stock": 50000000 } }, "mod": { "sys_analyser": { "enabled": True, "plot": True }, "sys_simulation": { "slippage": 0.002 } } } run_file(strategy_path, config)
def wapper(): rqalpha.run_file(info['path'], config)
"base": { "start_date": "", "end_date": "", "securities": ['stock'], "stock_starting_cash": 100000, "benchmark": "000001.XSHG" }, "extra": { "log_level": "info", }, "mod": { "sys_analyser": { "enabled": True, "plot": False, "output_file": "", "report_save_path": "", "plot_save_file": "" } } } for scene in SCENES: config['base']['start_date'] = scene['start_date'] config['base']['end_date'] = scene['end_date'] config['mod']['sys_analyser']['output_file'] = './results/' + scene['name'] + '.pkl' config['mod']['sys_analyser']['report_save_path'] = './results/' + scene['name'] config['mod']['sys_analyser']['plot_save_file'] = './results/' + scene['name'] + '.png' if not os.path.exists('./results/' + scene['name']): os.makedirs('./results/' + scene['name']) run_file(STRATEGY_FILE, config)
def run_bt(config): file_path = "C:\\Users\wilsonZhang\PycharmProjects\quant_ml\\rqalpha_backtest\Threat_up_tune_parameter\Threat_up.py" run_file(file_path, config)
if __name__ == "__main__": import os config = { "base": { "start_date": "2016-06-01", "end_date": "2016-06-05", "accounts": { "stock": 100000 }, "frequency": "1m", "benchmark": None, "data_bundle_path": os.path.expanduser("~/.rqalpha/bundle"), "strategy_file": __file__, "run_type": "p" }, "extra": { "log_level": "verbose", }, "mod": { "fxdayu_source": { "enabled": True, "source": "quantos", "enable_cache": False, }, "shipane_wrapper": { "enabled": True } } } run_file(__file__, config=config)
def run_bt(config): file_path = "C:\\Users\wilsonZhang\PycharmProjects\quant_ml\\rqalpha_backtest\Tune_parameter\Golden_cross.py" run_file(file_path, config)
"benchmark": sl[0], "accounts": { "stock": 200000 } }, "mod": { "sys_simulation": { "enabled": True, "signal": True, }, "sys_analyser": { "enabled": True, "plot": True, } } } str_format = lambda val: ('%.3f' % val).ljust(5) strategy_file_path = "./mg_enhance_value.py" result_dict = run_file(strategy_file_path, config) summary = (result_dict['sys_analyser'])['summary'] logger.info( "Result: alpha {}, beta {}, sharpe {}, information_ratio {}, total_returns {}" .format(str_format(summary['alpha']), str_format(summary['beta']), str_format(summary['sharpe']), str_format(summary['information_ratio']), str_format(summary['total_returns'])))
def run_strategy(strategy_file_path="hedge_rq.py"): run_file(strategy_file_path, __config__)
"extra": { "context_vars": { "num": num, "mon": mon, "con": con, }, "log_level": "error", }, "mod": { "sys_progress": { "enabled": True, "show": True, }, "sys_analyser": { "enabled": True, "output_file": r"./con-mon-ind/{con}-{mon}-{num}.pkl".format( num=num, mon=mon + 1, con=con + 1) }, }, } tasks.append(config) i = 0 strategy_file_path = "AR_strategy.py" for task in tasks: run_file(strategy_file_path, task) print(i) i += 1
def start(): run_file(strategy_file_path, config)
# -*- coding: utf-8 -*- from rqalpha import run_file config = { "base": { "start_date": "2016-06-01", "end_date": "2016-12-01", "securities": ['stock'], "stock_starting_cash": 100000, "benchmark": "000300.XSHG" }, "extra": { "log_level": "verbose", }, "mod": { "sys_analyser": { "enabled": True, "plot": True } } } strategy_file_path = "./buy_and_hold.py" run_file(strategy_file_path, config)
strategy_file_path = "/Users/zhifeng/Projects/rqalpha/rqalpha/examples/strategy_flow.py" host = "121.40.85.7" port = 9999 server_addr = "mongodb://%s:%d/" % (host, port) client = pymongo.MongoClient(server_addr) # exit(0) for i in range(1, 10): for j in range(1, 10): print("%d %d" % (i, j)) olt = "> %.1f" % (float(i) / 10) ost = "< -%.1f" % (float(i) / 10) clt = "< %.1f" % (float(j) / 10) cst = "> -%.1f" % (float(j) / 10) config = init_config config["strategy"]["flow_through"]["open_long_threshold"] = olt config["strategy"]["flow_through"]["open_short_threshold"] = ost config["strategy"]["flow_through"]["close_long_threshold"] = clt config["strategy"]["flow_through"]["close_short_threshold"] = cst res = run_file(strategy_file_path, config) info = res["sys_analyser"]["summary"] info["open_long_threshold"] = olt info["open_short_threshold"] = ost info["close_long_threshold"] = clt info["close_short_threshold"] = cst print(info) exit(0) client["backtrace_report_flow_through"]["I88"].insert(info)