Skip to content

做什么(One-liner)

ATR 平均真实波幅(14 日 Wilder RMA),position sizing / stop-loss 核心。

怎么用

python
from services.algo.technical import compute_atr
atr = compute_atr(high, low, close, period=14)

核心公式

TR_t = max(high_t - low_t, |high_t - close_{t-1}|, |low_t - close_{t-1}|)
ATR_t = pandas EWM(alpha=1/14, adjust=False, min_periods=14).mean() of TR

假设与适用场景

假设:OHLC 完整 + Wilder RMA(α=1/period)+ TR 取三者 max。

适用:position sizing、trailing stop、volatility breakout。

不适用:只有 close、tick、短序列。

已知局限

  1. Wilder RMA vs EMA/SMA 区别(不同 charting 软件 default 不一)
  2. 14 日 default
  3. pandas-ta 版本依赖

参考文献

Wilder (1978) 原始。

Golden Test

tests/golden/fixtures/tier1/compute_atr/,1e-10,2026-04-20 passing。

Changelog

  • 1.0.0 (2026-04-20) — 首次 Active

Verifiable intelligence for the decisions that demand scrutiny.