Resample data failing



  • Trying to resample some data. From 5min bars (or 15m bars, doesn't matter) to 60m. Fails with this error. I've tried a bunch of different options, files - all the same thing. If I switch to .Daily and compression=1 it doesn't fail - but it doesn't work either - the chart still shows the minute bars.

    Traceback (most recent call last):
    File "/home/chris/PycharmProjects/backtrader_gettingstarted/start.py", line 508, in <module>
    cerebro.run()
    File "/home/chris/anaconda3/lib/python3.6/site-packages/backtrader/cerebro.py", line 1142, in run
    runstrat = self.runstrategies(iterstrat)
    File "/home/chris/anaconda3/lib/python3.6/site-packages/backtrader/cerebro.py", line 1310, in runstrategies
    self._runnext(runstrats)
    File "/home/chris/anaconda3/lib/python3.6/site-packages/backtrader/cerebro.py", line 1568, in _runnext
    dt0 = min((d for i, d in enumerate(dts)
    ValueError: min() arg is an empty sequence


  • administrators

    The error alone doesn't help. How is the data being loaded? How does the data look like? (some lines) How is it resampled?



  • resampled like:

    cerebro.adddata(data)

    cerebro.resampledata(data, name="hour", timeframe=bt.TimeFrame.Minutes, compression=60)

    data loads fine (non resampled). looks like:

    ,close,date,high,low,open,volume,weightedAverage
    0,2220.1,2017-05-31 16:00:00,2228.99999,2214.99,2214.99999999,185503.59766414,2218.64712143
    1,2228,2017-05-31 16:05:00,2230.20025,2216.22,2225,222978.85375176,2227.49944904
    2,2229,2017-05-31 16:10:00,2234.01794077,2223.64379998,2228,96741.06959756,2231.5270648
    3,2225,2017-05-31 16:15:00,2229.99999999,2223.64379998,2225.99,86942.64376276,2228.13903275
    4,2228.90000014,2017-05-31 16:20:00,2234.99999999,2223.64379998,2228,185194.23815092,2228.92472684
    5,2228.6994172,2017-05-31 16:25:00,2234.999,2223.64390017,2228.90000014,101266.8286605,2231.24188522
    6,2216.5,2017-05-31 16:30:00,2235,2216.5,2228.6994172,207509.40443134,2229.98339086

    shouldn't matter but:

    data = btfeeds.GenericCSVData(
        dataname=filepath,
    
        fromdate=datetime.datetime(2016, 1, 1),
        todate=datetime.datetime.now(),
    
        nullvalue=0.0,
    
        dtformat=('%Y-%m-%d %H:%M:%S'),
    
    
        datetime=2,
        high=3,
        low=4,
        open=5,
        close=1,
        volume=6,
        openinterest=-1
    )

  • administrators

    Things do actually matter.

    @cemdev said in Resample data failing:

    data = btfeeds.GenericCSVData(
        dataname=filepath,
    
        fromdate=datetime.datetime(2016, 1, 1),
        todate=datetime.datetime.now(),
    
        nullvalue=0.0,
    
        dtformat=('%Y-%m-%d %H:%M:%S'),
    
    
        datetime=2,
        high=3,
        low=4,
        open=5,
        close=1,
        volume=6,
        openinterest=-1
    )
    

    With that, the platform has no way of knowing that the data is made up of 5-minutes bars. Even if it seems obvious to you, it might be the case that the data later has 1-minute bars and the shown data was only a period of thin trading. The default unless you say something else is to consider things to be 1-Day based.

    Use timeframe and compression. This is in the docs and for example in some other posts and in the Community - FAQ



  • @backtrader yes! that was it, thank you. i just assumed it picked up the timeframe from the data since it's defined there anyways (assuming bar data)


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.