ewma
statisticsCalculates Exponentially Weighted Moving Average (EWMA) for smoothing time series data
Syntax
ewma(column, alpha, min_periods?) Parameters
column (string) Column name to calculate EWMA on
alpha (number) Smoothing factor between 0 and 1 (higher = more weight on recent values)
min_periods (number) optional Minimum number of observations required (defaults to 1)
Returns
dataframe or array DataFrame or Array with additional {column}_ewma field/column
Examples
Calculate EWMA with alpha = 0.3
Input:
.price | ewma(0.3) Output:
[12.5, 14.3, 15.8, 17.2, ...] EWMA with minimum 5 periods requirement
Input:
.value | ewma(0.2, 5) Output:
[null, null, null, null, 42.3, 43.1, ...] Track smoothed trends
Input:
{ original: .sales, smoothed: (.sales | ewma(0.4)) } Output:
{"original": [100, 120, 110], "smoothed": [100, 112, 111.2]} The ewma() function calculates Exponentially Weighted Moving Average (EWMA) for smoothing time series data. The formula is: EWMA(t) = α × Value(t) + (1 - α) × EWMA(t-1).
Usage
Use ewma() for smoothing noisy time series data and identifying trends. Common alpha values: 0.1-0.2 for heavy smoothing, 0.3-0.5 for moderate smoothing, 0.6-0.8 for light smoothing. To convert span to alpha: alpha = 2 / (span + 1).