trophy

Long Only, ETF Alpha Streams Competition with $27,500 Prize Pool

Back

Timing of Events around market open

I was scheduling an event around market open and noticed that some data points were not being updated as expected.  Specifically, at market open some data from a prior day's EOD event was not updated, and even at one minute after the open an indicator with daily resolution was not updated. 

Ultimately I determined the events fire in this order:  Market Open + 0 minutes fires first, followed by the EOD event from the prior day, Then events 1 and 2 minutes after market open.  An RSI event with daily resolution (and others with daily resolution) was not updated until Market Open + 2 minutes.  This means that any trading right at market open using an indicator with daily resolution would be using day-old data.

Pertinent lines from my code:

self.sym = 'SPY'
self.AddEquity(self.sym, Resolution.Minute)
self.myRSI = self.RSI(self.sym, 14, MovingAverageType.Wilders, Resolution.Daily)

self.Schedule.On(self.DateRules.EveryDay(self.sym), \
self.TimeRules.AfterMarketOpen(self.sym, 0),\
Action(self.MktOpen0))

self.Schedule.On(self.DateRules.EveryDay(self.sym), \
self.TimeRules.AfterMarketOpen(self.sym, 1),\
Action(self.MktOpen1))

self.Schedule.On(self.DateRules.EveryDay(self.sym), \
self.TimeRules.AfterMarketOpen(self.sym, 2),\
Action(self.MktOpen2))

def OnEndOfDay(self):
self.prPrice = self.Securities[self.sym].Price # record prior close for tomorrow
prc = self.Securities[self.sym].Price
self.Log("EOD: "+ str(self.Time)+" : Price="+str(prc)+", PrevClose="+str(self.prPrice)+", RSI="+str(self.myRSI))

# the three MktOpen functions just log a line like the one in the EOD routine.

The following is from the log file for 4/1/2019:

2019-04-01 09:31:00 Open+0: 2019-04-01 09:30:00 : Price=282.62, PrevClose=280.78, RSI=48.12869
2019-04-01 09:31:00 EOD: 2019-03-29 23:58:00 : Price=282.62, PrevClose=282.62, RSI=48.12869
2019-04-01 09:31:00 Open+1: 2019-04-01 09:31:00 : Price=284.77, PrevClose=282.62, RSI=48.12869
2019-04-01 09:32:00 Open+2: 2019-04-01 09:32:00 : Price=284.68, PrevClose=282.62, RSI=53.71998

Note the order the events fire and that RSI is not updated until Open + 2 minutes. 

I recognize the first opportunity to trade is at 9:31, but I would have expected the EOD event to fire first and for indicators with a daily resolution to be updated prior to Market Open events.  This may be a bug, or it may be as designed,  Regardless it could cause issues with trading right at the open.

Thanks for the system, it is pretty amazing ( even when sometimes puzzling ).

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Hugh.

Thank you for your insight. The value of the RSI indicator is up to date in the method OnData(), where you can also implement your trading logic. You can verify this by printing out the RSI indicator value and compare it to the output from your functions MktOpen0 - MktOpen2:

# In OnData()
if self.myRSI.IsReady:
self.Log(self.myRSI.Current.Value)

I suggest you use consolidators when using different data resolution for an indicator and security. Check out this documentation section on consolidators for more information.

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed