Summary
IntegratedOrderFlowImbalance projects multi-level Cont-style OFI onto an online first
principal component of the level-event covariance. Each depth level contributes a rolling
Cont event; an EMA covariance matrix and power-iteration weights form a single integrated
scalar ofi plus the level-1 weight weight_l1.
Update API
import rtta
ind = rtta.IntegratedOrderFlowImbalance(
levels=5, window=1, ema_alpha=0.05, fillna=True
)
result = ind.update(bid_price, bid_size, ask_price, ask_size) # vectors length `levels`
# result.ofi, result.weight_l1
batch = ind.batch(bid_prices, bid_sizes, ask_prices, ask_sizes) # (n, levels)
advance(...) updates state without returning a result. Float32/float64 depth vectors and
batch matrices are supported.
Theory Of Operation
Raw multi-level OFI is a vector \(v_t \in \mathbb{R}^L\). In practice the components are highly collinear; Cont-style “integrated” OFI collapses depth into one factor by taking the leading eigenvector of the event covariance and the corresponding linear combination. RTTA maintains:
- Per-level Cont events and rolling sums \(v^{(\ell)}_t\) (same map as multi-level OFI).
- An exponential moving covariance \(\Sigma_t\) of the vector \(v_t\).
- Four power-iteration steps on \(\Sigma_t\) starting from the previous weight vector, re-oriented so the top-of-book weight is non-negative.
- Scalar projection \(\mathrm{ofi}_t = w_t^\top v_t\).
Initial weights are \(w = (1,0,\ldots,0)\). With fillna=False, outputs are NaN until
count >= window.
Recurrence
Cont events \(e^{(\ell)}_t\) and rolling sums \(v^{(\ell)}_t = S^{(\ell)}_t\) are identical to
MultiLevelOrderFlowImbalance (with incomplete windows forced to \(0\) when building \(v\)
under fillna=True logic that uses the sum when the window is not full only if fillna).
Covariance EMA with \(\alpha = \mathrm{ema\_alpha}\) (clamped to \([10^{-6},1]\)):
Power iteration (four steps) from previous weights \(w_{t-1}\):
Sign flip so \(\tilde{w}^{(4)}_0 \ge 0\):
Outputs:
If fillna=False and \(t < W\), both fields are NaN.
Implementation Notes
The recurrence is implemented in src/rtta/indicator.cpp in
class IntegratedOrderFlowImbalance. Covariance is stored row-major as a length-\(L^2\)
vector. Batch requires shape (n_samples, levels).
