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

Lines Coupling not working



  • Following the example in the documentation and it seems to give a index out of range when trying to use the lines coupling method ()

    class LineCoupler(bt.Strategy):
        params = dict(period=20)
    
        def __init__(self):
    
            # data0 is a daily data
            sma0 = btind.SMA(self.data0, period=7)  # 15 days sma
            # data1 is a weekly data
            sma1 = btind.SMA(self.data1, period=2)  # 5 weeks sma
    
            self.buysig = sma0 < sma1()
    
    data = pdr.get_data_yahoo('AAPL', start=datetime(2017, 8, 13), end=datetime(2018, 8, 14),interval='d')
    data1 = pdr.get_data_yahoo('AAPL', start=datetime(2017, 8, 13), end=datetime(2018, 8, 14), interval='w')
    
    cerebro.addstrategy(LineCoupler)
    
    
     # add the data from a pandasDataFrame
    df=PandasData(dataname=data)
    df1=PandasData(dataname=data1)
    cerebro.adddata(df)
    cerebro.adddata(df1)
    
    backtest = cerebro.run()
    
    

    Traceback (most recent call last):
    File "bt-pandas-demo.py", line 200, in <module>
    backtest = cerebro.run()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/cerebro.py", line 1127, in run
    runstrat = self.runstrategies(iterstrat)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/cerebro.py", line 1293, in runstrategies
    self._runonce(runstrats)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/cerebro.py", line 1652, in _runonce
    strat._once()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/lineiterator.py", line 297, in _once
    indicator._once()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/linebuffer.py", line 631, in _once
    self.once(self._minperiod, self.buflen())
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/linebuffer.py", line 755, in once
    self._once_op(start, end)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/linebuffer.py", line 772, in _once_op
    dst[i] = op(srca[i], srcb[i])
    IndexError: array index out of range


  • administrators

    You have to disable step-by-step evaluation as shown in the code.

    cerebro.run(stdstats=False, runonce=False). Coupling cannot be precalculated.

    Blog - Mixing Timeframes in Indicators


Log in to reply
 

});