def output(report): if Config.mode() == 'jupyter': display(report) else: if isinstance(report, dict): for key, value in report.items(): print(key, value) else: print(report)
def backtest(strategy, start, end, commission): """ :param strategy: strategy :param start: '2019-06-01' # 回测起始时间 :param end: '2019-07-01' # 回测结束时间 :param commission: {'buy': 0.001, 'sell': 0.001, 'open': 0.001, 'close': 0.001} :return: portfolio """ global error_complete error_complete = 0 strategy._initialize(strategy, start, end, commission) loop = asyncio.get_event_loop() if Config.mode() == 'jupyter': loop.create_task(_handle(strategy)) loop.create_task(_report(strategy)) else: loop.run_until_complete( asyncio.gather(_handle(strategy), _report(strategy))) loop.close()