From 5da562c6675d7c052560fa21a1a3300346f66f65 Mon Sep 17 00:00:00 2001 From: Soham Jain <36758674+sohamsjain@users.noreply.github.com> Date: Mon, 28 Feb 2022 19:43:33 +0530 Subject: [PATCH] Resolves resampling issues due to timezone differences. Datafeed sourced from IB API receives timezone info from contractdetails. This tz info was not passed to num2date() method in lines 275 and 276. This results in an offset in the point value returned by self._gettmpoint(tm). This offset distorts the resampling and produces bars at irregular intervals. Above modifications takes care of the same. Note: Modified code was tested on `Minute 1` timeframe resampled to 20, 25 & 75 minutes using ibdata and data form local csv file. --- backtrader/resamplerfilter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backtrader/resamplerfilter.py b/backtrader/resamplerfilter.py index 010a6b6bc..76506e2b8 100644 --- a/backtrader/resamplerfilter.py +++ b/backtrader/resamplerfilter.py @@ -46,6 +46,7 @@ class DTFaker(object): def __init__(self, data, forcedata=None): self.data = data + self._tz = data._tz # Aliases self.datetime = self @@ -271,8 +272,8 @@ def _barover_subdays(self, data): return False # Get time objects for the comparisons - in utc-like format - tm = num2date(self.bar.datetime).time() - bartm = num2date(data.datetime[0]).time() + tm = num2date(self.bar.datetime, tz=data._tz).time() + bartm = num2date(data.datetime[0], tz=data._tz).time() point, _ = self._gettmpoint(tm) barpoint, _ = self._gettmpoint(bartm)