Series.ewm() and
DataFrame.ewm() provide
Exponentially Weighted Moving aggregations,
mirroring pandas.Series.ewm(). Unlike rolling windows (fixed size)
or expanding windows (all past data equally), EWM weights recent observations more
heavily using an exponential decay.
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
Specify the decay via exactly one of span, com,
halflife, or alpha:
With adjust=true (default), the mean at position t
is the weighted average of all past values, where the weight for
xi is (1−α)t−i.
With adjust=false, EWM uses a simple Infinite Impulse Response
formula — the same as an exponential smoothing filter:
yt = α·xt + (1−α)·yt−1
EWM variance uses reliability-weights Bessel correction
(bias=false by default, matching pandas).
Compute pairwise exponentially weighted covariance between two Series. Negative covariance means the series move in opposite directions.
EWM Pearson correlation between two Series. Perfectly correlated series produce values of +1 or −1.
The ignoreNa option controls how missing values affect the
exponential weights. With ignoreNa=false (default), null
positions still advance time and cause extra decay. With
ignoreNa=true, nulls are completely skipped.
Apply EWM to every numeric column of a DataFrame independently.
Use apply(fn) to implement custom EWM aggregations. The
function receives the accumulated values and their EW weights.
Specify exactly one decay parameter. All methods return Series-like objects
with .values for inspection.
// Series.ewm(options) → EWM
// DataFrame.ewm(options) → DataFrameEwm
// EwmOptions (exactly one decay parameter required):
{
span?: number, // ≥ 1, alpha = 2/(span+1)
com?: number, // ≥ 0, alpha = 1/(1+com)
halflife?: number, // > 0, alpha = 1 − exp(−ln2/halflife)
alpha?: number, // (0, 1]
adjust?: boolean, // default: true
ignoreNa?: boolean, // default: false
minPeriods?: number // default: 0
}
// EWM methods:
ewm.mean() → Series (EwmSeriesLike)
ewm.std(bias?) → Series
ewm.var(bias?) → Series
ewm.cov(other, bias?) → Series
ewm.corr(other) → Series
ewm.apply(fn) → Series // fn: (values, weights) => number
// DataFrameEwm methods:
dfEwm.mean() → DataFrame
dfEwm.std(bias?) → DataFrame
dfEwm.var(bias?) → DataFrame