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
-
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')
-
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 )