Skip to content Skip to sidebar Skip to footer

How To Get An Inverted Covariance Matrix From A Dataframe On A Rolling Basis

I have a DataFrame of ten different portfolio returns an 12904 days. I am trying to get the rolling inverted covariance matrix for each date. I get the covariance matrix with the .

Solution 1:

I think you are almost there. The following code returns a series where each date corresponds to the covariance matrix over a 750 observations period:

excess_return.rolling(750).cov().groupby('Date').apply(lambda g: pd.DataFrame(np.linalg.inv(g.values), index=g.index, columns=g.columns))

Post a Comment for "How To Get An Inverted Covariance Matrix From A Dataframe On A Rolling Basis"