For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
GenericCSVdata timeframe
-
Hello,
I am trying to import some datafeeds from CSV files, which have one line per day. If I set the timeframe of the class to Days, as it should be, the strategy only goes through the next() method once. Weirdly enough, if I set the timeframe to Weeks instead, the strategy runs once per day, although then I get issues with the resampling.
Any hint where this weird behaviour could come from?
First lines of an example CSV data file:
date,open,close,high,low,turnoverPieces,turnoverEuro 2022-08-10,4.012,3.976,4.012,3.942,50311.0,199699.04 2022-08-09,4.022,4.008,4.09,3.994,94701.0,381702.55 2022-08-08,4.006,4.046,4.074,3.95,167475.0,671826.34 2022-08-05,3.998,3.97,3.998,3.89,93959.0,370817.28 2022-08-04,3.898,3.98,4.0,3.894,143614.0,569000.31 2022-08-03,3.868,3.896,3.896,3.82,162676.0,626748.42 2022-08-02,3.884,3.822,3.884,3.776,110984.0,423815.62 2022-08-01,3.848,3.842,3.902,3.826,126052.0,486242.22
My class:
class my_custom_csv(bt.feeds.GenericCSVData): params = ( ('headers', True), ('separator', ','), ('nullvalue', 0.0), ('dtformat', ('%Y-%m-%d')), ('time', -1), ('datetime', 0), ('high', 3), ('low', 4), ('open', 1), ('close', 2), ('volume', 5), ('openinterest', -1), ('timeframe', bt.TimeFrame.Days), #this is the parameters that can be set to weeks to make the code work )
And this is how I add and resample the data:
days = 365# how many days to backtest start = datetime.date.today() - datetime.timedelta(days=days) end = datetime.date.today() data = my_custom_csv(dataname = '.\History\DE0005493092.txt', fromdate = start, todate = end) data._name = symbol data._dataname = [symbol] cerebro_instance.adddata(data) # Give the data to cerebro rdata = cerebro_instance.resampledata(data, timeframe=bt.TimeFrame.Weeks) #this is where I resample to weeks my daily data rdata.plotinfo.plot = False