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/

    How to get historical data properly?

    General Discussion
    2
    3
    1019
    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.
    • eggachecat
      eggachecat last edited by

      Hi guys,

      I am a newbie for backtrader and I need for you help..

      Let's say that I have a strategy concerning with average price (like the average price of last 5 days)

      So I always need the last 5 days data, sure I can use a variable to track the index and use some thing like

      n_avg = 5
      hisrotical_prices = [self.dataclose[x - n_avg] for x in range(n_avg )]
      # without considering the first 4 days from beginning
      

      Any better approach for this?

      And what if the strategy need all the historical data? I would expect better than this

      def __init__(self):
          self.idx = 0 #track the timeline
      
      def next(self):
          hisrotical_prices = [self.dataclose[x - self.idx] for x in range(self.idx)]
          #blablabla
          self.idx += 1
      

      Because I think there's some reason that the framework hide the real idx variable and I don't want to break it...

      Thanks a lot!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        data.get(size=x, ago=y), where the default is ago=0 to start at the current point in time.

        Everything that has to do with the indexing model is explained here: Docs - Platform Concepts

        1 Reply Last reply Reply Quote 1
        • eggachecat
          eggachecat last edited by

          @backtrader Thanks a lot!

          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(); }); }