resampling 5minutes data to 1day data issue



  • Hello

    I have problem with resampledata.

    My original data is 5minutes data

    • resampling 5minutes data to 1day data - does not work
    • resampling 5minutes data to 1week data - works very well

    my problem / question is: how to make resampling 5 minutes data to 1day data???

    Code below shows problem

    • it generates *.png files (attached below) which shows that:
      • adddata (5minutes data) and resampling (5 minutes data to 1 day data) generates the same result so it's sth. wrong
      • adddata (5minutes data) and resampling (5 minutes data to 1 week data) generates different results and it's correct
    • additionaly it generates output which shows the same with data length:
    adddata: data length=2142
    resampledata-days: data length=2142
    resampledata-weeks: data length=5
    

    Code to generate problem:

    from __future__ import (absolute_import, division, print_function,
                            unicode_literals)
    import backtrader as bt
    import urllib.request
    
    dataurl='https://raw.githubusercontent.com/mementum/backtrader/master/datas/2006-min-005.txt'
    datapath='tmpfile.txt'
    urllib.request.urlretrieve(dataurl,datapath)
    
    def test(type):
        cerebro = bt.Cerebro(stdstats=False)
        cerebro.addstrategy(bt.Strategy)
        data = bt.feeds.GenericCSVData(
            dataname=datapath,
            nullvalue=0.0,
            dtformat=('%Y-%m-%d'),
            tmformat=('%H:%M:%S'),
            datetime=0,
            time=1,
            open=2,
            high=3,
            low=4,
            close=5,
            volume=6,
            openinterest=-1
        )
        if type=='adddata': cerebro.adddata(data)
        if type=='resampledata-days': cerebro.resampledata(data, timeframe=bt.TimeFrame.Days)
        if type=='resampledata-weeks': cerebro.resampledata(data, timeframe=bt.TimeFrame.Weeks)
        r1=cerebro.run()
        cerebro.plot(style='candle', savefig=True, figfilename='{}.png'.format(type))
        print('{}: data length={}'.format(type, r1[0].data_datetime.lencount))
    
    test('adddata')
    test('resampledata-days')
    test('resampledata-weeks')
    

    adddata - 5 minutes data
    0_1500239292644_adddata.png

    resampledata-days - 5 minutes data resampled to 1-day data (should be different than 5 minutes data)
    0_1500239390316_resampledata-days.png

    resampledata-days - 5 minutes data resampled to 1-week data (it is different than 5 minutes data)
    0_1500239397617_resampledata-weeks.png

    all suggestions are more than welcome :-)

    kind regards
    Pawel


  • administrators

    See the FAQ Community - FAQ (timeframe / compression) and this thread from today: Community - Resample data failing

    You are failing to tell the platform what is the original scope of your data.



  • Wooow :-)

    great thanks - it's amazing how quick You are with your help :-)
    I'll read community FAQ once more :-)

    grat thanks :-)

    regards
    Pawel


Log in to reply
 

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