Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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

    General Discussion
    2
    5
    1438
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jirathh last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • P
        Paska Houso last edited by

        • https://www.backtrader.com/docu/strategy.html
        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]
        
        1 Reply Last reply Reply Quote 0
        • J
          jirathh last edited by jirathh

          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
          1 Reply Last reply Reply Quote 0
          • P
            Paska Houso last edited by

            There has been a discussion on this just 2 days ago:

            • https://community.backtrader.com/topic/467/feeding-multiple-data-feeds-in-indicators/
            1 Reply Last reply Reply Quote 0
            • J
              jirathh last edited by

              Thank you @Paska-Houso for your actively help.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }