EWMA
Exponentially Weighted Moving Average

Description

Returns the exponentially weighted moving average of a vector or time series.

Usage

EWMA(x, n=9, lambda=(n - 1)/(n + 1), start="average", na.rm=F)

Arguments

x data to average: vector, matrix, timeSeries, or numeric data.frame.
n approximate number of terms to use in the moving average. Used to calculate lambda; ignored if lambda is given.
lambda exponential weight: positive number between 0 and 1.
start starting value for EWMA. Can be "average", to use the average of the first n observations; "first", to use the first observation; or a number to use as the starting value.
na.rm if TRUE, missing values will be removed from x before computing EWMA.

Details

The EWMA of a vector x at time t is calculuated as the weighted sum of the EWMA at time (weight lambda) t-1 and the value of x at time t (weight 1 - lambda). This is derived from having each EWMA output value being the weighted sum of the current and previous input values, with the value i back in the vector having the (exponential) weight lambda^i, and the sum multiplied by an overall weight of 1 - lambda.
If there is more than one column in x, then EWMAs are computed column-wise. In this case, vectors can be supplied for lambda and numeric start values, with values corresponding to each column.
Value
an object like x, with the data values replace by the column-wise n-term EWMA of x.
Package terrUtils version 6.0.0-69
Package Index