Skip to content

"Incorrect behavior of .expiration(0, 0) in Option Universe Selection" #2079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
thiryj opened this issue Mar 30, 2025 · 0 comments
Open

"Incorrect behavior of .expiration(0, 0) in Option Universe Selection" #2079

thiryj opened this issue Mar 30, 2025 · 0 comments

Comments

@thiryj
Copy link

thiryj commented Mar 30, 2025

Summary

The .expiration(0, 0) method in the Option Universe Selection filter does not select options expiring at the end of the current trading day. Instead, it selects options that have already expired at 0:00 AM on the current day. This contradicts the documentation and leads to incorrect option selection for 0DTE strategies.

Documentation Link

The issue occurs in the following documentation page:

https://www.lean.io/docs/v2/writing-algorithms/universes/option-filters#Expiration

Steps to Reproduce

  1. Create a QuantConnect algorithm that adds an Option universe for SPX.
  2. Use .set_filter() with a lambda function that includes .expiration(0, 0).
  3. In the OnData method, log the Expiry property of the selected option contracts.
  4. Run the algorithm for a period with 0DTE SPX options.
  5. Observe that the logged Expiry times are all at 0:00 AM on the current day.

Minimal Reproducible Code Example

from AlgorithmImports import *

class OptionExpiryTest(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2024, 6, 1)  
        index = self.add_index("SPX")
        self.spx_option = self.add_index_option(index.symbol,"SPXW")
        self.spx_option.set_filter(lambda universe: universe.include_weeklys().expiration(0, 0).strikes(-3,3))

    def on_data(self, data):
        chain = data.option_chains.get(self.spx_option.symbol)
        if not chain:
            return
        
        for option in chain:
            self.Log(f"Option Expiry: {option.expiry}")
        self.Quit()  # Stop after the first data point

Expected Behavior
The .expiration(0, 0) filter should select options that expire at the end of the current trading day, allowing for 0DTE strategies to function correctly.

Actual Behavior
The .expiration(0, 0) filter selects options that expired at 0:00 AM on the current day, making them unusable for trading.

Additional Information
This issue was discovered while attempting to implement an Iron Condor strategy. The incorrect filter behavior leads to selecting expired contracts, resulting in errors and incorrect trading decisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant