Universe Selection

Futures Universes

Introduction

A Future Universe Selection model selects contracts for a set of Futures.

Future Universe Selection

The FutureUniverseSelectionModel selects all the contracts for a set of Futures you specify. To use this model, provide a refreshInterval and a selector function. The refreshInterval defines the time period between refreshes. The selector function receives a DateTimedatetime object that represents the current Coordinated Universal Time (UTC) and returns a list of Symbol objects. The Symbol objects you return from the selector function are the Futures of the universe.

AddUniverseSelection(new FutureUniverseSelectionModel(refreshInterval, futureChainSymbolSelector));
from Selection.FutureUniverseSelectionModel import FutureUniverseSelectionModel

self.AddUniverseSelection(FutureUniverseSelectionModel(refreshInterval, futureChainSymbolSelector))

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
refreshIntervalTimeSpantimedeltaTime interval between universe refreshes
futureChainSymbolSelectorFunc<DateTime, IEnumerable<Symbol>>Callable[[datetime], List[Symbol]]A function that selects the Future symbols
universeSettingsUniverseSettingsUniverse settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removednullNone

If you don't provide a universeSettings argument, the algorithm.UniverseSettings is used by default.

public override void Initialize()
{
    AddUniverseSelection(
        new FutureUniverseSelectionModel(TimeSpan.FromDays(1), SelectFutureChainSymbols)
    );
}

private static IEnumerable<Symbol> SelectFutureChainSymbols(DateTime utcTime)
{
    return new[] {
        QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME),
        QuantConnect.Symbol.Create(Futures.Metals.Gold, SecurityType.Future, Market.COMEX)
    };
}
from Selection.FutureUniverseSelectionModel import FutureUniverseSelectionModel

def Initialize(self) -> None:
    universe = FutureUniverseSelectionModel(timedelta(days=1), self.future_chain_symbol_selector)
    self.SetUniverseSelection(universe)

def future_chain_symbol_selector(self, utc_time: datetime) -> List[Symbol]:
    return [ Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME),
             Symbol.Create(Futures.Metals.Gold, SecurityType.Future, Market.COMEX) ]

To view the implementation of this model, see the LEAN GitHub repositoryLEAN GitHub repository.

This model uses the default Future contract filter, which returns all of the Future contracts. To use a different filter, subclass the FutureUniverseSelectionModel and define a Filter method. The Filter method accepts and returns a FutureFilterUniverse object. For a full example, see the BasicTemplateFuturesFrameworkAlgorithm.

Open Interest Future Universe Selection

The OpenInterestFutureUniverseSelectionModel is an extension of the FutureUniverseSelectionModel that selects the contract with the greatest open interest on a daily basis.

AddUniverseSelection(new OpenInterestFutureUniverseSelectionModel(algorithm, futureChainSymbolSelector));

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
algorithmIAlgorithmAlgorithm
futureChainSymbolSelectorFunc<DateTime, IEnumerable<Symbol>>A function that selects the Future symbols
chainContractsLookupLimitint?Limit on how many contracts to query for open interest6
resultsLimitint?Limit on how many contracts will be part of the universe1
public override void Initialize()
{
    var symbols = new[] {
        QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME),
        QuantConnect.Symbol.Create(Futures.Metals.Gold, SecurityType.Future, Market.COMEX)
    }; 
    AddUniverseSelection(new OpenInterestFutureUniverseSelectionModel(this, dateTime => symbols));
}

To view the implementation of this model, see the LEAN GitHub repository.

The OpenInterestFutureUniverseSelectionModel isn't currently available for Python. To track the feature progress, subscribe to GitHub Issue #6352.

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: