Optimisation with step sizes
-
Good Day All,
From what I've gathered from the documentation and from various examples online, it appears that the way to optimise strategy parameters is by using
Cerebro.optstrategy(Strategy, Param1 = range(1, 10))
. My understanding is that by using theCerebro.optstrategy()
method in the way mentioned above, backtrader will conduct backtest runs for each value within the range of parameter values with a step size of 1(1-9 for our example). If say I wanted to optimise my strategies using a step size of 2 instead, could I useCerebro.optstrategy(Strategy, Param1 = [1, 3, 5, 7, 9])
instead? -
As
range(1, 10)
returns a list[1, 2, 3, 4, 5, 6, 7, 8, 9]
, I technically should be able to useCerebro.optstrategy(Strategy, Param1 = [1, 3, 5, 7, 9])
right? I just require confirmation that using theCerebro.optstrategy()
method with a list wouldn't break backtrader -
It takes probably 10 min to check in actual code, but lets take longer way.
From Docs - Cerebro - Reference -
optstrategy(strategy, *args, kwargs)
Adds a Strategy class to the mix for optimization. Instantiation will happen during run time. args and kwargs MUST BE iterables which hold the values to check.This list
[1, 3, 5, 7, 9]
seems an iterable, so should work.
-
@Ron-Aw said in Optimisation with step sizes:
As range(1, 10) returns a list
FYI in python 3 range does not return a list, it returns an immutable integer sequence type that is iterable.
-
Thank you. @ab_trader @run-out