Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Resampling data, list index out of range (despite same index)

    General Code/Help
    2
    5
    990
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      guwop last edited by guwop

      I have two sets of 5 minute data that I am working with, both having the same length and identical index. I originally tried to work with the 5 minute data by adding

      timeframe = bt.TimeFrame.Minutes,
      compression = 5
      

      to the initialization of each data feed (in the GenericCSVData field). I was able to work with the 5 minute data, but had no luck when trying to change the compression to 30, 60, 240 as it would keep sampling the 5 minute data. I then looked into using the resampling feature as follows, in place of where cerebro.adddata() would be:

      cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression = 5) 
      

      I am now met by the following error:

      ---------------------------------------------------------------------------
      
      IndexError                                Traceback (most recent call last)
      
      <ipython-input-8-4abde8512761> in <module>()
          180     print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
          181 
      --> 182     cerebro.plot()
          183 
      
      ~\Anaconda3\lib\site-packages\backtrader\cerebro.py in plot(self, plotter, numfigs, iplot, start, end, width, height, dpi, tight, use, **kwargs)
      
          989                 rfig = plotter.plot(strat, figid=si * 100,
          990                                     numfigs=numfigs, iplot=iplot,
      --> 991                                     start=start, end=end, use=use)
          992                 # pfillers=pfillers2)
          993 
      
      
      
      ~\Anaconda3\lib\site-packages\backtrader\plot\plot.py in plot(self, strategy, figid, numfigs, iplot, start, end, **kwargs)
      
          207                         xtemp.append(dt)
          208 
      --> 209                     self.pinf.xstart = bisect.bisect_left(dts, xtemp[0])
          210                     self.pinf.xend = bisect.bisect_right(dts, xtemp[-1])
          211 
      
      
      IndexError: list index out of range
      

      I'm not quite sure where it's going sour since the two data sets have an identical index and I'm not changing the start/end parameters. I would really appreciate any advice. Thank you for your time.

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @guwop last edited by

        @guwop said in Resampling data, list index out of range (despite same index):

        to the initialization of each data feed (in the GenericCSVData field). I was able to work with the 5 minute data, but had no luck when trying to change the compression to 30, 60, 240 as it would keep sampling the 5 minute dat

        The platform doesn't know what your data is. You tell the platform the timeframe. There is no magic AI in the background looking over your data and activating resampling for you.

        @guwop said in Resampling data, list index out of range (despite same index):

        in place of where cerebro.adddata() would be:
        cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression = 5)

        Yes, this is in the documentation: Docs - Resampling

        @guwop said in Resampling data, list index out of range (despite same index):

        I'm not quite sure where it's going sour since the two data sets have an identical index and I'm not changing the start/end parameters. I would really appreciate any advice. Thank you for your time.

        The problem is with plotting. backtesting is finished and has worked, but the data cannot be synchronized for plotting. There are some cases that produce that behavior.

        G 2 Replies Last reply Reply Quote 0
        • G
          guwop @backtrader last edited by

          @backtrader, thank you for the explanation, I'll turn on analytics for these cases.

          1 Reply Last reply Reply Quote 0
          • G
            guwop @backtrader last edited by

            @backtrader, it actually seems as though there might be issues with the backtest when using resampledata(). As a basic form of analytics I am using the output of initial portfolio value and final portfolio value as taken from the quickstart page. When using adddata(), I get an output of 16% change in portfolio value, however, when I use resampledata() there is a 0% change in value...

            G 1 Reply Last reply Reply Quote 0
            • G
              guwop @guwop last edited by guwop

              @guwop, Apologies, I was using resampledata() when I should have been using replaydata()

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }