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

multi-step optimization

  • Hi

    I want to do a separate parameter optimization, the idea is like I have a strategy with 2 moving averages. I want to do the optimization as follows:

    ma1=[5,15], ma2=50
    ma1=10, ma2=[40,60]

    It's just an example, please don't ask me why I don't optimize the two parameters simultaneously.

    I tried code like :

            # setup analyzers
            cerebro.optstrategy(MyStrategy, ma1=[5, 15], ma2=50)
            cerebro.optstrategy(MyStrategy, ma1=10, ma2=[40,60])

    But this is obviously not working.
    Any way to do this without reloading the data from the beginning please?


  • @asuralm said in multi-step optimization:

    It's just an example, please don't ask me why I don't optimize the two parameters simultaneously.

    But if we don't know what you are trying to achieve, it is difficult to suggest a solution.

    One suggestion. Have you tried passing lists a single parameter and then dealing with them in the strategy?


    opt_list = [[5,20],[15,50],[10,40],[10,60]]

    Then in your strategy:

    class MATest(bt.Strategy):
        params = (('sma_list', list()),)
        def __init__(self):
            self.sma1 = bt.indicators.SimpleMovingAverage(
                self.datas[0], period=self.params.sma_list[0])
            self.sma2 = bt.indicators.SimpleMovingAverage(
                self.datas[0], period=self.params.sma_list[1])

  • Thanks.
    Because I want to see how single parameter affects the performance of the strategy individually. Also, if I have 10 parameters in the strategy, if I test 10 parameters individually, there are only 10 cases. Too many if I have to combine them together.

    What you suggesting works well if there are only 2-3 parameters, but the code would be hard to read if I have a lot of parameters.

  • @asuralm

    Ok - Note that the code would be the same. Only the list would grow as you add more cases. So probably not a great solution if you a lot of test cases but manageable with 10.

  • @ThatBlokeDave
    so when a strategy is addstrategy(), or optstrategy(), it's done. Is there a way to clear it from cerebro?

    The efficiency is low because I need to initialize cerebro and load data every time when I change the strategy with slight different parameter set.

    Then it would be possible that the data is loaded only once, but different strategy can be run on the same data with the same cerebro.

Log in to reply