My df containing monthly returns looks like this:
df=pd.DataFrame((x*x).dropna(),columns=['mthly rtrn'])
mthly rtrn
2016-09-30 0.002488
2016-10-31 -0.004692
2016-11-30 0.003157
2016-12-30 -0.000503
2017-01-31 0.008019
2017-02-28 0.010055
2017-03-31 0.003435
2017-04-28 0.002577
2017-05-31 0.012107
2017-06-30 0.001089
How can I convert this into a df with columns Jan to Dec plus column for the cumulative yearly return. Lines should be the years 2016, 2017 etc. And the numbers should ideally be shown in %.
Desired output:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ANNUAL
2016 -5.0 -0.1 6.7 0.4 1.7 0.3 3.6 0.1 0.0 -1.7 3.7 2.0 12.0
2017 1.8 3.9 0.1 1.0 1.4 0.6 0.1 NA NA NA NA NA 9.3
where ANNUAL is the cumprod of the monthly returns.
What is the best pythonic way to achieve this?