quantlab.dataset.common_stock.CommonStockConstituentDataset#

class quantlab.dataset.common_stock.CommonStockConstituentDataset(config)[source]#

Bases: IndexConstituentDataset

Membership = every security of a price store, from its first to its last priced bar.

A priced bar is one with a finite close. The interval holds both ends, so a halt inside it (bars without a price) and the calendar days between bars read as member, and a delisted security stops being a member the day after its last priced bar. A security priced on the store’s last bar has an interval ending on that bar, so the panel’s last day is the store’s last bar (no as_of needed). The coverage starts at the store’s first bar.

A security without a price on the store’s last bars (a halt or a late print at the store’s end) is not a member on them: whether it trades again is not known yet. update() appends the new bars and keeps the stored ones, so those days stay non-member once it trades again (what was known at the time), while a build from scratch reads them as a halt inside the interval.

Parameters:
configConstituentDatasetConfig

kwargs["price_store"] is the whole-market price Zarr store (for Sharadar, sharadar_sep_1d.zarr, whose symbol axis is the permaticker). start_date and end_date limit the bars read; leave end_date unset for a panel that follows the store.

Examples

A store of two securities, 202 halted on the middle bar and 303 delisted after it:

>>> import numpy as np, pandas as pd, xarray as xr
>>> from quantlab.dataset.config import ConstituentDatasetConfig
>>> days = pd.bdate_range("2024-01-02", periods=3)
>>> xr.Dataset(
...     {"close": (("timestamp", "symbol"), [[1.0, 2.0], [np.nan, 2.0], [1.0, np.nan]])},
...     coords={"timestamp": days, "symbol": np.array([202, 303])},
... ).to_zarr("data/sep.zarr", mode="w")
<xarray.backends.zarr.ZarrStore object at ...>
>>> members = CommonStockConstituentDataset(ConstituentDatasetConfig(
...     zarr_file_path="data/common_stock.zarr",
...     kwargs={"price_store": "data/sep.zarr"},
... ))
>>> members.from_raw_data().get_xarray_dataset()["is_member"].to_pandas()
symbol       202    303
timestamp
2024-01-02  True   True
2024-01-03  True   True
2024-01-04  True  False