For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

More Features in

  • Hi, I tried searching for a consolidated summary after executing, but couldn't find one.
    The idea is to have a method to get some standard performance results of a strategy backtest
    may be like this res=; res.summary()

    The idea is from a tool in market called ninja trader (screenshot below), however I like backtrader more for it's ease in coding strategies as compared to NT.

    But the output of NT is worth exploring and I think it might be a good idea to add some of the features.


    This one shows details of orders, note the Entry/Exit reason/name

    This one shows the options and nice chart with signal description

  • You will likely get other more detailed responses here but as it stands, backtrader does return a results object from the .run(). The observers can then run against this information that is provided by the .run(). The task would be to write some of these other observers. The architecture is setup quite nicely to allow this modularity and analysis.

  • I actually may have also misspoke here but there is also the concept of analyzers which provide some of this detail as well.

  • Actually both observers and analyzers can be useful to output results. Observers for series of data, analyzers for value in the moment.

  • administrators

    @Usct As pointed out by @ab_trader and @randyt, the collection of the information is down to the Analyzer hierarchy.

    The difference with the aforementioned NinjaTrader (without having used the platform) as presented above is that backtrader is more like a construction kit.

    You decide which things you plug in. If you want the SharpeRatio you can plug it in and then retrieve it. If you don't need it, there is no need to calculate it.

    A TradeAnalyzer (for the Total # of trades from above) and you get it.

    You can even print out the results (or store them in a file) if you also plug a Writer (Documentation). The implementation is rather generic, but nothing forbids having a specialized implementation which produces for example HTML.

    Analyzers support also instantiating Indicator objects and other Analyzer objects in either __init__ or __start__, to make it easy to create your own Analyzer (by simply putting together some analyzers)

    An example using children Analyzer instances is the PyFolio Analyzer

  • Thanks for the feedback.
    I tried Analyzer and Writer and it's really good.
    Somehow the lot of good features are not easy to find on the docs page.

  • Hi, we extended the Cerebro class with a report method:

    from report import Cerebro
    cerebro = Cerebro()
    # add your strategy, data, observers, etc here

    which generates a report like this:
    alt text

    For the code, see and

  • administrators

    Good to see!!!

  • @backtrader you are welcome. Feel free to make any suggestions for further improvement.

Log in to reply