ValueError: time data '0' does not match format '%Y-%m-%d %H:%M:%S'
-
Hi! I am struggling with backtrader's param.
I have csv which has a column called "date":
date
2020-07-09 15:10:00
and as you can see it has a format like '%Y-%m-%d %H:%M:%S'...
and my backtrader datafeed like below,
and each tuple's 2nd element represents the dataframe's column as in iloc. ..
But I always get the error:
ValueError: time data '0' does not match format '%Y-%m-%d %H:%M:%S'
What should I do? Thanks for your help in advance!
data = bt.feeds.GenericCSVData(dataname='finallya.csv',
params = (('nullvalue', float('NaN')), ('dtformat', '%Y-%m-%d %H:%M:%S'), ('tmformat', '%H:%M:%S'), ('datetime', 1), ('time', 2), ('open', 3), ('high', 4), ('low', 5), ('close', 6), ('volume', -5), ))
-
It seems the
date
column contains both the date and time - they are not a separate columns - so you just need thedatetime
parameter to have a value >= 0 to specify thedate
column position ( which is zero based btw).So assuming your
date
column is the first column ( having an index 0 ):data = bt.feeds.GenericCSVData( dataname='finallya.csv', volume = -1, # assuming there is no such column openinterest = -1 )
will probably do the trick - all the other parameters will get their default values (see the csvgeneric.py code for default values):
class GenericCSVData(feed.CSVDataBase): params = ( ('nullvalue', float('NaN')), ('dtformat', '%Y-%m-%d %H:%M:%S'), ('tmformat', '%H:%M:%S'), ('datetime', 0), ('time', -1), ('open', 1), ('high', 2), ('low', 3), ('close', 4), ('volume', 5), ('openinterest', 6), )
-
Thank you for your answer! However I got another error from that inheriting part : "feed" since I don't know about backtrader very much yet so I googled but couldn't find how to import relevant module to find "feed" class. ..
-
@vladisld Thank you for your answer! However I got another error from that inheriting part : "feed" since I don't know about backtrader very much yet so I googled but couldn't find how to import relevant module to find "feed" class. ..