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/

    ValueError: time data '0' does not match format '%Y-%m-%d %H:%M:%S'

    General Code/Help
    2
    4
    229
    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.
    • Bangol Phoenix
      Bangol Phoenix last edited by

      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),
      
      ))
      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        It seems the date column contains both the date and time - they are not a separate columns - so you just need the datetime parameter to have a value >= 0 to specify the date 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),
            )
        
        Bangol Phoenix 1 Reply Last reply Reply Quote 0
        • Bangol Phoenix
          Bangol Phoenix last edited by

          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. ..

          1 Reply Last reply Reply Quote 0
          • Bangol Phoenix
            Bangol Phoenix @vladisld last edited by

            @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. ..

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
            $(document).ready(function () { app.coldLoad(); }); }