A function to calculate a function over an expanding window from the start of the timeseries. This wrapper allows easy calculation of “from inception” statistics.

apply.fromstart(R, FUN = "mean", gap = 1, ...)

Arguments

R

an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns

FUN

any function that can be evaluated using a single set of returns (e.g., rolling beta won't work, but Return.annualized will)

gap

the number of data points from the beginning of the series required to “train” the calculation

any other passthru parameters

See also

rollapply

Examples

data(managers) apply.fromstart(managers[,1,drop=FALSE], FUN="mean", width=36)
#> 1996-01-31 1996-02-29 1996-03-31 1996-04-30 1996-05-31 1996-06-30 #> 0.007400000 0.013350000 0.014066667 0.008275000 0.008140000 0.006133333 #> 1996-07-31 1996-08-31 1996-09-30 1996-10-31 1996-11-30 1996-12-31 #> 0.001957143 0.006650000 0.007544444 0.009670000 0.010209091 0.010825000 #> 1997-01-31 1997-02-28 1997-03-31 1997-04-30 1997-05-31 1997-06-30 #> 0.011623077 0.010950000 0.010846667 0.010956250 0.012888235 0.013455556 #> 1997-07-31 1997-08-31 1997-09-30 1997-10-31 1997-11-30 1997-12-31 #> 0.013557895 0.014065000 0.014438095 0.012840909 0.013369565 0.013270833 #> 1998-01-31 1998-02-28 1998-03-31 1998-04-30 1998-05-31 1998-06-30 #> 0.012964000 0.014115385 0.014933333 0.014678571 0.013375862 0.013333333 #> 1998-07-31 1998-08-31 1998-09-30 1998-10-31 1998-11-30 1998-12-31 #> 0.012209677 0.008878125 0.009360606 0.010726471 0.010780000 0.010750000 #> 1999-01-31 1999-02-28 1999-03-31 1999-04-30 1999-05-31 1999-06-30 #> 0.010208108 0.010186842 0.011110256 0.012107500 0.012207317 0.012692857 #> 1999-07-31 1999-08-31 1999-09-30 1999-10-31 1999-11-30 1999-12-31 #> 0.012625581 0.011963636 0.011597778 0.011332609 0.011165957 0.011239583 #> 2000-01-31 2000-02-29 2000-03-31 2000-04-30 2000-05-31 2000-06-30 #> 0.010802041 0.010832000 0.011747059 0.011909615 0.012324528 0.012324074 #> 2000-07-31 2000-08-31 2000-09-30 2000-10-31 2000-11-30 2000-12-31 #> 0.012189091 0.012662500 0.012463158 0.012115517 0.012086441 0.011771667 #> 2001-01-31 2001-02-28 2001-03-31 2001-04-30 2001-05-31 2001-06-30 #> 0.011708197 0.011651613 0.011300000 0.011662500 0.012373846 0.012218182 #> 2001-07-31 2001-08-31 2001-09-30 2001-10-31 2001-11-30 2001-12-31 #> 0.012344776 0.012400000 0.011768116 0.011615714 0.011930986 0.012704167 #> 2002-01-31 2002-02-28 2002-03-31 2002-04-30 2002-05-31 2002-06-30 #> 0.012715068 0.012375676 0.012294667 0.012193421 0.012015584 0.011552564 #> 2002-07-31 2002-08-31 2002-09-30 2002-10-31 2002-11-30 2002-12-31 #> 0.010450633 0.010416250 0.009577778 0.009823171 0.010501205 0.009991667 #> 2003-01-31 2003-02-28 2003-03-31 2003-04-30 2003-05-31 2003-06-30 #> 0.009389412 0.008988372 0.009303448 0.009937500 0.010204494 0.010433333 #> 2003-07-31 2003-08-31 2003-09-30 2003-10-31 2003-11-30 2003-12-31 #> 0.010512088 0.010401087 0.010386022 0.010787234 0.010851579 0.011025000 #> 2004-01-31 2004-02-29 2004-03-31 2004-04-30 2004-05-31 2004-06-30 #> 0.010965979 0.010853061 0.010831313 0.010680000 0.010655446 0.010804902 #> 2004-07-31 2004-08-31 2004-09-30 2004-10-31 2004-11-30 2004-12-31 #> 0.010700000 0.010650000 0.010632381 0.010526415 0.010796262 0.011103704 #> 2005-01-31 2005-02-28 2005-03-31 2005-04-30 2005-05-31 2005-06-30 #> 0.011002752 0.011098182 0.010811712 0.010528571 0.010473451 0.010522807 #> 2005-07-31 2005-08-31 2005-09-30 2005-10-31 2005-11-30 2005-12-31 #> 0.010510435 0.010517241 0.010650427 0.010401695 0.010508403 0.010638333 #> 2006-01-31 2006-02-28 2006-03-31 2006-04-30 2006-05-31 2006-06-30 #> 0.011122314 0.011150000 0.011382114 0.011281452 0.010977600 0.011061905 #> 2006-07-31 2006-08-31 2006-09-30 2006-10-31 2006-11-30 2006-12-31 #> 0.010861417 0.010902344 0.010870543 0.011115385 0.011119847 0.011122727