Index Options

Requesting Data

Introduction

Request Index Options data in your algorithm to receive a feed of contract prices in the OnData method. For more information about the specific dataset we use for backtests, see the US Index Options dataset listing.

Create Subscriptions

Before you can subscribe to an Index Option contract, you must configure the underlying Index and get the contract Symbol.

Configure the Underlying Index

In the Initialize method, subscribe to the underlying Index.

_symbol = AddIndex("SPX").Symbol;
self.symbol = self.AddIndex("SPX").Symbol

To override the initial guess of implied volatility, set and warm up the underlying volatility model.

Get Contract Symbols

To get Index Option contract Symbol objects, call the CreateOption method or use the OptionChainProvider. If you use the CreateOption method, you need to know the specific contract details.

_symbol = QuantConnect.Symbol.Create("SPX", SecurityType.Index, Market.USA);

// Standard contracts
_contractSymbol = QuantConnect.Symbol.CreateOption(_symbol, Market.USA,
    OptionStyle.European, OptionRight.Call, 3650, new DateTime(2022, 6, 17));

// Weekly contracts
_weeklyContractSymbol = QuantConnect.Symbol.CreateOption(_symbol, "SPXW", Market.USA,
    OptionStyle.European, OptionRight.Call, 3650, new DateTime(2022, 6, 17));
self.symbol = Symbol.Create("SPX", SecurityType.Index, Market.USA)

# Standard contracts
self.contract_symbol = Symbol.CreateOption(self.symbol, Market.USA,
    OptionStyle.European, OptionRight.Call, 3650, datetime(2022, 6, 17))

# Weekly contracts
self.weekly_contract_symbol = Symbol.CreateOption(self.symbol, "SPXW", Market.USA,
    OptionStyle.European, OptionRight.Call, 3650, datetime(2022, 6, 17))

Another way to get an Index Option contract Symbol is to use the OptionChainProvider. The GetOptionContractList method of OptionChainProvider returns a list of Symbol objects that reference the available Option contracts for a given underlying Index on a given date. To filter and select contracts, you can use the following properties of each Symbol object:

PropertyDescription
ID.DateThe expiration date of the contract.
ID.StrikePriceThe strike price of the contract.
ID.OptionRight The contract type. The OptionRight enumeration has the following members:
ID.OptionStyle The contract style. The OptionStyle enumeration has the following members:
var contractSymbols = OptionChainProvider.GetOptionContractList(_symbol, Time);
var expiry = contractSymbols.Select(symbol => symbol.ID.Date).Min();
var filteredSymbols = contractSymbols.Where(symbol => symbol.ID.Date == expiry && symbol.ID.OptionRight == OptionRight.Call);
_contractSymbol = filteredSymbols.OrderByDescending(symbol => symbol.ID.StrikePrice).Last();
contract_symbols = self.OptionChainProvider.GetOptionContractList(self.symbol, self.Time)
expiry = min([symbol.ID.Date for symbol in contract_symbols])
filtered_symbols = [symbol for symbol in contract_symbols if symbol.ID.Date == expiry and symbol.ID.OptionRight == OptionRight.Call]
self.contract_symbol = sorted(filtered_symbols, key=lambda symbol: symbol.ID.StrikePrice)[0]

The GetOptionContractList isn't currently fully functional for weekly contracts. To track our progress of updating it, subscribe to GitHub Issue #6872.

Subscribe to Contracts

To create an Index Option contract subscription, pass the contract Symbol to the AddIndexOptionContract method. Save a reference to the contract Symbol so you can easily access the contract in the OptionChain that LEAN passes to the OnData method. To override the default pricing model of the Option, set a pricing model.

var option = AddIndexOptionContract(_contractSymbol);
option.PriceModel = OptionPriceModels.BlackScholes();
option = self.AddIndexOptionContract(self.contract_symbol)
option.PriceModel = OptionPriceModels.BlackScholes()

The AddIndexOptionContract method creates a subscription for a single Index Option contract and adds it to your user-defined universe. To create a dynamic universe of Index Option contracts, add an Index Option universe.

Warm Up Contract Prices

If you subscribe to an Index Option contract with AddIndexOptionContract, you'll need to wait until the next Slice to receive data and trade the contract. To trade the contract in the same time step you subscribe to the contract, set the current price of the contract in a security initializer.

var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, seeder, this));
seeder = FuncSecuritySeeder(self.GetLastKnownPrices)
self.SetSecurityInitializer(BrokerageModelSecurityInitializer(self.BrokerageModel, seeder, self))

Supported Assets

To view the supported assets in the US Index Options dataset, see Supported Assets.

Resolutions

The following table shows the available resolutions and data formats for Index Option contract subscriptions:

ResolutionTradeBarQuoteBarTrade TickQuote Tick
Tick

Second

Minutegreen checkgreen check
Hourgreen checkgreen check
Dailygreen checkgreen check

The default resolution for Index Option subscriptions is Resolution.Minute. To change the resolution, pass a resolution argument to the AddIndexOptionContract method.

AddIndexOptionContract(_contractSymbol, Resolution.Hour);
self.AddIndexOptionContract(self.contract_symbol, Resolution.Hour)

To create custom resolution periods, see Consolidating Data.

Supported Markets

The following Market enumeration members are available for Index Options:

You don't need to pass a Market argument to the AddIndexOptionContract method because the contract Symbol already contains the market.

Fill Forward

Fill forward means if there is no data point for the current slice, LEAN uses the previous data point. Fill forward is the default data setting. If you disable fill forward, you may get stale fills or you may see trade volume as zero.

To disable fill forward for a security, set the fillDataForward argument to false when you create the security subscription.

AddIndexOptionContract(_contractSymbol, fillDataForward: false);
self.AddIndexOptionContract(self.contract_symbol, fillDataForward=False)

Margin and Leverage

LEAN models buying power and margin calls to ensure your algorithm stays within the margin requirements. Options are already leveraged products, so you can't change their leverage.

Remove Subscriptions

To remove a contract subscription that you created with AddIndexOptionContract, call the RemoveOptionContract method. This method is an alias for RemoveSecurity.

RemoveOptionContract(_contractSymbol);
self.RemoveOptionContract(self.contract_symbol)

The RemoveOptionContract method cancels your open orders for the contract and liquidates your holdings.

Properties

The AddIndexOptionContract method returns an Option object, which have the following properties:

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: