Index Options

Universes

Introduction

This page is a work in progress. We apologize for any errors.

This page explains how to request historical data for a universe of Index Option contracts.

Create Subscriptions

Follow these steps to subscribe to an Index Option universe:

  1. Load the assembly files and data types in their own cell.
  2. #load "../Initialize.csx"
  3. Import the data types.
  4. #load "../QuantConnect.csx"
    #r "../Microsoft.Data.Analysis.dll"
    
    using QuantConnect;
    using QuantConnect.Data;
    using QuantConnect.Algorithm;
    using QuantConnect.Research;
    using QuantConnect.Indicators;
    using QuantConnect.Securities.Index;
    using QuantConnect.Securities.IndexOption;
    using QuantConnect.Data.UniverseSelection;
    using Microsoft.Data.Analysis;
  5. Create a QuantBook.
  6. var qb = new QuantBook();
    qb = QuantBook()
  7. Add the underlying Index.
  8. var indexSymbol = qb.AddIndex("SPX", Resolution.Minute).Symbol;
    index_symbol = qb.add_index("SPX", Resolution.MINUTE).symbol

    To view the available Indices, see Supported Assets.

    If you do not pass a resolution argument, Resolution.MinuteResolution.MINUTE is used by default.

  9. Call the AddIndexOptionadd_index_option method with the underlying Index Symbol and, if you want non-standard Index Options, the target Option ticker.
  10. var option = qb.AddIndexOption(indexSymbol);
    option = qb.add_index_option(index_symbol)

Universe History

The contract filter determines which Index Option contracts are in your universe each trading day. The default filter selects the contracts with the following characteristics:

  • Standard type (exclude weeklys)
  • Within 1 strike price of the underlying asset price
  • Expire within 35 days

To change the filter, call the SetFilterset_filter method.

// Set the contract filter to select contracts that have the strike price 
// within 1 strike level and expire within 90 days.
option.SetFilter(-1, 1, 0, 90);
# Set the contract filter to select contracts that have the strike price 
# within 1 strike level and expire within 90 days.
option.set_filter(-1, 1, 0, 90)

To get the prices and volumes for all of the Index Option contracts that pass your filter during a specific period of time, call the OptionHistoryoption_history method with the underlying Index Symbol object, a start DateTimedatetime, and an end DateTimedatetime.

option_history = qb.option_history(
    index_symbol, datetime(2024, 1, 1), datetime(2024, 1, 5), Resolution.MINUTE, 
    fill_forward=False, extended_market_hours=False
)
var optionHistory = qb.OptionHistory(
    indexSymbol, new DateTime(2024, 1, 1), new DateTime(2024, 1, 5), Resolution.Minute,
    fillForward: false, extendedMarketHours: false
);

To convert the OptionHistory object to a DataFrame that contains the trade and quote information of each contract and the underlying, use the data_frame property.

option_history.data_frame
DataFrame of Options data

To get the expiration dates of all the contracts in an OptionHistory object, call the GetExpiryDatesget_expiry_dates method.

option_history.get_expiry_dates()
list of expiry dates

To get the strike prices of all the contracts in an OptionHistory object, call the GetStrikesget_strikes method.

option_history.get_strikes()
List of strike prices

Daily Tradable Contract History

To get daily data on all the tradable contracts for a given date, call the History<OptionUniverse>history method with the canoncial Option Symbol, a start date, and an end date. This method returns the entire Option chain for each trading day, not the subset of contracts that pass your universe filter. The daily Option chains contain the prices, volume, open interest, implied volaility, and Greeks of each contract.

# DataFrame format
history_df = qb.history(option.symbol, datetime(2024, 1, 1), datetime(2024, 1, 5))

# OptionUniverse objects
history = qb.history[OptionUniverse](option.symbol, datetime(2024, 1, 1), datetime(2024, 1, 5))
for chain in history:
    end_time = chain.end_time
    filtered_chain = [contract for contract in chain if contract.greeks.delta > 0.3]
    for contract in filtered_chain:
        price = contract.price
        iv = contract.implied_volatility
var history = qb.History<OptionUniverse>(option.Symbol, new DateTime(2024, 1, 1), new DateTime(2024, 1, 5));
foreach (var chain in history)
{
    var endTime = chain.EndTime;
    var filteredChain = chain.Data
        .Select(contract => contract as OptionUniverse)
        .Where(contract => contract.Greeks.Delta > 0.3m);
    foreach (var contract in filteredChain)
    {
        var price = contract.Price;
        var iv = contract.ImpliedVolatility;
    }
}

The method represents each contract with an OptionUniverse 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: