Creates a results timeseries of a function applied over a rolling window.
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.annualizedwill)- ...
any other passthru parameters
Details
Wrapper function for rollapply to hide some of the
complexity of managing single-column zoo objects.
Examples
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