Learn R Programming

FRAPO (version 0.4-2)

trdwma: Weighted Moving Average

Description

Calculation of a right ended weighted moving average with weights according to weights.

Usage

trdwma(y, weights, trim = FALSE)

Value

An object of the same class as y, containing the computed weighted moving averages.

Arguments

y

Objects of classes: numeric, matrix, data.frame, ts, mts, and timeSeries are supported.

weights

Numeric, a vector containing the weights.

trim

Logical, if FALSE (the default) the first value is set to NA, otherwise the object is trimmed by the first obeservation.

Methods

y = "data.frame"

The calculation is applied per column of the data.frame and only if all columns are numeric.

y = "matrix"

The calculation is applied per column of the matrix.

y = "mts"

The calculation is applied per column of the mts object. The attributes are preserved and an object of the same class is returned.

y = "numeric"

Calculation of the es trend.

y = "timeSeries"

The calculation is applied per column of the timeSeries object and an object of the same class is returned.

y = "ts"

Calculation of the es trend. The attributes are preserved and an object of the same class is returned.

y = "xts"

Calculation of the es trend. The attributes are preserved and an object of the same class is returned.

y = "zoo"

Calculation of the es trend. The attributes are preserved and an object of the same class is returned.

Author

Bernhard Pfaff

Details

If the sum of the weights is greater than unity, a warning is issued.

See Also

filter, trdbilson, trdbinary, trdhp, trdes, trdsma, capser

Examples

Run this code
data(StockIndex)
y <- StockIndex[, "SP500"]
wma <- trdwma(y, weights = c(0.4, 0.3, 0.2, 0.1))
head(wma, 30)

Run the code above in your browser using DataLab