Home > Mobile >  How to calculate cumulative return with pandas?
How to calculate cumulative return with pandas?

Time:12-15

How can I calculate cumulative return of portfolio, with daily return?

                    Return  Portfolio
1999-01-04             NaN        100
1999-01-05        0.011430        100
1999-01-06        0.024109        100

I tried this but it doesn't work:

df['Portfolio'] = df.shift(1)['Portfolio'] * (1   df['Return'])

I want to get 100, 101.14, 103.5 etc...

CodePudding user response:

I think you are looking for cumprod, but you would need to add 1 to the returns:

df.Return.fillna(0).add(1).cumprod() * df['Portfolio']

Output:

1999-01-04    100.000000
1999-01-05    101.143000
1999-01-06    103.581457
dtype: float64
  • Related