For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Import CSV into Backtrader
-
Hi, I'm new to backtrader and having a hard time reading in my csv file.
I get the error "ValueError: time data '10-18-2017T 17:59:29.5' does not match format '%m-%d-%YT%H:%M:%S.%f"
The CSV file has the following columns
Date Time Open High Low Close
10-18-2017 17:59:29.5 113.084 113.092 113.062 113.063import backtrader as bt import backtrader.feeds as btfeed class customCSV(btfeed.GenericCSVData): params = ( ('dtformat', '%m-%d-%Y'), ('tmformat', '%H:%M:%S.%f'), ('datetime', 0), ('time', 1), ('open', 2), ('high', 3), ('low', 4), ('close', 5), ('volume', -1), ('openinterest', -1), ) class SmaCross(bt.SignalStrategy): params = (('pfast', 10), ('pslow', 30),) def __init__(self): sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow) self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2)) cerebro = bt.Cerebro() data = customCSV(dataname='USDJPY_Backtrader2.csv') cerebro.adddata(data) cerebro.addstrategy(SmaCross) cerebro.run() cerebro.plot(style='candle')
-
Just wild guess - default separator is
(,)
, and your's isspace
and it is not specified. -
My upvote for @ab_trader shows my support of his theory