Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion 03 Writing Algorithms/26 Scheduled Events/10 Examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'''
Expand Down
20 changes: 20 additions & 0 deletions Resources/scheduled-events/date-rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@
<code class="csharp">DateRules.WeekEnd(Symbol symbol, int daysOffset = 0)</code></td>
<td>Trigger an event on the last tradable date of each week for a specific symbol minus an offset.</td>
</tr>
<tr>
<td><code class="python">self.date_rules.quarter_start(days_offset: int = 0)</code>
<code class="csharp">DateRules.QuarterStart(int daysOffset = 0)</code></td>
<td>Trigger an event on the first day of each quarter plus an offset.</td>
</tr>
<tr>
<td><code class="python">self.date_rules.quarter_start(symbol: Symbol, days_offset: int = 0)</code>
<code class="csharp">DateRules.QuarterStart(Symbol symbol, int daysOffset = 0)</code></td>
<td>Trigger an event on the first tradable date of each quarter for a specific symbol plus an offset.</td>
</tr>
<tr>
<td><code class="python">self.date_rules.quarter_end(days_offset: int = 0)</code>
<code class="csharp">DateRules.QuarterEnd(int daysOffset = 0)</code></td>
<td>Trigger an event on the last day of each quarter minus an offset.</td>
</tr>
<tr>
<td><code class="python">self.date_rules.quarter_end(symbol: Symbol, days_offset: int = 0)</code>
<code class="csharp">DateRules.QuarterEnd(Symbol symbol, int daysOffset = 0)</code></td>
<td>Trigger an event on the last tradable date of each quarter for a specific symbol minus an offset.</td>
</tr>
<tr>
<td><code class="python">self.date_rules.year_start(days_offset: int = 0)</code>
<code class="csharp">DateRules.YearStart(int daysOffset = 0)</code></td>
Expand Down