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

QuantConnect

US Equity Coarse Universe

Introduction

The US Equity Coarse Universe dataset by QuantConnect is a daily universe of all trading stocks in the US for a given day with the end of day price and volume. The data covers 30,000 US Equities in total, with approximately 8,000 Equities per day. The data starts in January 1998 and is delivered each trading day. This dataset is created by taking the closing auction price tick from the daily L1 trade and quote exchange dumps.

This dataset depends on the US Equities by AlgoSeek dataset because universe selection adds and removes market data subscriptions and on the US Equity Security Master dataset because the US Equity Security Master dataset contains information on splits, dividends, and symbol changes.

QuantConnect/LEAN combines the data of this dataset with MorningStar Fundamental data in runtime. You can use this dataset in local development without the Morningstar counterpart.

For more information about the US Equity Coarse Universe 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

The following snippet demonstrates how to request data from the US Equity Coarse Universe dataset:

  • Direct Access using the Security object
equity = self.add_equity("IBM")
ibm_fundamental = equity.fundamentals
var equity = AddEquity("IBM");
var ibmFundamental = equity.Fundamentals;
  • Direct Access using the Symbol object
ibm = Symbol.create("IBM", SecurityType.EQUITY, Market.USA)
ibm_fundamental = self.fundamentals
var ibm = QuantConnect.Symbol.Create("IBM", SecurityType.Equity, Market.USA);
var ibmFundamental = Fundamentals(ibm);
  • Universe Selection
def initialize(self) -> None:
    # Universe selection
    self._universe = self.add_universe(self.fundamental_filter_function)

def fundamental_filter_function(self, fundamental: List[Fundamental]):
    # Sort all equities with price above $10 by dollar volume
    sorted_by_dollar_volume = sorted([f for f in fundamental if f.price > 10],
                                key=lambda f: f.dollar_volume, reverse=True)
    # Take the top 10
    return [f.symbol for f in sorted_by_dollar_volume[:10]]
public override void Initialize()
{
    // Universe selection
    _universe = AddUniverseSelection(new FundamentalUniverseSelectionModel(FundamentalFilterFunction));
}

public override List<Symbol> FundamentalFilterFunction(List<Fundamental> fundamental)
{
    // Sort all equities with price above $10 by dollar volume, take the top 10
    return (from f in fundamental
            where f.Price > 10
            orderby f.DollarVolume descending
            select f.Symbol).Take(10);
}

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateJanuary 1998
Asset Coverage30,000 US Equities
Data DensityDense
ResolutionDaily
TimezoneNew York

This dataset doesn't include Over-the-Counter (OTC) stocks.

Requesting Data

You don't need any special code to request US Coarse Fundamental Data. You can access the current and historical fundamental data for any of the US Equities that this dataset includes.

class CoarseFundamentalDataAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2021, 1, 1)
        self.set_end_date(2021, 7, 1)
        self.set_cash(100000) 
        self.universe_settings.asynchronous = True

        # Option 1: Subscribe to individual US Equity assets
         self.add_equity("IBM")  

        # Option 2A: Create a fundamental universe (classic version)
         self._universe = self.add_universe(self.fundamental_function)

        # Option 2B: Create a fundamental universe (framework version)
        self.add_universe_selection(FundamentalUniverseSelectionModel(self.fundamental_function))
public class CoarseFundamentalDataAlgorithm : QCAlgorithm
{
    private Universe _universe:
    public override void Initialize()
    {
        SetStartDate(2021, 1, 1);
        SetEndDate(2021, 7, 1);
        SetCash(100000);
        UniverseSettings.Asynchronous = True;
        
        // Option 1: Subscribe to individual US Equity assets
        AddEquity("IBM");

        // Option 2A: Create a fundamental universe (classic version)
        _universe = AddUniverse(FundamentalFilterFunction);

        // Option 2B: Create a fundamental universe (framework version)
        AddUniverseSelection(new FundamentalUniverseSelectionModel(FundamentalFilterFunction));
    }
}

For more information about universe settings, see Settings.

Accessing Data

If you add a fundamental universe to your algorithm, you can access fundamental data in the universe selection function.

def fundamental_function(self, fundamental: List[Fundamental]) -> List[Symbol]:
    sorted_by_dollar_volume = sorted(fundamental, key=lambda x: x.dollar_volume, reverse=True)[:3]
    for cf in sorted_by_dollar_volume:
        self.debug(f"{cf.end_time} :: {cf.symbol} : {cf.adjusted_price} :: {cf.dollar_volume}")

    return [ x.symbol for x in sortedByDollarVolume]
public IEnumerable<Symbol> FundamentalFunction(IEnumerable<Fundamental> fundamental)
{
    var sortedByDollarVolume = fundamental
        .OrderByDescending(x => x.DollarVolume)
        .Take(3).ToList();

    foreach (var cf in sortedByDollarVolume)
    {
        Debug($"{cf.EndTime} :: {cf.Symbol} : {cf.AdjustedPrice} :: {cf.DollarVolume}");
    }

    return sortedByDollarVolume.Select(x => x.Symbol);
}

To get fundamental data for Equities in your algorithm, use the Fundamentalsfundamentals property of the Equity objects. The fundamental data represent the corporate fundamentals for the current algorithm time.

fundamentals = self.securities[symbol].fundamentals
var fundamentals = Securities[symbol].Fundamentals;

To get fundamental data for Equities, regardless of whether or not you have subscribed to them in your algorithm, call the Fundamentalsfundamentals method. If you pass one Symbol, the method returns a Fundamental object. If you pass a list of Symbol objects, the method returns a list of Fundamental objects.

// Single asset 
var ibm = QuantConnect.Symbol.Create("IBM", SecurityType.Equity, Market.USA);
var ibmFundamental = Fundamentals(ibm);

// Multiple assets
var nb = QuantConnect.Symbol.Create("NB", SecurityType.Equity, Market.USA);
var fundamentals = Fundamentals(new List<Symbol>{ nb, ibm }).ToList();
# Single asset
ibm = Symbol.create("IBM", SecurityType.EQUITY, Market.USA)
ibm_fundamental = self.fundamentals(ibm)

# Multiple assets
nb = Symbol.create("NB", SecurityType.EQUITY, Market.USA)
fundamentals = self.fundamentals([ nb, ibm ])

Historical Data

You can get historical fundamental data in an algorithm and in the Research Environment.

Historical Data in Algorithms

To get historical fundamental data in an algorithm, call the Historyhistory method with Fundamental type and the Equity Symbol. If there is no data in the period you request, the history result is empty.

var ibm = QuantConnect.Symbol.Create("IBM", SecurityType.Equity, Market.USA);

// Fundamental objects
var fundamentalHistory = History<Fundamental>(ibm, TimeSpan.FromDays(30));

// Fundamentals objects for all US Equities (including delisted companies)
var fundamentalsHistory = History<Fundamentals>(TimeSpan.FromDays(30));

// Collection of Fundamental objects for all US Equities (including delisted companies)
var collectionHistory = History(_universe, 30, Resolution.Daily);
foreach (var fundamental in collectionHistory)
{
    // Cast to Fundamental is required
    var mostLiquid = fundamental.OfType<Fundamental>().OrderByDescending(x => x.DollarVolume).Take(5);
}
ibm = Symbol.create("IBM", SecurityType.EQUITY, Market.USA)

# DataFrame of fundamental data for a given asset
df_history = self.history(Fundamental, ibm, timedelta(30), flatten=True)

# Fundamental objects
fundamental_history = self.history[Fundamental](ibm, timedelta(30))

# Fundamentals objects for all US Equities (including delisted companies)
fundamentals_history = self.history[Fundamentals](timedelta(30))

# DataFrame of fundamental data for universe constituents
df_history = self.history(self._universe, 30, Resolution.DAILY, flatten=True)

# Series of fundamental data for universe constituents
series_history = self.history(self._universe, 30, Resolution.DAILY)
for (universe_symbol, time), fundamental in series_history.items():
    most_liquid = sorted(fundamental, key=lambda x: x.dollar_volume)[-5:]

Historical Universe Data in Research

To get historical universe data in the Research Environment, call the UniverseHistoryuniverse_history method with the Universe object and the lookback period. This method returns the filtered universe. If there is no data in the period you request, the history result is empty.

var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-30), qb.Time);
foreach (var fundamentals in universeHistory)
{
    foreach (Fundamental fundamental in fundamentals)
    {
        Console.WriteLine($"{fundamental.Symbol} dollar volume at {fundamental.EndTime}: {fundamental.DollarVolume}");
    }
}
# DataFrame of fundamental data for universe constituents
df_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time, flatten=True)

# Series of fundamental data for universe constituents
series_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (universe_symbol, time), fundamentals in series_history.items():
    for fundamental in fundamentals:
        print(f"{fundamental.symbol} dollar volume at {fundamental.end_time}: {fundamental.dollar_volume}")

For more information about historical US Equity fundamental data, see Equity Fundamental Data.

Example Applications

The US Equity Coarse Universe dataset enables you to accurately design a universe of US Equities. Examples include the following strategies:

  • Selecting securities with the largest dollar volume
  • Selecting securities within a specific price range
  • Selecting securities that have fundamental data available (together with MorningStar Fundamental data in Fundamental objects)

Classic Algorithm Example

The following example algorithm creates a dynamic universe of the three most liquid US Equities. Each time the universe changes, the algorithm forms an equal-weighted portfolio of the three companies.

from AlgorithmImports import *
from QuantConnect.DataSource import *

class USEquityCoarseUniverseConstituentsDataAlgorithm(QCAlgorithm):

    _number_of_symbols = 3
    _changes = None

    def initialize(self) -> None:
        self.set_start_date(2021, 1, 1)
        self.set_end_date(2021, 7, 1)
        self.set_cash(100000)
        # Set Asynchronous to True to improve speed performance
        self.universe_settings.asynchronous = True
        # Requesting data
        self.add_universe(self.fundamental_selection_function)

    def fundamental_selection_function(self, fundamental: List[Fundamental]) -> List[Symbol]:
        # Select the top traded stocks, since they are the most popular with high capital flow
        sortedByDollarVolume = sorted(fundamental, key=lambda x: x.dollar_volume, reverse=True)
        return [ x.symbol for x in sortedByDollarVolume[:self._number_of_symbols] ]

    def on_data(self, slice: Slice) -> None:
        # if we have no changes, do nothing
        if self._changes is None: return

        # liquidate removed securities, since they are not the most popular stocks
        for security in self._changes.removed_securities:
            if security.invested:
                self.liquidate(security.symbol)

        # we want 1/N allocation in each security in our universe to evenly dissipate risk
        for security in self._changes.added_securities:
            self.set_holdings(security.symbol, 1 / self._number_of_symbols)

        self._changes = None

    def on_securities_changed(self, changes: SecurityChanges) -> None:
        self._changes = changes
        
        for security in changes.added_securities:
            # Historical data
            history = self.history(security.symbol, 7, Resolution.DAILY)
            self.debug(f"We got {len(history)} from our history request for {security.symbol}") 
public class USEquityCoarseUniverseConstituentsDataAlgorithm : QCAlgorithm
{
    private int _numberOfSymbols = 3;
    private SecurityChanges _changes = SecurityChanges.None;
    
    public override void Initialize()
    {
        SetStartDate(2021, 1, 1);
        SetEndDate(2021, 7, 1);
        SetCash(100000);
    
        // Set Asynchronous to True to improve speed performance 
        UniverseSettings.Asynchronous = True;
        // Requesting data
        AddUniverse(FundamentalSelectionFunction);
    }

    public IEnumerable<Symbol> FundamentalSelectionFunction(IEnumerable<Fundamental> fundamental)
    {
        // Select the top traded stocks, since they are the most popular with high capital flow
        return fundamental.OrderByDescending(x => x.DollarVolume)
            .Take(_numberOfSymbols).Select(x => x.Symbol);
    }

    public override void OnData(Slice slice)
    {
        // if we have no changes, do nothing
        if (_changes == SecurityChanges.None) return;

        // liquidate removed securities, since they are not the most popular stocks
        foreach (var security in _changes.RemovedSecurities)
        {
            if (security.Invested)
            {
                Liquidate(security.Symbol);
            }
        }

        // we want 1/N allocation in each security in our universe to evenly dissipate risk
        foreach (var security in _changes.AddedSecurities)
        {
            SetHoldings(security.Symbol, 1m / _numberOfSymbols);
        }

        _changes = SecurityChanges.None;
    }
    
    public override void OnSecuritiesChanged(SecurityChanges changes)
    {
        _changes = changes;


        foreach (var security in changes.AddedSecurities)
        {
            // Historical data
            var history = History(security.Symbol, 7, Resolution.Daily);
            Debug($"We got {history.Count()} from our history request for {security.Symbol}");
        }
    }
}

Framework Algorithm Example

The following example algorithm creates a dynamic universe of the three most liquid US Equities and forms an equal-weighted portfolio with them.

from AlgorithmImports import *
from QuantConnect.DataSource import *

class USEquityCoarseUniverseConstituentsDataAlgorithm(QCAlgorithm):

    _number_of_symbols = 3

    def initialize(self) -> None:
        self.set_start_date(2021, 1, 1)
        self.set_end_date(2021, 7, 1)
        self.set_cash(100000)

        # Set Asynchronous to True to improve speed performance
        self.universe_settings.asynchronous = True
            
        # Requesting data
        self.set_universe_selection(
            FundamentalUniverseSelectionModel(self.fundamental_selection_function))
        
        # we want 1/N allocation in each security in our universe to evenly dissipate risk
        self.set_alpha(ConstantAlphaModel(InsightType.PRICE, InsightDirection.UP, timedelta(1)))
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
         
        self.add_risk_management(NullRiskManagementModel())
        
        self.set_execution(ImmediateExecutionModel())

    def fundamental_selection_function(self, fundamental: List[Fundamental]) -> List[Symbol]:
        # Select the top traded stocks, since they are the most popular with high capital flow
        sortedByDollarVolume = sorted(fundamental, key=lambda x: x.dollar_volume, reverse=True)
        return [ x.symbol for x in sortedByDollarVolume[:self._number_of_symbols] ]
public class USEquityCoarseUniverseConstituentsDataAlgorithm : QCAlgorithm
{
    private int _numberOfSymbols = 3;
    
    public override void Initialize()
    {
        SetStartDate(2021, 1, 1);
        SetEndDate(2021, 7, 1);
        SetCash(100000);

        // Set Asynchronous to True to improve speed performance
        UniverseSettings.Asynchronous = True;

        // Requesting data
        SetUniverseSelection(
            new FundamentalUniverseSelectionModel(FundamentalSelectionFunction));

        // we want 1/N allocation in each security in our universe to evenly dissipate risk
        SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1)));
        SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
        
        AddRiskManagement(new NullRiskManagementModel());
        
        SetExecution(new ImmediateExecutionModel());
    }

    public IEnumerable<Symbol> FundamentalSelectionFunction(IEnumerable<Fundamental> fundamental)
    {
        // Select the top traded stocks, since they are the most popular with high capital flow
        return fundamental.OrderByDescending(x => x.DollarVolume)
            .Take(_numberOfSymbols).Select(x => x.Symbol);
    }
}

Research Example

The following example lists the three most liquid US Equities:

var qb = new QuantBook();

// Add Fundamental Universe Selection
IEnumerable<Symbol> FundamentalSelectionFunction(IEnumerable<Fundamental> fundamentals)
{
    return fundamentals.OrderByDescending(x => c.DollarVolume).Take(10).Select(x => c.Symbol);
}

var universe = qb.AddUniverse(FundamentalSelectionFunction); 

// Historical Universe data
var universeHistory = qb.UniverseHistory(universe, qb.Time.AddDays(-30), qb.Time);
foreach (var fundamentals in universeHistory)
{
    foreach (Fundamental fundamental in fundamentals)
    {
        Console.WriteLine($"{fundamental.Symbol} dollar volume at {fundamental.EndTime}: {fundamental.DollarVolume}");
    }
}
qb = QuantBook()

# Add Fundamental Universe Selection
def fundamental_selection_function(fundamentals):
    selected = sorted(fundamentals, key=lambda x: x.dollar_volume, reverse=True)[:10]
    return [x.symbol for x in selected]

universe = qb.add_universe(fundamental_selection_function)

# Historical Universe data
universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (universe_symbol, time), fundamentals in universe_history.items():
    for fundamental in fundamentals:
        print(f"{fundamental.symbol} dollar volume at {fundamental.end_time}: {fundamental.dollar_volume}")

Data Point Attributes

The US Equity Coarse Universe dataset provides its data within Fundamental objects, which have the following . The attributes from market_capMarketCap to asset_classificationAssetClassification listed in the following widget are NaN until this dataset is combined with the MorningStar Fundamental dataset.

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: