问答交流

回测trackeback: KeyError: Equity(4419 [002891.SZA])>

由bqf6ujar创建,最终由small_q 被浏览 34 用户

<ERROR: moduleinvoker: module name: backtest, module version: v8, trackeback: KeyError: Equity(4419 [002891.SZA])>


https://bigquant.com/experimentshare/0ccd168b09d14a66887be4f52a975b97

KeyError Traceback (most recent call last) <ipython-input-1-35d0cf4ac64b> in <module> 527 ) 528 --> 529 m4 = M.trade.v4( 530 instruments=m1.data, 531 options_data=m17.data_1,

<ipython-input-1-35d0cf4ac64b> in m4_handle_data_bigquant_run(context, data) 379 stock_risk_manage(context, data) 380 --> 381 sell_action(context, data) 382 buy_action(context, data) 383

<ipython-input-1-35d0cf4ac64b> in sell_action(context, data) 226 if data.can_trade(context.symbol(stock)): 227 context.order_target_percent(context.symbol(stock), 0) --> 228 del context.portfolio.positions[context.symbol(stock)] 229 230

KeyError: Equity(4419 [002891.SZA])

标签

回测
评论
  • del context.portfolio.positions\[context.symbol(stock)\]这句话报错。这句话改为del context.portfolio.positions\[stock\]
  • 不对,还是报错 [https://bigquant.com/experimentshare/073456dea5c64889a7eb4a38e7de2607](https://bigquant.com/experimentshare/073456dea5c64889a7eb4a38e7de2607) \
  • ![{w:100}](/wiki/api/attachments.redirect?id=59e5b7bd-6fd0-419a-a440-3769897f5049)因为此时context.portfolio.positions为空 ,看我截图打印的结果
{link}