From 14d6e300617a31399ed920153e296cf0b9324ab3 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Sun, 23 Feb 2020 23:51:06 +0100 Subject: [PATCH 01/16] Added missing spaces --- pandas/core/window/ewm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index e045d1c2211d7..7a35c9ca53bfc 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -41,7 +41,7 @@ class EWM(_Rolling): :math:`\alpha = 2 / (span + 1),\text{ for } span \geq 1`. halflife : float, optional Specify decay in terms of half-life, - :math:`\alpha = 1 - exp(log(0.5) / halflife),\text{for} halflife > 0`. + :math:`\alpha = 1 - exp(log(0.5) / halflife),\text{ for } halflife > 0`. alpha : float, optional Specify smoothing factor :math:`\alpha` directly, :math:`0 < \alpha \leq 1`. From 26bbf02480be75dc850f0c291a1486b0e69c75b9 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Tue, 25 Feb 2020 04:22:47 +0100 Subject: [PATCH 02/16] Clean DataFrame.ewm --- pandas/core/window/ewm.py | 66 +++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index e045d1c2211d7..ea816e86b0ea6 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -35,13 +35,13 @@ class EWM(_Rolling): ---------- com : float, optional Specify decay in terms of center of mass, - :math:`\alpha = 1 / (1 + com),\text{ for } com \geq 0`. + :math:`\alpha = 1 / (1 + com)`, for :math:`com \geq 0`. span : float, optional Specify decay in terms of span, - :math:`\alpha = 2 / (span + 1),\text{ for } span \geq 1`. + :math:`\alpha = 2 / (span + 1)`, for :math:`span \geq 1`. halflife : float, optional Specify decay in terms of half-life, - :math:`\alpha = 1 - exp(log(0.5) / halflife),\text{for} halflife > 0`. + :math:`\alpha = 1 - exp(-ln(2) / halflife)`, for :math:`halflife > 0`. alpha : float, optional Specify smoothing factor :math:`\alpha` directly, :math:`0 < \alpha \leq 1`. @@ -71,30 +71,42 @@ class EWM(_Rolling): Notes ----- - Exactly one of center of mass, span, half-life, and alpha must be provided. - Allowed values and relationship between the parameters are specified in the - parameter descriptions above; see the link at the end of this section for - a detailed explanation. - - When adjust is True (default), weighted averages are calculated using - weights (1-alpha)**(n-1), (1-alpha)**(n-2), ..., 1-alpha, 1. - - When adjust is False, weighted averages are calculated recursively as: - weighted_average[0] = arg[0]; - weighted_average[i] = (1-alpha)*weighted_average[i-1] + alpha*arg[i]. - - When ignore_na is False (default), weights are based on absolute positions. - For example, the weights of x and y used in calculating the final weighted - average of [x, None, y] are (1-alpha)**2 and 1 (if adjust is True), and - (1-alpha)**2 and alpha (if adjust is False). - - When ignore_na is True (reproducing pre-0.15.0 behavior), weights are based - on relative positions. For example, the weights of x and y used in - calculating the final weighted average of [x, None, y] are 1-alpha and 1 - (if adjust is True), and 1-alpha and alpha (if adjust is False). - - More details can be found at - https://pandas.pydata.org/pandas-docs/stable/user_guide/computation.html#exponentially-weighted-windows + Exactly one center of mass paramter: ``com``, ``span``, ``halflife``, or ``alpha`` must be provided. + Allowed values and the relation between the parameters are specified in the + parameter descriptions above (see the link at the end of this section for + a detailed explanation). + + Available EW (exponentially weighted) methods: ``mean()``, ``var()``, ``std()``, ``corr()``, ``cov()``. + + When ``adjust=True`` (default), the EW function is calculated using + weights :math:`w_i = (1 - \alpha)^i`. + For example, the EW moving average of the series :math:`x_0, x_1, ..., x_t` would be: + + .. math:: + y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... +(1 - \alpha)^t x_{0}}{1 + + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} + + When ``adjust=False``, the exponentially weighted function is calculated recursively: + + .. math:: + \begin{split} + y_0 &= x_0 \\ + y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, + \end{split} + + When ``ignore_na=False`` (default), weights are based on absolute positions. + For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the final weighted + average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` and :math:`1` (if ``adjust=True``), and + :math:`(1-\alpha)^2` and :math:`\alpha` (if ``adjust=False``). + + When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based + on relative positions. For example, the weights of :math:`x_0` and :math:`x_2` used in + calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are :math:`1-\alpha` and :math:`1` + (if ``adjust=True``), and :math:`1-\alpha` and :math:`\alpha` (if ``adjust=False``). + + More details can be found at: + `Exponentially weighted windows + `_. Examples -------- From 8251a3afad8537aa31f9082041815fc1efdf9c54 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Tue, 25 Feb 2020 04:51:01 +0100 Subject: [PATCH 03/16] Remove brackets --- pandas/core/window/ewm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index ea816e86b0ea6..0deb71f1a7e7b 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -80,7 +80,7 @@ class EWM(_Rolling): When ``adjust=True`` (default), the EW function is calculated using weights :math:`w_i = (1 - \alpha)^i`. - For example, the EW moving average of the series :math:`x_0, x_1, ..., x_t` would be: + For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would be: .. math:: y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... +(1 - \alpha)^t x_{0}}{1 + @@ -96,13 +96,13 @@ class EWM(_Rolling): When ``ignore_na=False`` (default), weights are based on absolute positions. For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the final weighted - average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` and :math:`1` (if ``adjust=True``), and - :math:`(1-\alpha)^2` and :math:`\alpha` (if ``adjust=False``). + average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` and :math:`1` if ``adjust=True``, and + :math:`(1-\alpha)^2` and :math:`\alpha` if ``adjust=False``. When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based on relative positions. For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are :math:`1-\alpha` and :math:`1` - (if ``adjust=True``), and :math:`1-\alpha` and :math:`\alpha` (if ``adjust=False``). + if ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``. More details can be found at: `Exponentially weighted windows From 0b25053d058b967bcc6aa4affd1428031c21a93e Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Tue, 25 Feb 2020 05:03:10 +0100 Subject: [PATCH 04/16] Trim lines <88 --- pandas/core/window/ewm.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 0deb71f1a7e7b..8231521d1414a 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -71,22 +71,26 @@ class EWM(_Rolling): Notes ----- - Exactly one center of mass paramter: ``com``, ``span``, ``halflife``, or ``alpha`` must be provided. + Exactly one center of mass paramter: ``com``, ``span``, ``halflife``, or ``alpha`` + must be provided. Allowed values and the relation between the parameters are specified in the parameter descriptions above (see the link at the end of this section for a detailed explanation). - Available EW (exponentially weighted) methods: ``mean()``, ``var()``, ``std()``, ``corr()``, ``cov()``. + Available EW (exponentially weighted) methods: ``mean()``, ``var()``, ``std()``, + ``corr()``, ``cov()``. When ``adjust=True`` (default), the EW function is calculated using weights :math:`w_i = (1 - \alpha)^i`. - For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would be: + For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would + be: .. math:: - y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... +(1 - \alpha)^t x_{0}}{1 + - (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} + y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} - When ``adjust=False``, the exponentially weighted function is calculated recursively: + When ``adjust=False``, the exponentially weighted function is calculated + recursively: .. math:: \begin{split} @@ -95,14 +99,16 @@ class EWM(_Rolling): \end{split} When ``ignore_na=False`` (default), weights are based on absolute positions. - For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the final weighted - average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` and :math:`1` if ``adjust=True``, and - :math:`(1-\alpha)^2` and :math:`\alpha` if ``adjust=False``. - - When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based - on relative positions. For example, the weights of :math:`x_0` and :math:`x_2` used in - calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are :math:`1-\alpha` and :math:`1` - if ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``. + For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the + final weighted average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` + and :math:`1` if ``adjust=True``, and :math:`(1-\alpha)^2` and + :math:`\alpha` if ``adjust=False``. + + When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based on + relative positions. For example, the weights of :math:`x_0` and :math:`x_2` used in + calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are + :math:`1-\alpha` and :math:`1` if ``adjust=True``, and :math:`1-\alpha` and + :math:`\alpha` if ``adjust=False``. More details can be found at: `Exponentially weighted windows From f62cc4b88c22dfe8232b0e99dfbe8e2aa93d16a5 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Tue, 25 Feb 2020 15:25:17 +0100 Subject: [PATCH 05/16] Removed trailing whitespaces --- pandas/core/window/ewm.py | 46 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 8231521d1414a..7902b089afc35 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -71,47 +71,47 @@ class EWM(_Rolling): Notes ----- - Exactly one center of mass paramter: ``com``, ``span``, ``halflife``, or ``alpha`` + Exactly one center of mass paramter: ``com``, ``span``, ``halflife``, or ``alpha`` must be provided. Allowed values and the relation between the parameters are specified in the parameter descriptions above (see the link at the end of this section for a detailed explanation). - Available EW (exponentially weighted) methods: ``mean()``, ``var()``, ``std()``, - ``corr()``, ``cov()``. + Available EW (exponentially weighted) methods: ``mean()``, ``var()``, ``std()``, + ``corr()``, ``cov()``. When ``adjust=True`` (default), the EW function is calculated using - weights :math:`w_i = (1 - \alpha)^i`. - For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would + weights :math:`w_i = (1 - \alpha)^i`. + For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would be: .. math:: - y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} - When ``adjust=False``, the exponentially weighted function is calculated + When ``adjust=False``, the exponentially weighted function is calculated recursively: - .. math:: - \begin{split} - y_0 &= x_0 \\ - y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, - \end{split} - + .. math:: + \begin{split} + y_0 &= x_0\\ + y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, + \end{split} + When ``ignore_na=False`` (default), weights are based on absolute positions. - For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the - final weighted average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` - and :math:`1` if ``adjust=True``, and :math:`(1-\alpha)^2` and + For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the + final weighted average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` + and :math:`1` if ``adjust=True``, and :math:`(1-\alpha)^2` and :math:`\alpha` if ``adjust=False``. - When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based on + When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based on relative positions. For example, the weights of :math:`x_0` and :math:`x_2` used in - calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are - :math:`1-\alpha` and :math:`1` if ``adjust=True``, and :math:`1-\alpha` and + calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are + :math:`1-\alpha` and :math:`1` if ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``. - More details can be found at: - `Exponentially weighted windows + More details can be found at: + `Exponentially weighted windows `_. Examples @@ -161,7 +161,7 @@ def _constructor(self): return EWM _agg_see_also_doc = dedent( - """ + """ See Also -------- pandas.DataFrame.rolling.aggregate @@ -169,7 +169,7 @@ def _constructor(self): ) _agg_examples_doc = dedent( - """ + """ Examples -------- From d9d2f942be32d4bb9b0748bad7703c42c4fdc6ff Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Tue, 25 Feb 2020 16:47:31 +0100 Subject: [PATCH 06/16] Replaced tabs with spaces -- total blasphemy --- pandas/core/window/ewm.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 7902b089afc35..fd55799b1b2c5 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -41,7 +41,7 @@ class EWM(_Rolling): :math:`\alpha = 2 / (span + 1)`, for :math:`span \geq 1`. halflife : float, optional Specify decay in terms of half-life, - :math:`\alpha = 1 - exp(-ln(2) / halflife)`, for :math:`halflife > 0`. + :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, for :math:`halflife > 0`. alpha : float, optional Specify smoothing factor :math:`\alpha` directly, :math:`0 < \alpha \leq 1`. @@ -71,7 +71,7 @@ class EWM(_Rolling): Notes ----- - Exactly one center of mass paramter: ``com``, ``span``, ``halflife``, or ``alpha`` + Exactly one paramter: ``com``, ``span``, ``halflife``, or ``alpha`` must be provided. Allowed values and the relation between the parameters are specified in the parameter descriptions above (see the link at the end of this section for @@ -85,18 +85,18 @@ class EWM(_Rolling): For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would be: - .. math:: - y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... - + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} + .. math:: + y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} When ``adjust=False``, the exponentially weighted function is calculated recursively: - .. math:: - \begin{split} - y_0 &= x_0\\ - y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, - \end{split} + .. math:: + \begin{split} + y_0 &= x_0\\ + y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, + \end{split} When ``ignore_na=False`` (default), weights are based on absolute positions. For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the @@ -161,7 +161,7 @@ def _constructor(self): return EWM _agg_see_also_doc = dedent( - """ + """ See Also -------- pandas.DataFrame.rolling.aggregate @@ -169,7 +169,7 @@ def _constructor(self): ) _agg_examples_doc = dedent( - """ + """ Examples -------- From f29d4e3fcb038701dbab01419d7da3e0d9c8a73d Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Tue, 25 Feb 2020 17:29:27 +0100 Subject: [PATCH 07/16] Fixed: line too long --- pandas/core/window/ewm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index fd55799b1b2c5..e7b0dc660ecb1 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -41,7 +41,8 @@ class EWM(_Rolling): :math:`\alpha = 2 / (span + 1)`, for :math:`span \geq 1`. halflife : float, optional Specify decay in terms of half-life, - :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, for :math:`halflife > 0`. + :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, + for :math:`halflife > 0`. alpha : float, optional Specify smoothing factor :math:`\alpha` directly, :math:`0 < \alpha \leq 1`. From 3dd58508261cf1cb8054e4c479ad2ccf7d8e4026 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Tue, 25 Feb 2020 17:33:25 +0100 Subject: [PATCH 08/16] Fix: line too long 2 --- pandas/core/window/ewm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index e7b0dc660ecb1..4f5ee5d0ce51f 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -41,7 +41,7 @@ class EWM(_Rolling): :math:`\alpha = 2 / (span + 1)`, for :math:`span \geq 1`. halflife : float, optional Specify decay in terms of half-life, - :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, + :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, for :math:`halflife > 0`. alpha : float, optional Specify smoothing factor :math:`\alpha` directly, From ce670992564a690566a3ff0bcdac59c5aad44ba4 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Wed, 26 Feb 2020 14:16:17 +0100 Subject: [PATCH 09/16] Insignifficant change --- pandas/core/window/ewm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 4f5ee5d0ce51f..e3543f5807d97 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -41,8 +41,8 @@ class EWM(_Rolling): :math:`\alpha = 2 / (span + 1)`, for :math:`span \geq 1`. halflife : float, optional Specify decay in terms of half-life, - :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, - for :math:`halflife > 0`. + :math:`\alpha = 1 - \exp\left(-\ln(2) / halflife\right)`, for + :math:`halflife > 0`. alpha : float, optional Specify smoothing factor :math:`\alpha` directly, :math:`0 < \alpha \leq 1`. From fdeaac5b32becf9a461f1bab199356a6102d0d06 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Thu, 27 Feb 2020 22:23:13 +0100 Subject: [PATCH 10/16] Move Notes to Parameter descriptions --- pandas/core/window/ewm.py | 77 +++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index e3543f5807d97..f565a4286a05e 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -31,6 +31,12 @@ class EWM(_Rolling): r""" Provide exponential weighted functions. + Available exponentially weighted functions: ``mean()``, ``var()``, ``std()``, + ``corr()``, ``cov()``. + + Exactly one parameter: ``com``, ``span``, ``halflife``, or ``alpha`` must be + provided. + Parameters ---------- com : float, optional @@ -53,9 +59,38 @@ class EWM(_Rolling): Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing EWMA as a moving average). + When ``adjust=True`` (default), the EW function is calculated using + weights :math:`w_i = (1 - \alpha)^i`. + For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] + would be: + + .. math:: + y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + (1 - + \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} + + When ``adjust=False``, the exponentially weighted function is calculated + recursively: + + .. math:: + \begin{split} + y_0 &= x_0\\ + y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, + \end{split} ignore_na : bool, default False - Ignore missing values when calculating weights; - specify True to reproduce pre-0.15.0 behavior. + Ignore missing values when calculating weights; specify ``True`` to reproduce + pre-0.15.0 behavior. + + When ``ignore_na=False`` (default), weights are based on absolute positions. + For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the + final weighted average of [:math:`x_0`, None, :math:`x_2`] are + :math:`(1-\alpha)^2` and :math:`1` if ``adjust=True``, and :math:`(1-\alpha)^2` + and :math:`\alpha` if ``adjust=False``. + + When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based on + relative positions. For example, the weights of :math:`x_0` and :math:`x_2` used + in calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] + are :math:`1-\alpha` and :math:`1` if ``adjust=True``, and :math:`1-\alpha` and + :math:`\alpha` if ``adjust=False``. axis : {0 or 'index', 1 or 'columns'}, default 0 The axis to use. The value 0 identifies the rows, and 1 identifies the columns. @@ -72,44 +107,6 @@ class EWM(_Rolling): Notes ----- - Exactly one paramter: ``com``, ``span``, ``halflife``, or ``alpha`` - must be provided. - Allowed values and the relation between the parameters are specified in the - parameter descriptions above (see the link at the end of this section for - a detailed explanation). - - Available EW (exponentially weighted) methods: ``mean()``, ``var()``, ``std()``, - ``corr()``, ``cov()``. - - When ``adjust=True`` (default), the EW function is calculated using - weights :math:`w_i = (1 - \alpha)^i`. - For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would - be: - - .. math:: - y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... - + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} - - When ``adjust=False``, the exponentially weighted function is calculated - recursively: - - .. math:: - \begin{split} - y_0 &= x_0\\ - y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, - \end{split} - - When ``ignore_na=False`` (default), weights are based on absolute positions. - For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the - final weighted average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` - and :math:`1` if ``adjust=True``, and :math:`(1-\alpha)^2` and - :math:`\alpha` if ``adjust=False``. - - When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based on - relative positions. For example, the weights of :math:`x_0` and :math:`x_2` used in - calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are - :math:`1-\alpha` and :math:`1` if ``adjust=True``, and :math:`1-\alpha` and - :math:`\alpha` if ``adjust=False``. More details can be found at: `Exponentially weighted windows From 663a4bf59a75aeeaa67b353eba34844ffd6d184e Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Thu, 27 Feb 2020 22:30:33 +0100 Subject: [PATCH 11/16] Abbreviation --- pandas/core/window/ewm.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index f565a4286a05e..f3b92c401d85d 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -29,10 +29,9 @@ class EWM(_Rolling): r""" - Provide exponential weighted functions. + Provide exponential weighted (EW) functions. - Available exponentially weighted functions: ``mean()``, ``var()``, ``std()``, - ``corr()``, ``cov()``. + Available EW functions: ``mean()``, ``var()``, ``std()``, ``corr()``, ``cov()``. Exactly one parameter: ``com``, ``span``, ``halflife``, or ``alpha`` must be provided. @@ -79,7 +78,7 @@ class EWM(_Rolling): ignore_na : bool, default False Ignore missing values when calculating weights; specify ``True`` to reproduce pre-0.15.0 behavior. - + When ``ignore_na=False`` (default), weights are based on absolute positions. For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are From 1cb54ceb2a178c93ce808e6c85291ff12ed274a9 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Thu, 27 Feb 2020 23:15:23 +0100 Subject: [PATCH 12/16] Remove whitespace --- pandas/core/window/ewm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index f3b92c401d85d..ec86cdc93294f 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -33,7 +33,7 @@ class EWM(_Rolling): Available EW functions: ``mean()``, ``var()``, ``std()``, ``corr()``, ``cov()``. - Exactly one parameter: ``com``, ``span``, ``halflife``, or ``alpha`` must be + Exactly one parameter: ``com``, ``span``, ``halflife``, or ``alpha`` must be provided. Parameters From 9029d4a8bad3b57b7e69a786ae0a9a612e63dd4b Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Thu, 5 Mar 2020 17:51:56 +0100 Subject: [PATCH 13/16] Bullet points --- pandas/core/window/ewm.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index ec86cdc93294f..87cf84c278470 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -56,18 +56,15 @@ class EWM(_Rolling): (otherwise result is NA). adjust : bool, default True Divide by decaying adjustment factor in beginning periods to account - for imbalance in relative weightings - (viewing EWMA as a moving average). - When ``adjust=True`` (default), the EW function is calculated using - weights :math:`w_i = (1 - \alpha)^i`. - For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] - would be: + for imbalance in relative weightings (viewing EWMA as a moving average). + + - When ``adjust=True`` (default), the EW function is calculated using weights :math:`w_i = (1 - \alpha)^i`. For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would be: .. math:: y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} - When ``adjust=False``, the exponentially weighted function is calculated + - When ``adjust=False``, the exponentially weighted function is calculated recursively: .. math:: @@ -79,17 +76,17 @@ class EWM(_Rolling): Ignore missing values when calculating weights; specify ``True`` to reproduce pre-0.15.0 behavior. - When ``ignore_na=False`` (default), weights are based on absolute positions. + - When ``ignore_na=False`` (default), weights are based on absolute positions. For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] are :math:`(1-\alpha)^2` and :math:`1` if ``adjust=True``, and :math:`(1-\alpha)^2` and :math:`\alpha` if ``adjust=False``. - When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based on - relative positions. For example, the weights of :math:`x_0` and :math:`x_2` used - in calculating the final weighted average of [:math:`x_0`, None, :math:`x_2`] - are :math:`1-\alpha` and :math:`1` if ``adjust=True``, and :math:`1-\alpha` and - :math:`\alpha` if ``adjust=False``. + - When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based + on relative positions. For example, the weights of :math:`x_0` and :math:`x_2` + used in calculating the final weighted average of + [:math:`x_0`, None, :math:`x_2`] are :math:`1-\alpha` and :math:`1` if + ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``. axis : {0 or 'index', 1 or 'columns'}, default 0 The axis to use. The value 0 identifies the rows, and 1 identifies the columns. From a38bd0c33f680f158894bf020bb5a617dca0e7b9 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Thu, 5 Mar 2020 18:06:15 +0100 Subject: [PATCH 14/16] Shortned line --- pandas/core/window/ewm.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 87cf84c278470..801f6af6f6cef 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -58,7 +58,9 @@ class EWM(_Rolling): Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings (viewing EWMA as a moving average). - - When ``adjust=True`` (default), the EW function is calculated using weights :math:`w_i = (1 - \alpha)^i`. For example, the EW moving average of the series [:math:`x_0, x_1, ..., x_t`] would be: + - When ``adjust=True`` (default), the EW function is calculated using weights + :math:`w_i = (1 - \alpha)^i`. For example, the EW moving average of the series + [:math:`x_0, x_1, ..., x_t`] would be: .. math:: y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + (1 - From 78561f2f25e1f282e4c31f387e246af1d46757fa Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Thu, 5 Mar 2020 18:26:21 +0100 Subject: [PATCH 15/16] Add proper indentation to bullet paragraphs --- pandas/core/window/ewm.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 801f6af6f6cef..f1f6709220834 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -59,15 +59,15 @@ class EWM(_Rolling): for imbalance in relative weightings (viewing EWMA as a moving average). - When ``adjust=True`` (default), the EW function is calculated using weights - :math:`w_i = (1 - \alpha)^i`. For example, the EW moving average of the series - [:math:`x_0, x_1, ..., x_t`] would be: + :math:`w_i = (1 - \alpha)^i`. For example, the EW moving average of the series + [:math:`x_0, x_1, ..., x_t`] would be: .. math:: y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + ... + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + ... + (1 - \alpha)^t} - When ``adjust=False``, the exponentially weighted function is calculated - recursively: + recursively: .. math:: \begin{split} @@ -79,16 +79,16 @@ class EWM(_Rolling): pre-0.15.0 behavior. - When ``ignore_na=False`` (default), weights are based on absolute positions. - For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the - final weighted average of [:math:`x_0`, None, :math:`x_2`] are - :math:`(1-\alpha)^2` and :math:`1` if ``adjust=True``, and :math:`(1-\alpha)^2` - and :math:`\alpha` if ``adjust=False``. + For example, the weights of :math:`x_0` and :math:`x_2` used in calculating + the final weighted average of [:math:`x_0`, None, :math:`x_2`] are + :math:`(1-\alpha)^2` and :math:`1` if ``adjust=True``, and + :math:`(1-\alpha)^2` and :math:`\alpha` if ``adjust=False``. - When ``ignore_na=True`` (reproducing pre-0.15.0 behavior), weights are based - on relative positions. For example, the weights of :math:`x_0` and :math:`x_2` - used in calculating the final weighted average of - [:math:`x_0`, None, :math:`x_2`] are :math:`1-\alpha` and :math:`1` if - ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``. + on relative positions. For example, the weights of :math:`x_0` and :math:`x_2` + used in calculating the final weighted average of + [:math:`x_0`, None, :math:`x_2`] are :math:`1-\alpha` and :math:`1` if + ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``. axis : {0 or 'index', 1 or 'columns'}, default 0 The axis to use. The value 0 identifies the rows, and 1 identifies the columns. From fb5de6d451b00bab003d58ee0256478824602042 Mon Sep 17 00:00:00 2001 From: Sandu Ursu Date: Sat, 7 Mar 2020 19:38:34 +0100 Subject: [PATCH 16/16] Link: change url to cross-reference --- pandas/core/window/ewm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index f1f6709220834..9da762d15dadd 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -107,8 +107,7 @@ class EWM(_Rolling): ----- More details can be found at: - `Exponentially weighted windows - `_. + :ref:`Exponentially weighted windows `. Examples --------