Detecting if we are running an Optimization from within a Strategy
I am looking for a way inside a strategy to detect if we a running a regular backtest or if we are running an optimization. Is this possible?
The background is that I would like to do logging only in regular backtest runs. During (multiprocessor) optimization runs there should be no logging (it would not be properly readable anyway, right)?
So my function
logwould start with something like this:
if is_opt: return
One workaround idea would be to use regular python
loggingmodule in the strategy and to disable the
loggerfrom outside before starting the optimization run.
Put a parameter
is_optin the strategy and set it to
Ok, thanks, thats another solution. But I thought it would be nice to make that parameter not part of the regular strategy parameter set. Mainly because I would prefer if that parameter would not appear as normal parameter in my result evaluation scriptings.
I went for using this:
if self.cerebro._dooptimize: return
_dooptimizeis not part of the official API and might break anytime but I think it is ok for now ofr my use case. Thanks!
Cerebro, add an attribute which you set to
optstrategyis called (obviously you override that method) and you won't have to depend on an internal value.
Ok, thanks alot!