For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Error at the end of backtesting if I use resampled data



  • When I resample '12H' data into '1D' data I get and error in the end of backtesting.

        results = cerebro.run()
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1127, in run
        runstrat = self.runstrategies(iterstrat)
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1298, in runstrategies
        self._runnext(runstrats)
      File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1557, in _runnext
        dt0 = min((d for i, d in enumerate(dts)
    ValueError: min() arg is an empty sequence
    


  • I don't understand what is the issue here. Please help!
    This is how I add data:

    GRANULARITY = {
        '1Min': [bt.TimeFrame.Minutes, 1],
        '5Min': [bt.TimeFrame.Minutes, 5],
        '30Min': [bt.TimeFrame.Minutes, 30],
        '1H': [bt.TimeFrame.Minutes, 60],
        '4H': [bt.TimeFrame.Minutes, 60 * 4],
        '12H': [bt.TimeFrame.Minutes, 60 * 12],
        '1D': [bt.TimeFrame.Days, 1],
    }
    
    data = bt.feeds.PandasData(
                
                	dataname=data_raw,
                
                	openinterest=None
                
                )
                
                
                
                cerebro.adddata(data, name=symbol + "_" + freqs[0])
                
                if len(freqs) > 1:
                
                	for freq in freqs[1:]:
                
                		name = symbol + "_" + freq
                
                		timeframe, compression = GRANULARITY[freq]
                
                		cerebro.resampledata(
                
                			data,
                
                			name=name,
                
                			timeframe=timeframe,
                
                			compression=compression,
                
                		)


  • Seems you didn't set time frame and compression for baseline data. If I remember correctly bts default time frame is Daily. So you are re-sampling from days to intraday now.



  • @ab_trader said in Error at the end of backtesting if I use resampled data:

    Seems you didn't set time frame and compression for baseline data. If I remember correctly bts default time frame is Daily. So you are re-sampling from days to intraday now.

    Thanks! It worked!

                timeframe, compression = GRANULARITY[freqs[0]]
                data = bt.feeds.PandasData(
                    dataname=data_raw,
                    openinterest=None,
                    timeframe=timeframe,
                    compression=compression,
                )
    

Log in to reply
 

});