Equity
ETF Constituents Universes
Introduction
An ETF constituents universe lets you select a universe of securities in an exchange traded fund. The US ETF Constituents dataset includes 2,650 US ETFs you can use to create your universe.
Create Universes
To add an ETF Constituents universe, call the Universe.ETF
method.
public class ETFConstituentsAlgorithm : QCAlgorithm { public override void Initialize() { AddUniverse(Universe.ETF("SPY", Market.USA, UniverseSettings)); } }
class ETFConstituentsAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.AddUniverse(self.Universe.ETF("SPY", Market.USA, self.UniverseSettings))
The following table describes the ETF
method arguments:
Argument: |
Argument: |
Argument: |
Argument: |
To select a subset of the ETF constituents, provide a universeFilterFunc
argument. The filter function receives ETFConstituentData
objects, which represent one of the ETF constituents. ETFConstituentsData
objects have the following attributes:
public class ETFConstituentsAlgorithm : QCAlgorithm { public override void Initialize() { var universe = Universe.ETF("SPY", Market.USA, UniverseSettings, ETFConstituentsFilter); AddUniverse(universe); } private IEnumerable<Symbol> ETFConstituentsFilter(IEnumerable<ETFConstituentData> constituents) { // Get the 10 securities with the largest weight in the index return constituents.OrderByDescending(c => c.Weight).Take(10).Select(c => c.Symbol); } }
class ETFConstituentsAlgorithm(QCAlgorithm): def Initialize(self) -> None: universe = self.Universe.ETF("SPY", Market.USA, self.UniverseSettings, self.ETFConstituentsFilter) self.AddUniverse(universe) def ETFConstituentsFilter(self, constituents: List[ETFConstituentData]) -> List[Symbol]: # Get the 10 securities with the largest weight in the index selected = sorted([c for c in constituents if c.Weight], key=lambda c: c.Weight, reverse=True)[:10] return [c.Symbol for c in selected]