I have 2 columns with returns dataframe (one is Bitcoin returns over time and one is one crypto asset's returns). I want to calculate rolling cov between them, then variance and then calculate rolling beta coefficient. By the end beta should look like beta and I want to make chart like this rolling beta
cov = df[['Return Market','Return Asset']].rolling(window=3).cov()
cov
var = pd.rolling_var(df['Return Market'], window=3)
var
df['Beta'] = cov / var
When I run
cov = df[['Return Market','Return Asset']].rolling(window=3).cov()
I am getting this output and I it prevents me from finishing the rest of the code. I do not need full covariance matrix, I only need cov between 'Return Market' and 'Return Asset'. I want to drop the rest. The problem is that every index has 2 rows. How to fix it?
This error: TypeError: incompatible index of inserted column with frame index
must be caused by incorrect cov output
Please help me to figure it out. I use Python 3.7 and pandas version is 0.22.0