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 weekly data in next(self) when data source is sparse hourly data

    Indicators/Strategies/Analyzers
    3
    9
    1101
    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
      paindemie last edited by

      My data source is hourly with many hours missing but I only need weekly data in my custom indicator/strategy. I used timeframe=bt.TimeFrame.Weeks when calling bt.feeds.GenericCSVData(..) but I'm still getting every tick from my hourly data in the next() method, where I only want one value a week (same for my strategy where every data point should be weekly), how can I achieve that? Thanks.

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

        Docs - Resample

        1 Reply Last reply Reply Quote 0
        • P
          paindemie last edited by

          I did use timeframe=bt.TimeFrame.Weeks, still getting every point of data, one after another in the next

          A 1 Reply Last reply Reply Quote 0
          • A
            ab_trader @paindemie last edited by ab_trader

            @paindemie please show the code. if you call correctly cerebro.resampledata(data, **kwargs) it should be weekly bars returned.

            • If my answer helped, hit reputation up arrow at lower right corner of the post.
            • Python Debugging With Pdb
            • New to python and bt - check this out
            1 Reply Last reply Reply Quote 0
            • P
              paindemie last edited by

              data = bt.feeds.GenericCSVData(
                  dataname=data_source,
                  fromdate=start,
                  todate=stop,
                  nullvalue=0.0,
                  dtformat=('%Y-%m-%d %H:%M:%S'),
                  tmformat=('%Y-%m-%d %H:%M:%S'),
                  openinterest=-1,
                  timeframe=bt.TimeFrame.Days,
                  compression=1,
                  plot=False)
              
              
              # Create a cerebro entity
              cerebro = bt.Cerebro(stdstats=True)
              
              #cerebro.adddata(data)
              cerebro.resampledata(data, bt.TimeFrame.Weeks)
              

              in next self.data[-1] is the DAY before self.data[0] where it should be 7 days before if Im not missing smith obvious..

              B 1 Reply Last reply Reply Quote 0
              • A
                ab_trader last edited by

                All examples that I've seen use the following syntax:

                cerebro.resampledata(data, timeframe=bt.TimeFrame.Weeks)
                

                Maybe resampledata method doesn't recognize timeframe in your case.

                • If my answer helped, hit reputation up arrow at lower right corner of the post.
                • Python Debugging With Pdb
                • New to python and bt - check this out
                B 1 Reply Last reply Reply Quote 1
                • B
                  backtrader administrators @paindemie last edited by

                  @paindemie said in Getting weekly data in next(self) when data source is sparse hourly data:

                  cerebro.resampledata(data, bt.TimeFrame.Weeks)
                  

                  That won't resample to anything unless you use the right syntax (as pointed out by @ab_trader)

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

                    @ab_trader said in Getting weekly data in next(self) when data source is sparse hourly data:

                    Maybe resampledata method doesn't recognize timeframe in your case.

                    It doesn't because the timeframe named argument is not being provided.

                    1 Reply Last reply Reply Quote 0
                    • P
                      paindemie last edited by

                      Aaah got it thanks

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