I have a dataframe with annual price and dividend data for numerous companies. I am looking to calculate the 3-year annualized return by adding all of the dividends received during the three years to the ending stock price, and then taking the CAGR. I know how to calculate the CAGR, but where I am stuck is adding dividends received over the period to the ending price.
Sample data:
RIC Date Price Dividend
0 RSG.AX 2018 0.814 0.000
1 RSG.AX 2017 0.889 0.015
2 RSG.AX 2016 0.937 0.012
3 RSG.AX 2015 0.181 0.000
4 RSG.AX 2014 0.216 0.000
5 RSG.AX 2013 0.494 0.000
6 QBE.AX 2018 7.119 0.352
7 QBE.AX 2017 8.331 0.202
8 QBE.AX 2016 8.961 0.389
9 QBE.AX 2015 9.159 0.363
10 QBE.AX 2014 9.156 0.302
Using the company RSG.AX (RIC=company code), an example calculation from 2015 to 2018 would be:
3-year return = (End price + cumulative dividends) / Start price = (0.814+0.015+0.012)/0.182 = 4.63
Annualized return = (return)^(1/years)-1 = (4.63)^(1/3)-1 = 0.66 = 66%
How do I do this with Python? Perhaps .groupby() would work to separate each company's data. Any help is appreciated!