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 resampling data



  • I have a 15m bar feed, which I am resampling to 1hr and 2hr bars - works fine. But when I change the 2hr bar to resample to daily I get this error:

    File "/home/chris/anaconda3/lib/python3.6/site-packages/backtrader/strategy.py", line 424, in getwritervalues
    values.extend([''] * iocsv.lines.isize())
    AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Indicat' object has no attribute 'isize'

    I am writing to csv, but it doesn't seem to be related because the error continues even if i disable csv output for that datafeed. Not really sure where to start with this one?

            data = btfeeds.GenericCSVData(
                dataname=datafilepath,
    
                fromdate=datetime.datetime(2016, 1, 1),
                todate=datetime.datetime.now(),
                timeframe=bt.TimeFrame.Seconds,
                compression=candlestick_period,
    
                nullvalue=0.0,
    
                dtformat=('%Y-%m-%d %H:%M:%S'),
    
                datetime=2,
                high=3,
                low=4,
                open=5,
                close=1,
                volume=6,
                openinterest=-1
            )
            cerebro.adddata(data, name=x)
            cerebro.resampledata(data, name=x + "_hour", timeframe=bt.TimeFrame.Minutes, compression=60)
            cerebro.resampledata(data, name=x + "_daily", timeframe=bt.TimeFrame.Minutes, compression=60*24)
    

    Note, TimeFrame.Daily, compression=1 does the same thing. Just tried this to see. Everything up to 8hours works fine. After 8, I get this error.


  • administrators

    A use case which was never caught before and the code contains a typo.

    Corrected in the development branch: https://github.com/mementum/backtrader/commit/a7cdb5dcf2d1226e661995415d3ea44304d9fab9



  • thank you! i modified strategy.py with that change and it works now. your support is amazing.