# How to calculate cumulative returns with one lag in R

I have a huge data frame with over 1000 column, which are companies(column headers) and in each column I have their estimated return(monthly). The sample period of the data frame in 11 years. I want to calculate cumulative returns over the past 12 months with with one month lag. Meaning cumulative returns of January 2005 are estimated on the basis of Jan-04 to Dec.04 and February 2005 are estimated on the basis of Feb-04 to Jan-05. I present my data as follows:

df
Month    A       B      C     D      E
Jan-00  0.01    0.00    NA  -0.01   NA
Feb-00  0.01    0.00    NA  0.00    NA
Mar-00  -0.02   0.00    NA  0.01    NA
Apr-00  -0.01   0.00    NA  -0.01   NA
May-00  -0.01   0.00    NA  0.01    NA
Jun-00  0.00    0.01    NA  -0.01   NA
Jul-00  0.00    -0.01   NA  0.00    NA
Aug-00  0.00    0.01    NA  0.00    NA
Sep-00  0.00    0.00    NA  0.00    NA
Oct-00  -0.01   0.00    NA  0.00    NA
Nov-00  -0.01   -0.01   NA  0.01    NA
Dec-00  -0.01   0.00    NA  0.01    NA
Jan-01  -0.01   0.00    NA  0.00    NA


There also NAs within the data which cannot be removed due to the nature of data. I appreciate your help in this regard.

• @vonjd there is funciton in performance analytics return.cumulative but I'm hesistant to use it as I have already estimated the returns and I need guidance for 1 lag i.e. what does it imply? – Aquarius Feb 26 '16 at 12:43
• did you try lag function of dplyr? – berkorbay Feb 26 '16 at 19:36