# 移動平均

（重定向自移动平均

## 简单移动平均

{\displaystyle {\begin{aligned}{\overline {p}}_{\text{SM}}&={\frac {p_{M}+p_{M-1}+\cdots +p_{M-(n-1)}}{n}}\\&={\frac {1}{n}}\sum _{i=0}^{n-1}p_{M-i}.\end{aligned}}}

${\displaystyle {\overline {p}}_{\text{SM}}={\overline {p}}_{{\text{SM}},{\text{prev}}}+{\frac {1}{n}}(p_{M}-p_{M-n}).}$

SMA的主要缺点是，它使比窗口长度短的大量信号通过。更糟糕的是，它实际上将其反转。这可能会导致意外的伪影，例如，平滑结果中的峰值出现在数据中出现波谷的位置。由于某些较高的频率未正确消除，这也导致结果不如预期的平滑。

## 指數移動平均

EMA，N=15

${\displaystyle S_{t}=\alpha \times Y_{t}+(1-\alpha )\times S_{t-1}}$

${\displaystyle EMA_{t}=\alpha \times p_{t}+(1-\alpha )\times EMA_{t-1}=EMA_{t-1}+\alpha \times (p-EMA_{t-1})}$

${\displaystyle EMA_{t-1}}$ 遞迴代入：

${\displaystyle EMA_{t}=\alpha \times (p_{t}+(1-\alpha )p_{t-1}+(1-\alpha )^{2}p_{t-2}+(1-\alpha )^{3}p_{t-3}+\cdots )}$

${\displaystyle {\text{EMA權 重}}=\alpha \times \left(1+(1-\alpha )+(1-\alpha )^{2}+(1-\alpha )^{3}+\cdots +(1-\alpha )^{N}\right)}$
${\displaystyle =(1-(1-\alpha )^{N+1})}$

${\displaystyle {(1+N) \over 2}={1 \over \alpha },\alpha ={2 \over (N+1)}}$

​根據1697年 Johann Bernoulli: ${\displaystyle \lim _{n\to \infty }{(1+{x \over N})^{N}}={\mbox{e}}^{x}}$ , 則

${\displaystyle 1-(1-\alpha )^{N+1}=1-(1-{2 \over (N+1)})^{N+1}=1-{\mbox{e}}^{-2}=86\%}$ ; 即當${\displaystyle \alpha ={2 \over (N+1)}}$ 時,涵蓋了86%權重;

​ 若要包含99.9%的加權，即${\displaystyle (1-\alpha )^{N+1}=0.1\%,(N+1)={\log _{e}(0.001) \over {\log _{e}(1-\alpha )}}}$ , 。

${\displaystyle {N+1}={\log _{e}(0.001) \over {-\alpha }}}$

## 加權移動平均

${\displaystyle WMA_{M}={np_{M}+(n-1)p_{M-1}+\cdots +2p_{M-n+2}+p_{M-n+1} \over n+(n-1)+\cdots +2+1}}$

WMA，N=15

${\displaystyle WMA_{M+1}={N_{M+1} \over n+(n-1)+\cdots +2+1}}$

## 累积移动平均

${\displaystyle {\text{CMA}}_{n}={{x_{1}+\cdots +x_{n}} \over n}\,.}$

${\displaystyle {\text{CMA}}_{n+1}={{x_{n+1}+n\cdot {\text{CMA}}_{n}} \over {n+1}}.}$

${\displaystyle x_{1}+\cdots +x_{n}=n\cdot {\text{CMA}}_{n}}$

{\displaystyle {\begin{aligned}x_{n+1}&=(x_{1}+\cdots +x_{n+1})-(x_{1}+\cdots +x_{n})\\[6pt]\end{aligned}}}

{\displaystyle {\begin{aligned}{\text{CMA}}_{n+1}&={x_{n+1}+n\cdot {\text{CMA}}_{n} \over {n+1}}\\[6pt]&={x_{n+1}+(n+1-1)\cdot {\text{CMA}}_{n} \over {n+1}}\\[6pt]&={(n+1)\cdot {\text{CMA}}_{n}+x_{n+1}-{\text{CMA}}_{n} \over {n+1}}\\[6pt]&={{\text{CMA}}_{n}}+{{x_{n+1}-{\text{CMA}}_{n}} \over {n+1}}\end{aligned}}}

## 參考文献

1. ^ Statistical Analysis, Ya-lun Chou, Holt International, 1975, ISBN 0-03-089422-0, section 17.9.
2. ^ The derivation and properties of the simple central moving average are given in full at Savitzky–Golay filter.
3. ^ NIST/SEMATECH e-Handbook of Statistical Methods: Single Exponential Smoothing页面存档备份，存于互联网档案馆），National Institute of Standards and Technology