quantlab.dataset.nbbo.resample#

Resample NBBO quote records onto a regular bar grid.

The NBBO (National Best Bid and Offer) is the best bid and best ask across all US exchanges. Each NBBO record is one update of that quote, with a timestamp, a bid and ask price, and the size (shares) offered at each. A session is one trading day, with its open and close time.

NbboResampler turns these irregular records into one row per (symbol, bar label) for each session, after NbboFilterPolicy has dropped the records the caller does not want. It is pure polars with no file access; NbboPanelDataset in this package feeds it the raw files and puts its output onto the (timestamp, symbol) panel.

Bars are right-closed and labelled at their end. With session open o and bar length d, the labels are o + k*d for k = 1..N, and bar k covers (o + (k-1)*d, o + k*d], so a label is the time at which the bar’s information was known. Snapshot variables (bid, ask, …) come from the last record at or before the label; tw_* variables are time-weighted averages over the bar. A quote stays in force until it is replaced, so a bar with no update reports the quote still in force, with n_updates = 0; a quote is never carried over from one session date to the next. A null side means there is no quote on that side: its price and size are NaN, never 0, and every variable derived from it is NaN while that side is missing.

Classes

NbboFilterPolicy

Filter applied to NBBO records before resampling.

NbboResampler

Resample NBBO records onto a regular right-closed bar grid.

Functions

snapshot_derived_variables

Return the expressions deriving mid, spread_bps and imbalance.