Universe Selection
Futures Universes
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
DateTime
datetime
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:
Argument | Data Type | Description | Default Value |
---|---|---|---|
refreshInterval | TimeSpan timedelta | Time interval between universe refreshes | |
futureChainSymbolSelector | Func<DateTime, IEnumerable<Symbol>> Callable[[datetime], List[Symbol]] | A function that selects the Future symbols | |
universeSettings | UniverseSettings | Universe settings define attributes of created subscriptions, such as their resolution and the minimum time in universe before they can be removed | null None |
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:
Argument | Data Type | Description | Default Value |
---|---|---|---|
algorithm | IAlgorithm | Algorithm | |
futureChainSymbolSelector | Func<DateTime, IEnumerable<Symbol>> | A function that selects the Future symbols | |
chainContractsLookupLimit | int? | Limit on how many contracts to query for open interest | 6 |
resultsLimit | int? | Limit on how many contracts will be part of the universe | 1 |
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.
OpenInterestFutureUniverseSelectionModel
isn't currently available for Python. To track the feature progress, subscribe to GitHub Issue #6352.