I have the following dataframe. How do I create a new column that has the monthly return?
Exhibit A:
Scenario | TimeStep | CumReturn |
---|---|---|
1 | 0 | 1 |
1 | 1 | 1.05 |
1 | 2 | 1.07 |
2 | 0 | 1 |
2 | 1 | 1.04 |
2 | 2 | 1.02 |
Exhibit B:
Scenario | TimeStep | CumReturn |
---|---|---|
1 | 0 | .05 |
1 | 1 | .019 |
1 | 2 | na |
2 | 0 | .04 |
2 | 1 | -.019 |
2 | 2 | na |
Where row n is (n-1 / n)-1 for each change in time, stopping at the end of each scenario.
The end goal is to do this iteratively for cumulative indeces, then create a linearly combination from the individual returns, then RE roll to a new cumulative number.
I am doing this in pandas.
So far I have this code:
for idx,wght, i in zip( indeces,fundweights , range(len(indeces)-1)):
df_temp = pd.read_csv(filepath + file_names[idx],header=None)
df_temp = df_temp.stack()
df_temp.index.names=['Scen','TIME']
df_temp= df_temp.to_frame(name='CumGrowth_idx')
df_temp.reset_index(inplace=True)
df_temp['Scen'] = df_temp['Scen'] + 1
df_temp[idx] = idx
df_temp = df_temp.rename(columns={'TIME':'Month'})
df_temp["Monthly_Return"]=
I want to create the monthly return dataframe, then append these all to a dataframe, take a linear combination. Can anyone offer some input?
Thanks