Skip to content

EMA 指数移动平均

上游序列的指数移动平均。Edge-first 且可链,未连接时按 symbol 自取。连到多个 Price Factor 时按标的 fan out 为 by_symbol

做什么(One-liner)

EWM 递推平滑(α = 2/(span+1),adjust=False)—— 比 SMA 反应更快,喂给 MACD / Bollinger / momentum 链。

输入

  • span(number,可选)—— EMA 跨度,默认 20。
  • symbol(string,可选)—— 无上游序列时的兜底标的。

输出

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

怎么用

  1. 连一个上游序列。
  2. 设置 span(默认 20;MACD 组件用 12 / 26)。
  3. 输出 series 可接下游。

核心公式

α = 2 / (span + 1)
EMA_0 = P_0
EMA_t = α·P_t + (1-α)·EMA_{t-1}

# pandas 等价
series.ewm(span=span, adjust=False).mean()

假设与适用场景

假设:TradingView / MT4 convention α = 2/(span+1) + recursive (adjust=False) + first-value init。

适用:MACD 组件、Bollinger middle band、momentum 策略;任意资产类别、任意频率。

不适用:Wilder α = 1/n(那是 RSI)、triangular / WMA 权重、短序列。

已知局限

  1. 比 SMA 更灵敏,但在噪声输入上也更易 whipsaw。
  2. 早期值在跨度填满前反映的有效回溯偏短(递推初始化偏差)。
  3. α = 2/(span+1) 与 adjust=False 是硬编码惯例。

参考文献

Murphy (1999), Technical Analysis of the Financial Markets;Roberts (1959), EWM 统计起源。

Golden Test

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

Changelog

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

Verifiable intelligence for the decisions that demand scrutiny.