问答交流

回测报错求助——

由bigquantofficial创建,最终由small_q 被浏览 41 用户

<TypeError: symbol() expected argument 'symbol_str' to be a string, but got Equity(685 [518880.HOF]) instead.>

麻烦大佬看下,我问了chat也没搞懂


{w:100}{w:100}{w:100}

\

[2023-07-08 18:44:51.062946] INFO algo: trading transform.../usr/local/python3/lib/python3.8/site-packages/empyrical/stats.py:710: RuntimeWarning: divide by zero encountered in true_divide  np.divide(/usr/local/python3/lib/python3.8/site-packages/pandas/core/indexing.py:1124: FutureWarning: Indexing a timezone-naive DatetimeIndex with a timezone-aware datetime is deprecated and will raise KeyError in a future version.  Use a timezone-naive object instead.  return self._get_label(key, axis=axis)[2023-07-08 18:44:51.127342] ERROR moduleinvoker: module name: backtest, module version: v8, trackeback: KeyError: 'ZOF2'[2023-07-08 18:44:51.139479] ERROR moduleinvoker: module name: trade, module version: v4, trackeback: KeyError: 'ZOF2'Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File /var/app/enabled/biglearning/module2/modules/backtest/v8/__init__.py:769, in _get_market_info(***failed resolving arguments***)
File /var/app/enabled/biglearning/module2/modules/backtest/v8/__init__.py:769, in (x)
KeyError: 'ZOF2'
During handling of the above exception, another exception occurred:
TypeError                                 Traceback (most recent call last)
Cell In[10], line 1
----> 1 m6 = M.trade.v4(
      2     instruments=fd_list,
      3     options_data=df,                                                              
      4     start_date='2023-06-06',
      5     end_date='2023-07-06',
      6     initialize=initialize,
      7     handle_data=handle_data,
      8     prepare=prepare_bigquant_run,
      9     before_trading_start=before_trading_start_bigquant_run,
     10     volume_limit=0.025,
     11     order_price_field_buy='close',
     12     order_price_field_sell='close',
     13     capital_base=100000,
     14     auto_cancel_non_tradable_orders=True,
     15     data_frequency='daily',
     16     price_type='后复权',
     17     product_type='股票',
     18     plot_charts=True,
     19     backtest_only=False,
     20     benchmark=''
     21 )
File /var/app/enabled/biglearning/module2/common/modulemanagerv2.py:88, in __call__(self, **kwargs)
File /var/app/enabled/biglearning/module2/common/moduleinvoker.py:331, in module_invoke(name, version, custom_module, kwargs)
File /var/app/enabled/biglearning/module2/common/moduleinvoker.py:214, in _invoke_with_cache(module, kwargs, module_cache_key, name, version, remote_run)
File /var/app/enabled/biglearning/module2/common/moduleinvoker.py:171, in _module_run(module, kwargs)
File /var/app/enabled/biglearning/module2/modules/trade/v4/__init__.py:363, in bigquant_run(start_date, end_date, initialize, handle_data, instruments, prepare, before_trading_start, volume_limit, order_price_field_buy, order_price_field_sell, capital_base, auto_cancel_non_tradable_orders, data_frequency, price_type, product_type, plot_charts, backtest_only, options_data, options, history_ds, benchmark_ds, benchmark, trading_calendar, amount_integer, m_meta_kwargs)
File /var/app/enabled/biglearning/module2/common/modulemanagerv2.py:88, in __call__(self, **kwargs)
File /var/app/enabled/biglearning/module2/common/moduleinvoker.py:331, in module_invoke(name, version, custom_module, kwargs)
File /var/app/enabled/biglearning/module2/common/moduleinvoker.py:214, in _invoke_with_cache(module, kwargs, module_cache_key, name, version, remote_run)
File /var/app/enabled/biglearning/module2/common/moduleinvoker.py:173, in _module_run(module, kwargs)
File /var/app/enabled/biglearning/module2/modules/backtest/v8/__init__.py:1055, in run(self)
File /var/app/enabled/biglearning/module2/modules/backtest/v8/__init__.py:1029, in run_algo(self)
File /var/app/enabled/bigline/zipline/algorithm.py:877, in TradingAlgorithm.run(self, data, overwrite_sim_params)
    875 try:
    876     perfs = []
--> 877     for perf in self.get_generator():
    878         perfs.append(perf)
    880         if self.show_debug_info:
File /var/app/enabled/bigline/zipline/gens/tradesimulation.py:262, in AlgorithmSimulator.transform(self)
    257 for dt, action in self.clock:
    258     if action == BAR:
    259         # !optimize
    260         # for capital_change_packet in every_bar(dt):
    261         #     yield capital_change_packet
--> 262         every_bar(dt)
    263     elif action == SESSION_START:
    264         if not prev_dt:
    265             # Fix for paper trading only gens one day
File /var/app/enabled/bigline/zipline/gens/tradesimulation.py:151, in AlgorithmSimulator.transform..every_bar(dt_to_use, current_data, handle_data)
    143 blotter.get_transactions(algo, current_data)
    144 # transactions = blotter.get_transactions(algo, current_data)
    145 # if transactions:
    146 #     blotter.in_handle_trade = True
    147 #     for transaction in transactions:
    148 #         algo.handle_trade(transaction)
    149 #     blotter.in_handle_trade = False
--> 151 handle_data(algo, current_data, dt_to_use)
    153 # grab any new orders from the blotter, then clear the list.
    154 # this includes cancelled orders.
    155 new_orders = blotter.new_orders
File /var/app/enabled/bigline/zipline/utils/events.py:214, in EventManager.handle_data(self, context, data, dt)
    212 with self._create_context(data):
    213     for event in self._events:
--> 214         event.handle_data(
    215             context,
    216             data,
    217             dt,
    218         )
File /var/app/enabled/bigline/zipline/utils/events.py:236, in Event.handle_data(self, context, data, dt)
    232 """
    233 Calls the callable only when the rule is triggered.
    234 """
    235 if self.rule.should_trigger(dt):
--> 236     self.callback(context, data)
File /var/app/enabled/bigline/zipline/algorithm.py:534, in TradingAlgorithm.handle_data(self, data)
    532 def handle_data(self, data):
    533     if self._handle_data:
--> 534         self._handle_data(self, data)
    536     # Unlike trading controls which remain constant unless placing an
    537     # order, account controls can change each bar. Thus, must check
    538     # every bar no matter if the algorithm places an order or not.
    539     self.validate_account_controls()
...
    125 else:
--> 126     raise TypeError(
    127         "{0}() expected argument '{1}' to"
    128         " be a string, but got {2} instead.".format(
    129             func.__name__,
    130             argname,
    131             arg,
    132         ),
    133     )
TypeError: symbol() expected argument 'symbol_str' to be a string, but got Equity(1090 [518880.HOF]) instead.



代码发群里了,是个简单基金轮动策略



已解决:


{w:100}

标签

回测
评论
  • 查询已持仓代码有误,请阅读bigtrader的文档,有详细的介绍如何查询持仓的代码,复制黏贴即可
{link}