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/

    Getting errors when using resample

    General Code/Help
    2
    2
    339
    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.
    • P
      PhillBeck last edited by

      I have data in 1H intervals, and I'm trying to resample it to 1D.

      My data looks like this:

                         time   open   high    low  close   volume
      0   2018-07-02 11:00:00  48.89  49.05  48.54  49.03  1792700
      1   2018-07-02 12:00:00  49.03  49.19  48.84  49.07   941700
      2   2018-07-02 13:00:00  49.07  49.13  48.70  48.90   736600
      3   2018-07-02 14:00:00  48.90  48.91  48.70  48.79   534500
      4   2018-07-02 15:00:00  48.79  48.81  48.52  48.66  1296200
      5   2018-07-02 16:00:00  48.66  48.82  48.61  48.62   910300
      6   2018-07-02 17:00:00  48.62  48.86  48.60  48.69  1199300
      7   2018-07-02 18:00:00  48.69  48.90  48.68  48.90   811500
      8   2018-07-03 11:00:00  49.30  49.49  48.89  48.99  1908400
      9   2018-07-03 12:00:00  48.99  49.10  48.45  48.71  2134600
      

      The code that loads it into Cerebro is:

      data_hour = btfeeds.PandasData(
              dataname=df,
      
              fromdate=datetime(2018, 7, 3),
              todate=datetime(2018, 10, 24),
      
              datetime=0,
              open=1,
              high=2,
              low=3,
              close=4,
              volume=5,
              openinterest=-1
          )
      
          cerebro = bt.Cerebro()
      
          cerebro.adddata(data_hour)
          cerebro.resampledata(data_hour, timeframe=bt.TimeFrame.Weeks, compression=1)
      

      and my next function is just a pass.

      Still, I get the error:

      Traceback (most recent call last):
        File "test.py", line 65, in <module>
          cerebro.run()
        File "~/miniconda3/envs/algo_testing/lib/python3.6/site-packages/backtrader/cerebro.py", line 1127, in run
          runstrat = self.runstrategies(iterstrat)
        File "~/miniconda3/envs/algo_testing/lib/python3.6/site-packages/backtrader/cerebro.py", line 1298, in runstrategies
          self._runnext(runstrats)
        File "~/miniconda3/envs/algo_testing/lib/python3.6/site-packages/backtrader/cerebro.py", line 1557, in _runnext
          dt0 = min((d for i, d in enumerate(dts)
      ValueError: min() arg is an empty sequence
      

      When I change my next to print(self.datetime.date(ago=0)), it prints the dates up to the second to last one, and then it fails.

      Can anyone help me?

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

        @phillbeck said in Getting errors when using resample:

        I have data in 1H intervals

        Your data may be 1-hour, but where do you tell the platform that it is so?

        @phillbeck said in Getting errors when using resample:

        data_hour = btfeeds.PandasData(
                dataname=df,
        
                fromdate=datetime(2018, 7, 3),
                todate=datetime(2018, 10, 24),
        
                datetime=0,
                open=1,
                high=2,
                low=3,
                close=4,
                volume=5,
                openinterest=-1
            )
        

        There is no artificial intelligence there to parse your data and understand that it is 1-hour.

        You should clearly state with the timeframe and compression parameters what your data is. See Community - FAQ

        @phillbeck said in Getting errors when using resample:

        and I'm trying to resample it to 1D.

        Apparently not.

        @phillbeck said in Getting errors when using resample:

            cerebro.resampledata(data_hour, timeframe=bt.TimeFrame.Weeks, compression=1)
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors