Compute rolling window covariance matrix
- by user1665355
I am trying to compute a rolling window (shifting by 1 day) covariance matrix for a number of assets.
Say my df looks like this:
df <- data.frame(x = 0:4, y = 5:9,z=1:5,u=4:8)
How would a possible for loop look like if I want to calculate a covariance matrix on a rolling basis by shifting the rolling window by 1 day? Or should I use some apply family function?
What time series class would be preferrable if I want to create a time series object for the loop above?
I simply can't get it...
Best Regards