Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

statistics-rollMean

Rolling Statistics


Description

Computes rolling mean, min, max and median for a 'timeSeries' object.

Usage

rollStats(x, k, FUN=mean, na.pad=FALSE, 
    align=c("center", "left", "right"), ...)
    
rollMean(x, k, na.pad = FALSE, 
    align = c("center", "left", "right"), ...)
rollMin(x, k, na.pad = FALSE, 
    align = c("center", "left", "right"), ...)
rollMax(x, k, na.pad = FALSE, 
    align = c("center", "left", "right"), ...)
rollMedian(x, k, na.pad = FALSE, 
    align = c("center", "left", "right"), ...)

Arguments

x

an uni- or multivariate 'timeSeries' object.

k

an integer width of the rolling window. Must be odd for rollMedian.

FUN

the function to be rolled.

na.pad

a logical flag. Should NA padding be added at beginning? By default FALSE.

align

a character string specifying whether the index of the result should be left- or right-aligned or centered compared to the rolling window of observations. The default choice is set to align="center".

...

optional arguments to be passed.

Details

The code in the core of the functions rollMean, rollMin, rollMax, and rollMedian was borrowed from the package zoo authored by Achim Zeileis, Gabor Grothendieck and Felix Andrews.

Value

returns an object of class 'timeSeries'.

Author(s)

Achim Zeileis, Gabor Grothendieck and Felix Andrews for code from the contributed R package zoo used in the functions rollMean, rollMin, rollMax, and rollMedian.

Examples

## Use Swiss Pension Fund Data Set of Returns - 
   head(LPP2005REC)
   SPI <- LPP2005REC[, "SPI"]
   head(SPI)
   
## Plot Drawdowns - 
   rmean <- rollMean(SPI, k = 10)
   plot(rmean)

timeSeries

Financial Time Series Objects (Rmetrics)

v3062.100
GPL (>= 2)
Authors
Diethelm Wuertz [aut] (original code), Tobias Setz [cre], Yohan Chalabi [ctb], Martin Maechler [ctb] (<https://orcid.org/0000-0002-8685-9910>)
Initial release
2020-01-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.