wma {hacks}R Documentation

Weighted Moving Average

Description

Calculates a weighted moving average for a given vector or matrix.

Usage

wma(x, w = 1, stdz = TRUE)

Arguments

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).

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.

Value

A matrix where each row represents the weighted average of it and all preceding rows.

Author(s)

Nathan Stephens

Examples

wma(1:10,0.5)

[Package hacks version 0.1-5 Index]