I have an
(n,m) array (specifically containing asset returns over
n days for
m assets). I'm trying to calculate the rolling exponentially-weighted covariance matrix for these assets over this time frame, but I want to limit how much data with which each covariance matrix is calculated.
To be more specific, I'm wanting to calculate these covariance matrices using 20-observation half-lives, but I don't want to include more than 40 observations in each of these calculations.
I've come as far as constructing a pandas DataFrame which has a shape of
(n, m, 40), so each value of
n contains the last 40 observations of the
m assets. I was thinking I'd be able to calculate a single exponentially-weighted covariance matrix with 20-observation half-life at each
n using the data in that row , but I'm coming up short. Am I able to calculate it this way or is there a different approach I should take?
I'm looking to avoid
for loops in this solution.