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/

    How does compression work when resampling feed data (...and I have read the docs)

    Indicators/Strategies/Analyzers
    2
    2
    1070
    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.
    • S
      Søren Pallesen last edited by Søren Pallesen

      Reading the documentation/examples and studying community posts on resampling I still have a few questions. Mainly related to how compression in the feed relates to compression in resampledata and the specific role of sessionstart/sessionend.

      Question 1: Im loading 1 hour bar data. Can I resample from 1 hour bars to 90 minute bars, like this?:

      data = bt.feeds.GenericCSVData(
          dataname='./data/VXX-1h-2016-08-09us.csv', #1 hour bars
          timeframe=bt.TimeFrame.Minutes, 
          compression=60,
          sessionstart=datetime.time(9, 30),
          sessionend=datetime.time(15, 0))
      
      #souce resolution is a higher timeframe than destination resolution - does that work?
      cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=90)
      

      Question 2: Im loading 15min bar data. Can i resample from 15min bars to 120min bars like this?:

      data = bt.feeds.GenericCSVData(
          dataname='./data/VXX-15m-2016-08-09us.csv', #15 minute bars
          timeframe=bt.TimeFrame.Minutes, 
          compression=15,
          sessionstart=datetime.time(9, 30),
          sessionend=datetime.time(16, 0))
      
      #souce resolution is divisible with destination resolution - is that a requirement?
      cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=120)
      

      Question 3: Im loading 15min bar data. Can i resample from 15min bars to 50min bars like this?:

      data = bt.feeds.GenericCSVData(
          dataname='./data/VXX-15m-2016-08-09us.csv', #15 minute bars
          timeframe=bt.TimeFrame.Minutes, 
          compression=15,
          sessionstart=datetime.time(9, 30),
          sessionend=datetime.time(16, 0))
      
      #souce resolution is indivisible with destination resolution - does that work?
      cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=50)
      

      Question 4: Using NASDAQ as an example trading session starts 9.30 and ends 16.00 and my feed data consists of 1 hour bars with first daily bar at 10.00 last daily bar at 15.00. Should sessionstart and sessionend be set:

          #the data's trading hours
          sessionstart=datetime.time(10, 0),
          sessionend=datetime.time(15, 0)
      

      Or:

          #the exchange's actual trading hours
          sessionstart=datetime.time(9, 30),
          sessionend=datetime.time(16, 0)
      

      Also if possible please explain the role og sessionstart and sessionend, like what does it do? And should always set them when loading data?

      Thx in advance :-)

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @Søren Pallesen last edited by

        @søren-pallesen said in How does compression work when resampling feed data (...and I have read the docs):

        Question 1: Im loading 1 hour bar data. Can I resample from 1 hour bars to 90 minute bars, like this?:

        Sorry but it would be a miracle to get a meaningful compression from 1-hour (i.e.: 60-minutes) to 90-minutes. Common sense and math dictate that you need a divisor of 90 to resample up to 90-minutes

        @søren-pallesen said in How does compression work when resampling feed data (...and I have read the docs):

        #souce resolution is a higher timeframe than destination resolution - does that work?
        

        And no: 1-hour is not higher than 90-minutes

        @søren-pallesen said in How does compression work when resampling feed data (...and I have read the docs):

        Question 2: Im loading 15min bar data. Can i resample from 15min bars to 120min bars like this?:

        120 / 15 = 8. Yes.

        @søren-pallesen said in How does compression work when resampling feed data (...and I have read the docs):

        Question 3: Im loading 15min bar data. Can i resample from 15min bars to 50min bars like this?:

        Go back to the answer for question 1.

        @søren-pallesen said in How does compression work when resampling feed data (...and I have read the docs):

        Also if possible please explain the role og sessionstart and sessionend, like what does it do? And should always set them when loading data?

        They let the resampling code know when a new session has started or ended to avoid working directly with day boundaries.

        You should use 09:30 if it does start at 09:30

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