| rollingFunction {PerformanceAnalytics} | R Documentation |
This is a wrapper for providing n-period trailing calculations for the data and functions provided.
rollingFunction(R, width, trim = TRUE, na.rm = TRUE, digits = 4, rf = 0, FUN = "mean", ...)
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 |
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
results over a rolling period
Inspired by rollFun written by Diethelm Wurtz. We've extended the idea to all the columns provided.
Peter Carl