For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
How to pass a list of dicts to optstrategy?
-
I want to optimize my strategy with customized parameters, for example:
cerebro.optstrategy(bt.strategies.MA_CrossOver, fast=range(2,8), slow=range(4, 16))
The above configuration generates a lot of parameters that I don't want.
Instead, I want to specify parameters manually as the following:
cerebro.optstrategy(bt.strategies.MA_CrossOver, myparams=[ {'fast': 2, 'slow': 4}, {'fast': 4, 'slow': 8}, {'fast': 3, 'slow': 7}, ])
How can I achieve this? Thanks
-
Pass parameters to
cerebro
as you shown above. In the strategy:... params = ((`myprams`, {'fast': 1, 'slow': 5}),) ... p1 = self.p.myparams['fast'] p2 = self.p.myparams['slow'] ... self.ind1 = bt.Indicators.SMA(period=p1) self.ind2 = bt.Indicators.SMA(period=p2) ...
I didn't test it, but I don't see any reasons that this should not work.
-
@ab_trader Good idea, I'll try it, thanks!