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/

    failed to load csv data

    General Discussion
    2
    2
    80
    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.
    • K
      kundan174 last edited by

      Re: Import CSV into Backtrader

      Hi,

      I am trying to load 15 minutes data from csv but getting below error.

      IndexError: list index out of range

      Below is the code.

      class Tickstory(btfeed.GenericCSVData):
      params = (
      ('dtformat', '%d-%m-%Y %H:%M'),
      ('datetime', 0),
      ('open', 1),
      ('high', 2),
      ('low', 3),
      ('close', 4),
      ('timeframe', bt.TimeFrame.Minutes)
      )

      data = Tickstory(dataname='JUBLFOOD_15(1).csv')

      R 1 Reply Last reply Reply Quote 0
      • R
        rajanprabu @kundan174 last edited by

        @kundan174

        You dont need to define a class for that.. you can directly pass like the following

        from backtrader import feeds as btfeed
        data = btfeed.GenericCSVData(
            dataname='/Users/prabu/Downloads/JUBLFOOD.csv',
            datetime = 0,
            open = 1,
            high = 2,
            low = 3,
            close = 4,
            volume= -1,
            openinterest=-1,
            timeframe=bt.TimeFrame.Minutes,
            compression = 15
            )
        

        In case if you do want to have the custom class, you can use the following

        from backtrader import feeds as btfeed
        class Tickstory(btfeed.GenericCSVData):
            params = (
                ('datetime', 0),
                ('open', 1),
                ('high', 2),
                ('low', 3),
                ('close', 4),
                ('volume', 5),
                ('openinterest', -1),
            )
        
        data = Tickstory(dataname='JUBLFOOD_15(1).csv', 
                timeframe=bt.TimeFrame.Minutes,
                compression = 15
        )
        
        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors