quantlab.factor.predefined.intraday#

High-frequency factors: daily statistics of each session’s one-minute bars.

IntradayStats reads one-minute bars (the Massive Trade bars, on the permaticker axis) and computes, at every bar, a statistic of the session so far: realized moments of the minute returns, their jump and semivariance parts, the return of parts of the session, order imbalance, the price-volume relation, the shape of the volume over the day and the share of the closing auction. The value at a session’s last bar is the statistic of the whole session, so resampled to "1d" with "last" the factor is one value per stock and day:

daily = IntradayStats(config).resample("1d", "last")

IntradayAverage then averages the stored daily values over the last window sessions, the form in which the literature sorts stocks on them (a week in Amaya et al. 2015, a month in most of the rest).

Both are KunQuant graphs. KunQuant has no notion of a session, so IntradayStats adds four inputs computed from the bar timestamps and prices before the graph runs (_kunquant_inputs): the bar’s position in its session and the bars left to its close, the last trade price at or before the bar, and the reference price a bar’s return is measured from. The session statistics are running sums that restart at each session’s first bar (_session_sums), so a half day sums its own 210 bars and nothing of the day before, and each bar costs the same whatever its position in the session. A correlation’s second moments come from the same running sums (sum xy - sum x sum y / n), the price taken from the session’s first trade so its sums stay small in float32.

The minute return of bar t is log(p_t / p_{t-1}), p the last trade price at or before a bar’s end within the session, carried over bars without a trade (previous-tick sampling, so a bar without a trade returns 0). The first traded bar’s return is measured from its open, so the session’s returns add up to log(last price / first trade) and the overnight move is not one of them. The literature behind each output:

output

definition, source

rvol

sqrt(sum r^2), realized volatility (Andersen et al. 2001)

rskew

sqrt(N) sum r^3 / RV^1.5 (Amaya, Christoffersen, Jacobs and Vasquez 2015, JFE)

rkurt

N sum r^4 / RV^2 (same)

rsj

(RV+ - RV-) / RV, signed jump variation from realized semivariances (Barndorff-Nielsen, Kinnebrock and Shephard 2010; Bollerslev, Li and Zhao 2020, JFQA)

jump

max(RV - BV, 0) / RV, BV = pi/2 N/(N-1) sum |r_t||r_{t-1}|, bipower variation (Barndorff-Nielsen and Shephard 2004; Jiang and Yao 2013)

ret_autocorr

sum r_t r_{t-1} / RV, first-order autocorrelation of minute returns, a price-efficiency measure

ret_intraday

sum r, first trade to last price (Lou, Polk and Skouras 2019, JFE)

ret_overnight

log(first trade / previous official close) (same)

ret_open30

sum r over the first 30 bars (Gao, Han, Li and Zhou 2018, JFE; Heston, Korajczyk and Sadka 2010, JF)

ret_close30

sum r over the last 30 bars (same)

vwap_dev

log(last price / VWAP)

oib

(buy - sell) / (buy + sell) tick-rule volume (Chordia and Subrahmanyam 2004, JFE)

corr_rv

correlation of minute return and volume (Llorente, Michaely, Saar and Wang 2002, RFS)

corr_pv

correlation of minute price and volume, the “price-volume divergence” factor of A-share broker research

volume_cv

standard deviation over mean of minute volume

volume_close30

share of the continuous volume in the last 30 bars

auction_share

closing-auction volume over the day’s volume (Bogousslavsky and Muravyev 2023, JFM)

offexchange_share

share of the volume reported through a TRF

amihud

1e6 sum |r| / sum dollar volume (Amihud 2002, on minute bars)

trade_size

log(volume / trades)

RV is sum r^2 and N the number of minute returns. A session with fewer than min_returns bars with a trade gives NaN in every output.

Classes

CompositePart

One part of an IntradayComposite output, parsed from "[-]<output>:<statistic>:<window>".

IntradayAverage

The mean of each output of a stored factor over its last window bars.

IntradayComposite

Equal-weight combinations of the cross-sectional ranks of trailing statistics of a stored factor.

IntradayParameters

Parameters of IntradayStats, read from config.kwargs.

IntradayStats

Session statistics of one-minute bars, one value per bar for the session so far.

Functions

session_inputs

Return the session inputs of IntradayStats for [time, symbol] prices.