quantlab.universe.SP500MembershipFetcher#
- class quantlab.universe.SP500MembershipFetcher(cache_dir)[source]#
Bases:
IndexMembershipFetcherPoint-in-time S&P 500 membership from a GitHub CSV anchor and Wikipedia.
The anchor is the
datasets/s-and-p-500-companiesCSV, which carries aDate addedcolumn.PIT_COVERAGE_STARTis the earliest row of the Wikipedia change table (1976-07-01), not the earlier coverage the page’s prose claims; queries before it are refused.Examples
>>> fetcher = SP500MembershipFetcher(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 = 'sp500_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.
- CHANGES_TABLE_ATTRS = {'id': 'changes'}#
Optional
pd.read_html(attrs=...)pre-filter for a page that marks its change-log table with an id or class.
- DATE_HEADER = 'Effective Date'#
The
EXPECTED_SOURCE_HEADERentry carrying the effective date.
- EXPECTED_SOURCE_HEADER = ('Effective Date', 'Added Ticker', 'Added Security', 'Removed Ticker', 'Removed Security', 'Reason', 'Refs')#
Exact flattened header (see
_flatten_header) of the change-log table. It both selects the table and names the columns read from it.