QuantConnect

US Futures Security Master

Introduction

The US Futures Security Master dataset by QuantConnect provides mapping reference data for the most liquid contracts of the CME Group exchanges, calculated with popular rolling techniques. The data covers 75 root Future contracts, starts in 2012, and is delivered on a daily frequency with a zip file with all the contract mappings. This dataset is created by daily processing of the US historical Future chains.

This dataset, paired the US Futures dataset, supports the following rolling techniques: ForwardPanamaCanal, BackwardsPanamaCanal, and Backwards Ratio. You can set the specific date of rolling to occur on the LastTradingDay, FirstDayMonth, or on the day where the contract with the greatest OpenInterest changes.

For more information about the US Futures Security Master dataset, including CLI commands and pricing, see the dataset listing.

About the Provider

QuantConnect was founded in 2012 to serve quants everywhere with the best possible algorithmic trading technology. Seeking to disrupt a notoriously closed-source industry, QuantConnect takes a radically open-source approach to algorithmic trading. Through the QuantConnect web platform, more than 50,000 quants are served every month.

Getting Started

You don't need any special code to utilize the US Futures Security Master. It automatically loads when you request US Futures data.

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateJanuary 2012
Asset Coverage75 Liquid Futures
Data DensityRegular
ResolutionDaily

Data Point Attributes

The US Futures Security Master dataset provides SymbolChangedEvent objects, which have the following attributes:

Key Concept

The US Futures Security Master lets you to construct continuous Futures, allowing the access of normalized historical data of the underlying assets, as well as trading the “lead” Future contracts for those assets.

Continuous Futures refer to sets of rolling lead Future contracts during their actively trading periods. Since Future contracts expire at their maturities, to analyze the historical price of a Future and to apply technical indicators, you need the continuous Future price series.

To access the continuous Future, use the Future's Symbol property.

future = self.add_future(Futures.Energies.CRUDE_OIL_WTI,
    data_normalization_mode = DataNormalizationMode.BACKWARDS_RATIO,
    data_mapping_mode = DataMappingMode.OPEN_INTEREST,
    contract_depth_offset = 0)
self.continuous_contract_symbol = future.symbol
var future = AddFuture(Futures.Energies.CrudeOilWTI,
    dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
    dataMappingMode: DataMappingMode.OpenInterest,
    contractDepthOffset: 0
);
_continuousFutureSymbol = future.Symbol;

The dataNormalizationMode and dataMappingMode arguments makes the transition of the underlying contracts seemless. However, the Future Symbol doesn't map to an underlying Future contract. It works fine to trade within backtests, but could be subjected to friction costs during live trading since the order price could be a normalized price. For more information about this topic, see the Live Trading Considerations section.

Data Normalization Modes

The data normalization mode defines how the price series of two contracts are stitched together when the contract rollovers occur. The DataNormalizatoinMode enumeration has the following members available for continuous contracts:

If you use a data normalization mode that's not in the preceding list, LEAN automatically converts it to DataNormalizationMode.BackwardsRatio.

Data Mapping Modes

The data mapping mode defines when contract rollovers occur. The DataMappingMode enumeration has the following members:

Tracking Contract Changes

As the contracts roll over, the Mapped property of the Future object references the next contract in the series and you receive a SymbolChangedEvent. To get the current Symbol change events, index the SymbolChangedEvents property of the current Slice with the continuous Futures Symbol. Slice objects deliver unique events to your algorithm as they happen, but the Slice may not contain data for your Future at every time step. To avoid issues, check if the Slice contains the data you want before you index it.

def on_data(self, slice: Slice) -> None:
    changed_event = slice.symbol_changed_events.get(self.continuous_future_symbol)
    if changed_event:
        old_symbol = changed_event.old_symbol
        new_symbol = changed_event.new_symbol
        tag = f"Rollover - Symbol changed at {self.time}: {old_symbol} -> {new_symbol}"
        quantity = self.portfolio[old_symbol].quantity

        # Rolling over: to liquidate any position of the old mapped contract and switch to the newly mapped contract
        self.liquidate(old_symbol, tag = tag)
        if quantity != 0: self.market_order(new_symbol, quantity, tag = tag)
        self.log(tag)
public override void OnData(Slice slice)
{
    if (slice.SymbolChangedEvents.TryGetValue(_continuousFutureSymbol, out var changedEvent))
    {
        var oldSymbol = changedEvent.OldSymbol;
        var newSymbol = changedEvent.NewSymbol;
        var tag = $"Rollover - Symbol changed at {Time}: {oldSymbol} -> {newSymbol}";
        var quantity = Portfolio[oldSymbol].Quantity;
        // Rolling over: to liquidate any position of the old mapped contract and switch to the newly mapped contract
        Liquidate(oldSymbol, tag: tag);
        if (quantity != 0) MarketOrder(newSymbol, quantity, tag: tag);
        Log(tag);
    }
}

SymbolChangedEvent objects have the following attributes:

Live Trading Considerations

You can trade continuous Futures, but the continuous Future Symbol doesn't map to a single underlying Future contract. Instead, it represents a set of rolling contracts. Thus, the prices could be frictional during a contract rollover, which could be catastrophic in live trading! For live trading, you should place your orders directly on the underlying contracts. To get the current underlying contract in the continuous Future series, use the Mapped property.

current_contract = self.continuous_contract.mapped
self.buy(current_contract, 1)
var currentContract = _continuousContract.Mapped;
Buy(currentContract, 1);

Data Format

If you download the files in the US Futures Security Master, you get a factor file and a map file for each of the exchanges with supported continuous Futures. To view the files, see the \data\future\<exchange_name> directory under your LEAN CLI base directory.

For the factor file, it is a .zip collection of REST API styled .csv files for each Future Symbol, including the date, scaling factors for each type of data normalization and the data mapping mode that indicates the Symbol changing event is on that day for that mapping mode. The following line is an example line in the .csv file:

{"Date":"2009-10-31T00:00:00","BackwardsRatioScale":[0.9914163090128755364806866953,1.0,1.0],"BackwardsPanamaCanalScale":[-2.0,0.0,0.0],"ForwardPanamaCanalScale":[0.0,0.0,0.0],"DataMappingMode":1}

For the map file, it is a .zip collection of .csv files for each Future Symbol, including the date, new underlying contract Symbol, the exchange code, and the data mapping mode that indicates the Symbol changing event is on that day for that mapping mode. The following line is an example line in the .csv file:

20091130,aw uii3j0m6zbj9,CBOT,1

Example Applications

The US Futures Security Master enables you to design strategies harnessing continuous Futures contracts. Examples include the following strategies:

  • Trading cyclical patterns in commodity Futures.
  • Buying gold Futures as an inflation hedge with automatic contract roll overs.
  • Detecting arbitrage opportunities between index Futures and Equities.

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: