For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
GenericCSVData - accessing time attribute
-
I'm using GenericCSVData to import hourly bars. The source data has the format date, time, O, H, L, C, volume and I create the data feed like this:
data = bt.feeds.GenericCSVData ( dataname='xx-1h.csv', separator=";", fromdate=datetime.datetime(2017, 8, 16), todate=datetime.datetime(2017, 12, 31), nullvalue=0.0, dtformat=('%d/%m/%Y'), tmformat=('%H:%M:%S'), datetime=0, time=1, open=2, high=3, low=4, close=5, volume=6, openinterest=-1 )
This works to the extent that I can retrieve the date, OHLC and volume however the time portion of the datetime attribute is not being correctly set (or more likely I just do not know how to access it properly). For example, this:
print(self.datas[0].lines.close[0]) print(self.datas[0].lines.open[0]) print(self.datas[0].lines.datetime.date()) print(self.datas[0].lines.datetime.time())
Produces this output:
3.068 3.065 2017-09-14 23:59:59.999989
...where the time (for this bar) should be 18:00:00. Here is the corresponding row from the source CSV file:
14/09/2017;18:00:00;3.065;3.068;3.065;3.068;90
How do I retrieve the time? Any help appreciated.
-
Argh I found the solution moments after posting. For reference the timeframe needs to be set, like this (there does not seem to be a TimeFrame.Hours but Minutes does the trick):
timeframe=bt.TimeFrame.Minutes