Creates a results timeseries of a function applied over a rolling window.
apply.rolling(R, width, trim = TRUE, gap = 12, by = 1, FUN = "mean", ...)
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 |
… | 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.
apply
rollapply
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 #> 1996-11-30 NA #> 1996-12-31 NA #> 1997-01-31 NA #> 1997-02-28 NA #> 1997-03-31 NA #> 1997-04-30 NA #> 1997-05-31 NA #> 1997-06-30 NA #> 1997-07-31 NA #> 1997-08-31 NA #> 1997-09-30 NA #> 1997-10-31 NA #> 1997-11-30 NA #> 1997-12-31 NA #> 1998-01-31 NA #> 1998-02-28 NA #> 1998-03-31 NA #> 1998-04-30 NA #> 1998-05-31 NA #> 1998-06-30 NA #> 1998-07-31 NA #> 1998-08-31 NA #> 1998-09-30 NA #> 1998-10-31 NA #> 1998-11-30 NA #> 1998-12-31 0.010750000 #> 1999-01-31 0.010286111 #> 1999-02-28 0.010011111 #> 1999-03-31 0.010863889 #> 1999-04-30 0.012533333 #> 1999-05-31 0.012772222 #> 1999-06-30 0.013786111 #> 1999-07-31 0.014700000 #> 1999-08-31 0.013144444 #> 1999-09-30 0.012611111 #> 1999-10-31 0.011794444 #> 1999-11-30 0.011458333 #> 1999-12-31 0.011377778 #> 2000-01-31 0.010505556 #> 2000-02-29 0.010786111 #> 2000-03-31 0.012122222 #> 2000-04-30 0.012333333 #> 2000-05-31 0.012058333 #> 2000-06-30 0.011758333 #> 2000-07-31 0.011466667 #> 2000-08-31 0.011883333 #> 2000-09-30 0.011311111 #> 2000-10-31 0.011672222 #> 2000-11-30 0.011266667 #> 2000-12-31 0.010772222 #> 2001-01-31 0.010836111 #> 2001-02-28 0.009872222 #> 2001-03-31 0.008575000 #> 2001-04-30 0.009316667 #> 2001-05-31 0.011566667 #> 2001-06-30 0.011288889 #> 2001-07-31 0.012461111 #> 2001-08-31 0.015530556 #> 2001-09-30 0.013975000 #> 2001-10-31 0.012455556 #> 2001-11-30 0.013050000 #> 2001-12-31 0.014658333 #> 2002-01-31 0.015291667 #> 2002-02-28 0.014686111 #> 2002-03-31 0.013577778 #> 2002-04-30 0.012288889 #> 2002-05-31 0.011797222 #> 2002-06-30 0.010222222 #> 2002-07-31 0.007852778 #> 2002-08-31 0.008525000 #> 2002-09-30 0.007052778 #> 2002-10-31 0.007894444 #> 2002-11-30 0.009633333 #> 2002-12-31 0.008327778 #> 2003-01-31 0.007466667 #> 2003-02-28 0.006427778 #> 2003-03-31 0.005841667 #> 2003-04-30 0.007088889 #> 2003-05-31 0.007083333 #> 2003-06-30 0.007597222 #> 2003-07-31 0.007950000 #> 2003-08-31 0.006883333 #> 2003-09-30 0.007097222 #> 2003-10-31 0.008647222 #> 2003-11-30 0.008827778 #> 2003-12-31 0.009780556 #> 2004-01-31 0.009708333 #> 2004-02-29 0.009477778 #> 2004-03-31 0.010011111 #> 2004-04-30 0.008933333 #> 2004-05-31 0.007552778 #> 2004-06-30 0.008213889 #> 2004-07-31 0.007638889 #> 2004-08-31 0.007344444 #> 2004-09-30 0.008455556 #> 2004-10-31 0.008408333 #> 2004-11-30 0.008558333 #> 2004-12-31 0.007902778 #> 2005-01-31 0.007530556 #> 2005-02-28 0.008472222 #> 2005-03-31 0.007722222 #> 2005-04-30 0.007013889 #> 2005-05-31 0.007175000 #> 2005-06-30 0.008291667 #> 2005-07-31 0.010641667 #> 2005-08-31 0.010741667 #> 2005-09-30 0.013063889 #> 2005-10-31 0.011719444 #> 2005-11-30 0.010525000 #> 2005-12-31 0.012147222 #> 2006-01-31 0.015213889 #> 2006-02-28 0.016313889 #> 2006-03-31 0.016405556 #> 2006-04-30 0.014566667 #> 2006-05-31 0.012888889 #> 2006-06-30 0.012633333 #> 2006-07-31 0.011744444 #> 2006-08-31 0.012183333 #> 2006-09-30 0.012122222 #> 2006-10-31 0.011972222 #> 2006-11-30 0.011827778 #> 2006-12-31 0.011383333