Universe Selection

Fundamental Universes

Introduction

A FundamentalUniverseSelectionModel selects a universe of US Equities based on CoarseFundamental and, sometimes, FineFundamental data. If the model uses CoarseFundamental data, it relies on the US Coarse Universe dataset. If the Universe Selection model uses FineFundamental data, it relies on the US Fundamental dataset.

These types of universes operate on daily schedule. In backtests, they select assets at midnight. In live trading, the selection timing depends on the data feed you use.

If you use a fundamental Universe Selection model, the only way to unsubscribe from a security is to return a list from the selection functions that doesn't include the security Symbol. The RemoveSecurity method doesn't work with these types of Universe Selection models.

Coarse Fundamental Selection

The CoarseFundamentalUniverseSelectionModel selects assets based on CoarseFundamental data. To use this model, define a coarse selection function. The coarse selection function receives a list of CoarseFundamental objects and returns a list of Symbol objects. The Symbol objects you return from the coarse selection function are the constituents of the universe.

public override void Initialize()
{
    AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(SelectCoarse));
}

private IEnumerable<Symbol> SelectCoarse(IEnumerable<CoarseFundamental> coarse)
{
    // Return most liquid assets w/ fundamentals
    return coarse.Where(c => c.HasFundamentalData)
                 .OrderByDescending(c => c.DollarVolume)
                 .Take(100)
                 .Select(c => c.Symbol);
}
def Initialize(self) -> None:
    self.AddUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.SelectCoarse))

def SelectCoarse(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
    selected = [c for c in coarse if c.HasFundamentalData]
    sorted_by_dollar_volume = sorted(selected, key=lambda c: c.DollarVolume, reverse=True)
    return [c.Symbol for c in sorted_by_dollar_volume[:100]] # Return most liquid assets w/ fundamentals

To return the current universe constituents from the coarse or fine selection function, return Universe.Unchanged.

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

Fine Fundamental Selection

     

The FineFundamentalUniverseSelectionModel selects assets based on CoarseFundamental and FineFundamental data. This is the only model that provides corporate fundamental data to your algorithm. To use this model, define a coarse selection function and a fine selection function. The coarse selection function receives a list of CoarseFundamental objects and returns a list of Symbol objects. To filter the CoarseFundamental down to the securities that have fundamental data, add a HasFundamentalData filter to the coarse selection function. The fine selection function receives a subset of FineFundamental objects generated from coarse selection results and returns a list of Symbol objects. The Symbol objects you return from the fine selection function are the constituents of the universe.

public override void Initialize()
{
     AddUniverseSelection(new FineFundamentalUniverseSelectionModel(SelectCoarse, SelectFine));
}

private IEnumerable<Symbol> SelectCoarse(IEnumerable<CoarseFundamental> coarse)
{
    // Return most liquid assets w/ fundamentals
    return coarse.Where(c => c.HasFundamentalData)
                 .OrderByDescending(c => c.DollarVolume)
                 .Take(100)
                 .Select(c => c.Symbol);
}

private IEnumerable<Symbol> SelectFine(IEnumerable<FineFundamental> fine) {
    // Return assets with lowest P/E ratios
    return fine.OrderBy(f => f.ValuationRatios.PERatio)
               .Take(10)
               .Select(f => f.Symbol);
}
def Initialize(self) -> None:
    self.AddUniverseSelection(FineFundamentalUniverseSelectionModel(self.SelectCoarse, self.SelectFine))

def SelectCoarse(self, coarse: List[CoarseFundamental]) -> List[Symbol]:
    selected = [c for c in coarse if c.HasFundamentalData]
    sorted_by_dollar_volume = sorted(selected, key=lambda c: c.DollarVolume, reverse=True)
    return [c.Symbol for c in sorted_by_dollar_volume[:100]] # Return most liquid assets w/ fundamentals

def SelectFine(self, fine: List[FineFundamental]) -> List[Symbol]:
    sorted_by_pe_ratio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio, reverse=False)
    return [c.Symbol for c in sorted_by_pe_ratio[:10]] # Return assets with lowest P/E ratios

To return the current universe constituents from the coarse or fine selection function, return Universe.Unchanged.

If you add a FineFundamentalUniverseSelectionModel to your algorithm, you can access fundamental data in the fine selection function or from the Equity object. To access fundamental data from the Equity object, use the Equity.Fundamentals property.

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

EMA Cross Selection

The EmaCrossUniverseSelectionModel applies two exponential moving average (EMA) indicators to the price history of assets and then selects the assets that have their fast EMA furthest above their slow EMA on a percentage basis.

public override void Initialize()
{
    AddUniverseSelection(new EmaCrossUniverseSelectionModel());
}
def Initialize(self) -> None:
    self.AddUniverseSelection(EmaCrossUniverseSelectionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
fastPeriodintFast EMA period100
slowPeriodintSlow EMA period300
universeCountintMaximum number of members of this universe selection500
universeSettingsUniverseSettingsThe settings used when adding symbols to the algorithmNonenull

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

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

Uncorrelated Assets Selection

The UncorrelatedUniverseSelectionModel selects the most liquid assets and then calculates the rolling correlation of each asset to a benchmark. The model then ranks the assets by the z-score of their trailing correlation values and selects the assets that have the highest absolute z-score. In other words, the model picks stocks that currently have their correlation to a benchmark deviated from their mean correlation to the benchmark.

from Selection.UncorrelatedUniverseSelectionModel import UncorrelatedUniverseSelectionModel
  
self.AddUniverseSelection(UncorrelatedUniverseSelectionModel())

The following table describes the arguments the model accepts:

ArgumentData TypeDescriptionDefault Value
benchmarkSymbolSymbol of the benchmarkSymbol.Create("SPY", SecurityType.Equity, Market.USA)QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)
numberOfSymbolsCoarseintNumber of coarse symbols400
numberOfSymbolsintNumber of symbols selected by the Universe Selection model10
windowLengthintRolling window length period for correlation calculation5
historyLengthintHistory length period25
thresholdintThreadhold for the minimum mean correlation between security and benchmark0.5

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

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: