Skip to content

计算 RSI

相对强弱指标 RSI,默认 Wilder 平滑(可选 Cutler/SMA)。经 pandas-ta 与 Bloomberg 交叉验证到 1.4e-14。Edge-first 消费上游 close 序列。连到多个 Price Factor 时按标的 fan out 为 by_symbol

做什么(One-liner)

Layer-1 变换:消费上游 close 序列,输出 RSI 序列。Wilder's RMA 为默认(对标 Bloomberg 1.4e-14);Cutler's SMA 是 smoothing = 'sma'

输入

  • period(number,可选)—— 回溯周期,默认 14。
  • smoothing(string,可选)——『wilder』(Bloomberg,默认)或『sma』(Cutler)。

输出

  • rsi —— RSI 序列(与输入对齐),范围 [0, 100]。
  • by_symbol —— 连多个 Price Factor 时的 per-ticker 映射。

怎么用

  1. 上游 price_factor 提供 close 序列。
  2. 设置 period(默认 14)。
  3. 选择 smoothing =『wilder』(默认)或 『sma』(Cutler)。

核心公式

delta = prices.diff()
pos = delta.clip(lower=0); neg = (-delta).clip(lower=0)

# Wilder (default, Bloomberg parity):
gain = pos.ewm(alpha=1/14, adjust=False, min_periods=14).mean()
loss = neg.ewm(alpha=1/14, adjust=False, min_periods=14).mean()

# Cutler's (opt-in):
gain = pos.rolling(14).mean()
loss = neg.rolling(14).mean()

rs = gain / loss
rsi = 100 - 100 / (1 + rs)

假设与适用场景

假设:Wilder's 是 canonical(大部分 terminal + TradingView 默认)+ 除零 → 100 + 前 period 个 NaN。

适用:超买超卖、divergence、momentum feature;equities / fx / crypto / commodities,global,daily–monthly,最少 15 个观测。

不适用:intraday tick、<15 日、横盘 whipsaw。

已知局限

  1. 单指标动量度量 —— 不能单独作为信号。
  2. Wilder vs Cutler 差异显著(不要混用);整张图保持一致。
  3. period 个 NaN。
  4. 跳空 / 停牌需调用方预处理。

参考文献

Wilder (1978) 原始 + Cutler (1991) 变体。详见 frontmatter。

Golden Test

tests/golden/fixtures/tier1/rsi/,1e-12 tolerance,2026-05-25 passing。参考:pandas EWM(alpha=1/N, adjust=False) + pandas-ta cross-check;Bloomberg parity 1.4e-14。

Changelog

  • 1.1.0 (2026-05-25) —— 提升为 Active 的 Layer-1 变换;并入已弃用 Layer-0 rsi 卡片的完整治理字段。
  • 1.0.0 (2026-05-23) —— 初始 edge-first Layer-1 Draft 卡片。

Verifiable intelligence for the decisions that demand scrutiny.