Universe Selection

Options Universes


An Option Universe Selection model selects contracts for a set of Options.

Options Universe Selection

The OptionUniverseSelectionModel selects all the available contracts for the Equity Options, Index Options, and Future Options you specify. To use this model, provide a refreshInterval and a selector function. The refreshInterval defines the time period between refreshes. The selector function receives a DateTimedatetime object that represents the current Coordinated Universal Time (UTC) and returns a list of Symbol objects. The Symbol objects you return from the selector function are the Options of the universe.

AddUniverseSelection(new OptionUniverseSelectionModel(refreshInterval, optionChainSymbolSelector));
from Selection.OptionUniverseSelectionModel import OptionUniverseSelectionModel 

self.AddUniverseSelection(OptionUniverseSelectionModel(refreshInterval, optionChainSymbolSelector))

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
refreshIntervalTimeSpantimedeltaTime interval between universe refreshes
optionChainSymbolSelectorFunc<DateTime, IEnumerable<Symbol>>Callable[[datetime], List[Symbol]]A function that selects the Option symbols
universeSettingsUniverseSettingsUniverse settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removednullNone

If you don't provide a universeSettings argument, the algorithm.UniverseSettings is used by default.

public override void Initialize()
        new OptionUniverseSelectionModel(TimeSpan.FromDays(1), SelectOptionChainSymbols)

private IEnumerable<Symbol> SelectOptionChainSymbols(DateTime utcTime)
    // Equity Options example:
    //var tickers = new[] {"SPY", "QQQ", "TLT"};
    //return tickers.Select(ticker => QuantConnect.Symbol.Create(ticker, SecurityType.Option, Market.USA));

    // Index Options example:
    //var tickers = new[] {"VIX", "SPX"};
    //return tickers.Select(ticker => QuantConnect.Symbol.Create(ticker, SecurityType.IndexOption, Market.USA));

    // Future Options example:
    var futureSymbol = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
    var futureContractSymbols = FutureChainProvider.GetFutureContractList(futureSymbol, Time);
    foreach (var symbol in futureContractSymbols)
        yield return QuantConnect.Symbol.CreateCanonicalOption(symbol);
from Selection.OptionUniverseSelectionModel import OptionUniverseSelectionModel 

def Initialize(self) -> None:
    universe = OptionUniverseSelectionModel(timedelta(days=1), self.option_chain_symbol_selector)

def option_chain_symbol_selector(self, utc_time: datetime) -> List[Symbol]:
    # Equity Options example:
    #tickers = ["SPY", "QQQ", "TLT"]
    #return [Symbol.Create(ticker, SecurityType.Option, Market.USA) for ticker in tickers]

    # Index Options example:
    #tickers = ["VIX", "SPX"]
    #return [Symbol.Create(ticker, SecurityType.IndexOption, Market.USA) for ticker in tickers]

    # Future Options example:
    future_symbol = Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME)
    future_contract_symbols = self.FutureChainProvider.GetFutureContractList(future_symbol, self.Time)
    return [Symbol.CreateCanonicalOption(symbol) for symbol in future_contract_symbols]

To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.

This model uses the default Option filter, which returns all of the Option contracts. To use a different filter for the contracts, subclass the OptionUniverseSelectionModel and define a Filter method. The Filter method must accept and return an OptionFilterUniverse object. For a full example, see the BasicTemplateOptionsFrameworkAlgorithmBasicTemplateOptionsFrameworkAlgorithm.

Option Chained Universe Selection

An Option chained universe subscribes to Option contracts on the constituents of a US Equity universe.

AddUniverseOptions(universe, optionFilter);
self.AddUniverseOptions(universe, optionFilter)

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
universeUniverseThe universe to chain onto the Option Universe Selection model
optionFilterFunc<OptionFilterUniverse, OptionFilterUniverse>Callable[[OptionFilterUniverse], OptionFilterUniverse]The Option filter universe to use

The optionFilter function receives and returns an OptionFilterUniverse to select the Option contracts. The following table describes the methods of the OptionFilterUniverse class:

Strikes(int minStrike, int maxStrike)Strikes(minStrike: int, maxStrike: int)Selects contracts that are within minStrike strikes below the underlying price and maxStrike strikes above the underlying price
CallsOnly()Selects call contracts
PutsOnly()Selects put contracts
StandardsOnly()Selects standard contracts
IncludeWeeklys()Selects non-standard weeklys contracts
WeeklysOnly()Selects weekly contracts
FrontMonth()Selects the front month contract
BackMonths()Selects the non-front month contracts
BackMonth()Selects the back month contracts
Expiration(TimeSpan minExpiry, TimeSpan maxExpiry)Expiration(minExpiry: timedelta, maxExpiry: timedelta)Selects contracts that expire within a range of dates relative to the current day
Expiration(int minExpiryDays, int maxExpiryDays)Expiration(minExpiryDays: int, maxExpiryDays: int)Selects contracts that expire within a range of dates relative to the current day
Contracts(IEnumerable<Symbol> contracts)Contracts(contracts: List[Symbol])Selects a list of contracts
Contracts(Func<IEnumerable<Symbol>, IEnumerable< Symbol>> contractSelector)Contracts(contractSelector: callable[List[Symbol], List[Symbol]])Selects contracts that a selector function selects
OnlyApplyFilterAtMarketOpen()Instructs the engine to only filter contracts on the first time step of each market day
public override void Initialize()
    var universe = AddUniverse(Universe.DollarVolume.Top(10));
    AddUniverseOptions(universe, OptionFilterFunction);

private OptionFilterUniverse OptionFilterFunction(OptionFilterUniverse optionFilterUniverse)
    return optionFilterUniverse.Strikes(-2, +2).FrontMonth().CallsOnly();
def Initialize(self) -> None:
    universe = self.AddUniverse(self.Universe.DollarVolume.Top(10))
    self.AddUniverseOptions(universe, self.OptionFilterFunction)

def OptionFilterFunction(self, option_filter_universe: OptionFilterUniverse) -> OptionFilterUniverse:
    return option_filter_universe.Strikes(-2, +2).FrontMonth().CallsOnly()

To view the implementation of this model, see the LEAN GitHub repository.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: