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/

    Error when Reading in Custom CSV Data

    General Code/Help
    3
    9
    265
    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.
    • Parth Patel
      Parth Patel last edited by

      data = btfeeds.GenericCSVData(dataname='Data/ES_15min.csv',
      time=1,
      open=2,
      high=3,
      low=4,
      close=5,
      volume=-1,
      openinterest=-1,
      dtformat='%m-%d-%Y %H%M')

      This code gives me the following error: "re.error: redefinition of group name 'H' as group 6; was group 4 at position 133"
      I cannot figure this out. Anyone else seen this?

      Parth Patel 1 Reply Last reply Reply Quote 0
      • Parth Patel
        Parth Patel @Parth Patel last edited by

        Full Error code:
        d9916230-fa95-45f6-a502-ebcc9b890283-image.png

        Parth Patel 1 Reply Last reply Reply Quote 0
        • Parth Patel
          Parth Patel @Parth Patel last edited by

          Here is my data: 9ee10cf2-e77a-4dc6-96ca-dde5650b7305-image.png
          Loading in data:

              data = btfeeds.GenericCSVData(dataname='Data/ES_15min.csv',
                                            name='ES',
                                            fromdate=dt(2019, 1, 1),
                                            todate=dt(2019, 12, 31),
                                            time=1,
                                            open=2, 
                                            high=3,
                                            low=4,
                                            close=5,
                                            volume=-1,
                                            openinterest=-1,
                                            dtformat=('%m-%d-%Y %H:%M'),
                                            tmformat=('%H:%M'))
          
          1 Reply Last reply Reply Quote 0
          • Yaroslav Horyslavets
            Yaroslav Horyslavets last edited by

            Hello.

            I think you should specify the datetime param:

            data = btfeeds.GenericCSVData(dataname='Data/ES_15min.csv',
                                          name='ES',
                                          fromdate=dt(2019, 1, 1),
                                          todate=dt(2019, 12, 31),
                                          datetime=0,
                                          time=1,
                                          open=2, 
                                          high=3,
                                          low=4,
                                          close=5,
                                          volume=-1,
                                          openinterest=-1,
                                          dtformat=('%m-%d-%Y %H:%M'),
                                          tmformat=('%H:%M'))
            

            Read more here:

            • dataname (None)

            • name ()

            • compression (1)

            • timeframe (5)

            • fromdate (None)

            • todate (None)

            • sessionstart (None)

            • sessionend (None)

            • filters ([])

            • tz (None)

            • tzinput (None)

            • qcheck (0.0)

            • calendar (None)

            • headers (True)

            • separator (,)

            • nullvalue (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)

            and here: https://www.backtrader.com/docu/dataautoref/

            Parth Patel 1 Reply Last reply Reply Quote 0
            • vladisld
              vladisld last edited by

              @Parth-Patel said in Error when Reading in Custom CSV Data:

              data = btfeeds.GenericCSVData(dataname='Data/ES_15min.csv',
              name='ES',
              fromdate=dt(2019, 1, 1),
              todate=dt(2019, 12, 31),
              time=1,
              open=2,
              high=3,
              low=4,
              close=5,
              volume=-1,
              openinterest=-1,
              dtformat=('%m-%d-%Y %H:%M'),
              tmformat=('%H:%M'))

              The problem is that you've specified the time format for both date and time columns

              According to your data format, the date and time columns are separate, so the format of the date column should be '%m-%d-%Y' and the format of the time column should be '%H:%M'

              (No need to specify datetime=0 - it is a default )

              So the code may look like:

              data = btfeeds.GenericCSVData(dataname='Data/ES_15min.csv',
                                                name='ES',
                                                fromdate=dt(2019, 1, 1),
                                                todate=dt(2019, 12, 31),
                                                time=1,
                                                open=2, 
                                                high=3,
                                                low=4,
                                                close=5,
                                                volume=-1,
                                                openinterest=-1,
                                                dtformat='%m-%d-%Y',
                                                tmformat='%H:%M')
              
              Parth Patel 1 Reply Last reply Reply Quote 0
              • Parth Patel
                Parth Patel @vladisld last edited by

                @vladisld I tried that already but then get the following error.
                3a6f881a-1235-4b4a-99f4-4c509fed1e7b-image.png

                1 Reply Last reply Reply Quote 0
                • Parth Patel
                  Parth Patel @Yaroslav Horyslavets last edited by

                  @Yaroslav-Horyslavets I tried that as well but no luck

                  1 Reply Last reply Reply Quote 0
                  • vladisld
                    vladisld last edited by

                    please try:

                    dtformat='%m/%d/%Y'
                    
                    Parth Patel 1 Reply Last reply Reply Quote 0
                    • Parth Patel
                      Parth Patel @vladisld last edited by

                      @vladisld -_- wow I'm an idiot thank you

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