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/

    Is it possible to backtest minute data with a lunch break?

    General Discussion
    3
    3
    603
    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.
    • K
      kelvinho8 last edited by kelvinho8

      Hi pros,

      I'm looking for a backtester that can help me to backtest minute data with a lunch break (the stock market is closed from 11:31 to 12:59 at weekdays). Thus, I'd like to clarify if BackTrader supports this required market trading datetime period before using it. If so, could you show me the way how to do it?

      Many thanks and have a good day!!!

      Kelvin

      =================================
      I've read the thread below and sort of know how to apply minute data
      https://community.backtrader.com/topic/244/backtesting-1-minute-data

      # Data feed kwargs
      kwargs = dict(
          timeframe=bt.TimeFrame.Minutes,
          compression=5,
          sessionstart=datetime.time(9, 0),
          sessionend=datetime.time(17, 30),
      )
      1 Reply Last reply Reply Quote 0
      • N
        nooby_mcnoob last edited by

        You'd do something like this:

        class MyStrategy(...):
          def next(self):
            now = self.data0.datetime.datetime(0)
            if now.time() >= datetime.time(11,31) and now.time() <= datetime.time(12,59):
               ... your logic here ...
        
        1 Reply Last reply Reply Quote 1
        • B
          backtrader administrators last edited by

          I wonder if I would have come to such a simple an elegant solution so quickly. The only contribution I could think of is to use the simplification in the comparison that Python offers

          class MyStrategy(...):
            def next(self):
              timenow = self.data0.datetime.time(0)
              if datetime.time(11, 31) <= timenow <= datetime.time(12, 59):
                 ... your logic here ...
          

          Storing the time instances would be wise to avoid creation and recreation of the instances.

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