quantlab.dataset.config.CrspDatasetConfig#

class quantlab.dataset.config.CrspDatasetConfig(*, zarr_file_path, start_date=None, end_date=None, symbols=None, kwargs=None, resample_freq=None, resample_how=None, name=None, raw_data_dir_path, market='us_equity', frequency='1d', vendor='wrds', reference_dir, permnos=None, security_filter='equity_common', roster_universe=None)[source]#

Bases: DatasetConfig

Config of the CRSP Stock v2 daily panel.

The three market fields have defaults rather than being required: CRSP Stock v2 is US equity, daily, and reached through the wrds account. They remain fields (not constants on the dataset) because the vendor registry resolves the converter from (market, frequency, data_type) read off this object.

The panel’s symbol axis is the integer PERMNO, so the inherited ticker-side symbols field is refused by the dataset’s config setter; use permnos instead. See docs/user-guide/wrds.md.

Examples

>>> cfg = CrspDatasetConfig(
...     zarr_file_path="/data/us_equity/1d/crsp.zarr",
...     raw_data_dir_path="/data/downloads/us_equity/1d/crsp/wrds",
...     reference_dir="/data/reference/crsp",
...     start_date="2015-01-01",
...     end_date="2024-12-31",
...     permnos=("14593", "10107"),
... )
>>> cfg.market, cfg.frequency, cfg.vendor
('us_equity', '1d', 'wrds')
>>> cfg.security_filter
'equity_common'
classmethod etf_benchmark(*, permno, zarr_file_path, raw_data_dir_path, reference_dir, start_date=None, end_date=None)[source]#

Return the config of a store holding only one benchmark ETF.

The general form of qqq_benchmark: permnos=(permno,) selects the ETF alone and security_filter="none" keeps it, because an ETF is a fund, which the default filter drops. Use SPY_PERMNO for the S&P 500 and QQQ_PERMNO for the Nasdaq-100.

Parameters:
permnostr

The ETF’s CRSP PERMNO.

zarr_file_pathstr

Path of the benchmark’s own Zarr store.

raw_data_dir_pathstr

Root of the CRSP raw download tree.

reference_dirstr

Directory of the CRSP reference tables.

start_datestr | None

First date to keep, inclusive.

end_datestr | None

Last date to keep, inclusive.

Examples

>>> cfg = CrspDatasetConfig.etf_benchmark(
...     permno=SPY_PERMNO,
...     zarr_file_path="/data/us_equity/1d/spy.zarr",
...     raw_data_dir_path="/data/downloads/us_equity/1d/crsp/wrds",
...     reference_dir="/data/reference/crsp",
... )
>>> cfg.permnos, cfg.security_filter
(('84398',), 'none')
frequency = '1d'#

Always daily for this vendor.

market = 'us_equity'#

Always US equity for this vendor.

permnos = None#

Restrict the conversion to these PERMNOs, as digit strings. None means every PERMNO present in the raw tier; an empty tuple is refused at config assignment because it could mean either “none” or “all”. A PERMNO listed here is an explicit roster: every one of its rows survives security_filter regardless of its share or security type, and the override is recorded under roster_overrides in the filter report written next to the store.

classmethod qqq_benchmark(*, zarr_file_path, raw_data_dir_path, reference_dir, start_date=None, end_date=None)[source]#

Return the config of a store holding only the QQQ ETF.

The benchmark gets its own store rather than one more symbol in the equity panel: everything in the panel enters cross-sectional ranking and model training, and an ETF ranked against its own constituents is the index competing with itself. Two settings are fixed here because getting either wrong is silent: permnos=(QQQ_PERMNO,) selects the ETF alone, and security_filter="none" is required because QQQ is a fund, which the default filter drops.

Pass a dataset over this store as BacktestConfig.benchmark_dataset to compare a backtest against QQQ.

Parameters:
zarr_file_pathstr

Path of the benchmark’s own Zarr store.

raw_data_dir_pathstr

Root of the CRSP raw download tree.

reference_dirstr

Directory of the CRSP reference tables.

start_datestr | None

First date to keep, inclusive.

end_datestr | None

Last date to keep, inclusive.

Examples

>>> cfg = CrspDatasetConfig.qqq_benchmark(
...     zarr_file_path="/data/us_equity/1d/qqq.zarr",
...     raw_data_dir_path="/data/downloads/us_equity/1d/crsp/wrds",
...     reference_dir="/data/reference/crsp",
...     start_date="2015-01-01",
... )
>>> cfg.permnos, cfg.security_filter
(('86755',), 'none')
reference_dir#

Directory of the CRSP reference tables (stksecurityinfohist and friends) the conversion reads its symbology (the mapping from PERMNO to ticker over time) from. It is required rather than derived from raw_data_dir_path because the reference tables are downloaded by a separate step, and a missing download must fail with a clear error.

roster_universe = None#

Name of an index (one of CrspMembership.INDEXES) whose point-in-time membership (who was in the index on each date, as known on that date) acts as an explicit roster for this conversion. During a PERMNO’s membership spell it is exempt from security_filter; outside its spells the filter applies normally. Overrides are recorded under roster_overrides in the filter report. None means no index roster.

security_filter = 'equity_common'#

Which securities the panel holds: either the name of a preset ("equity_common", "shrcd_10_11", "none") or an explicit {column: allowed values} mapping over the filterable CRSP type columns. The default keeps common stock, including REITs and non-US incorporated issuers, and drops ADRs, units, funds, ETFs and unknown types. The predicate is evaluated per date against the daily type columns, so a security that changed type keeps only the era in which it qualified. Filtering happens at conversion time, never in the raw tier, so a re-filter is a re-conversion rather than a re-download.

vendor = 'wrds'#

Always WRDS for this dataset.