quantlab.acquisition.wrds.taq_bars.WrdsTaqNbboBarsAcquisition#

class quantlab.acquisition.wrds.taq_bars.WrdsTaqNbboBarsAcquisition(config)[source]#

Bases: WrdsTaqNbboAcquisition

Download NBBO bars resampled on the WRDS server from the TAQ day tables.

Everything about the WRDS session, the symbols, the trading days, the subscription check and the failure policy is the tick download’s (WrdsTaqNbboAcquisition). What differs is the page: one NbboBarsQuery per trading day and symbol batch, whose result is one row per (ticker, bar) for every ticker with a record that day. The session bounds of each day come from the XNYS calendar on this side and are passed into the statement. Each page logs its day, batch, rows and seconds, and its row count is checked against the count the server put on every row; a short page fails its batch.

The raw tier is .../wrds/nbbo_bars/date=/symbol=/, laid out like the tick tier whatever the bar size, with timestamp the bar’s end in naive UTC, symbol the ticker, vendor, the SERVER_BAR_VARIABLES and the ticker’s FILTER_STATS_COUNTS for the day, set on its first bar’s row and null on the others. The watermarks, and the request settings (_request.json), go to .../_watermarks/wrds/nbbo_bars/.

Parameters:
configAcquisitionConfig

Built by build_config: frequency is the bar size, kwargs["data_type"] is "nbbo_bars" and the other REQUEST_KWARGS set the session window and the filters; a missing one takes NbboBarsRequest’s default.

Raises:
ValueError

At construction, for a frequency that is not a bar size, a wrong data type or invalid request settings; at download() or refresh(), when the raw tier was built with other settings.

Examples

Needs WRDS_USERNAME and a ~/.pgpass entry:

cfg = WrdsTaqNbboBarsAcquisition.build_config(
    ("AAPL", "MSFT"), start_date="2024-01-24", end_date="2024-01-25"
)
WrdsTaqNbboBarsAcquisition(cfg).download()

Shards land under .../wrds_taq/wrds/nbbo_bars/date=2024-01-24/symbol=AAPL/.

DATA_TYPE = 'nbbo_bars'#

The data type: the raw directory under the vendor root, the watermark directory and the registry capability.

DEFAULT_BATCH_SIZE = 10#

Symbols per day-table statement. A statement returns nothing until the server has built every bar, and some routes to WRDS cut a connection that is silent for about 60 s; a page of 10 S&P 500 tickers takes up to about 40 s, one of 25 can take a minute. Overridable through kwargs["batch_size"].

HIVE_KEYS = ('date', 'symbol')#

The raw tier is laid out like the tick tier, whatever the bar size.

RAW_COLUMNS = ('timestamp', 'symbol', 'vendor', 'bid', 'bid_size', 'ask', 'ask_size', 'n_updates', 'tw_spread', 'tw_bid_size', 'tw_ask_size', 'n_ambiguous_ties', 'records_in', 'dropped_nonpositive_price', 'dropped_condition', 'dropped_crossed', 'dropped_locked', 'one_sided_kept', 'both_null_kept')#

The shard columns and their order. TAQ’s date is stored as taq_date, because the shard writer adds its own date column for the date= directory and would otherwise overwrite the raw one.

classmethod build_config(symbols, start_date=None, end_date=None, kwargs=None, subdir='wrds_taq', *, bar_interval='1m', session_start='09:30', session_end='16:00', drop_crossed=True, drop_locked=False, drop_nonpositive_price=True, keep_qu_cond=None)[source]#

Build the AcquisitionConfig for a server-bar download.

This is the config_factory of the registry’s nbbo_bars capability. frequency is the bar size; the session window and the filters go into kwargs. The raw directory is .../{subdir}/wrds and the watermarks go to .../{subdir}/_watermarks/wrds, both under get_data_root() / "downloads" / "us_equity" / bar_interval.

Parameters:
symbolsiterable of str

Tickers in dot notation, for example "BRK.B".

start_date, end_datestr or None, default None

The window, inclusive, as ISO dates.

kwargsdict or None, default None

Extra options, such as batch_size or max_workers. data_type is set to "nbbo_bars".

subdirstr, default “wrds_taq”

Directory under downloads/us_equity/<bar size>.

bar_intervalstr, default “1m”

The bar size.

session_start, session_endstr, default “09:30”, “16:00”

The session window, New York clock time.

drop_crossed, drop_locked, drop_nonpositive_price, keep_qu_cond

The quote filters, as for NbboFilterPolicy.

Returns:
AcquisitionConfig

The config for WrdsTaqNbboBarsAcquisition.

Raises:
ValueError

If kwargs names another data type or sets a request setting, which belongs to the keyword arguments.

Examples

>>> cfg = WrdsTaqNbboBarsAcquisition.build_config(
...     ("AAPL",), start_date="2024-01-24", end_date="2024-01-25"
... )
>>> cfg.frequency, cfg.kwargs["data_type"], cfg.kwargs["session_start"]
('1m', 'nbbo_bars', '09:30')
request#

The settings the bars are cut with; built now so bad settings fail at construction.