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/

    resample is not working

    General Code/Help
    2
    6
    341
    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.
    • thrall chen
      thrall chen last edited by

      15f07e99-aefe-4055-9d19-8bfecc8b3a93-image.png ![alt text](image url)

      I'm tring to resmaple 1 minute bar to 10 minutes, but the line not update after resampled

      thrall chen 1 Reply Last reply Reply Quote 0
      • thrall chen
        thrall chen @thrall chen last edited by

        dcebcfab-3b2b-44c0-9bd1-a8b93e2b57b4-image.png

        The output

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

          RESAMPLE IS WORKING. When your 1-min gets to 16:00:00 (from 15:59:00) the 10-min resampled data moves from 15:50:00 to 16:00:00.

          And every 10 minutes, history repeats itself.

          As expected.

          Note: I imagine there is a world conspiracy somewhere and I missed it by virtue of age. Because pasting images it is a lot more difficult than pasting text, which can quoted.

          thrall chen 2 Replies Last reply Reply Quote 1
          • thrall chen
            thrall chen @backtrader last edited by

            @backtrader

            class MyCSVData(bt.feeds.GenericCSVData):
                def _loadline(self, linetokens):
                    itoken = iter(linetokens)
            
                    dttxt = next(itoken)  # Format is YYYY-MM-DD - skip char 4 and 7
                    dt = bt.date2num(datetimeParser.parse(dttxt))
            
                    self.lines.datetime[0] = dt
                    self.lines.open[0] = float(next(itoken))
                    self.lines.high[0] = float(next(itoken))
                    self.lines.low[0] = float(next(itoken))
                    self.lines.close[0] = float(next(itoken))
                    self.lines.volume[0] = float(next(itoken))
                    self.lines.openinterest[0] = 0
                    return True
            
            
            class Test(bt.Strategy):
                def next(self):
                    print(bt.num2date(self.data.datetime[0]), self.data.close[0], '      ' , bt.num2date(self.data1.datetime[0]), self.data1.close[0])
            
            cerebro = bt.Cerebro()
            cerebro.broker.set_cash(15000000)
            csv = '20181010-1013.csv'
            # data0 = MyCSVData(dataname=csv, timeframe=bt.TimeFrame.Minutes)
            data0 = bt.feeds.GenericCSVData(dataname=csv, timeframe=bt.TimeFrame.Minutes, openinterest=-1)
            
            cerebro.adddata(data0)
            # cerebro.adddata(data1)
            cerebro.resampledata(data0, compression=10, timeframe=bt.TimeFrame.Minutes)
            

            The datetime looks the same. And i had try rightedge=False when calling resample, But the results have not changed.

            Thanks for your help!

            1 Reply Last reply Reply Quote 0
            • thrall chen
              thrall chen @backtrader last edited by

              The 10 minutes bar always equals to the first 1 minutes bar, open close high low and volume all are not updated.

              I don't know where there is the problem, I have been delayed by this problem for 2 days.

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

                A bar can only be resampled when the period is complete. The bar does not equal the first 1-minute bar. The timestamp is the same until the next resample cycle is complete.

                It would seem you are looking for replay, which is something different. Take a break and try to understand the concepts.

                • Docs - Data Replay

                • Docs - Data Resample

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors