1
$\begingroup$

If X is a $T\times N$ pandas DataFrame of multivariate asset returns, the cumulative returns can be computed in python as

(1 + X).cumprod() - 1

How can I reverse this operation so that I go backwards from cumulative returns to the original returns matrix X?

$\endgroup$
0

1 Answer 1

2
$\begingroup$

DataFrame df with a few random returns that I made up:

import pandas as pd
df = pd.DataFrame({'rets': (.5, .5, .4, .3)})

Add cum_rets column:

df['cum_rets'] = (1 + df['rets']).cumprod() - 1

Add inv_cum_rets colum:

df['inv_cum_rets'] = ((1 + df['cum_rets']) / (1 + df['rets'])) - 1

If you want it lined up with your original returns, just shift it up 1 row

EDIT:

If you are missing the original returns and want to back into them from cum_rets you can use this:

df['rets_missing'] = (1 + df['cum_rets']) / (1 + df['cum_rets'].shift(1)) - 1
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.