Count option expirations on their last trading date - #9796
Open
jhonabreul wants to merge 11 commits into
Open
jhonabreul wants to merge 11 commits into
jhonabreul wants to merge 11 commits into
Conversation
at(), closest_expiry(), select() and days_to_expiry count Saturday and holiday expiries on the previous trading day, matching the shared filters.
Equity options listed before February 2015 carry the OCC Saturday expiration date but stop trading on the Friday, and some weeklies are listed on holidays. ContractSecurityFilterUniverse.GetLastTradingDate feeds Expiration(), the option base moves non trading dates back to the previous open day, memoized per date, and the strategy pickers use the same date, so expiration(0, 0) selects a 0 DTE contract on its last trading day.
…ver holiday expiries
…ding the day before their AM settlement
…ndex option selection expects
…t, as the exchange and the brokerage mapping do
…he universe exchange hours
…p the last resolved expiration
Martin-Molinero
approved these changes
Sep 16, 2026
… hand them to its filter universe
…cts and chains read them without a cast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The option expiration filters count days to the expiration date. Contracts dated on a Saturday or a holiday stop trading the previous open day, so
zero_dte()missed them on that day.What changes:
ContractSecurityFilterUniverse.Expiration(min, max)compares a new virtualGetLastTradingDate(contract), default the expiration date, so futures keep their behavior.OptionFilterUniverseoverrides it:OptionSymbol.GetLastDayOfTradingfor equity options, the expiration date for index and future options.OptionSymbol.GetLastDayOfTradinggains an overload taking the exchange hours. The universe passes its own and keeps the last resolved expiration, since contracts come grouped by it.option_chain()'s lookup, and hand them to the chain filters anddays_to_expiry.zero_dte(),expiration(days, days)andexpiration(timedelta, timedelta)follow, on the universe and the chain.min_days_till_expiryuses the same date, sonaked_call(0)on the last trading date picks the contract dated the next day.OptionContract.days_to_expirycounts to the last trading date, matching the filters.expiring_after(),expiring_before()andexpiration(dates)keep comparing the expiration date itself.Related Issue
N/A
Motivation and Context
An option dated on a Saturday or a holiday is a 0 DTE contract on its last trading date, which is when algorithms look for it. Counting to the calendar date hid it for a day and shifted every relative expiration window.
Requires Documentation Change
Yes: the relative expiration filters and
days_to_expirycount to the last trading date.How Has This Been Tested?
OptionChainTests.ExpirationFilterCountsSaturdayExpiriesOnTheirLastTradingDate: 2012 Saturday expiries are 0 DTE on the Friday, universe and chain, including after Good Friday.OptionChainTests.StrategyFiltersCountSaturdayExpiriesOnTheirLastTradingDate:naked_call(min_days)picks the Saturday-dated contract on its last trading date.OptionChainTests.ZeroDteCountsHolidayExpiriesOnThePreviousTradingDate: five holiday expiries are 0 DTE the previous trading date and 1 DTE the day before. All fail on master.OptionChainTests.ZeroDteCountsIndexAndFutureOptionsOnTheirExpirationDate: SPX, SPXW and an ES future option are 0 DTE on their expiration date, on the universe, the chain anddays_to_expiry.OptionChainTests.ChainBuiltWithExchangeHoursCountsSaturdayExpiriesOnTheFriday: the walk-back runs on the hours the chain was built with, for filters anddays_to_expiry, also after filtering.OptionFilterTests: the weekend expiries 8 and 9 days out now count as 7 on a Friday, so the 7-day window keeps them.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>