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 data with timeframe.days at specific (non-midnight) time

    General Code/Help
    2
    6
    1061
    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.
    • A
      algoguy235 last edited by

      I'm interested in using an indicator that uses daily candles, not from 0:00a to 11:59p, but rather from 4:16p to 4:15p. Can I do this using the cerebro.resampledata(), perhaps with the boundoff parameter?

      If not, is there another way?

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

        Set the sessionend parameter of the data feed which is going to be resampled. It is a parameter for all data feeds, because it is inherited from the superclass.

        See Docs - Data Feeds Reference

        1 Reply Last reply Reply Quote 0
        • A
          algoguy235 last edited by algoguy235

          That worked perfectly, thanks @backtrader.

          It wasn't clear how sessionend and sessionstart parameters are used in other places in the engine. My next challenge is that I want to start the session at 600p and end at 415p. setting the sessionstart param did not solve this, My daily candles are still going form 415 to 415.

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

            @algoguy235 said in Resample data with timeframe.days at specific (non-midnight) time:

            My daily candles are still going form 415 to 415

            The best thing would be that you show what you do and how you come to the conclusion that the daily candle goes from 04:15 to 04:15.

            In any case your problem is probably the resolution of your timeframe. A sessionstart larger than a sessionend makes only sense when you have a sub-day timeframe. Else it would be a running-backwards session.

            1 Reply Last reply Reply Quote 0
            • A
              algoguy235 last edited by algoguy235

              @backtrader

              Is it possible to change the sessionend parameter in cerebro.resampledata?

                  cerebro = bt.Cerebro()
                  cerebro.addstrategy(strat)
              
                  data = btfeeds.GenericCSVData( # 1-min csv feed 
                                  dataname     = datapath,
                                  fromdate     = startDate_feed,
                                  todate       = endDate,
                                  nullvalue    = 0.0,
                                  openinterest = -1,
                                  timeframe    = bt.TimeFrame.Minutes,
                                  sessionend   = session_End,
                                  dtformat     = ('%m/%d/%Y'),
                                  tmformat     = ('%H:%M'),
                                  time=1, open=2, high=3, low=4, close=5, volume=6)
              
                  # Add the 1m Data Feed to Cerebro
                  cerebro.adddata(     data, name = 'a0_Hf') 
              
                  # create a daily data feed with standard session end time (session_End)
                  cerebro.resampledata(data, name = 'a0_d1a', timeframe = bt.TimeFrame.Days, compression = 1)
              
                  # create a daily data feed with a different session end time
                  cerebro.resampledata(data, name = 'a0_d1b', timeframe = bt.TimeFrame.Days, compression = 1, sessionend = datetime.time(14,15))
              

              I want two 1-day resampled feeds with different sessionend. One idea I had was to feed the CSV data in twice with the different sessionend. I think that would work, but I was hoping I could do this using only resample data. Thoughts?

              It seems the whole platform takes the sessionend parameter from the first feed, and ignores it later on, even if I leave it empty/default.

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

                A resampled version of a data feed must have the same sessionend as the original.

                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(); }); }