Skip to content

Commit b364f91

Browse files
committed
Merge pull request #4499 from Komnomnomnom/moments-doc-
DOC: fix conflicting ewma documentation
2 parents dc3ead3 + 2886ff1 commit b364f91

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

doc/source/computation.rst

+12-2
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ average as
450450

451451
.. math::
452452
453-
y_t = \alpha y_{t-1} + (1 - \alpha) x_t
453+
y_t = (1 - \alpha) y_{t-1} + \alpha x_t
454454
455455
One must have :math:`0 < \alpha \leq 1`, but rather than pass :math:`\alpha`
456456
directly, it's easier to think about either the **span** or **center of mass
@@ -461,9 +461,19 @@ directly, it's easier to think about either the **span** or **center of mass
461461
\alpha =
462462
\begin{cases}
463463
\frac{2}{s + 1}, s = \text{span}\\
464-
\frac{1}{c + 1}, c = \text{center of mass}
464+
\frac{1}{1 + c}, c = \text{center of mass}
465465
\end{cases}
466466
467+
.. note::
468+
469+
the equation above is sometimes written in the form
470+
471+
.. math::
472+
473+
y_t = \alpha' y_{t-1} + (1 - \alpha') x_t
474+
475+
where :math:`\alpha' = 1 - \alpha`.
476+
467477
You can pass one or the other to these functions but not both. **Span**
468478
corresponds to what is commonly called a "20-day EW moving average" for
469479
example. **Center of mass** has a more physical interpretation. For example,

pandas/stats/moments.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
----------
5757
%s
5858
com : float. optional
59-
Center of mass: \alpha = com / (1 + com),
59+
Center of mass: :math:`\alpha = 1 / (1 + com)`,
6060
span : float, optional
61-
Specify decay in terms of span, \alpha = 2 / (span + 1)
61+
Specify decay in terms of span, :math:`\alpha = 2 / (span + 1)`
6262
min_periods : int, default 0
6363
Number of observations in sample to require (only affects
6464
beginning)
@@ -75,8 +75,8 @@
7575
Either center of mass or span must be specified
7676
7777
EWMA is sometimes specified using a "span" parameter s, we have have that the
78-
decay parameter \alpha is related to the span as
79-
:math:`\alpha = 1 - 2 / (s + 1) = c / (1 + c)`
78+
decay parameter :math:`\alpha` is related to the span as
79+
:math:`\alpha = 2 / (s + 1) = 1 / (1 + c)`
8080
8181
where c is the center of mass. Given a span, the associated center of mass is
8282
:math:`c = (s - 1) / 2`

0 commit comments

Comments
 (0)