Skip to content

滚动 Z-score

上游序列的滚动 z-score (x − 滚动均值) / 滚动标准差 —— 均值回归构件。常数窗返回 0 而非 NaN。Edge-first。连到多个 Price Factor 时按标的 fan out 为 by_symbol

怎么用

  1. 连一个上游序列(价格或收益)。
  2. window(默认 20)与 ddof(0 = 总体,1 = 样本)。
  3. |z| 大表示序列偏离其滚动均值较远。

核心公式

z_t = (x_t − mean(窗口_t)) / std(窗口_t, ddof)
首 (window−1) 个点或含 NaN/None 的窗口为 None
std(窗口_t) < 1e-12(常数窗)时为 0.0

假设与适用性

假设:窗口内局部平稳;window ≥ 2。

适用:任意资产类别 / 频率;≥ 2 个观测。

不适用:全历史标准化(用非滚动 z_score)、自适应窗口。

已知局限

  1. 常数窗坍缩为 0 —— 防 NaN,但无信号。
  2. 假设窗口内局部平稳。
  3. 首 window−1 个点为 None(warmup)。

参考

标准统计标准化的滚动形式(教科书式均值回归标准化)。

Golden 测试

tests/golden/fixtures/tier1/compute_zscore/ —— 1e-9 绝对、独立 pandas-rolling 参照、2026-05-25 passing。锁住常数窗 → 0、warmup None、含 NaN 窗 → None、ddof。

变更记录

  • 1.0.0(2026-05-25)—— Draft → Active;补 golden;补齐必填字段。

Verifiable intelligence for the decisions that demand scrutiny.