diff --git a/03 Writing Algorithms/26 Scheduled Events/10 Examples.html b/03 Writing Algorithms/26 Scheduled Events/10 Examples.html index dc9a54b09d..b1872279f4 100644 --- a/03 Writing Algorithms/26 Scheduled Events/10 Examples.html +++ b/03 Writing Algorithms/26 Scheduled Events/10 Examples.html @@ -86,12 +86,26 @@ TimeRules.AfterMarketOpen("SPY", 5), RebalancingCode); - // Schedule an event to fire at the end of the week, the symbol is optional. + // Schedule an event to fire at the end of the week, the symbol is optional. // If specified, it will fire the last trading day for that symbol of the week. // Otherwise, it will fire on the first day of the week. Schedule.On(DateRules.WeekEnd("SPY"), TimeRules.BeforeMarketClose("SPY", 5), RebalancingCode); + + // Schedule an event to fire at the beginning of the quarter, the symbol is optional. + // If specified, it will fire the first trading day for that symbol of the quarter. + // Otherwise, it will fire on the first day of the quarter. + Schedule.On(DateRules.QuarterStart("SPY"), + TimeRules.AfterMarketOpen("SPY"), + RebalancingCode); + + // Schedule an event to fire at the end of the quarter, the symbol is optional. + // If specified, it will fire the last trading day for that symbol of the quarter. + // Otherwise, it will fire on the last day of the quarter. + Schedule.On(DateRules.QuarterEnd("SPY"), + TimeRules.BeforeMarketClose("SPY"), + RebalancingCode); } // The following methods are not defined in Initialize: @@ -193,6 +207,20 @@ self.time_rules.before_market_close("SPY", 5), self._rebalancing_code) + # Schedule an event to fire at the beginning of the quarter, the symbol is optional. + # If specified, it will fire the first trading day for that symbol of the quarter. + # Otherwise, it will fire on the first day of the quarter. + self.schedule.on(self.date_rules.quarter_start("SPY"), + self.time_rules.after_market_open("SPY"), + self._rebalancing_code) + + # Schedule an event to fire at the end of the quarter, the symbol is optional. + # If specified, it will fire the last trading day for that symbol of the quarter. + # Otherwise, it will fire on the last day of the quarter. + self.schedule.on(self.date_rules.quarter_end("SPY"), + self.time_rules.before_market_close("SPY"), + self._rebalancing_code) + # The following methods from examples above should be defined in the algorithm body. def _liquidate_unrealized_losses(self) -> None: ''' if we have over 1000 dollars in unrealized losses, liquidate''' diff --git a/Resources/scheduled-events/date-rules.html b/Resources/scheduled-events/date-rules.html index 320ed77570..f7c384ab1d 100644 --- a/Resources/scheduled-events/date-rules.html +++ b/Resources/scheduled-events/date-rules.html @@ -78,6 +78,26 @@ DateRules.WeekEnd(Symbol symbol, int daysOffset = 0) Trigger an event on the last tradable date of each week for a specific symbol minus an offset. + + self.date_rules.quarter_start(days_offset: int = 0) + DateRules.QuarterStart(int daysOffset = 0) + Trigger an event on the first day of each quarter plus an offset. + + + self.date_rules.quarter_start(symbol: Symbol, days_offset: int = 0) + DateRules.QuarterStart(Symbol symbol, int daysOffset = 0) + Trigger an event on the first tradable date of each quarter for a specific symbol plus an offset. + + + self.date_rules.quarter_end(days_offset: int = 0) + DateRules.QuarterEnd(int daysOffset = 0) + Trigger an event on the last day of each quarter minus an offset. + + + self.date_rules.quarter_end(symbol: Symbol, days_offset: int = 0) + DateRules.QuarterEnd(Symbol symbol, int daysOffset = 0) + Trigger an event on the last tradable date of each quarter for a specific symbol minus an offset. + self.date_rules.year_start(days_offset: int = 0) DateRules.YearStart(int daysOffset = 0)