Learn R Programming

AutoSEARCH (version 1.2)

eqwma: Equally Weighted Moving Average (EqWMA) of the pth. exponentiated values

Description

Returns an Equally Weighted Moving Average (EqWMA) of the pth. exponentiated values lagged. Optionally, the absolute values are computed before averaging, and the log of EqWMA can be returned.

Usage

eqwma(x, length=5, lag=1, start=1, p=1, log=FALSE, abs=FALSE)

Arguments

x
numeric vector, time-series or zoo object. Note that missing values in the beginning or at the end of the series is allowed, as they are removed with the na.trim command from the zoo package
length
integer or vector of integers each equal to or greater than 1. The length or lengths of the moving window or windows of averages. Default: length=20
lag
integer equal to or greater than 0. If 0, then the moving averages are not lagged. Default: lag=1
start
integer equal to or greater than 1. Where to start the moving windows of averages. Default: start=1 (the first observation)
p
numeric greater than zero. The exponent or p in x^p. Default: p=2
log
logical. If TRUE, then the logarithm of the moving average is returned. Default: log = FALSE
abs
logical. Whether x should be transformed to absolute values (TRUE) before averages are computed or not (FALSE). Default: abs = FALSE

Value

  • ewmanumeric vector, time series or zoo object (depending on the properties of x, the input) containing the values of the moving average

Details

The function's intended primary use is to construct socalled 'mixed frequency regressors' for the mean. For the log-volatility specification the function leqwma is used.

See Also

leqwma, sm, gets.mean, gets.vol

Examples

Run this code
#Generate an iid normal series:
set.seed(123)
x <- rnorm(200)

#Compute lag of EqWMA(20) for x^2:
eqwma(x, p=2)

#Compute lag of log(EqWMA(30)) for abs(x)^1:
eqwma(x, length=30, p=1, log=TRUE, abs=TRUE)

#Compute lag of EqWMA(5) and lag of EqWMA(20) for x:
eqwma(x, length=c(5,20))

Run the code above in your browser using DataLab