@@ -528,10 +528,18 @@ In general, a weighted moving average is calculated as
528
528
529
529
y_t = \frac {\sum _{i=0 }^t w_i x_{t-i}}{\sum _{i=0 }^t w_i},
530
530
531
- where :math: `x_t` is the input at :math: `y_t` is the result.
531
+ where :math: `x_t` is the input and :math: `y_t` is the result.
532
+
533
+ The EW functions support two variants of exponential weights.
534
+ The default, ``adjust=True ``, uses the weights :math: `w_i = (1 - \alpha )^i`
535
+ which gives
536
+
537
+ .. math ::
538
+
539
+ y_t = \frac {x_t + (1 - \alpha )x_{t-1 } + (1 - \alpha )^2 x_{t-2 } + ...
540
+ + (1 - \alpha )^t x_{0 }}{1 + (1 - \alpha ) + (1 - \alpha )^2 + ...
541
+ + (1 - \alpha )^t}
532
542
533
- The EW functions support two variants of exponential weights:
534
- The default, ``adjust=True ``, uses the weights :math: `w_i = (1 - \alpha )^i`.
535
543
When ``adjust=False `` is specified, moving averages are calculated as
536
544
537
545
.. math ::
@@ -556,6 +564,34 @@ which is equivalent to using weights
556
564
557
565
y_t = \alpha ' y_{t-1 } + (1 - \alpha ') x_t.
558
566
567
+ The difference between the above two variants arises because we are
568
+ dealing with series which have finite history. Consider a series of infinite
569
+ history:
570
+
571
+ .. math ::
572
+
573
+ y_t = \frac {x_t + (1 - \alpha )x_{t-1 } + (1 - \alpha )^2 x_{t-2 } + ...}
574
+ {1 + (1 - \alpha ) + (1 - \alpha )^2 + ...}
575
+
576
+ Noting that the denominator is a geometric series with initial term equal to 1
577
+ and a ratio of :math: `1 - \alpha ` we have
578
+
579
+ .. math ::
580
+
581
+ y_t &= \frac {x_t + (1 - \alpha )x_{t-1 } + (1 - \alpha )^2 x_{t-2 } + ...}
582
+ {\frac {1 }{1 - (1 - \alpha )}}\\
583
+ &= [x_t + (1 - \alpha )x_{t-1 } + (1 - \alpha )^2 x_{t-2 } + ...] \alpha \\
584
+ &= \alpha x_t + [(1 -\alpha )x_{t-1 } + (1 - \alpha )^2 x_{t-2 } + ...]\alpha \\
585
+ &= \alpha x_t + (1 - \alpha )[x_{t-1 } + (1 - \alpha ) x_{t-2 } + ...]\alpha \\
586
+ &= \alpha x_t + (1 - \alpha ) y_{t-1 }
587
+
588
+ which shows the equivalence of the above two variants for infinite series.
589
+ When ``adjust=True `` we have :math: `y_0 = x_0 ` and from the last
590
+ representation above we have :math: `y_t = \alpha x_t + (1 - \alpha ) y_{t-1 }`,
591
+ therefore there is an assumption that :math: `x_0 ` is not an ordinary value
592
+ but rather an exponentially weighted moment of the infinite series up to that
593
+ point.
594
+
559
595
One must have :math: `0 < \alpha \leq 1 `, but rather than pass :math: `\alpha `
560
596
directly, it's easier to think about either the **span **, **center of mass
561
597
(com) ** or **halflife ** of an EW moment:
0 commit comments