Learn R Programming

PerformanceAnalytics (version 0.9.5)

rollingFunction: wrapper to apply functions over a rolling period

Description

This is a wrapper for providing n-period trailing calculations for the data and functions provided.

Usage

rollingFunction(R, width, trim = TRUE, na.rm = TRUE, digits = 4, rf = 0, FUN = "mean", ...)

Arguments

R
a vector, matrix, data frame, timeSeries or zoo object of asset returns
width
the number of periods over which a function is to be calculated. Use the value zero (0) to roll the statistic from inception
trim
TRUE/FALSE, whether to keep alignment caused by NA's
na.rm
TRUE/FALSE Remove NA's from the returns?
digits
number of digits to round results to
rf
risk free rate, in same period as your returns
FUN
function to apply rolling period over
...
any other passthru parameters

Value

  • results over a rolling period

Details

Examples: > rollingFunction(gg.ts[,1],n=3,FUN="Return.annualized") Manager 2002-02-28 0.0306 2002-03-31 0.0521 2002-04-30 0.0387 ...

> rollingFunction(gg.ts[,1],n=3,trim=FALSE,FUN="Return.annualized") Manager 2001-12-31 NA 2002-01-31 NA 2002-02-28 0.0306 2002-03-31 0.0521 2002-04-30 0.0387 ... > rollingFunction(gg.ts[,1],n=3,trim=FALSE,FUN="SharpeRatio.annualized") Manager 2001-12-31 NA 2002-01-31 NA 2002-02-28 1.5302 2002-03-31 4.3768 2002-04-30 6.9640 ... > rollingFunction(gg.ts[,1],n=3,trim=FALSE,FUN="SharpeRatio.annualized",rf=.03/12) Manager 2001-12-31 NA 2002-01-31 NA 2002-02-28 0.0298 2002-03-31 1.8587 2002-04-30 1.5598

See Also

rollFun