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

Avoid optstrategy redundant calculation



  • With cerebro.optstrategy(MyStrategy, maShort_period=range(15, 25))

    does it recalculate not only self.ma1 but self.ma2 and self.rsi too?
    How can I prevent redundant calculation if no swing in input parameter?
    I am optimizing only maShort_period but not maLong_period and rsi_period.

    my code:

     class TestStrategy(bt.Strategy):
    
     def __init__(self):
     self.ma1 = bt.talib.SMA(self.datas[0].close, timeperiod=int(self.p.maShort_period))  
     self.ma2 = bt.talib.SMA(self.datas[0].close, timeperiod=int(self.p.maLong_period))
     self.rsi = bt.talib.RSI(self.datas[0].close, timeperiod=int(self.p.rsi_period))