## Sarem Seitz # ARMA forecasting for non-Gaussian time-series data using Copulas

ARMA (AutoRegressive – Moving Average) models are arguably the most popular approach to time-series forecasting. Unfortunately, plain ARMA is made for Gaussian distributed data only. On the one hand, you can often still use ARMA by transforming the raw data. On the other hand, this typically makes probabilistic forecasts quite tedious.

One approach to apply ARMA to non-Normal data are Copula models. Roughly, the latter allow us to exchange the Gaussian marginal for any other continuous distribution. At the same time, they preserve the implicit time-dependency between observations that is imposed by ARMA.

If this sounds confusing, I suggest reading the next paragraph carefully. Also, you might want to read some external sources for a deeper understanding, too.

## What are Copulas and how can we use them with ARMA?

Informally, Copulas (or Copulae if you are a Latin hardliner) define joint cumulative distribution functions (c.d.f.) for unit-uniform random variables. Formally, we can describe this as

\begin{gathered}
C(u_1,...,u_m)=P(U_1\leq u_1,...,U_m\leq u_m)\\
U_1,...,U_M\stackrel{i.i.d}{\sim} \mathcal{U}(0,1)
\end{gathered}

That property alone is quite unspectacular as uniform random variables are not very expressive for practical problems. However, an important result in probability theory will make things more interesting.

The probability integral transform states that we can transform any continuous random variable to a uniform one by plugging it into its own c.d.f.:

\begin{gathered}
\text{Let }X \text{ be continuous with c.d.f. }F_X(x)\text{, then}\\
F_X(X)\sim\mathcal{U(0,1)}
\end{gathered}

We can verify this empirically for a standard Normal example: Probability integral transform in action – applying the standard Gaussian c.d.f. on standard Gaussian data creates Uniform distributed data

As the inverse of a c.d.f. is the quantile function, we can easily invert this transformation. Even cooler, we can transform a uniform random variable to any continuous random variable via

\begin{gathered}
P(F_X^{-1}(U) \leq x)=F_X(x)\\
F_X^{-1}(\cdot)\text{ := inverse (quantile) function of } F_X(\cdot)
\end{gathered}

This inverse transformation will become relevant later on.

#### Combining Copulas and the inverse probability transform

In conjunction with Copulas, this allows us to separate the marginal distributions from the dependency structure of joint random variables.

A concrete example: Consider two random variables, X and Y with standard Gamma and Beta marginal distributions, i.e.

X\sim\Gamma(1,1),\quad Y\sim\mathcal{B}(1,1)

With the help of a Copula and the probability integral transform, we can now define a joint c.d.f over both variables such that we preserve their marginal distributions:

P(X\leq x,Y\leq y)=C(F_X(x),F_Y(y))

#### Introducing the Gaussian Copula

So far, we haven’t specified any Copula function yet. A simplistic one is the Gaussian Copula, which is defined as follows:

\begin{gathered}
C_{Gauss}(u_1,...,u_m;R)=\Phi_R(\Phi^{-1}(u_1),...,\Phi^{-1}(u_m))\\\\
\Phi_R(\cdot,...,\cdot)\text{ := Joint c.d.f. of multivariate Gaussian s.t. }\\
\mu=0,\Sigma=R  \\
diag(R)=1\\\\
\Phi^{-1}(\cdot)\text{ := Quantile function of standard Gaussian}
\end{gathered}

If we combine this with the Gamma-Beta example from before, we get the following Gaussian Copula joint c.d.f.:

P(X\leq x,Y\leq y)=\Phi_R(\Phi^{-1}(F_X(x)),\Phi^{-1}(F_Y(y)))

The implicit rationale behind this approach can be described in three steps:

1. Transform the Gamma and Beta marginals into Uniform marginals via the respective c.d.f.s
2. Transform the Uniform marginals into standard Normal marginals via the quantile functions
3. Define the joint distribution via the multivariate Gaussian c.d.f. with zero mean, unit variance and non-zero covariance (covariance matrix R)

By inverting these steps, we can easily sample from a bi-variate random variable that has the above properties. I.e. standard Gamma/Beta marginals with Gaussian Copula dependencies:

1. Draw a sample from a bi-variate Gaussian with mean zero, unit variance and non-zero covariance (covariance matrix R). You now have two correlated standard Gaussian variables.
2. Transform both variables with the standard Gaussian c.d.f. – you now have two correlated Uniform variables. (= probability integral transform)
3. Transform these variables with the standard Beta and Gamma quantile functions – you now have a pair of correlated GammaBeta variables. (= inverse probability integral transform)

Notice that we could drop the zero-mean, unit-variance assumption on the multivariate Gaussian. In that case we would have to adjust the Gaussian c.d.f. to the corresponding marginals in order to keep the integral probability transform valid.

Since we are only interested in the dependency structure (i.e. covariances), standard Gaussian marginals are sufficient and easier to deal with.

Now let us sample some data in Julia:

Congratulations, you have just sampled from your first Copula model!

#### But wait – I want to fit a model!

Let’s say we observed the above data without the underlying generating process. We only presume that we know that Gamma-Beta marginals and a Gaussian copula are a good choice. How could we fit the model parameters (i.e. ‘learn’ them in the Machine Learning world)?

As often for statistical models, Maximum Likelihood is a good approach. However, we need a density function for that, so what do we do? We already found out, that a Copula model describes a valid c.d.f. for continuous marginals. Thus, we can derive the corresponding probability density by taking derivatives:

\begin{gathered}
p(x_1,...,x_m)\\
=\frac{\partial^m}{\partial x_1\cdots\partial x_m}F(x_1,...,x_m)\\
=\frac{\partial^m}{\partial x_1\cdots\partial x_m}C(F(x_1),...,F(x_m))\\
=c(F(x_1),...,F(x_m))\cdot\frac{\partial}{\partial x_1}F(x_1)\cdots\frac{\partial}{\partial x_m}F(x_m)
\\
=c(F(x_1),...,F(x_m))\cdot p(x_1)\cdots p(x_m)\\\\
\text{(where } c(\cdot,...,\cdot) \text{ is called a 'Copula density function';}\\
p(\cdot) \text{ denotes a probability density function)}

\end{gathered}


If you carefully look at the last line, you see that the joint density equals the product of the marginal densities times the Copula density. Recall that the product of the marginal densities alone would imply independency. Thus, the Copula density serves as a correction factor to account for the actual dependency between the marginals.

This structure allows us to separate the marginal distributions from the their dependency structure.

Now, for the Gaussian Copula, one can prove the following Copula density function:

c_{Gauss}(u_1,...,u_m;R)=\frac{1}{\sqrt{|R|}}exp\left(-0.5\begin{pmatrix}\Phi^{-1}(u_1)\\\vdots\\\Phi^{-1}(u_m)\end{pmatrix}^T\cdot(R^{-1}-I)\cdot\begin{pmatrix}\Phi^{-1}(u_1)\\\vdots\\\Phi^{-1}(u_m)\end{pmatrix}\right)

In order to estimate the model parameters for the Gamma-Beta example, we simply need to plug this function into the full density. Then, we take logarithms and get the target log-likelihood function for optimization.

## ARMA with non-normal data via Copulas

Finally, we can return to our initial problem. For this example, we will focus on the stationary ARMA(1,1) model:

\begin{gathered}
y_t=\phi y_{t-1}+\theta\epsilon_{t-1}+\epsilon_t\\
\epsilon_t\sim\mathcal{N}(0,\sigma^2)\\
\end{gathered}

For a time-series with T observations, we can derive the unconditional, stationary distribution (see e.g. here):

\begin{gathered}

\begin{pmatrix}y_1\\\vdots\\y_T\end{pmatrix}\sim\mathcal{N}\left(0,\Sigma=\begin{bmatrix} \gamma(0)&\gamma(1)&\cdots&\gamma(T-1)\\\gamma(1)&\gamma(0)&\cdots&\gamma(T-2)\\\vdots&\vdots&\ddots&\vdots\\\gamma(T-1)&\gamma(T-2)&\cdots&\gamma(0)\end{bmatrix}\right)\\\\

\text{where } \gamma(h) \text{ the ARMA(1,1) auto-covariance function for lag }h\text{:}\\
\gamma(h)=\begin{cases}\sigma^2\left(1+\frac{(\phi+\theta)^2}{1-\theta^2}\right)&h=0\\\sigma^2\left((\phi+\theta)\phi^{h-1}+\frac{(\phi+\theta)^2\phi^h}{1-\phi^2}\right)&h>0\end{cases}

\end{gathered}

Informally, the unconditional distribution considers a fixed-length time-series as a single, multivariate random vector. As a consequence, it doesn’t matter whether we are sampling from the unconditional distribution or the usual ARMA equations (for an equally long time-series) themselves.

In some instances, such as this one, the unconditional distribution is easier to work with.

Also, notice that the unconditional marginal distributions (the distributions of the y_t's) are the same regardless of the time-lag we are looking at. In fact, we have zero-mean Gaussians with variance equal to the auto-covariance function at zero.

Next, let us define:

\begin{gathered}
G=\frac{1}{\gamma(0)}\cdot I\\
\tilde{\Sigma}=G\Sigma\\\\
\Rightarrow diag(\tilde{\Sigma})=1
\end{gathered}

The transformed covariance matrix now implies unit variance while preserving the dependency structure of the unconditional time-series. Literally, we have just derived the correlation matrix but let us stick to the idea of a standardized covariance matrix.

If we plug this back into a Gaussian copula – let us call the ARMA(1,1) Copula. Now, we could use the ARMA(1,1) Copula dependency structure together with any continuous marginal distribution. For example, we could define

\begin{gathered}
p(y_t)=Exp(y_t|0.5)\\
=\frac{1}{0.5}e^{-\frac{y_t}{0.5}}\\
y_t>0

\end{gathered}

i.e. the unconditional marginals are Exponential-distributed with rate parameter 0.5. Putting everything together, we obtain the following unconditional density:

p\begin{pmatrix}y_1\\\vdots \\y_T\end{pmatrix}=\prod_{t=1}^T Exp(y_t|0.5)\cdot c_{Gauss}(F_{Exp(0.5)}(y_1),...,F_{Exp(0.5)}(y_T);G\Sigma G)

Let us combine everything so far and plot an example: Sample from ARMA(1,1) model with unit variance (top) and ARMA(1,1) Copula model with Exp(0.5) marginals (bottom)

Clearly, the samples from the Copula model are not Gaussian anymore. In fact, we observe a single draw from a ARMA(1,1) Copula with Exponential-distributed marginals.

#### Parameter estimation with Maximum Likelihood

So far, we have only been able to simulate a time-series from the ARMA(1,1) Copula model. In order to fit the model, we will apply Maximum Likelihood. When using Copulas for cross-sectional data, it is usually possible to separate fitting the marginal distributions from fitting the Copula. Unfortunately, this does not work here.

As we only observe one realization of the process per marginal, fitting a distribution based on the marginals alone is impossible. Rather, we now need to optimize both the marginals and the copula at once. This begs the additional difficulty of having to deal with the marginal’s parameters inside the marginal’s c.d.f..

Namely, our Maximum likelihood objective looks as follows:

\begin{gathered}
=\underset{\phi,\theta,\sigma,\lambda}{\max}\log c(F_\lambda(y_1),...,F_\lambda(x_m);R(\phi,\theta,\sigma))+\sum_{t=1}^T\log p_\lambda(y_t)\\\\
\text{where}\\\\
R(\phi,\theta,\sigma):=\text{Standardized Gaussian Copula covariance matrix}\\
\text{(with respect to the ARMA parameters)}\\
F_\lambda(\cdot):=\text{ c.d.f. of an Exponential distribution with paramater }\lambda\\
p_\lambda(\cdot):=\text{ probability density of an Exponential distribution with parameter }\lambda
\end{gathered}


Optimizing this can become quite ugly as derivatives with respect to a c.d.f.’s parameters are usually fairly complex. Luckily, the Exponential distribution is quite simple and respective derivatives are easily found. Even better, the Optim.jl package can optimize our log-likelihood via finite differences without requiring any derivatives at all.

If we chose another distribution than the Exponential, finite differences might not suffice. In that case, we would have to either implement the c.d.f. derivatives by hand or hope that ChainRules.jl can handle them for us.

Also, we transform our model parameters to the correct domains via exp and tanh instead of applying Box constraints in the Optim optimizer. This worked reasonably accurate and fast here:

Now, let us evaluate the result. For the Exponential distribution, the estimated parameter should be close to the true parameter. Regarding the latent ARMA parameters, we primarily need the estimated auto-covariance to be close to ground-truth. This is indeed the case here: Comparison of estimation VS. ground truth – the model closely matches the underlying ARMA dynamics and the marginal Exponential distribution.

#### Forecasting with the Copula model

Finally, we want to use our model to produce actual forecasts. Due to the Copula construction, we can derive the conditional forecast density in closed form. As we will see however, mean and quantile forecasts need to be calculated numerically.

First, recall how the Copula model defines a joint density over all ‘training’-observations:

p(y_1,...,y_T)=c(F(y_1),...,F(y_T))\cdot p(y_1)\cdots p(y_T)

In order to forecast a conditional density at h steps ahead, we simply need to follow standard probability laws:

\begin{gathered}
p(y_{T+h}|y_1,...,y_T)\\
=\frac{p(y_{T+h},y_1,...,y_T)}{p(y_1,...,y_T)}\\
=\frac{c(F(y_{T+h}),F(y_1),...,F(y_T))\cdot p(y_{T+h})\cdot p(y_1)\cdots p(y_T)}{c(F(y_1),...,F(y_T))\cdot p(y_1)\cdots p(y_T)}\\\\
=\frac{c(F(y_{T+h}),F(y_1),...,F(y_T))}{c(F(y_1),...,F(y_T))}\cdot p(y_{T+h})
\end{gathered}

This boils down to the ratio of two Copula evaluations times the marginal density evaluated at the target point. However, we still need to find a way to use this equation to calculate a mean forecast and a forecast interval.

As the density is arguably fairly complex, we won’t even try to derive any of these values in closed form. Rather, we use numerical methods to find the target quantities.

For the mean, we simply use quadrature to approximate the usual integral:

\mathbb{E}[y_{T+h}|y_1,...,y_T]\approx\int_0^U y_{T+h}\cdot p(y_{T+h}|y_1,...,y_T)dy_{T+h}

with U a sufficiently large value to capture most of the probability mass (approximation up to infinity is obviously not possible).

For the forecast interval, we use the 90% prediction interval. Thus, we need to find the 5% and the 95% quantiles of the conditional density. This can be done via another approximation, this time through an Ordinary Differential Equation:

\begin{gathered}
\frac{dF^{-1}}{du}=\frac{1}{p(F^{-1}(u)|y_1,...,y_T)}\\\\

\text{with } F^{-1}(u)\text{ the quantile function corresponding to }p(y_{T+h}|y_1,...,y_T) \\
\text{evaluated at }u \in [0.0,1.0]
\end{gathered}

For a derivation of this formula, see, for example, here. Integrating the ODE from zero up to the target quantile yields the respective target quantile value. The latter can be done numerically via DifferentialEquations.jl.

With this, we can finally calculate the forecast and plot the result:

The looks indeed quite reasonable and the forecast appears to converge to a stable distribution as we predict further ahead into the future.

## Conclusion

As we have seen, Copulas make it possible to extend well-known models to non-Gaussian data. This allowed us to transfer the simplicity of the ARMA model to Exponential marginals that were only defined for positive values.

One complication arises when the size of the observed time-series becomes very large. In that case, the unconditional covariance matrix will scale poorly and the model fitting step will likely become impossible.

Then, we need to find a computationally more efficient solution. One possible approach are Implicit Copulas which define a Copula density through a chain of conditional densities.

Of course, there are many other ways to integrate Copulas into classical statistical and Machine Learning models. For the latter, research is still a little sparse. However, I strongly believe that there is at least some potential for a modern application of these classic statistical objects.

## References

 Hamilton, James Douglas. Time series analysis. Princeton university press, 2020.

 Nelsen, Roger B. An introduction to copulas. Springer Science & Business Media, 2007.

 Smith, Michael Stanley. Implicit copulas: An overview. Econometrics and Statistics, 2021.

WordPress Theme by RichWP