Navigation

    Backtrader Community

    • Register
    • 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/

    Yield cerebro.run strategy runs one at a time

    General Code/Help
    3
    7
    53
    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
      tospip last edited by

      At the moment, when using optstrategy, cerebro.run() creates a list of results and then returns them all together when all of the iterations are over.

      Is there a way to iterate over each result as soon as the strategy has been run?

      T 1 Reply Last reply Reply Quote 0
      • T
        tospip @tospip last edited by

        To explain a bit better what I have in mind. If I have the current code:

        results = cerebro.run()
        
        for strategy_result in results:
            analysis = strategy_result.analyzers.some_analyzer.get_analysis()
            # Do other stuff (e.g. save results on file, or whatever)
        

        This will first evaluate cerebro.run() and compute all of the strategy results. Once this is finished (a few hours later) it will start iterating over the results.

        What I'd like to do, instead, is to access the items of the results list as soon as they are available. So cerebro.run() should use something like a yield rather than populating a list and returning it when it's done. I'm not sure whether this is already possible, but I'd be happy to have some hints :)

        1 Reply Last reply Reply Quote 0
        • vladisld
          vladisld last edited by

          Take a look at the optcallback Cerebro's method in the docs. Is it what you've been looking for?

          1 Reply Last reply Reply Quote 0
          • T
            tospip last edited by

            @vladisld Thank you for your answer. This solves one part of my problem (handling each result as soon as it is available).

            However, I think that with this approach the previous results are still kept in memory after they are created, even though I don't need them anymore. I'd like to avoid this and have a behaviour similar to that of a generator.

            1 Reply Last reply Reply Quote 0
            • vladisld
              vladisld last edited by

              I'm afraid this is not easy to achieve without re-writing parts of the Cerebro logic :-(

              1 Reply Last reply Reply Quote 0
              • T
                tospip last edited by

                That's a pity. Thank you for your help @vladisld !

                1 Reply Last reply Reply Quote 0
                • run-out
                  run-out last edited by

                  I do have a non-backtrader solution for this if you like. Let me know.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                  $(document).ready(function () { app.coldLoad(); }); }