问答交流

模拟交易绘制结果失败

由bqkul07v创建,最终由bqkul07v 被浏览 22 用户

我怀疑问题是这样:\n现在的新版模拟交易必须使用M.bigtrader.v9。然而这个模块回测和之前我使用的M.hftrade.v2不一样,回测区间如果只有一天是不能绘图的。问题是提交模拟交易的时候,每天运行的时候确实就只有一天,所以绘图失败了。

\

2024-02-05 22:45:21 任务运行状态更新 state=failed event=20240205 cfa00cef-240f-4586-9e05-10f0f2fa38f6
Traceback (most recent call last):
  File "/var/app/enabled/aiflowtaskrun.py", line 150, in <module>
    run(run_id=sys.argv[1], task_id=sys.argv[2], event_name=sys.argv[3], dry_run=sys.argv[4])
  File "/var/app/enabled/aiflowtaskrun.py", line 145, in run
    raise ex from ex
  File "/var/app/enabled/aiflowtaskrun.py", line 132, in run
    do_run(task_id, event_name)
  File "/var/app/enabled/aiflowtaskrun.py", line 109, in do_run
    pm.execute_notebook(
  File "/usr/local/python3/lib/python3.8/site-packages/papermill/execute.py", line 128, in execute_notebook
    raise_for_execution_errors(nb, output_path)
  File "/usr/local/python3/lib/python3.8/site-packages/papermill/execute.py", line 232, in raise_for_execution_errors
    raise error
papermill.exceptions.PapermillExecutionError: 
---------------------------------------------------------------------------
Exception encountered at "In [4]":
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[4], line 474
    438     pass
    443 # m4 = M.hftrade.v2(
    444 #     instruments=instruments,
    445 #     options_data=calc,
   (...)
    470 #     backtest_only=False
    471 # )
--> 474 m4 = M.bigtrader.v9(
    475     data=instruments,
    476     options_data=calc,
    477     start_date='',
    478     end_date='',
    479     initialize=m4_initialize_bigquant_run,
    480     before_trading_start=m4_before_trading_start_bigquant_run,
    481     handle_tick=m4_handle_tick_bigquant_run,
    482     handle_data=m4_handle_data_bigquant_run,
    483     handle_trade=m4_handle_trade_bigquant_run,
    484     handle_order=m4_handle_order_bigquant_run,
    485     after_trading=m4_after_trading_bigquant_run,
    486     capital_base=10000000,
    487     frequency='daily',
    488     product_type='股票',
    489     before_start_days=0,
    490     volume_limit=1,
    491     order_price_field_buy='open',
    492     order_price_field_sell='open',
    493     benchmark='000300.SH',
    494     plot_charts=True,
    495     disable_cache=False,
    496     debug=False,
    497     backtest_only=False
    498 )
File module2/common/modulemanagerv2.py:88, in biglearning.module2.common.modulemanagerv2.BigQuantModuleVersion.__call__()
File module2/common/moduleinvoker.py:374, in biglearning.module2.common.moduleinvoker.module_invoke()
File module2/common/moduleinvoker.py:221, in biglearning.module2.common.moduleinvoker._module_postrun()
File /var/app/data/custom_module/publicmodules/bigtrader/v9/__init__.py:353, in post_run(outputs)
    350 if func_post_run is None:
    351     raise Exception(f"not supported {outputs.run_engine=}, {outputs.run_mode=}")
--> 353 return func_post_run(outputs)
File /var/app/data/custom_module/publicmodules/bigtrader/v9/core/pybacktest/__init__.py:536, in bigquant_postrun(outputs)
    533 extend_class_methods(outputs, get_all_orders=get_all_orders)
    535 if outputs.plot_charts:
--> 536     outputs.display()
    538 return outputs
File /var/app/data/custom_module/publicmodules/bigtrader/v9/core/pybacktest/postrun.py:31, in display(outputs, plot_series_compare)
     23         render_future(
     24             outputs,
     25             round_num=3,
   (...)
     28             raw_perf_df=raw_perf
     29         )
     30     elif acct_types[0] in [AcctType.STOCK]:
---> 31         render_stock(
     32             outputs,
     33             round_num=3,
     34             data_frequency=data_frequency,
     35             plot_series_compare=plot_series_compare,
     36             acct_type=acct_types,
     37             raw_perf_df=raw_perf
     38         )
     39 elif len(acct_types) > 1:
     40     render_portfolio(
     41         outputs,
     42         round_num=3,
   (...)
     45         acct_type=acct_types,
     46     )
File /var/app/data/custom_module/publicmodules/bigtrader/v9/core/pybacktest/perf_render.py:81, in render(outputs, output, round_num, data_frequency, plot_series_compare, return_script, acct_type, raw_perf_df)
     77 if outputs.debug:
     78     print("{} perf_render raw_perf={}, benchmark_data={}, process stats..." \
     79           .format(datetime.now(), outputs.raw_perf, outputs.benchmark_data))
---> 81 stats = get_stats(outputs, acct_type=acct_type, raw_perf_df=raw_perf_df)
     82 general_html = (
     83     stats
     84     if output == "object"
   (...)
     89     )
     90 )
     91 odict = OrderedDict()
File /var/app/data/custom_module/publicmodules/bigtrader/v9/core/pybacktest/perf_render.py:242, in get_stats(outputs, acct_type, raw_perf_df)
    240         market_value["portfolio_value"]= results.iloc[i].portfolio_value
    241         market_values.append(market_value)
--> 242 df=pd.concat(market_values)
    243 diversity_buy=round(df["market_value"] / df["portfolio_value"],4)
    244 diversity_buy=max(diversity_buy.tail(90))
File /usr/local/python3/lib/python3.8/site-packages/pandas/core/reshape/concat.py:285, in concat(objs, axis, join, ignore_index, keys, levels, names, verify_integrity, sort, copy)
     82 def concat(
     83     objs: Union[Iterable["NDFrame"], Mapping[Label, "NDFrame"]],
     84     axis=0,
   (...)
     92     copy: bool = True,
     93 ) -> FrameOrSeriesUnion:
     94     """
     95     Concatenate pandas objects along a particular axis with optional set logic
     96     along the other axes.
   (...)
    283     ValueError: Indexes have overlapping values: ['a']
    284     """
--> 285     op = _Concatenator(
    286         objs,
    287         axis=axis,
    288         ignore_index=ignore_index,
    289         join=join,
    290         keys=keys,
    291         levels=levels,
    292         names=names,
    293         verify_integrity=verify_integrity,
    294         copy=copy,
    295         sort=sort,
    296     )
    298     return op.get_result()
File /usr/local/python3/lib/python3.8/site-packages/pandas/core/reshape/concat.py:342, in _Concatenator.__init__(self, objs, axis, join, keys, levels, names, ignore_index, verify_integrity, copy, sort)
    339     objs = list(objs)
    341 if len(objs) == 0:
--> 342     raise ValueError("No objects to concatenate")
    344 if keys is None:
    345     objs = list(com.not_none(*objs))
ValueError: No objects to concatenate

\

标签

模拟交易交易
评论
  • 应该和这个问题无关,能分享一下代码我们排查一下具体问题吗?
{link}