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/

    Multiple Datafeeds and multiple Timeframes

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

      Hi all,
      I am running backtests with multiple feeds (multiple stocks all USA market). So am following recommended approach: sudo code

      for stock in stockiist:
          data = load corresponding csv file into Pandas dataframe
         cerebro.adddata(data)
      

      Then in next func of strategy:

      for stock in self.datas:
            do whatever 
      

      And that is working well for me. However, now I need to use Fibonnaci pivot point indicator which requires monthly data. According to this documentation
      https://www.backtrader.com/docu/data-multitimeframe/data-multitimeframe/
      I will need to add resampled line after adding the data, something like this

      for stock in stockiist:
         data = load corresponding csv file into Pandas dataframe
         cerebro.adddata(data) #Daily sampled data
         cerebro.resampledata(data,bt.TimeFrame.Months)
      

      My understanding is that now self.datas will have the following:
      "stock1 daily line, stock1 monthly line, stock2 daily line, stock2 monthly line, ..etc
      Which is not convenient to iterate through in next function of strategy.
      I wonder if there is a way to have monthly data added to another feed (other than self.datas) so in next function will have daily data fetched from self.datas and monthly data fetched from this additional feed.
      The documentation here
      https://www.backtrader.com/docu/data-resampling/data-resampling/
      States that
      "backtrader has built-in support for resampling by passing the original data through a filter object. Although there are several ways to achieve this, a straightforward interface exists to achieve this"
      The straightforward it is referring to is to add "cerebro.adddata(data)" but nothing is said about other approaches. Would appreciate if anybody has done this and can provide help
      Thanks

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

        @FaiqS said in Multiple Datafeeds and multiple Timeframes:

        Which is not convenient to iterate through in next function of strategy.

        It may not be convenient for you. Don't mix them in such a way then. Add first the lower timeframes and later the higher timeframes. You will have two clear partitions.

        Or iterate using steps other than 1 and with different starting indices.

        @FaiqS said in Multiple Datafeeds and multiple Timeframes:

        The straightforward it is referring to is to add "cerebro.adddata(data)"

        No. It is referring to resampledata(data, ...). Using any other approach won't change the order in which things are in the system and where.

        1 Reply Last reply Reply Quote -1
        • FaiqS
          FaiqS last edited by

          Thanks @backtrader. Yes that is an option to do it but I just wish it was more flexible.
          I guess I will have to live with it.

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