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

Using Analyzer in Strategy and Log Files



  • Hi @backtrader

    To start I have to say, you created a great library here! I played with a few and found yours library has good performance and is the most complete. Thank you.

    I was wondering what development pattern you'd recommend for my problem. I notice that the analyzer.next()'s are called after strategy.next(). This has created a delay when I try to use the analyzers in the strategy itself. Two different cases have come up as to why I would want to do this:

    1. I am using the analyzer to determine the trading itself. In my example, I'm using bt.analyzers.drawdown.DrawDown to determine the level of risk taken in the trades executed during strategy.next().

    2. I am taking a series of outputs calculated in strategy.next(), my analyzers, and outputting them to a log file for analysis. I'm doing this during strategy.next(), but this creates a 1-day delay in my analyzers.

    What would you suggest to do so that I can have this data available without the delay during strategy.next(), or is there another development pattern I should follow?

    Thanks
    Kamil



  • To clarify point #2 above a bit. Some of these things being logged, would fit into the description of an analyzer, but I calculated them in the strategy for efficiency as they're byproducts of determining the trades to be executed.


  • administrators

    @kamil-szynkarczuk said in Using Analyzer in Strategy and Log Files:

    I notice that the analyzer.next()'s are called after strategy.next(). This has created a delay when I try to use the analyzers in the strategy itself

    The analyzer is analyzing what has happened. If it were to be called before Strategy.next it wouldn't know that the strategy is doing.

    @kamil-szynkarczuk said in Using Analyzer in Strategy and Log Files:

    I am using the analyzer to determine the trading itself

    Probably the wrong place. Logic belongs in the strategy and not in something which is making an analysis (and not executing logic, although as proven by yourself and being this Python, you can bend the rules as much as you wish)

    @kamil-szynkarczuk said in Using Analyzer in Strategy and Log Files:

    What would you suggest to do so that I can have this data available without the delay during strategy.next(), or is there another development pattern I should follow?

    Do it in the strategy



  • Thank you