ewma¶
Description¶
Calculates the exponentially weighted moving average of a value. More weight is given to more recent observations, and the weight decreases exponentially.
Arguments are the value to take the EWMA over, the EWMA window size, and optionally the weight. The window size is the number of previous observations to use in the ewma calculation, and must be an integer in the range [1, 20]. A larger window size means that the EWMA is calculated over more previous data points. The weight must be a float in the range [0, 1). If weight is not set, weight will default to 0.5. A larger weight smoothes the data more by giving more emphasis to earlier observations, while a lower weight means the current observation will have more impact on the results.
EWMA works for data with a time grid, which are typically produced by timechart
or align
.
It is recommended to not set a custom frame()
with EWMA and use the default query window as the input, as the behavior may be unexpected after setting a frame.
Return type¶
value
Domain¶
This is a window function (calculates over a group of multiple input rows using windowing.)
Categories¶
Usage¶
ewma(value, window_size, [ weight ])
Argument |
Type |
Optional |
Repeatable |
Restrictions |
---|---|---|---|---|
value |
storable |
no |
no |
none |
window_size |
int64 |
no |
no |
constant |
weight |
float64 |
yes |
no |
constant |
Examples¶
make_col ewma:window(ewma(input_data, 3))
This creates a new column ewma
with the exponentially weighted moving average of input_data
, with a window size of 3. The weight used will be the default 0.5.
make_col ewma:window(ewma(input_data, 3, 0.75))
This creates a column ewma
with the exponentially weighted moving average of input_data
, with a window size of 3 and weight of 0.75. The higher weight of 0.75 gives more significance to previous values, resulting in a smoother average with less emphasis on recent observations.