美文网首页
2.1 Cerebro

2.1 Cerebro

作者: wanggs66 | 来源:发表于2020-04-19 14:13 被阅读0次

    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

    1. Deliver any store notifications
    2. Ask data feeds to deliver the next set of ticks/bars (第一个载入的数据为主数据,其他数据项主数据看齐)
    3. Notify the strategy about queued broker notifications of orders, trades and cash/value
    4. Tell the broker to accept queued orders and execute the pending orders with the new data
    5. 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中的相关操作)
    6. Tell any writers to write the data to its target
      注意: 订单的执行在x+1时刻没因为x时刻产生相关交易信号和下单时,相关的市场状态已经成为历史。

    相关文章

      网友评论

          本文标题:2.1 Cerebro

          本文链接:https://www.haomeiwen.com/subject/vhsubhtx.html