Requesting Data

Individual Contracts

Introduction

The AddFutureOptionContractadd_future_option_contract method enables you to add an individual Option contract to your algorithm. To check which contracts are currently available to add to your algorithm, use the OptionChainProvider.GetOptionContractListoption_chain_provider.get_option_contract_list method. If you want to subscribe to a set of contracts instead of individual contracts one-by-one, see Universes.

Create Subscriptions

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

public class BasicFutureOptionAlgorithm : QCAlgorithm
{
    private Future _future;
    private Symbol _contractSymbol;
    public override void Initialize()
    {
        SetStartDate(2020,1,1);
        _future = AddFuture(Futures.Indices.SP500EMini,
            extendedMarketHours: true,
            dataMappingMode: DataMappingMode.OpenInterest,
            dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
            contractDepthOffset: 0);
        _future.SetFilter(0, 182);
    }

    public override void OnData(Slice data)
    {
        if (_contractSymbol == null)
        {
            // Method 1: Add the desired option chain for the mapped contract
            _contractSymbol = SelectOptionContract(_future.Mapped);
            AddFutureOptionContract(_contractSymbol);
            
            // Method 2: Get all future contracts from the Future chain provider
            var futureContractSymbol = FutureChainProvider.GetFutureContractList(_future.Symbol, Time)
                .OrderBy(symbol => symbol.ID.Date).FirstOrDefault();
            var symbol = SelectOptionContract(futureContractSymbol);
            AddFutureOptionContract(symbol);
            
            // Method 3: Iterate all Future chains to find the desired future options contracts  
            foreach (var (_, chain) in data.FutureChains)
            {
                var expiry = chain.Min(contract => contract.Expiry);
                var futureContract = chain.Where(contract => contract.Expiry == expiry).FirstOrDefault();
                symbol = SelectOptionContract(futureContract.Symbol);
                AddFutureOptionContract(symbol);
            }
        }
    }

    private Symbol SelectOptionContract(Symbol futureContractSymbol)
    {
        var contractSymbols = OptionChainProvider.GetOptionContractList(futureContractSymbol, Time)
            .Where(symbol => symbol.ID.OptionRight == OptionRight.Call).ToList();
        var expiry = contractSymbols.Min(symbol => symbol.ID.Date);
        return contractSymbols.Where(symbol => symbol.ID.Date == expiry).OrderBy(symbol => symbol.ID.StrikePrice).FirstOrDefault();
    }
}
class BasicFutureOptionAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2020, 1, 1)
        self._future = self.add_future(Futures.Indices.SP_500_E_MINI,
            extended_market_hours=True,
            data_mapping_mode=DataMappingMode.OPEN_INTEREST,
            data_normalization_mode=DataNormalizationMode.BACKWARDS_RATIO,
            contract_depth_offset=0)
        self._future.set_filter(0, 182)
        self._contract_symbol = None
    
    def on_data(self, data):
        if not self._contract_symbol:
            # Method 1: Add the desired option chain for the mapped contract
            self._contract_symbol = self._select_option_contract(self._future.mapped)
            self.add_future_option_contract(self._contract_symbol)

            # Method 2: Get all future contracts from the Future chain provider
            future_contract_symbols = self.future_chain_provider.get_future_contract_list(self._future.symbol, self.time)
            future_contract_symbol = sorted(future_contract_symbols, key=lambda symbol: symbol.id.date)[0]
            symbol = self._select_option_contract(future_contract_symbol)
            self.add_future_option_contract(symbol)

            # Method 3: Iterate all Future chains to find the desired future options contracts         
            for symbol, chain in data.future_chains.items():
                expiry = min([contract.expiry for contract in chain])
                future_contract = next(contract for contract in chain if contract.expiry == expiry)
                symbol = self._select_option_contract(future_contract.symbol)
                self.add_future_option_contract(symbol)

    def _select_option_contract(self, future_contract_symbol):
        contract_symbols = self.option_chain_provider.get_option_contract_list(future_contract_symbol, self.time)
        contract_symbols = [symbol for symbol in contract_symbols if symbol.id.option_right == OptionRight.CALL]
        expiry = min([symbol.id.date for symbol in contract_symbols])
        filtered_symbols = [symbol for symbol in contract_symbols if symbol.id.date == expiry]
        return sorted(filtered_symbols, key=lambda symbol: symbol.id.strike_price)[0]

Configure the Underlying Futures Contract

In most cases, you should subscribe to the underlying Futures contract before you subscribe to a Futures Option contract.

_future = AddFuture(Futures.Indices.SP500EMini,
    extendedMarketHours: true,
    dataMappingMode: DataMappingMode.OpenInterest,
    dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
    contractDepthOffset: 0);
self._future = self.add_future(Futures.Indices.SP_500_E_MINI,
    extended_market_hours=True,
    data_mapping_mode=DataMappingMode.OPEN_INTEREST,
    data_normalization_mode=DataNormalizationMode.BACKWARDS_RATIO,
    contract_depth_offset=0)

You can use the Mappedmapped property of the Future object or the Symbolsymbol property of the FutureContract objects in the Slice.FutureChainsSlice.future_chains collection.

Get Contract Symbols

To subscribe to a Future Option contract, you need the contract Symbol. The preferred method to getting Option contract Symbol objects is to use the OptionChainProvideroption_chain_provider. The GetOptionContractListget_option_contract_list method of OptionChainProvideroption_chain_provider returns a list of Symbol objects for a given date and underlying Future, which you can then sort and filter to find the specific contract(s) you want to trade.

var contractSymbols = OptionChainProvider.GetOptionContractList(futureContractSymbol, Time)
    .Where(symbol => symbol.ID.OptionRight == OptionRight.Call).ToList();
var expiry = contractSymbols.Min(symbol => symbol.ID.Date);
_contractSymbol = contractSymbols.Where(symbol => symbol.ID.Date == expiry).OrderBy(symbol => symbol.ID.StrikePrice).FirstOrDefault();
contract_symbols = self.option_chain_provider.get_option_contract_list(future_contract_symbol, self.time)
contract_symbols = [symbol for symbol in contract_symbols if symbol.id.option_right == OptionRight.CALL]
expiry = min([symbol.id.date for symbol in contract_symbols])
filtered_symbols = [symbol for symbol in contract_symbols if symbol.id.date == expiry]
self._contract_symbol = sorted(filtered_symbols, key=lambda symbol: symbol.id.strike_price)[0]

To filter and select contracts, you can use the following properties of each Symbol object:

PropertyDescription
ID.Dateid.dateThe expiration date of the contract.
ID.StrikePriceid.strike_priceThe strike price of the contract.
ID.OptionRightid.option_right The contract type, OptionRight.PutOptionRight.PUT or OptionRight.CallOptionRight.CALL.
ID.OptionStyleid.option_style The contract style, OptionStyle.AmericanOptionStyle.AMERICAN or OptionStyle.EuropeanOptionStyle.EUROPEAN. We currently only support European-style Options for US Future Options.

Subscribe to Contracts

To create a Future Option contract subscription, pass the contract Symbol to the AddFutureOptionContractadd_future_option_contract method. Save a reference to the contract Symbolsymbol so you can easily access the Option contract in the OptionChain that LEAN passes to the OnDataon_data method. This method returns an Option object. To override the default pricing model of the Option, set a pricing model.

var option = AddFutureOptionContract(_contractSymbol);
option.PriceModel = OptionPriceModels.BinomialCoxRossRubinstein();
option = self.add_future_option_contract(self._contract_symbol)
option.price_model = OptionPriceModels.binomial_cox_ross_rubinstein()

Warm Up Contract Prices

If you subscribe to a Future Option contract with AddFutureOptionContractadd_future_option_contract, 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));
seeder = FuncSecuritySeeder(self.get_last_known_prices)
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, seeder))

Supported Assets

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

Resolutions

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

ResolutionTradeBarQuoteBarTrade TickQuote Tick
TickTICK

SecondSECOND

MinuteMINUTEgreen checkgreen check
HourHOURgreen checkgreen check
DailyDAILYgreen checkgreen check

There is only one resolution option, so you don't need to pass a resolution argument to the AddFutureOptionContractadd_future_option_contract method.

AddFutureOptionContract(_optionContractSymbol, Resolution.Minute);
self.add_future_option_contract(self._option_contract_symbol, Resolution.MINUTE)

To create custom resolution periods, see Consolidating Data.

Supported Markets

The following Market enumeration members are available for Future Options:

You don't need to pass a Market argument to the AddFutureOptionContractadd_future_option_contract 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 fillForwardfill_forward argument to false when you create the security subscription.

AddFutureOptionContract(_optionContractSymbol, fillForward: false);
self.add_future_option_contract(self._option_contract_symbol, fill_forward=False)

Margin and Leverage

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

Extended Market Hours

By default, your security subscriptions only cover regular trading hours. To subscribe to pre and post-market trading hours for a specific asset, enable the extendedMarketHoursextended_market_hours argument when you create the security subscription.

AddFutureOptionContract(_optionContractSymbol, extendedMarketHours: true);
self.add_future_option_contract(self._option_contract_symbol, extended_market_hours=True)

You only receive extended market hours data if you create the subscription with minute, second, or tick resolution. If you create the subscription with daily or hourly resolution, the bars only reflect the regular trading hours.

To view the schedule of regular and extended market hours, see Market Hours.

Data Normalization

The data normalization mode doesn't affect the data that LEAN passes to OnDataon_data or the data from history request. If you change the data normalization mode, it won't change the outcome.

Remove Subscriptions

To remove a contract subscription that you created with AddFutureOptionContractadd_future_option_contract, call the RemoveOptionContractremove_option_contract method. This method is an alias for RemoveSecurityremove_security.

RemoveOptionContract(_optionContractSymbol);
self.remove_option_contract(self._option_contract_symbol)

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

Properties

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

Helper Methods

The Option object provides methods you can use for basic calculations. These methods require the underlying price. To get the Option object and the Security object for its underlying in any function, use the Option Symbolsymbol to access the value in the Securitiessecurities object.

var option = Securities[_optionContractSymbol];
var underlying = Securities[_optionContractSymbol.Underlying];
var underlyingPrice = underlying.Price;
option = self.securities[self._option_contract_symbol]
underlying = self.securities[self._option_contract_symbol.underlying]
underlying_price = underlying.price

To get the Option payoff, call the GetPayOffget_pay_off method.

var payOff = option.GetPayOff(underlyingPrice);
pay_off = option.get_pay_off(underlying_price)

To get the Option intrinsic value, call the GetIntrinsicValueget_intrinsic_value method.

var intrinsicValue = option.GetIntrinsicValue(underlyingPrice);
intrinsic_value = option.get_intrinsic_value(underlying_price)

To get the Option out-of-the-money amount, call the OutOfTheMoneyAmountout_of_the_money_amount method.

var otmAmount = option.OutOfTheMoneyAmount(underlyingPrice);
otm_amount = option.out_of_the_money_amount(underlying_price)

To check whether the Option can be automatic exercised, call the IsAutoExercisedis_auto_exercised method.

var isAutoExercised = option.IsAutoExercised(underlyingPrice);
is_auto_exercised = option.is_auto_exercised(underlying_price)

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: