Beginner- the date data format Error
siavash last edited by siavash
I'm a beginner and i have problem to add data to Cerebra engine. The error part of code is:
fromdate = datetime(2012,1,1) todate = datetime(2012,1,5) datapath = 'G:/python/EURUSD.m1.csv' data0 = bt.feeds.GenericCSVData( timeframe=bt.TimeFrame.Minutes, compression=1, dataname=datapath, nullvalue=0.0, dtformat=('%Y.%m.%d %H:%M:%S'), fromdate=fromdate, todate=todate, datetime=0, time=-1, high=3, low=4, open=2, close=5, volume=6, openinterest=-1 #-1 means not used )
And my data field in csv file is :
And this is the Error :
Traceback (most recent call last): File "G:/python/channel20.py", line 48, in <module> cerebro.run() File "C:\Users\asus\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\asus\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\cerebro.py", line 1212, in runstrategies data.preload() File "C:\Users\asus\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\feed.py", line 685, in preload while self.load(): File "C:\Users\asus\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\feed.py", line 476, in load _loadret = self._load() File "C:\Users\asus\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\feed.py", line 707, in _load return self._loadline(linetokens) File "C:\Users\asus\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\feeds\csvgeneric.py", line 114, in _loadline dt = datetime.strptime(dtfield, dtformat) File "C:\Users\asus\AppData\Local\Programs\Python\Python36\lib\_strptime.py", line 565, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "C:\Users\asus\AppData\Local\Programs\Python\Python36\lib\_strptime.py", line 362, in _strptime (data_string, format)) ValueError: time data '"2017.08.07 14:16:00"' does not match format '%Y.%m.%d %H:%M:%S'
*** Please give me some help. ***bolded text
Please give me some help.
You want it, you get it. Look at the top of the forum for how to format your code and output. Re-post and when people are actually able to see what you have posted, they may be able to help.
This is not intended to talk you down or patronize you. It is meant as real help for a beginner: learn to see what you have before your eyes, be it code, be it how to post to a forum to ask for help or exchange code.
AliAskari last edited by
I had a similar issue and couldn't find what was wrong for the life of me. Instead I used the following class and it worked like a charm
class custom_csv(btfeed.GenericCSVData): params = ( ('datetime', 0), ('time', -1), ('open', 1), ('high', 2), ('low', 3), ('close', 4), ('volume', 5), ('openinterest', -1), ('timeframe', bt.TimeFrame.Minutes), ('compression', 1), )
and to actually use it you can do
data = custom_csv(dataname='some_csvf_file')
if you have found another solution for your problem please post it here so others can use it.
siavash last edited by
Thanks Mr.AliAskari for your reply. I've solved this problem. It was because of my data file's format.
I would like to send you a message to share our experience about working with backtrader, but I dont know where and how to send a private message.