Summary
DecomposedOrderFlowImbalance splits Cont-style best-quote pressure into three additive
channels — add, cancel, and trade (proxy) — each rolled with a sum window, plus
their sum as total. Inputs are top-of-book bid/ask price and size only.
Update API
import rtta
ind = rtta.DecomposedOrderFlowImbalance(window=1, fillna=True)
result = ind.update(bid_price, bid_size, ask_price, ask_size)
# result.add, result.cancel, result.trade, result.total
advance(...) updates state without returning a result. Batch helpers accept parallel
arrays of bid/ask price and size.
Theory Of Operation
Standard Cont OFI mixes liquidity additions, cancellations, and aggressive trades into one scalar. This indicator attributes each quote revision to:
- Add — new liquidity that increases Cont-style buy pressure (bid improve / size increase, or ask worsen in the Cont sign convention).
- Cancel — removed liquidity with opposite Cont signs.
- Trade — heuristic: mid moves up while ask size decreases without an ask price improvement (buyer lifting offers), or mid moves down while bid size decreases without bid price worsening (seller hitting bids).
Each component is accumulated in its own RollingSumWindow. The first snapshot seeds
previous state with zero contributions.
Recurrence
Let \((b_t, B_t, a_t, A_t)\) be top-of-book bid/ask price and size, and \(m_t = \tfrac12(b_t + a_t)\). On the first tick, instantaneous contributions are zero. Thereafter, instantaneous pieces \(e^{\mathrm{add}}_t\), \(e^{\mathrm{cancel}}_t\), \(e^{\mathrm{trade}}_t\) are formed as follows.
Bid side
Ask side (Cont signs flipped relative to bid)
Trade proxy
Rolling outputs (\(W =\) window):
If fillna=False and any window is incomplete, all four fields are NaN.
Implementation Notes
The recurrence is implemented in src/rtta/indicator.cpp in
class DecomposedOrderFlowImbalance. Three independent RollingSumWindow instances hold
add/cancel/trade.
