i am trying to get a balance column in a python dataframe with an initial static value.
The logic:
start balance = 1000
current balance = previous current balance*(1+df[‘return’])
My attempt:
df.at[1,'current balance'] = 1000
df['current balance'] = df['current balance'].shift(1)*(1+df['return])
I can’t get this output
Output dataframe:
return current balance
0.01 1010.00
0.03 1040.30
0.045 1087.11
>Solution :
Standard compound return:
initial_balance = 1000
df['current balance'] = (1 + df['return']).cumprod() * initial_balance
>>> df
return current balance
0 0.010 1010.0000
1 0.030 1040.3000
2 0.045 1087.1135