Why the datetime is set to the end of day for minute period bars in the csv data feed?
I want get the datetime series of the data, and I am not sure whether is right of my using/ understing the csv data feed, I fed the minutes period bar data to the GenericCSVData, when I check the datatime for the loaded data by 'data.lines.datetime.array', I found they were coverted to the end of the day. I debug the code found the logic for the datetime feeding in GenericCSVData._loadline() is as below, the line remarked by ' #*****WHY REPLACE THE dtnum BY dteosnum?', how do I get the right datetime of fed data? thanks!
if self.p.timeframe >= TimeFrame.Days: # check if the expected end of session is larger than parsed if self._tzinput: dtin = self._tzinput.localize(dt) # pytz compatible-ized else: dtin = dt dtnum = date2num(dtin) # utc'ize dteos = datetime.combine(dt.date(), self.p.sessionend) dteosnum = self.date2num(dteos) # utc'ize if dteosnum > dtnum: #*****WHY REPLACE THE dtnum BY dteosnum? self.lines.datetime = dteosnum else: # Avoid reconversion if already converted dtin == dt self.l.datetime = date2num(dt) if self._tzinput else dtnum else: self.lines.datetime = date2num(dt)
I fed the minutes period bar data
And the code you are checking has an
ifguard at the beginning that says:
if self.p.timeframe >= TimeFrame.Days:
So, you are either not feeding minutes or you are checking the wrong code section.
In any case and for timeframe
1-Dayand above, the bar is placed at the end of the session
eos == end of session, which if not specified is the end of the day. If this weren't done for such timeframes, any minute of the session would happen after the
1-Daytimeframe which cannot be.
Thanks you help @backtrader !
I am sure my data are minutes bars, a segment as below:
was my using of the csv feed wrong? my code of feed is as below:
datafile = os.path.join(modpath, '../data/IF0000_1min.csv') # Create a Data Feed data = bt.feeds.GenericCSVData( dataname=datafile, fromdate=datetime.datetime(2012, 1, 1), todate=datetime.datetime(2012, 1, 31), dtformat=('%Y-%m-%d'), tmformat=('%H:%M:%S'), datetime=0, time=1, high=3, low=4, open=2, close=5, volume=6, openinterest=-1)
@backtrader , It works well now, it need set 'timeframe = bt.TimeFrame.Minutes' explicitly.
it need set 'timeframe = bt.TimeFrame.Minutes' explicitly.
If you don't tell the platform what your data feed is, it cannot know it.