Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Control the Analyzer to start

    General Discussion
    2
    4
    1055
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tomcpli.update last edited by

      I have 3 years of data adding to the cerebro. I only interest on the performance from the 2nd year to the end of the data. Is there a way to tell the Analyzer to start from the 2nd year?

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        Without knowing the details it would seem that even if you want the analyzer (which?) to look at the data from the 2nd and later years, you are actually doing something (trades) during the 1st year.

        Analyzers are actually looking all the time at whatever it happens in the system (for example at the current value of the portfolio to calculate returns)

        TimeReturn provides a parameter (_doprenext) to actually only calculate returns from the point at which the strategy could formally start trading (when next is called) This is especially useful when using it as Benchmark (@dimitar-petrov found an issue with resampled data and this hook a couple of days ago), because benchmarking against a data or some other asset only happens when next is active.

        With that in mind and if TimeReturn is in use you could add an indicator to the strategy which forces prenext to be called until the end of the 1st year. Setting _doprenext=False would achieve the effect.

        Yes, the problem is that such an indicator which may for for example be SimpleMovingAverage with period=p, requires p to be calculated in advance at the start for it to be completely generic (you can always set a fixed value if you use the same data feed several times), which is not possible if the code has to work with data feeds of unknown length.

        1 Reply Last reply Reply Quote 0
        • T
          tomcpli.update last edited by tomcpli.update

          @backtrader said in Control the Analyzer to start:

          _doprenext

          Thank you very much. _doprenext=False is working in my case. Is it also apply to other built-in analyzer ? it looks like analyzers.SharpeRatio does not support _doprenext. Any suggestion?

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            The SharpeRatio analyzer doesn't do rolling calculations, it does the calculation when everything is over.

            You can subclass it, override __init__ and create the sub analyzer TimeReturn analyzer with your _doprenext of choice.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors