quantlab.dataset.nbbo.panel.NbboPanelBase#
- class quantlab.dataset.nbbo.panel.NbboPanelBase(dataset_config)[source]#
Bases:
StockDatasetDense NBBO bar panel on the PERMNO axis, from bars a subclass supplies.
It inherits from
StockDatasetthe vendor-root check, the scan root inside theDATA_TYPEdirectory, the hive schema andhas_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, soclean_nbbo_panelvalidates it instead.The raw
symbol=directories are tickers, and every(date, ticker)is resolved to its PERMNO through the CRSP symbology inconfig.reference_dir. Withconfig.permnosset, 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 underunmappedin the filter-stats sidecar. The inherited ticker-sidesymbolsfield is refused.A subclass declares
config_clsandDATA_TYPEand implements three hooks:_check_bar_size(the config’s frequency and bar size),_bar_interval(the bar size, aBAR_INTERVAL_SECONDSkey) and_read_bars(one window’s bars and drop counts).resample_labelsis a different step: it cuts the finished panel into coarser bars forresample.- 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;
Noneuntil 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
ResampleFrequencytoken.
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;
Nonewhen 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 aCrspTickerLookup.Examples
>>> ds.ticker_sidecar_path() PosixPath('data/us_equity/tick/wrds_nbbo_1m.zarr.crsp_tickers.json')