Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Beginner- the date data format Error

    General Code/Help
    3
    4
    1642
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      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 :
      2017.07.31 21:17:00,1.18410,1.18410,1.18401,1.18404,28

      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

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @siavash last edited by

        @siavash said in Beginner:

        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.

        1 Reply Last reply Reply Quote 2
        • A
          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.

          1 Reply Last reply Reply Quote 2
          • S
            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.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors