I am running into something odd - wondering if anyone has seen this. I run the following code
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.AfterMarketOpen("SPY", -120), () =>
{
Log("EveryDay.SPY 120 min before open: Fired at: " + Time);
});
and i'm getting this log where the Time and log time don't match.
2020-05-04 09:31:00 EveryDay.SPY 120 min before open: Fired at: 5/4/2020 7:30:00 AM
Confusing me!
Adam W
I have come across this a few times as well. I think it is because any messages sent for logging outside market hours are only printed out when the market actually opens and data is received, but pre-market scheduled functions are still called correctly.
Rahul Chowdhury
Hey Stephen,
Although the scheduled event is set to fire at 7:30 AM, the event does not fire at that time because there is no data at that time. Instead the algorithm fires the scheduled event once there is data when the market opens.
Although the event fires at a later time, the algorithm passes the scheduled time as algorithm.Time into the event, which is why the time stamp 7:30:00 AM does not reflect the log timestamp.
If we use extended market hours data, we'll see that the log message times are now aligned with the scheduled event times. This means our scheduled events are firing on time.
AddEquity("SPY", Resolution.Minute, Market.USA, true, 1, true);
Keep in mind, that in live trading, it does not matter which datafeed you use; your scheduled events will fire on time.
Best
Rahul
Adam W
Hi Rahul,
Just to clarify - since the scheduled event is fired only when data streams at market open, will .OnData() calls be halted or called in a separate thread simultaeneously?Â
For instance:
def Initialize(self):
  self.someVar = 0.5
  self.Schedule.On(self.DateRules.EveryDay("SPY"),
              self.TimeRules.At(7,30),
              self.MyFunc)
def MyFunc(self):
  """
  Some computationally expensive stuff here
  """
  time.sleep(900)
  self.someVar = 0.8 # Calculated in MyFunc
def OnData(self):
  self.SetHoldings("SPY", self.someVar)
Since MyFunc takes 15 minutes to run (and is delayed to 9:30), does this imply that by default OnData will be using the "pre-scheduled event" value of someVar=0.5 between 9:30-9:45 algorithm time instead of 0.8?
Stephen
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!