分解订单流失衡(DecomposedOrderFlowImbalance)

增量式、因果技术分析文档

摘要

DecomposedOrderFlowImbalance 将 Cont 风格的最优报价压力拆分为三个可加通道——新增撤单成交(代理量);每个通道均使用滚动求和窗口,并以三者之和作为 total。输入仅为盘口最优档的买卖价格与数量。

更新 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(...) 更新状态但不返回结果。批量辅助函数接受并行的买卖价格与数量数组。

工作原理

标准 Cont OFI 把流动性新增、撤单和主动成交混合为一个标量。本指标将每次报价变动归入:

每个分量都在各自的 RollingSumWindow 中累积。首个快照只用于初始化前一状态,各分量贡献均为零。

递推公式

令 \((b_t,B_t,a_t,A_t)\) 为盘口最优买价、买量、卖价和卖量,并令 \(m_t=\tfrac12(b_t+a_t)\)。首个时点的瞬时贡献为零。此后,瞬时分量 \(e^{\mathrm{add}}_t\)、\(e^{\mathrm{cancel}}_t\)、\(e^{\mathrm{trade}}_t\) 按如下规则计算。

买方一侧

\[\begin{aligned} b_t > b_{t-1} &\Rightarrow e^{\mathrm{add}} {+}{=} B_t,\\ b_t < b_{t-1} &\Rightarrow e^{\mathrm{cancel}} {-}{=} B_{t-1},\\ b_t = b_{t-1},\; B_t > B_{t-1} &\Rightarrow e^{\mathrm{add}} {+}{=} B_t - B_{t-1},\\ b_t = b_{t-1},\; B_t < B_{t-1} &\Rightarrow e^{\mathrm{cancel}} {-}{=} B_{t-1} - B_t. \end{aligned}\]

卖方一侧(Cont 符号与买方相反)

\[\begin{aligned} a_t < a_{t-1} &\Rightarrow e^{\mathrm{add}} {-}{=} A_t,\\ a_t > a_{t-1} &\Rightarrow e^{\mathrm{cancel}} {+}{=} A_{t-1},\\ a_t = a_{t-1},\; A_t > A_{t-1} &\Rightarrow e^{\mathrm{add}} {-}{=} A_t - A_{t-1},\\ a_t = a_{t-1},\; A_t < A_{t-1} &\Rightarrow e^{\mathrm{cancel}} {+}{=} A_{t-1} - A_t. \end{aligned}\]

成交代理量

\[\begin{aligned} m_t > m_{t-1} \;\land\; A_t < A_{t-1} \;\land\; a_t \le a_{t-1} &\Rightarrow e^{\mathrm{trade}} {+}{=} A_{t-1} - A_t,\\ m_t < m_{t-1} \;\land\; B_t < B_{t-1} \;\land\; b_t \ge b_{t-1} &\Rightarrow e^{\mathrm{trade}} {-}{=} B_{t-1} - B_t. \end{aligned}\]

滚动输出(\(W=\)window):

\[\mathrm{add}_t = \sum e^{\mathrm{add}},\quad \mathrm{cancel}_t = \sum e^{\mathrm{cancel}},\quad \mathrm{trade}_t = \sum e^{\mathrm{trade}} \quad\text{(最近 \(W\) 个样本)},\]
\[\mathrm{total}_t = \mathrm{add}_t + \mathrm{cancel}_t + \mathrm{trade}_t.\]

fillna=False 且任一窗口尚未填满,四个字段均为 NaN

实现说明

该递推过程在 src/rtta/indicator.cppclass DecomposedOrderFlowImbalance 中实现。新增、撤单和成交分别保存在三个独立的 RollingSumWindow 实例中。

参考资料