Creates a results timeseries of a function applied over a rolling window.
apply.rolling(R, width, trim = TRUE, gap = 12, by = 1, FUN = "mean", ...)an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns
number of periods to apply rolling function window over
TRUE/FALSE, whether to keep alignment caused by NA's
numeric number of periods from start of series to use to train risk calculation
calculate FUN for trailing width points at every by-th time point.
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
A timeseries in a zoo object of the calculation results
Wrapper function for rollapply to hide some of the
complexity of managing single-column zoo objects.
data(managers)
apply.rolling(managers[,1,drop=FALSE], FUN="mean", width=36)
#> calcs
#> 1996-01-31 NA
#> 1996-02-29 NA
#> 1996-03-31 NA
#> 1996-04-30 NA
#> 1996-05-31 NA
#> 1996-06-30 NA
#> 1996-07-31 NA
#> 1996-08-31 NA
#> 1996-09-30 NA
#> 1996-10-31 NA
#> ...
#> 2006-03-31 0.01640556
#> 2006-04-30 0.01456667
#> 2006-05-31 0.01288889
#> 2006-06-30 0.01263333
#> 2006-07-31 0.01174444
#> 2006-08-31 0.01218333
#> 2006-09-30 0.01212222
#> 2006-10-31 0.01197222
#> 2006-11-30 0.01182778
#> 2006-12-31 0.01138333