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

Optstrategy Problem



  • I'm having problems with using cerebro.optstrategy().

    1. Can't use multi-CPU computations. cerebro.run() only works with maxcpus=1.

    2. It doesn't give me the nice printout which can be seen in the end of Quickstart Guide.

    The rest I can live with but next one is really important.

    1. I used optstrategy() like this.
    cerebro.optstrategy(
        TrendStrategy,
        trend_period=range(5, 7)
    )
    

    Then attempted to peek at the results like this.

    strats = cerebro.run(maxcpus=1)
    
    for s in strats:
        print(s[0].p.trend_period)
        print(s[0].broker.get_value())
    

    But the output isn't correct.

    5
    29964.1648
    6
    29964.1648
    

    get_value() seems to return the value from last run for each run. If I change params = (('trend_period', 5), ) manually then cerebro.broker.getvalue() does indeed return different values for 5 and 6.

    Thanks!


  • administrators

    The broker is unique to the system. You need to keep the value in the strategy itself. For example in stop

    @developing-coder said in Optstrategy Problem:

    Can't use multi-CPU computations. cerebro.run() only works with maxcpus=1.

    This is probably your own fault, because you run under Windows in one of those super nice Python hijacking IDEs which destroy the multiprocessing module.

    @developing-coder said in Optstrategy Problem:

    It doesn't give me the nice printout which can be seen in the end of Quickstart Guide.

    And which printout do you get?



  • The broker is unique to the system. You need to keep the value in the strategy itself. For example in stop

    OK, clear!

    This is probably your own fault, because you run under Windows in one of those super nice Python hijacking IDEs which destroy the multiprocess module.

    You are right, I am using PyCharm on Windows. Wouldn't call it exactly a fault tho. PyCharm is a valuable tool and widely used. I've used multiprocessing module in the past without issues.

    Tried running the script via cmd and still same problem. Maybe it's happening because I use a virtual env?

    And which printout do you get?

    Nothing, just the stuff I print from inside strategy.


  • administrators

    @developing-coder said in Optstrategy Problem:

    You are right, I am using PyCharm on Windows. Wouldn't call it exactly a fault tho. PyCharm is a valuable tool and widely used. I've used multiprocessing module in the past without issues.

    Some things work, some doesn't. But it is a well known issue. See this for example: https://stackoverflow.com/questions/48078722/no-multiprocessing-print-outputs-spyder?noredirect=1&lq=1



  • Yeah, in my case it doesn't even work when running directly on command line tho.

    Stumbled across this, might be related.

    https://github.com/kernc/backtesting.py/issues/5


 

});