Cerebro 是BackTrader的核心,将各个元素聚集到一起,执行回测,返回结果,并提供可视化界面
Gathering input
- Start by creating a cerebro
- Add Data feeds
- Add Strategies
- Other elements
- Changing the broker
- Receive notifications
- Add a callback to a cerebro instance via the addnotifycallback(callback) call
- Override the notify_store method in the Strategy subclass which is added to a cerebro instance
- Subclass Cerebro and override notify_store (same signature as in the Strategy)(The least preferred)
Execute the backtesting
- Standard Observers: Broker observer, Trades observer, Buy/Sell observer
Returning the results
Giving access to the plotting facilities
Backtesting logic
- Deliver any store notifications
- Ask data feeds to deliver the next set of ticks/bars (第一个载入的数据为主数据,其他数据项主数据看齐)
- Notify the strategy about queued broker notifications of orders, trades and cash/value
- Tell the broker to accept queued orders and execute the pending orders with the new data
- Call the strategies’ next method to let the strategy evaluate the new data (and maybe issue orders which are queued in the broker)(同步执行observers,indicators, analyzers中的相关操作)
- Tell any writers to write the data to its target
注意: 订单的执行在x+1时刻没因为x时刻产生相关交易信号和下单时,相关的市场状态已经成为历史。
网友评论