[BC Break] IndexError: index out of range after commit cdb80f8472fc1aeb05d84c5b52b86412e3f89632



  • Hi @backtrader,

    This code has stopped working for me after commit db80f8472fc1aeb05d84c5b52b86412e3f89632

    pypy bc-break.py --adddata1m -> OK
    pypy bc-break.py --addresample10m -> OK
    pypy bc-break.py --addresample15m -> OK
    pypy bc-break.py --adddata1m --addresample10m --addresample15m -> FAIL

    from __future__ import (absolute_import, division, print_function,
                            unicode_literals)
    
    
    import argparse
    import datetime
    
    import backtrader as bt
    
    
    class St(bt.Strategy):
        params = dict(
    
                      talib=False
                      )
    
        def __init__(self):
            ''''''
           
    
        def next(self):
            txt = []
            txt.append('{:04d}'.format(len(self)))
            txt.append('{:04d}'.format(len(self.data0)))
            txt.append(self.data0.datetime.datetime())
            txt.append('{:.2f}'.format(self.data0.close[0]))
    
            try:
                if len(self.datas[1]):
                    txt.append('{:04d}'.format(len(self.data1)))
                    txt.append(self.data1.datetime.datetime())
                    txt.append('{:.2f}'.format(self.data1.close[0]))
    
            except IndexError:
                False #Nothing to do
    
            try:
                if len(self.datas[2]):
                    txt.append('{:04d}'.format(len(self.data2)))
                    txt.append(self.data2.datetime.datetime())
                    txt.append('{:.2f}'.format(self.data2.close[0]))
            except IndexError:
                False #Nothing to do
    
            print(','.join(str(x) for x in txt))
    
    
    def runstrat(args=None):
        args = parse_args(args)
    
        cerebro = bt.Cerebro()
    
        # Data feed kwargs
        kwargs = dict(
                      timeframe=bt.TimeFrame.Minutes,
                      compression=5,
                      )
    
        # Parse from/to-date
        dtfmt, tmfmt = '%Y-%m-%d', 'T%H:%M:%S'
        for a, d in ((getattr(args, x), x) for x in ['fromdate', 'todate']):
            if a:
                strpfmt = dtfmt + tmfmt * ('T' in a)
                kwargs[d] = datetime.datetime.strptime(a, strpfmt)
    
        # Data feed
        data0 = bt.feeds.BacktraderCSVData(dataname=args.data0, ** kwargs)
    
        if args.adddata1m:
            cerebro.adddata(data0)
    
        if args.addresample10m:
            cerebro.resampledata(data0, timeframe=bt.TimeFrame.Minutes, compression=10)
    
        if args.addresample15m:
            cerebro.resampledata(data0, timeframe=bt.TimeFrame.Minutes, compression=15)
    
        # Broker
        cerebro.broker = bt.brokers.BackBroker(** eval('dict(' + args.broker + ')'))
    
        # Sizer
        cerebro.addsizer(bt.sizers.FixedSize, ** eval('dict(' + args.sizer + ')'))
    
        # Strategy
        cerebro.addstrategy(St, ** eval('dict(' + args.strat + ')'))
    
        # Execute
        cerebro.run(** eval('dict(' + args.cerebro + ')'))
    
        if args.plot:  # Plot if requested to
            cerebro.plot(** eval('dict(' + args.plot + ')'))
    
    
    def parse_args(pargs=None):
        parser = argparse.ArgumentParser(
                                         formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                         description=(
                                         'Sample Skeleton'
                                         )
                                         )
    
        parser.add_argument('--data0', default='../../datas//2006-min-005.txt',
                            required=False, help='Data to read in')
    
        # Defaults for dates
        parser.add_argument('--fromdate', required=False, default='',
                            help='Date[time] in YYYY-MM-DD[THH:MM:SS] format')
    
        parser.add_argument('--todate', required=False, default='',
                            help='Date[time] in YYYY-MM-DD[THH:MM:SS] format')
    
        parser.add_argument('--cerebro', required=False, default='',
                            metavar='kwargs', help='kwargs in key=value format')
    
        parser.add_argument('--broker', required=False, default='',
                            metavar='kwargs', help='kwargs in key=value format')
    
        parser.add_argument('--sizer', required=False, default='',
                            metavar='kwargs', help='kwargs in key=value format')
    
        parser.add_argument('--strat', required=False, default='',
                            metavar='kwargs', help='kwargs in key=value format')
    
        parser.add_argument('--plot', required=False, default='',
                            nargs='?', const='{}',
                            metavar='kwargs', help='kwargs in key=value format')
    
        parser.add_argument('--adddata1m', action='store_true', required=False,
                            help='Add 1 minute data')
    
        parser.add_argument('--addresample10m', action='store_true', required=False,
                            help='Add resample for 10 minute data')
    
        parser.add_argument('--addresample15m', action='store_true', required=False,
                            help='Add resample for 15 minute data')
    
    
        return parser.parse_args(pargs)
    
    
    if __name__ == '__main__':
        runstrat()
    

    It seems a problem while combining adddata and resampledata

    Thanks in advance!


  • administrators

    That's the development branch. It's not guaranteed to work and in this case it doesn't.

    The latest commit for the stable and working (as good as possible) master branch: Latest commit 61ae6d9 17 days ago



  • I realized that it is only in the development branch. Sometimes I sync this branch and test my code.
    Should we contact you if we detect any problems on this branch?


  • administrators

    You can always post anything you may consider relevant, but in general a development branch should only be used to check the functionality of a specific commit which may solve something of your interest.


Log in to reply
 

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