quantlab.dataset.massive.resample.TradeBarResampler#
- class quantlab.dataset.massive.resample.TradeBarResampler(bar_interval, *, close_auction=True)[source]#
Bases:
objectResample trade records onto right-closed Trade bars; see the module docstring.
- Parameters:
- bar_intervalstr
The bar size, a key of
BAR_INTERVAL_SECONDS.- close_auctionbool, default True
Whether the sessions end at the exchange’s close, so that the closing auction printed after it belongs to their last bar. A window that ends earlier has none.
- Raises:
- ValueError
If
bar_intervalis unknown.
Examples
>>> TradeBarResampler("5m").interval_ns 300000000000
- labels(sessions)[source]#
Return every bar label of
sessions.- Parameters:
- sessionspl.DataFrame
Columns
date,openandclose(naive UTC).
- Returns:
- pl.DataFrame
Columns
dateandtimestamp(Datetime("ns")): for each sessionopen + k * intervalwhile before the close, then the close, sorted.
Examples
>>> TradeBarResampler("1m").labels(sessions)["timestamp"].head(1).to_list() [datetime.datetime(2024, 1, 24, 14, 31)]
- resample_with_stats(trades, conditions, sessions)[source]#
Resample trades onto bars and count what each rule dropped.
- Parameters:
- tradespl.DataFrame
Columns
symbol,date(the session date),conditions(comma-separated ids, or null),correction,price,size,sip_timestamp(Int64 nanoseconds since the epoch, UTC),sequence_number,trf_id(0 or null when not reported through a TRF) andexchange.- conditionspl.DataFrame
The condition table, as
read_conditionsreturns it.- sessionspl.DataFrame
Columns
date,openandclose(naive UTC) of the sessions the trades belong to.
- Returns:
- barspl.DataFrame
Columns
symbol,date,timestampandTRADE_BAR_VARIABLES: every bar of the session for each symbol with at least one record on that date, sorted by symbol and label. Prices are null where no trade was eligible; the volumes are Float64,n_tradesInt64.- statspl.DataFrame
Columns
date,symbolandTRADE_STATS_COUNTS(Int64), one row per(date, symbol)with a record.
Examples
With
tradesread byquantlab.dataset.massive.raw.read_trades(tickerrenamedsymbol, adatecolumn added), the condition table and that day’s XNYS session bounds:sessions = XnysSessionCalendar().session_bounds([date(2016, 11, 25)]) bars, stats = TradeBarResampler("1m").resample_with_stats(trades, conditions, sessions)