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



  • 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?



  • 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 :)



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



  • @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.



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



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



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


Log in to reply
 

});