Is it possible to backtest minute data with a lunch break?
kelvinho8 last edited by kelvinho8
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!!!
I've read the thread below and sort of know how to apply minute data
# Data feed kwargs kwargs = dict( timeframe=bt.TimeFrame.Minutes, compression=5, sessionstart=datetime.time(9, 0), sessionend=datetime.time(17, 30), )
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 ...
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 ...
timeinstances would be wise to avoid creation and recreation of the instances.