I have a Dataframe in the below format and I am trying to create df['New'] where it is a rotating value as per below which I will use to calculate the correlation between Alpha and New
Date Alpha Bravo Charlie New Correlation
2018-01-03 1 3 2 3 (from bravo column) NaN
2018-01-04 2 6 4 6 (from bravo column) NaN
2018-01-05 3 9 6 9 (from bravo column) NaN
2018-01-06 4 12 8 12 (from bravo column) NaN
2018-01-07 5 15 10 10 (from Charlie column) X
Next Date:
Date Alpha Bravo Charlie New Correlation
2018-01-03 1 3 2 3 (from bravo column) NaN
2018-01-04 2 6 4 6 (from bravo column) NaN
2018-01-05 3 9 6 9 (from bravo column) NaN
2018-01-06 4 12 8 12 (from bravo column) NaN
2018-01-07 5 15 10 15 (from bravo column) X
2018-01-08 6 18 12 12 (from Charlie column) Y
df['Correlation'] = df['Alpha'].rolling(window=5).corr(other=df['New'])
Any advise how can I create this New column with rotating values? (Such that my previous correlation will remain unchanged as X. My final objective is to get the Correlation column and the New column is just used for calculating the correlation only)
In other words, every time the correlation column is calculated it will use the latest value as Charlie but all the previous as Bravo.
Another way of explaining this will be that is will always use the last date of Charlie column and past 4 days of bravo to calculate the correlation with Alpha as per below: