quantlab.acquisition.wrds.taq_bars.WrdsTaqNbboBarsAcquisition#
- class quantlab.acquisition.wrds.taq_bars.WrdsTaqNbboBarsAcquisition(config)[source]#
Bases:
WrdsTaqNbboAcquisitionDownload 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: oneNbboBarsQueryper 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, withtimestampthe bar’s end in naive UTC,symbolthe ticker,vendor, theSERVER_BAR_VARIABLESand the ticker’sFILTER_STATS_COUNTSfor 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:frequencyis the bar size,kwargs["data_type"]is"nbbo_bars"and the otherREQUEST_KWARGSset the session window and the filters; a missing one takesNbboBarsRequest’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()orrefresh(), when the raw tier was built with other settings.
Examples
Needs
WRDS_USERNAMEand a~/.pgpassentry: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
dateis stored astaq_date, because the shard writer adds its owndatecolumn for thedate=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
AcquisitionConfigfor a server-bar download.This is the
config_factoryof the registry’snbbo_barscapability.frequencyis the bar size; the session window and the filters go intokwargs. The raw directory is.../{subdir}/wrdsand the watermarks go to.../{subdir}/_watermarks/wrds, both underget_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_sizeormax_workers.data_typeis 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
kwargsnames 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.