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/

    Doing data resampling in a custom Live feed

    General Discussion
    1
    2
    942
    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.
    • K
      kausality last edited by

      I am developing a custom data feed for live data. I am following the Oanda data feed example to fetch the data.

      The exchange supports only these timeframes: 1m, 5m, 10m, 1d

      When I do:
      cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=15)

      it is recalling the start() method of the feed. Since the exchange doesn't support this format, the feed exits. I have tried to play with the resample() and replay() function but to no avail.

      My issue is this: How to load the data using exchange supported timeframes like 5m and then resample it to 15m internally using backtrader.

      The portion of start() function from the oanda example:

          otf = self.o.get_granularity(self._timeframe, self._compression) # resampling calls this with the new timeframe and it fails since exchange doesn't support the resampled timeframe
          if otf is None:
              self.put_notification(self.NOTSUPPORTED_TF)
              self._state = self._ST_OVER
              return
      
      1 Reply Last reply Reply Quote 1
      • K
        kausality last edited by kausality

        Ok. I figured this one out.

        When you call resampledata, it calls the start function of the data feed with the resampled timeframe and compression.

        Suppose the resampled data feed is timeframe=bt.TimeFrame.Minutes, compression=15 and the supported timeframe by the exchange is timeframe=bt.TimeFrame.Minutes, compression=5 and 1.

        For efficient execution, you need to find the highest timeframe which can upsample to the required timeframe/compression. By timestamping the data, backtrader makes sure to return the data in the correct time interval. In this case it will be timeframe=bt.TimeFrame.Minutes, compression=5.

        One just needs to make sure that the timeframe requested can be created by the timeframes returned by the exchange.

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors