Please explain 'self.data0' and 'self.data1' in detail



  • Could anyone please explain to me the concept of self.data0 and self.data1?
    I am trying to understand by reading documents but it seems not quite clear to me on how the values are construct and how can we use them.

    I would like to use bt.indicators.OLS_Slope_InterceptN which it seems that it needs both variables.

    Thank you.



  • Member Attributes
      datas: array of data feeds which have been passed to cerebro
    
        - data/data0 is an alias for datas[0]
        - dataX is an alias for datas[X]
    


  • Thank you for your information.
    Could you please have a look on how we can pass data to this indicator?
    For example, if we load Yahoo 'AAPL' data and want to find the slope and intercept.

    Thank you.

    ========================================================
    class OLS_Slope_InterceptN(PeriodN):
    '''
    Calculates a linear regression using statsmodel.OLS (Ordinary least
    squares) of data1 on data0
    Uses pandas and statsmodels
    Use prepend_constant to influence the paramter prepend of
    sm.add_constant
    '''
    _mindatas = 2 # ensure at least 2 data feeds are passed

    packages = (
        ('pandas', 'pd'),
        ('statsmodels.api', 'sm'),
    )
    lines = ('slope', 'intercept',)
    params = (
        ('period', 10),
        ('prepend_constant', True),
    )
    
    def next(self):
        p0 = pd.Series(self.data0.get(size=self.p.period))
        p1 = pd.Series(self.data1.get(size=self.p.period))
        p1 = sm.add_constant(p1, prepend=prepend_constant)
        slope, intercept = sm.OLS(p0, p1).fit().params
    
        self.lines.slope[0] = slope
        self.lines.intercept[0] = intercept




  • Thank you @Paska-Houso for your actively help.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.