Backtrader Community

    • 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/

    #IndexError: list index out of range problem.

    General Code/Help
    1
    1
    86
    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.
    • Talha Islam
      Talha Islam last edited by

      The data is coming in as unix timestamp in milliseconds.
      So i am using #dtformat=lambda x: datetime.datetime.utcfromtimestamp(int(x) / 1000).
      import backtrader as bt
      import datetime

      cerebro = bt.Cerebro()
      data = bt.feeds.GenericCSVData(dataname="ftx1h.csv", dtformat=lambda x: datetime.datetime.utcfromtimestamp(int(x) / 1000))
      cerebro.adddata(data)
      cerebro.run()
      cerebro.plot()

      But now there is an #IndexError: list index out of range problem.
      Traceback (most recent call last):
      File "/Users/talha/VScode/Backtest/Strategy5.py", line 7, in
      cerebro.run()
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/backtrader/cerebro.py", line 1127, in run
      runstrat = self.runstrategies(iterstrat)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/backtrader/cerebro.py", line 1212, in runstrategies
      data.preload()
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/backtrader/feed.py", line 688, in preload
      while self.load():
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/backtrader/feed.py", line 479, in load
      _loadret = self._load()
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/backtrader/feed.py", line 710, in _load
      return self._loadline(linetokens)
      File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/backtrader/feeds/csvgeneric.py", line 148, in _loadline
      csvfield = linetokens[csvidx]
      IndexError: list index out of range

      The Data
      1660435200000,24454.0,24528.0,24355.0,24527.0,67147303.3027
      1660438800000,24527.0,24682.0,24422.0,24598.0,116587503.2913
      1660442400000,24598.0,24632.0,24514.0,24608.0,34892443.4722
      1660446000000,24608.0,24635.0,24553.0,24584.0,22989205.8046
      1660449600000,24584.0,24652.0,24506.0,24581.0,44973942.2299
      1660453200000,24581.0,24636.0,24540.0,24603.0,47360860.8874
      1660456800000,24613.0,24695.0,24603.0,24689.0,32459071.9839
      1660460400000,24689.0,25065.0,24682.0,24900.0,301312472.1925
      1660464000000,24900.0,24902.0,24608.0,24673.0,170952143.2637
      1660467600000,24672.0,24790.0,24643.0,24758.0,70969336.6324
      1660471200000,24758.0,24759.0,24618.0,24627.0,64221863.5382
      1660474800000,24627.0,24682.0,24525.0,24569.0,76070172.2453
      1660478400000,24569.0,24593.0,24475.0,24535.0,59713290.9481
      1660482000000,24535.0,24538.0,24406.0,24481.0,89923365.2962
      1660485600000,24481.0,24534.0,24466.0,24518.0,49835330.6131
      1660489200000,24518.0,24549.0,24468.0,24528.0,46556537.1289
      1660492800000,24528.0,24560.0,24313.0,24315.0,108465182.8929
      1660496400000,24315.0,24332.0,24178.0,24232.0,176757581.0963
      1660500000000,24232.0,24300.0,24155.0,24282.0,68322221.4964
      1660503600000,24281.0,24327.0,24244.0,24289.0,34982570.2998
      1660507200000,24289.0,24352.0,24255.0,24315.0,40799224.029
      1660510800000,24315.0,24448.0,24278.0,24349.0,94709768.3767
      1660514400000,24349.0,24372.0,24182.0,24265.0,75704499.2116
      1660518000000,24265.0,24358.0,24240.0,24310.0,46011851.1185
      1660521600000,24310.0,24418.0,24171.0,24406.0,90810435.293
      1660525200000,24406.0,24665.0,24340.0,24655.0,233812433.3012
      1660528800000,24654.0,24950.0,24653.0,24937.0,223521446.7061
      1660532400000,24937.0,25232.0,24813.0,24883.0,373106086.273
      1660536000000,24883.0,24900.0,24696.0,24863.0,172798798.982
      1660539600000,24863.0,24998.0,24762.0,24835.0,110243603.1486
      1660543200000,24835.0,24841.0,24088.0,24129.0,338761936.3576
      1660546800000,24130.0,24218.0,23950.0,24026.0,287354302.5387
      1660550400000,24025.0,24089.0,23873.0,24044.0,151992609.2842
      1660554000000,24044.0,24210.0,23992.0,24176.0,132115004.5245
      1660557600000,24180.0,24300.0,24133.0,24275.0,88762538.3025
      1660561200000,24275.0,24316.0,24009.0,24057.0,116716391.6228
      1660564800000,24057.0,24197.0,23891.0,23966.0,135401782.9878

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