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

apply.rolling

calculate a function over a rolling window


Description

Creates a results timeseries of a function applied over a rolling window.

Usage

apply.rolling(R, width, trim = TRUE, gap = 12, by = 1, FUN = "mean", ...)

Arguments

R

an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns

width

number of periods to apply rolling function window over

trim

TRUE/FALSE, whether to keep alignment caused by NA's

gap

numeric number of periods from start of series to use to train risk calculation

by

calculate FUN for trailing width points at every by-th time point.

FUN

any function that can be evaluated using a single set of returns (e.g., rolling beta won't work, but Return.annualized will)

...

any other passthru parameters

Details

Wrapper function for rollapply to hide some of the complexity of managing single-column zoo objects.

Value

A timeseries in a zoo object of the calculation results

Author(s)

Peter Carl

See Also

Examples

data(managers)
apply.rolling(managers[,1,drop=FALSE], FUN="mean", width=36)

PerformanceAnalytics

Econometric Tools for Performance and Risk Analysis

v2.0.4
GPL-2 | GPL-3
Authors
Brian G. Peterson [cre, aut, cph], Peter Carl [aut, cph], Kris Boudt [ctb, cph], Ross Bennett [ctb], Joshua Ulrich [ctb], Eric Zivot [ctb], Dries Cornilly [ctb], Eric Hung [ctb], Matthieu Lestel [ctb], Kyle Balkissoon [ctb], Diethelm Wuertz [ctb], Anthony Alexander Christidis [ctb], R. Douglas Martin [ctb], Zeheng 'Zenith' Zhou [ctb], Justin M. Shea [ctb]
Initial release
2020-02-05

We don't support your browser anymore

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