quantlab.dataset.nbbo.panel.NbboPanelBase#

class quantlab.dataset.nbbo.panel.NbboPanelBase(dataset_config)[source]#

Bases: StockDataset

Dense NBBO bar panel on the PERMNO axis, from bars a subclass supplies.

It inherits from StockDataset the vendor-root check, the scan root inside the DATA_TYPE directory, the hive schema and has_raw_data. It overrides how the axes and each window’s panel are built, and _clean: the panel has no OHLCV (open, high, low, close, volume) columns, so clean_nbbo_panel validates it instead.

The raw symbol= directories are tickers, and every (date, ticker) is resolved to its PERMNO through the CRSP symbology in config.reference_dir. With config.permnos set, the axis is exactly that roster and only the tickers those PERMNOs used are read; otherwise the axis is every PERMNO the raw tickers resolve to. A ticker that resolves to no PERMNO on its date is dropped and listed under unmapped in the filter-stats sidecar. The inherited ticker-side symbols field is refused.

A subclass declares config_cls and DATA_TYPE and implements three hooks: _check_bar_size (the config’s frequency and bar size), _bar_interval (the bar size, a BAR_INTERVAL_SECONDS key) and _read_bars (one window’s bars and drop counts). resample_labels is a different step: it cuts the finished panel into coarser bars for resample.

Attributes:
last_filter_statsdict or None

The filter-stats sidecar content after the last window built.

DATA_TYPE#

The data type whose directory under the vendor root holds the raw files.

config_cls#

The config class used to rebuild the dataset from a saved config.json.

alias of NbboDatasetConfig

property filter_stats_path#

Return the path of the filter-stats sidecar next to the store.

Examples

>>> ds.filter_stats_path
'data/us_equity/tick/wrds_nbbo_1m.zarr.nbbo_filter_stats.json'
last_filter_stats = None#

The merged filter-stats sidecar content after the last window this instance built; None until then. Windows skipped because the chunk ledger marks them done leave it, and the sidecar, unchanged.

resample_labels(timestamps, freq)[source]#

Return the bar each NBBO bar belongs to, cut by trading session.

NBBO bars are labelled at their end inside a session window, so a bar belongs to the session whose open < t <= close. "1d" labels a session with its date at midnight, which lines a daily panel up with daily stores; any other frequency cuts the session into right-closed bars from its open, labelled at their end, the last one clipped to the close. The candidate sessions are the UTC dates the bars fall on and the day before each, since an extended close lands on the next UTC calendar day.

Parameters:
timestampsnp.ndarray

The panel’s bar labels, naive UTC.

freqstr

A ResampleFrequency token.

Examples

>>> bars = pd.to_datetime(["2024-01-24 14:31", "2024-01-24 21:00"])
>>> ds.resample_labels(bars.values, "1d").astype("datetime64[D]")
array(['2024-01-24', '2024-01-24'], dtype='datetime64[D]')
ticker_lookup()[source]#

Return the lookup over the CRSP ticker sidecar beside the store.

The panel’s symbol axis is the PERMNO, so its symbols are named as on a CRSP store; None when the dataset has no store.

Examples

>>> ds.ticker_lookup()
CrspTickerLookup('data/us_equity/tick/wrds_nbbo_1m.zarr.crsp_tickers.json')
ticker_sidecar_path()[source]#

Return the path of the ticker sidecar written next to the store.

It is the same file the CRSP conversion writes, so ticker_lookup() reads it with a CrspTickerLookup.

Examples

>>> ds.ticker_sidecar_path()
PosixPath('data/us_equity/tick/wrds_nbbo_1m.zarr.crsp_tickers.json')