I have created this data table in R and now I would like to compute the cumulative return of a stock (stock is shown by ID and a stock can be seen on different time periods). If I have month t, the cumulative return should be computed from month t-11 to month t - 1. Columns new_11 and new_1 are helping columns which show me for eg on first row, for Dec 1980 cumulative return should be computed from Jan 1980 to Nov 1980, grouped by Id. I know the cumulative return formula in R is cumprod(1 + RETURN), but I do not know how to write the code according to starting and ending month.
Can anyone please help me? Press to see the table -> 1