Skip to content

SMA 简单移动平均

上游序列的简单移动平均。这是 edge-first、可链 transform:消费所连上游节点的序列,可链式 price_factor → SMA → Crossover;未连接时按 symbol 自取。连到多个 Price Factor 时按标的 fan out 为 by_symbol

做什么(One-liner)

上游序列的滚动均值(窗口默认 20)—— 喂给 MACD、Bollinger、momentum 链的基础平滑 primitive。

输入

  • window(number,可选)—— 滚动窗口,默认 20。
  • symbol(string,可选)—— 无上游序列时的兜底标的。

输出

  • series —— SMA 序列(与输入对齐,预热为 None)。
  • current —— 最新 SMA 值。
  • by_symbol —— 连多个 Price Factor 时的 per-ticker 映射。

怎么用

  1. 连一个上游 price_factor(或另一个 transform)。
  2. 设置 window(默认 20)。
  3. 输出 series 可接入下一个 transform。

核心公式

sma_t = series.rolling(window=window).mean()[t]

假设与适用场景

假设:等距时间戳 + 有序数值序列 + window ≥ 2。

适用:价格 smoothing、MACD 组件、GC/DC 策略;任意资产类别、任意频率。

不适用:weighted MA / EMA(用 compute_ema_v1)、adaptive window。

已知局限

  1. 等权窗口对趋势拐点滞后(比 EMA 慢)。
  2. 左对齐预热(前 window-1 个点为 None)。
  3. 不处理 calendar gap。

参考文献

Murphy (1999), Technical Analysis of the Financial Markets。

Golden Test

tests/golden/fixtures/tier1/compute_sma/ —— 容差 1e-12 absolute,对标 pandas.Series.rolling().mean(),最后验证 2026-05-25,状态 passing。

Changelog

  • 1.0.0 (2026-05-25) —— 作为 Layer-1 规范 transform 激活;并入已弃用 Layer-0 compute_sma 卡的治理字段。

Verifiable intelligence for the decisions that demand scrutiny.