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 do I restrict data to market open hours

    General Code/Help
    4
    6
    765
    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.
    • C
      Callan99 last edited by

      I would like to backtest my csv data and only use the market hours of 10am to 3pm and ignore other times.

      I have tried restricting the import of csv data with sessionstart and sessionend but it doesn't work?

      Any suggestions welcome

      Thanks

      '''

      Add our data

      data = bt.feeds.GenericCSVData(dataname= f'{PATH}SPX500_USD_ALL.csv',
      datetime=0,
      fromdate=datetime.datetime(2018,12,21),
      #todate=datetime.datetime(2018,6,10),
      sessionstart=datetime.time(10),
      sessionend=datetime.time(15),
      open=2,
      high=3,
      low=4,
      close=5,
      openinterest=-1,
      time=-1,
      volume=1,
      # Need code below to display time
      timeframe=bt.TimeFrame.Ticks,
      dtformat="%Y-%m-%d %H:%M:%S")

      '''

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

        @callan99 said in How do I restrict data to market open hours:

        '''
        

        is not

            ```
        

        @callan99 said in How do I restrict data to market open hours:

        I have tried restricting the import of csv data with sessionstart and sessionend

        Because the parameters sessionstart and sessionend are there to inform the engine and let it know when things like resampling should fold and when timers have to be called. They will not automagically filter your data.

        Apply a filter in any case

        • Docs - Filters
        • Docs - Filters Reference and use the SessionFilter
        1 Reply Last reply Reply Quote 1
        • C
          Callan99 last edited by

          Many thanks.. The filters work perfectly

          I love this product!!!

          Keep up the good work, apologies for confusing my ''' and ```

          Cheers

          Jeffrey C F Wong 1 Reply Last reply Reply Quote 0
          • Jeffrey C F Wong
            Jeffrey C F Wong @Callan99 last edited by

            @Callan99, I am stuck in the same situation as you from a few years back and would like to see an example of how you used the SessionFilter to process the csv for specified session if possible. Thanks!

            1 Reply Last reply Reply Quote 0
            • vladisld
              vladisld last edited by

              Take a look at:
              https://community.backtrader.com/topic/1598/ib-live-trading-datafeed-on-rth

              Jeffrey C F Wong 1 Reply Last reply Reply Quote 1
              • Jeffrey C F Wong
                Jeffrey C F Wong @vladisld last edited by

                @vladisld awesome, i got my codes to work, thank you for sharing the link :)

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