Scheduled events allow you to trigger code blocks for execution at specific times according to rules you set. This feature helps coordinate your algorithm activities and perform analysis at regular intervals; while letting the trading engine take care of market holidays.
The scheduling is set with two rules: the DateRules
and TimeRules
classes. The schedule manager takes one of each and executes an action code block:
Schedule.On(DateRules.On(2013, 10, 7), TimeRules.At(13, 0), () =>{
Debug("Specific Time: Fired at : " + Time);
});
The date rules can be specified as below:
Scheduled Events Date Rules | |
---|---|
DateRules.On(2013, 10, 7) |
On a specific date |
DateRules.EveryDay("SPY") |
Every trading day for SPY |
DateRules.Every(DayOfWeek.Monday, ...) |
On specific days of week |
DateRules.EveryDay() |
Every day |
DateRules.MonthStart("SPY") |
SPY trading start of each month |
The time rules trigger specify when on the day the event should be triggered. They can be specified as below:
Scheduled Events Time Rules | |
---|---|
TimeRules.At(13, 0) |
At a specific time, 1:00pm |
TimeRules.AfterMarketOpen("SPY", 10) |
Run 10 minutes after market open for SPY |
TimeRules.BeforeMarketClose("SPY", 10) |
Run 10 minutes before market close for SPY |
TimeRules.Every(TimeSpan.FromMinutes(10)) |
Every 10 minutes during day specified |
For a demonstration see the tutorial video below:
https://youtu.be/SUu4MKlm93I
Jared Broad
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!