Doing data resampling in a custom Live feed
-
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
-
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.