wma {hacks} | R Documentation |
Calculates a weighted moving average for a given vector or matrix.
wma(x, w = 1, stdz = TRUE)
x |
a numeric vector or matrix. |
w |
weight value in (0, 1]. |
stdz |
should the weights sum to one? If
FALSE then the output resembles a weighted
moving sum (see Details ). |
This function calculates a weighted moving average where the
first element or row represents the starting time period and
the last element or row represents the ending time period. The
unstandardized weights are calculated as wt[i,j] = w^(i-j)
.
If stdz = TRUE
then the weights are standardized such that
the weights for each column sum to one.
A matrix where each row represents the weighted average of it and all preceding rows.
Nathan Stephens
wma(1:10,0.5)