Optstrategy Problem
-
I'm having problems with using
cerebro.optstrategy()
.-
Can't use multi-CPU computations.
cerebro.run()
only works withmaxcpus=1
. -
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.
- 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 changeparams = (('trend_period', 5), )
manually thencerebro.broker.getvalue()
does indeed return different values for 5 and 6.Thanks!
-
-
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.
-
@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.