def add(ctx, arguments): pass_ctx_from_parent(ctx) if ctx.name == '*': ctx.name = datetime.datetime.today().strftime('%Y%m%d') ctx.arguments = {arg[0]: arg[1] for arg in arguments} cv = EXTENSION_REGISTRY_BT.get_extension(ctx.group)(ctx) cv.write_data_to_journal() cv.read_data_from_journal()
def rm(ctx, filepath, time): pass_ctx_from_parent(ctx) journal_path = os.path.join(ctx.home, ctx.category, ctx.group, ctx.name) if os.path.exists(journal_path) or '*' in journal_path: for file in glob.glob(journal_path): shutil.rmtree(file) click.echo('history journals in {} is cleared'.format(file)) else: click.echo('invalid journal path') # yarn dev backtest -g tushare rm
def run(ctx, path, session_id): pass_ctx_from_parent(ctx) ctx.path = path ctx.low_latency = False ctx.logger = create_logger( ctx.name, ctx.log_level, pyyjj.location(pyyjj.mode.BACKTEST, pyyjj.category.STRATEGY, ctx.group, ctx.name, ctx.locator)) ctx.strategy = Strategy(ctx) runner = Runner(ctx, pyyjj.mode.BACKTEST) runner.add_strategy(ctx.strategy) ctx.session_id = session_id setup(ctx, session_id, run, runner) runner.run()
def trace(ctx, session_id, io_type, tablefmt, pager): pass_ctx_from_parent(ctx) trace_df = kfj.trace_journal(ctx, session_id, io_type) trace_df['gen_time'] = trace_df['gen_time'].apply( lambda t: kft.strftime(t)) trace_df['trigger_time'] = trace_df['trigger_time'].apply( lambda t: kft.strftime(t)) table = tabulate(trace_df.values, headers=trace_df.columns, tablefmt=tablefmt) if pager: click.echo_via_pager(table) else: click.echo(table) # yarn dev backtest -g xtp -n tushare trace -t out -i 1
def sessions(ctx, sortby, ascending, tablefmt, pager): pass_ctx_from_parent(ctx) all_sessions = kfj.find_sessions(ctx).sort_values(by=sortby, ascending=ascending) all_sessions['begin_time'] = all_sessions['begin_time'].apply( lambda t: kft.strftime(t, kft.SESSION_DATETIME_FORMAT)) all_sessions['end_time'] = all_sessions['end_time'].apply( lambda t: kft.strftime(t, kft.SESSION_DATETIME_FORMAT)) all_sessions['duration'] = all_sessions['duration'].apply( lambda t: kft.strftime(t - kft.DURATION_TZ_ADJUST, kft.DURATION_FORMAT )) table = tabulate(all_sessions.values, headers=all_sessions.columns, tablefmt=tablefmt) if pager: click.echo_via_pager(table) else: click.echo(table) # yarn dev backtest -g xtp -n tushare sessions