已弃用 (2026-05-25) —— 该算子是 Layer-1 变换、非 Layer-0 原子输入,已并入
compute_macd_v1。保留作历史。
做什么(One-liner)
MACD 三元组(line / signal / histogram),Appel 12/26/9 default。PR #23 修复了 pandas-ta 派遣 + column ordering bug。
怎么用
python
from services.algo.technical import compute_macd
macd, signal, hist = compute_macd(prices, fast=12, slow=26, signal=9)核心公式
MACD = EMA(prices, 12) - EMA(prices, 26)
signal = EMA(MACD, 9)
histogram = MACD - signalpandas-ta 返回 columns 是 [MACD_12_26_9, MACDh_12_26_9, MACDs_12_26_9] —— MACD, histogram, signal。之前的 BUG-GOLDEN-002 把 index 1 和 2 搞反;golden test 捕获。
假设与适用场景
假设:Appel defaults 12/26/9 + EMA adjust=False + pandas-ta 1e-10 等价。
适用:trend / divergence / crossover signal。
不适用:intraday tick、n<35、横盘。
已知局限
- Column ordering 曾 swap(BUG-GOLDEN-002,已修)
- pandas-ta 版本漂移风险
- 固定 12/26/9
参考文献
Appel (1979) 原始 + Murphy (1999) 标准解释。
Golden Test
tests/golden/fixtures/tier1/compute_macd/,1e-10,2026-04-20 passing。
Changelog
- 1.0.0 (2026-04-20) — BUG-GOLDEN-002 修复 + 首次 Active

