quantlab.dataset.nbbo.bars.NbboBarsDataset#

class quantlab.dataset.nbbo.bars.NbboBarsDataset(dataset_config)[source]#

Bases: NbboPanelBase

Dense NBBO bar panel from bars the WRDS server resampled (nbbo_bars).

The raw tier is written by quantlab.acquisition.wrds.taq_bars.WrdsTaqNbboBarsAcquisition under .../wrds/nbbo_bars/date=.../symbol=.../*.pqt: one row per (ticker, bar) with the SERVER_BAR_VARIABLES, labelled at the bar’s end. The panel is the one NbboPanelDataset builds from ticks: the same 13 variables, the same session grid, the PERMNO axis, the ticker and filter-stats sidecars and the cleaning, all inherited from NbboPanelBase. This class only reads the bars, maps each raw (date, ticker) to its PERMNO and derives mid, spread, spread_bps and imbalance from the snapshot.

Two differences from the tick path follow from the data being bars:

  • the session window and the filters were applied on the server, so the config must match the settings recorded with the download (NbboBarsRequest), or the conversion refuses. The record is found in the watermark directory the acquisition writes beside the raw root, <raw root>/../_watermarks/<vendor>/nbbo_bars/, the layout every config factory and place_downloads produce;

  • the tick path merges the records of two raw tickers that resolve to one PERMNO on a date, but bars cannot be merged exactly, so such a date is refused, naming the tickers.

The server counts the records each filter dropped per (date, ticker) and the acquisition keeps the counts on each ticker’s first bar; the conversion puts them on the PERMNO axis and merges them into the filter-stats sidecar, so the sidecar equals the tick path’s.

Parameters:
dataset_configNbboBarsDatasetConfig

frequency is the bar size and must be a BAR_INTERVAL_SECONDS key; reference_dir holds the CRSP reference tables.

Examples

Needs a raw nbbo_bars tier and the CRSP reference tables:

config = NbboBarsDatasetConfig(
    raw_data_dir_path="downloads/wrds",
    zarr_file_path="data/wrds_nbbo_server_1m.zarr",
    reference_dir="downloads/_reference",
    start_date="2024-01-24",
    end_date="2024-01-25",
)
NbboBarsDataset(config).from_raw_data_chunked(granularity="day")
panel = NbboBarsDataset(config).panel("2024-01-24", "2024-01-25")
panel["bid"].dims   # ('timestamp', 'symbol')
DATA_TYPE = 'nbbo_bars'#

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

HIVE_SCHEMA = {'date': Date, 'symbol': String}#

The raw tier is laid out like the tick tier, one directory per (date, ticker), whatever the bar size; the keys and their dtypes.

config_cls#

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

alias of NbboBarsDatasetConfig