polars.Series.ewm_sum_by
-
Compute time-based exponentially weighted moving sum.
Warning
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Given observations \(x_0, x_1, \ldots, x_{n-1}\) at times \(t_0, t_1, \ldots, t_{n-1}\), the EWMS is calculated as
\[ \begin{align}\begin{aligned}y_0 &= x_0\\\lambda_i &= \exp \left\{ \frac{ -\ln(2)(t_i-t_{i-1}) } { \tau } \right\}\\y_i &= x_i + \lambda_i y_{i-1}; \quad i > 0\end{aligned}\end{align} \]where \(\tau\) is the
half_life.- Parameters:
-
- by
-
Times to calculate the sum by. Should be
DateTime,Date,UInt64,UInt32,Int64, orInt32data type. - half_life
-
Unit over which observation decays to half its value.
Examples
>>> df = pl.DataFrame( ... { ... "values": [1, 2, 3, 4, 5], ... "times": [0, 1, 2, 5, 6], ... } ... ) >>> df["values"].ewm_sum_by(df["times"], half_life="1i") shape: (5,) Series: 'values' [f64] [ 1.0 2.5 4.25 4.53125 7.265625 ]
Series.ewm_sum_by(
by: IntoExpr,
*,
half_life: str_ | timedelta,
) → Series
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/series/api/polars.Series.ewm_sum_by.html