[R-SIG-Finance] efficient yearly return on a monthly basis

Fabrizio Pollastri f.pollastri at inrim.it
Mon Mar 22 15:32:47 CET 2010


The following code computes yearly returns every month on the xts seqence s.

s=xts(1:1000,as.Date(0:999))
yret_by_month = diff(s,lag=365)/lag(s,k=365)[endpoints(s,on="months")]

There is a more efficient way to avoid diff and lag to perform 
computations over the whole sequence? Thanks in advance for any help.


Regards,
F. Pollastri



More information about the R-SIG-Finance mailing list