# What is the best way to calculate the covariance matrix of a group non stationary time series?

I have sales data of a group of products over the same time period. I would like to calculate a covariance matrix of the products, but the time series are not stationary, there are seasonalities and trends.

How can one use the standard covariance formula:

$COV(X,Y)=E[(X-E(X))(Y-E(Y))]$ if $E(X)$ and $E(Y)$ are time dependent? What is a suitable substitute for $E(X)$ and $E(Y)$?

I've tried replacing $X-E(X)$ with $X(t)-\hat{X}(t)$ and $Y-E(Y)$ with $Y(t)-\hat{Y}(t)$, with $\hat{X}(t)$ and $\hat{Y}(t)$ being suitable chosen models of the time series.

So that:

$COV(X,Y)=E[(X(t)-\hat{X}(t))(Y(t)-\hat{Y}(t))]$,

But I'm not shore if this is correct. (Is this a valid approach? Am I missing something?)

Also I need to calculate the covariance matrix not just of my actuals but for future time frames, so even if my approach is valid, I don't know what to use for future time frames, since $X(t)-\hat{X}(t)$ and $Y(t)-\hat{Y}(t)$ don't make sense for future times.