quantlab.universe.Nasdaq100MembershipFetcher#

class quantlab.universe.Nasdaq100MembershipFetcher(cache_dir)[source]#

Bases: IndexMembershipFetcher

Point-in-time Nasdaq-100 membership from a scraped anchor and Wikipedia.

PIT_COVERAGE_START is the earliest row of the Wikipedia change table (2007-02-01), about three decades later than the S&P 500’s, so the two categories must not be unioned onto one axis that implies coverage neither has.

The anchor is scraped from a commercial listing page (ANCHOR_URL), because Wikipedia’s Nasdaq-100 page renders its components through a template with no parseable table. It is the least stable input in this module, which is why fetch_anchor has a row-count floor of its own. The live anchor has 102 rows, not 100, because some issuers carry two share classes (GOOGL/GOOG, FOX/FOXA). Neither source carries a date_added column, so the anchor’s is all null and every member without a change-log event opens at PIT_COVERAGE_START.

Examples

>>> fetcher = Nasdaq100MembershipFetcher(cache_dir="data/reference/_cache")
>>> intervals = fetcher.build_intervals()  # downloads anchor and change log
>>> intervals.columns
['symbol', 'start_date', 'end_date', 'end_date_is_inferred']
CATEGORY = 'nasdaq100_constituent'#

The catalog category this index is stored under. Typed as the literal so an unknown token is a type error rather than a runtime surprise.

DATE_HEADER = 'Date'#

The EXPECTED_SOURCE_HEADER entry carrying the effective date.

EXPECTED_SOURCE_HEADER = ('Date', 'Added Ticker', 'Added Security', 'Removed Ticker', 'Removed Security', 'Reason')#

Exact flattened header (see _flatten_header) of the change-log table. It both selects the table and names the columns read from it.

fetch_anchor()[source]#

Scrape the constituents table and return [symbol, date_added].

The first table carrying a Symbol column is used and date_added is all null. Missing cells are dropped by nullness, never by comparing against the string "nan", so that pandas’ missing-value vocabulary cannot swallow a real ticker.

Raises:
ValueError

If no table carries a Symbol column, or fewer than MIN_ANCHOR_ROWS symbols survive cleaning.

Examples

>>> fetcher = Nasdaq100MembershipFetcher(cache_dir="/tmp/cache")
>>> anchor = fetcher.fetch_anchor()  # downloads the listing page
>>> anchor.columns
['symbol', 'date_added']