QuantConnect

US ETF Constituents

Introduction

The US ETF Constituents dataset by QuantConnect tracks the constituents and weighting of US Equities in 2,650 ETF listings. The data starts in January 2009 and is delivered on a daily basis. This dataset is created by tracking the host ETF websites and can be delayed by up to 1 week.

This dataset depends on the US Equity Security Master dataset because the US Equity Security Master dataset contains information on splits, dividends, and symbol changes.

For more information about the US ETF Constituents 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 160,000 quants are served every month.

Getting Started

The following snippet demonstrates how to request data from the US ETF Constituents dataset:

from QuantConnect.DataSource import *

# Use the following method for a Classic Algorithm
self.AddUniverse(self.Universe.ETF("SPY", Market.USA, self.UniverseSettings, self.ETFConstituentsFilter))

symbol = Symbol.Create("SPY", SecurityType.Equity, Market.USA)
# Use the following method for a Framework Algorithm
self.AddUniverseSelection(ETFConstituentsUniverseSelectionModel(symbol, self.UniverseSettings, self.ETFConstituentsFilter))
using QuantConnect.DataSource;

// Use the following method for a Classic Algorithm
AddUniverse(Universe.ETF("SPY", Market.USA, UniverseSettings, ETFConstituentsFilter));

var symbol = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
// Use the following method for a Framework Algorithm
AddUniverseSelection(new ETFConstituentsUniverseSelectionModel(symbol, UniverseSettings, ETFConstituentsFilter));

Data Summary

The following table describes the dataset properties:

PropertyValue
Start DateJanuary 2009
Asset Coverage2,650 US ETF Listings
Data DensityDense
ResolutionDaily
TimezoneNew York

Supported ETFs

The following table shows the available ETFs:

Data Point Attributes

The ETF Constituents dataset provides ETFConstituentData objects, which have the following attributes:

Requesting Data

To add US ETF Constituents data to your algorithm, call the AddUniverse and Universe.ETF methods.. To select which constituents occupy the universe, provide the ETF Symbol and a selection function.

class ETFConstituentsDataAlgorithm(QCAlgorithm):

    def Initialize(self) -> None:
        self.SetStartDate(2018, 1, 1)
        self.SetEndDate(2020, 8, 25)
        self.SetCash(100000)

        self.AddUniverse(self.Universe.ETF("SPY", self.UniverseSettings, self.ETFConstituentsFilter))
namespace QuantConnect
{
   public class ETFConstituentsDataAlgorithm : QCAlgorithm
   {
       public override void Initialize()
       {
           SetStartDate(2018, 1, 1);
           SetEndDate(2020, 8, 25);
           SetCash(100000);

           AddUniverse(Universe.ETF("SPY", UniverseSettings, ETFConstituentsFilter));
       }
    }
}

Accessing Data

To access the US ETF Constituent data, use the ETFConstituentData objects in your selection function. The data is available in daily resolution. The Symbol objects you return from your selection function defines the universe constituents.

def ETFConstituentsFilter(self, constituents: List[ETFConstituentData]) -> List[Symbol]:
    for c in constituents:
        self.Debug(f'{c.EndTime} :: {c.LastUpdate} :: {c.Weight} :: {c.SharesHeld} :: {c.MarketValue}')
    return [x.Symbol for x in constituents]
public IEnumerable<Symbol> ETFConstituentsFilter(IEnumerable<ETFConstituentData> constituents)
{
    foreach (var c in constituents)
    {
        Debug($"{c.EndTime} :: {c.LastUpdate} :: {c.Weight} :: {c.SharesHeld} :: {c.MarketValue}");
    }

    return constituents.Select(c => c.Symbol);
}

Historical Data

You can't request historical ETFConstituentData objects, but you can you can use the Symbol member of each object to request historical market data of the securities that the ETFConstituentData objects reference. If there is no data in the period you request, the history result is empty.

def ETFConstituentsFilter(self, constituents: List[ETFConstituentData]) -> List[Symbol]:
    # Get the 20 largest weighting constituents
    selected = sorted([c for c in constituents if c.Weight],
        key=lambda c: c.Weight, reverse=True)[:20]
    selectedSymbols = [c.Symbol for c in selected]

    history = History(selectedSymbols, 10, Resolution.Daily)
                
    return selectedSymbols 
private IEnumerable<Symbol> ETFConstituentsFilter(IEnumerable<ETFConstituentData> constituents)
{
    // Get the 20 largest weighting constituents
    var selectedSymbols = constituents
        .OrderByDescending(c => c.Weight)
        .Take(10)
        .Select(c => c.Symbol)

    var history = History(selectedSymbols, 10, Resolution.Daily);

    return selectedSymbols;
}

Example Applications

The ETF Constituents dataset provides an excellent source of tradable universes for strategies without selection bias. When you use an ETF universe, the original ETF can serve as an excellent benchmark for your strategy performance. Other use cases include the following:

  • Creating an index-tracking algorithm for customized passive portfolio management
  • Performing statistical arbitrage with the base ETF

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: