quantlab.universe.Nasdaq100MembershipFetcher#
- class quantlab.universe.Nasdaq100MembershipFetcher(cache_dir)[source]#
Bases:
IndexMembershipFetcherPoint-in-time Nasdaq-100 membership from a scraped anchor and Wikipedia.
PIT_COVERAGE_STARTis 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 whyfetch_anchorhas 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 adate_addedcolumn, so the anchor’s is all null and every member without a change-log event opens atPIT_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_HEADERentry 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
Symbolcolumn is used anddate_addedis 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
Symbolcolumn, or fewer thanMIN_ANCHOR_ROWSsymbols survive cleaning.
Examples
>>> fetcher = Nasdaq100MembershipFetcher(cache_dir="/tmp/cache") >>> anchor = fetcher.fetch_anchor() # downloads the listing page >>> anchor.columns ['symbol', 'date_added']