MA: Moving Average

Description Usage Arguments Details Value Author(s) References Examples

Description

Computes multiple flavors of the moving average.

Usage

1
MA(price, period, method = "SMA", weight = NULL, k = NULL)

Arguments

price

A vector of past prices or an equivalent xts object.

period

Integer or vector/list of integers. Number of datapoints over which calculate the average.

method

One of c('SMA', 'EMA', 'WMA'), for simple-, exponential-, or weighted- moving average respectively. Shortcurts 's', 'e' or 'w' work as well.

weight

The vector of weights to assign to the weighted moving average. If NULL, default is Linearly Weighted Moving Average weights.

k

Weighting multiplier for the EMA. If NULL, default is 2/(n+1) where n is the length of the smoothing period.

Details

The weighted moving average method (WMA) is a bit trickier to handle because it requires an input (weight) that is functional of the value an other (period). If no weights are provided, then they are automatically assigned linearly, e.g. 1/55, 2/55, ..., 10/55 with 10 periods. If period has more than 1 value, then user weight is ignored and Linearly Weighted Moving Average (LWMA) is computed. For EMA the parameter period is the time span over which calculate the initial point average.

Value

A vector or an xts object, accordingly to the input, of the same length of the input. The first period-1 values are NA.

Author(s)

Giovanni Kraushaar <giovanni.kraushaar@usi.ch>

References

Murphy John J. (1999), Technical Analysis of the Financial Markets, New York Institute of Finance.

Examples

1
2
3
4
5
6
# prices vector
p <- c( 20, 22, 24, 25, 23, 26, 28, 26, 29, 27, 28, 30, 27, 29, 28 )
MA(p, method='s', period = c(10,2))

# Compute Exponential Moving Average of Bank of America quotes
MA( BAC$Close, 50, method = 'EMA' )

giovannikraushaar/TradingIndicatoR documentation built on May 20, 2019, 12:14 p.m.