Hi!
I have a dataframe, like this:
isin Year Month MV P RI VA MNEM
1 BMG0539N1020 2011 12 804.00 20.10 92.80 2888.1 N:AOD
2 BMG0539N1020 2012 12 1148.00 28.70 132.50 13.5 N:AOD
3 BMG067231032 2014 12 3598.35 100.91 90.40 406557.6 N:AVAN
.
.
With 4691 observations of annual stock price data (545 companies/isin, with various length of each observation). The observations start and end at different time intervals, some companies have annual data from 1980-2020, and some might have data for 2010-2015 etc.
My problem is: I need to calculate the returns for each company/isin from RI. -> create a column/vector of returns calculated from RI ((RIt/RIt-1)-1)).
I will then need the return column to be shifted, so the returns are represented as rt+1 compared to the other data, meaning for the year 2012 I will represent the 2013 returns.
isin Year Month MV P RI VA RETURN
1 BMG0539N1020 2011 12 804.00 20.10 92.80 return for year+1 (2011+1=2012)
2 BMG0539N1020 2012 12 1148.00 28.70 132.50 return for year+1 (2012+1=2013)
3 BMG067231032 2014 12 3598.35 100.91 90.40 return for year+1 (2014+1=2015)
Any advice?
Thanks!