book
Checkout our new book! Hands on AI Trading with Python, QuantConnect, and AWS Learn More arrow

Futures Options

Universes

Introduction

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

Create Subscriptions

Follow these steps to subscribe to a Futures Options 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;
    using QuantConnect.Data.UniverseSelection;
    using Microsoft.Data.Analysis;
  5. Create a QuantBook.
  6. var qb = new QuantBook();
    qb = QuantBook()
  7. Add the underlying Future.
  8. var future = qb.AddFuture(Futures.Indices.SP500EMini);
    future = qb.add_future(Futures.Indices.SP_500_E_MINI)

    To view the available underlying Futures in the US Future Options dataset, see Supported Assets.

Price History

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

  • Standard type (weeklies and non-standard contracts are not available)
  • Within 1 strike price of the underlying asset price
  • Expire within 35 days

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

start_date = datetime(2024, 1, 1)

# Select an underlying Futures contract. For example, get the front-month contract.
chain = list(qb.history[FutureUniverse](future.symbol, start_date, start_date+timedelta(2)))[0]
futures_contract = list(chain)[0].symbol

# Get the Options data for the selected Futures contract.
option_history = qb.option_history(
    futures_contract, start_date, futures_contract.id.date, Resolution.HOUR, 
    fill_forward=False, extended_market_hours=False
)
var startDate = new DateTime(2024, 1, 1);

// Select an underlying Futures contract. For example, get the front-month contract.
var chain = qb.History<FutureUniverse>(future.Symbol, startDate, startDate.AddDays(2)).First();
var futuresContract = chain.First().Symbol;

// Get the Options data for the selected Futures contract.
var optionHistory = qb.OptionHistory(
    futuresContract, startDate, futuresContract.ID.Date, Resolution.Hour, 
    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
askcloseaskhighasklowaskopenasksizebidclosebidhighbidlowbidopenbidsizeclosehighlowopenvolume
expirystriketypesymboltime
2024-03-154575.00ES YGT6I1W1ONB8|ES YGT6HGVF2SQP2024-01-02 10:00:00262.0316.50248.75256.01.0247.25257.25187.25253.501.0254.625286.875218.000254.750NaN
2024-01-02 11:00:00250.5300.00248.25262.02.0248.50256.50215.00247.252.0249.500278.250231.625254.625NaN
2024-01-02 12:00:00261.0300.00250.00250.51.0259.25259.75216.25248.501.0260.125279.875233.125249.500NaN
.........................................................
5215.01ES 32FX6NKT3COAS|ES YGT6HGVF2SQP2024-03-14 15:00:0070.592.2558.0064.52.069.7570.2536.7552.001.070.12581.25047.37558.250NaN
2024-03-14 16:00:0075.0183.5063.2570.510.044.7589.752.1069.7510.067.75067.75067.75067.7501.0
2024-03-14 17:00:0063.584.0058.0075.01.058.5061.5035.5044.751.061.00072.75046.75059.875NaN

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

Examples

The following examples demonstrate some common practices for applying the Future Options dataset.

Example 1: Implied Volatility Line Chart

The following example plots a line chart on the implied volatility curve of the cloest expiring calls.

// Load the required assembly files and data types in a separate cell.
#load "../Initialize.csx"

#load "../QuantConnect.csx"
using System;
using System.Collections.Generic;
using QuantConnect;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Algorithm;
using QuantConnect.Research;

// Import Plotly for plotting.
#r "../Plotly.NET.dll"
using Plotly.NET;
using Plotly.NET.LayoutObjects;

// Create a QuantBook.
var qb = new QuantBook();
// Set the date being studied.
var date = new DateTime(2024, 1, 4);

// Subscribe to the underlying Future.
var future = qb.AddFuture(Futures.Indices.SP500EMini);
// Select the front-month contract.
var chain = qb.History<FutureUniverse>(future.Symbol, date, date.AddDays(2)).First();
var futuresContract = chain.First().Symbol;

// Get the Options data for the selected Futures contract at the selected date.
var optionHistory = qb.OptionHistory(
    futuresContract, date.AddDays(-1), date, Resolution.Daily, 
    fillForward: false, extendedMarketHours: false
).Last();

var chain = optionHistory.OptionChains.Values.First();
// Study the closest expiring contracts.
var expiry = chain.Min(x => x.Expiry);
// Filter for the closest expiring calls to study only.
var filterContracts = chain.Where(x => x.Expiry == expiry && x.Right == OptionRight.Call).ToList();

// Obtain the strike and IV for plotting the IV curve.
var ivByStrike = new Dictionary<decimal, decimal>();
foreach (var contract in filterContracts)
{
    var strike = contract.Strike;
    var iv = contract.ImpliedVolatility;
    ivByStrike[strike] = iv;
}

// Crete the Line Chart with the PE Ratios.
var chart = Chart2D.Chart.Line<decimal, decimal, string>(
    ivByStrike.Keys,
    ivByStrike.Values
);
// Create a Layout as the plot settings.
LinearAxis xAxis = new LinearAxis();
xAxis.SetValue("title", "Strike");
LinearAxis yAxis = new LinearAxis();
yAxis.SetValue("title", "Implied Volatility");
Title title = Title.init($"IV Curve of {futuresContract}");

Layout layout = new Layout();
layout.SetValue("xaxis", xAxis);
layout.SetValue("yaxis", yAxis);
layout.SetValue("title", title);
// Assign the Layout to the chart.
chart.WithLayout(layout);

// Display the plot.
HTML(GenericChart.toChartHTML(chart))
# Instantiate a QuantBook instance.
qb = QuantBook()
# Set the date being studied.
date = datetime(2024, 1, 4)

# Subscribe to the underlying Future.
future = qb.add_future(Futures.Indices.SP_500_E_MINI)
# Select an underlying Futures contract. For example, get the front-month contract.
chain = list(qb.history[FutureUniverse](future.symbol, date, date+timedelta(2)))[0]
futures_contract = list(chain)[0].symbol
# Get the Options data for the selected Futures contract.
option_history = qb.option_history(
    futures_contract, date - timedelta(1), date, Resolution.DAILY, 
    fill_forward=False, extended_market_hours=False
)

chain = list(option_history)[-1].OptionChains.values()[0]
# Study the closest expiring contracts.
expiry = min(x.expiry for x in chain)
# Filter for the closest expiring calls to study only.
filter_contracts = [x for x in chain if x.expiry == expiry and x.right == OptionRight.CALL]

# Obtain the strike and IV for plotting the IV curve.
iv_by_strike = pd.Series({x.strike: x.implied_volatility for x in filter_contracts})
iv_by_strike.plot(title=f"IV Curve of {futures_contract}", ylabel="Implied Volatility", xlabel="Strike")

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: