Learn R Programming

FRAPO (version 0.3-7)

trdsma: Simple Moving Average

Description

Calculation of a right ended simple moving average with equal weights determined by n.periods.

Usage

trdsma(y, n.periods, trim = FALSE)

Arguments

y
Objects of classes: numeric, matrix, data.frame, ts, mts, timeSeries, zoo and xts are supported.
n.periods
Integer, the number of periods to be included in the calculation of the simple moving average.
trim
Logical, if FALSE (the default) the first value is set to NA, otherwise the object is trimmed by the first obeservation.

Value

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

concept

  • Simple Moving Averages
  • Trend
  • Moving Average

See Also

filter, trdbilson, trdbinary, trdhp, trdwma, capser, trdes

Examples

Run this code
data(StockIndex)
y <- StockIndex[, "SP500"]
sma <- trdsma(y, n.periods = 24)
head(sma, 30)

Run the code above in your browser using DataLab