20  ARMA processes

Setup
library(dplyr)
# required for figures  
library(ggplot2)
library(gridExtra)
# required for render latex 
library(backports)
library(latex2exp)
# required for render tables
library(knitr)
library(kableExtra)
# Random seed 
set.seed(1)

20.1 ARMA(p, q)

An Auto Regressive Moving Average processes, or for short ARMA(p,q), is a combination of an MA(q) () and an AR(p) (), i.e.  (20.1)Yt=μ+i=1pϕiYti+j=1qθjutj+ut, where in general utWN(0,σu2) ().

ARMA(1,1) simulation
set.seed(6) # random seed
# *************************************************
#                      Inputs 
# *************************************************
# Number of steps ahead 
t_bar <- 300 
# Intercept 
mu <- 0.5
# AR parameters
phi <- c(phi1 = 0.95)
# MA parameters
theta <- c(theta1 = 0.45)
# Variance of the residuals 
sigma2_u <- 1 
# *************************************************
#                   Simulations 
# *************************************************
# Initial value
Yt <- c(mu / (1 - phi[1])) 
# Simulated residuals
u_t <- rnorm(t_bar, 0, sqrt(sigma2_u)) 
# Simulated ARMA(1,1)
for(t in 2:t_bar){
  # AR component
  sum_AR <- phi[1] * Yt[t-1]
  # MA component
  sum_MA <- theta[1] * u_t[t-1] 
  # Update Yt 
  Yt[t] <- mu + sum_AR + sum_MA + u_t[t]
}
Figure 20.1: ARMA(1,1) simulation on the top and empirical autocovariance at the bottom.

20.1.1 Matrix form

An Autoregressive process of order p AR(p) () can be written in matrix form as Yt=c+ΦYt1+but, where (YtYt1Ytp)Yt=(μ00)c+(ϕ1ϕ2ϕp1ϕp1000010000100000)Φ(Yt1Yt2Ytp1)Yt1+(100)but where Yt, c and b have dimension p×1, while Φ is p×p.

Let’s consider the vector containing the coefficients of the model, i.e. γp×1=(ϕ1ϕ2ϕp1ϕp). If the order of the Autoregressive process is greater than 1, i.e. p>1, let’s consider an identity matrix () with dimension (p1)×(p1), i.e.  Ip1=(1000010000100001), and combine it with a column of zeros, i.e. L(p1)×p=(Ip101×(p1)). Finally, add on the top of L with the AR parameters, i.e.  Φp×p=(γL).

Example 20.1 Let’s consider an AR(4) process of the form Yt=μ+ϕ1Yt1+ϕ2Yt2+ϕ3Yt3+ϕ4Yt4+ut. Then, the vector containing the coefficients of the model reads γ4×1=(ϕ1ϕ2ϕ3ϕ4).

For an AR(4) we start with a diagonal matrix with dimension 3×3, i.e.  I3=(100010001), and we add a column of zeros, i.e. L33×4=(100001000010). and the parameters Φ4×4=(ϕ1ϕ2ϕ3ϕ4100001000010). In order to verify the above result, let’s consider the iteration from t1 to time t, in matrix form one obtain (YtYt1Yt2Yt3)=(μ000)+(ϕ1ϕ2ϕ3ϕ4100001000010)(Yt1Yt2Yt3Yt4)+(1000)ut. After an explicit computation, one can verify that it lead to the classic AR(4) recursion, i.e. (YtYt1Yt2Yt3)=(μ000)+(ϕ1Yt1+ϕ2Yt2+ϕ3Yt3+ϕ4Yt4Yt1Yt2Yt3)+(ut000)

Let’s now consider the matrix form an ARMA (p,q) process (), i.e.  Xt=c+AXt1+but, where, the first component, namely Yt=ep+qXt, is extracted as: Yt=ep+qc+ep+qAXt1+ep+qbut. where ep+q is a basis vector () with dimension p+q.

(YtYt1Ytputut1utq)Xt=(μ0000)c+(ϕ1ϕ2ϕp1ϕpθ1θ2θq1θq10000000010000000010000000000010)A(Yt1Yt2Ytp1ut1ut2utp1)Xt1+(100100)but

Let’s consider the vector γ containing the coefficients of the model, i.e. γ1×(q+p)=(ϕ1ϕ2ϕp1ϕpθ1θ2θq1θq). For an ARMA(p,q) we consider two distinct matrices, i.e. a matrix for the AR part we consider the identity matrix () with order p1, i.e. Ip1(p1)×(p1)=(1000010000100001), and we combine it with a column of zeros, i.e. LAR(p1)×p=(Ip10(p1)×1)=(100000100000010000010). For the MA part we consider the identity matrix with order q1, i.e. Iq1=(1000010000100001), and we combine it with a column of zeros, i.e. LMA(q1)×q=(Iq10(q1)×1)=(100000100000010000010). To combine the matrices Lp1 and Lq1, we need add a matrix of zeros. More precisely: L(q+p1)×(q+p)=(LAR0(p1)×q01×p01×q0(q1)×pLMA). Finally we combine L with the parameters, i.e. A(q+p)×(q+p)=(γL). Then, the vector b is constructed by combining two basis vectors (), to ensure it is equal to one in the position 1 and in the position p+1, i.e. b=(epeq).

Example 20.2 For example let’s consider an ARMA(2,3): γ=(ϕ1ϕ2θ1θ2θ3). The matrix for the AR part that is equal to Φ combined with a matrix of zeros, i.e. LAR1×2=(10), For the MA part we consider a similar matrix as in the single case but with first row equal to zero, i.e. LMA2×3=(100010), and we combine L4×5=(LAR02×301×201×302×2LMA)=(10000000000010000010). Finally we combine A5×5=(γL)=(ϕ1ϕ2θ1θ2θ310000000000010000010). Then, the vector b is constructed by combining two vectors b=(e2e3)=(10100). Let’s check it would lead to a classic ARMA(2,3): (YtYt1utut1ut2)=(ϕ1Yt1+ϕ2Yt2+θ1ut1+θ2ut1+θ2ut2Yt10ut1ut2)+(ut0ut00)=(ϕ1Yt1+ϕ2Yt2+θ1ut1+θ2ut1+θ3ut2+utYt1utut1ut2)

20.2 Moments

Proposition 20.1 Given the information at time t, the forecasted value at time t+h for an AR(p) process reads: (20.2)Xt+h=j=0h1Ajc+AhXt+j=0h1Ajbut+hj.

Proof. Let’s start developing the with h=1, i.e.  Xt+1=c+AXt+but+1, with h=2: Xt+2=c+AXt+1+but+2==A(c+AXt+but+1)+but+2==c+Ac+A2Xt+but+2+Abut+1 with h=3: Xt+3=c+AXt+2+b ut+3==c+A(c+Ac+A2Xt+but+2+Abut+1)+but+3==c+Ac+A2c+A3Xt+but+3+Abut+2+A2but+1 and so on. Hence the impact of the shocks decrease exponentially over time.

Proposition 20.2 (Expectation of an ARMA)
The conditional expectation at time t+h of Xt+h given the information up to time t can be easily computed from , i.e.  E{Xt+hFt}=c (IpAh) (IpA)1+AhXt.

Proof. The expectation of reads: E{Xt+hFt}=j=0h1Ajc+AhXt+j=0h1AjbE{ut+hjFt}. Under the assumption that ut+hjMDS(0,1), we have that for all t E{ut+1Ft}=0. Therefore E{Xt+hFt}=j=0h1Ajc+AhXt, where for constant c, the series further simplifies in j=0h1Ajc=(IpAh) (IpA)1c, with Ip the identity matrix ().

Proposition 20.3 (Variance of an ARMA)
Taking the variance of on both sides gives V{Xt+hFt}=σu2j=0h1Ajbb(Aj). Moreover, Assuming utWN(0,σu2), and independence across time, the conditional covariance is: Cv{Xt+h,Xt+kFt}=σu2j=0min(h,k)1Ah1jbb(Ak1j).

Proof. Taking the conditional variance gives V{Xt+hFt}=j=0h1V{Ajbut+hjFt}=j=0h1AjbV{ut+hjFt}b(Aj). Then, if ut is White Noise process, then its variance is constant, hence independent from t, and equal to σu2. For the covariance formula, each Xt+h is influenced by past shocks ut+hj. Since the shocks are uncorrelated across time, only shared shocks affect both Xt+h and Xt+k. The number of common shocks is min(h,k), and each contributes: Cv{Ah1jbut+1+j,Ak1jbut+1+j}=σu2Ah1jbb(Ak1j).

Example 20.3 Let’s use Monte Carlo simulations to establish if the results are accurate.

simulate_ARMA
# Simulate an ARMA(p, q) process
simulate_ARMA <- function(t_bar, nsim = 1, mu = 0, phi = c(0.5, 0.2), theta = c(0.4, 0.1), sigma2 = 1, y0, eps0){
  scenarios <- list()
  # MA order
  q <- length(theta)
  # AR order 
  p <- length(phi)
  # Initial lag to start 
  i_start <- max(c(p, q)) + 1
  for(sim in 1:nsim){
    # Simulated residuals 
    if (!missing(eps0)){
      eps <- c(eps0, rnorm(t_bar - q, sd = sqrt(sigma2)))
    } else {
      eps <- rnorm(t_bar, sd = sqrt(sigma2))
    }
    # Initialize the simulation 
    if (!missing(y0)){
      x <- c(y0)
    } else {
      x <- eps
    }
    for(t in i_start:t_bar){
      # AR part 
      ar_part <- 0
      for(i in 1:length(phi)){
        ar_part <- ar_part + phi[i] * x[t-i]
      }
      # MA part 
      ma_part <- 0
      for(i in 1:length(theta)){
        ma_part <- ma_part + theta[i] * eps[t-i]
      }
      # Next step simulation 
      x[t] <- mu + ar_part + ma_part + eps[t]
    }
    scenarios[[sim]] <- x
  }
  scenarios
}
pow_matrix
# Compute the power of a matrix 
pow_matrix <- function(x, n = 0){
  M <- x
  # Case power == 0
  if (n == 0) {
    M <- diag(1, nrow(M), ncol(M))
  } else if(n > 1) {
    M_pow <- M
    for(i in 2:n){
      M_pow <- M_pow %*% M
    }
    M <- M_pow
  }
  return(M)
}
expectation_ARMA
# Compute the expected value with the iterative formula 
expectation_ARMA <- function(X0, h = 10, A, b, c){
  A_h <- pow_matrix(A, h)
  I_p <- diag(1, nrow = nrow(A_h))
  (I_p - A_h) %*% solve(I_p - A) %*% c  + A_h %*% X0
}
covariance_ARMA
# Compute the covariance with the iterative formula 
covariance_ARMA <- function(h, k, A, b, sigma2 = 1){
  cv_x <- 0
  for(j in 0:(min(h, k)-1)){
    A_hj <- pow_matrix(A, h-1-j)
    A_kj <- pow_matrix(A, k-1-j)
    cv_x <- cv_x + A_hj %*% b %*% t(b) %*% t(A_kj)
  }
  sigma2 * cv_x
}
ARMA moments
# *************************************************
#                      Inputs 
# *************************************************
set.seed(6) # random seed
nsim <- 200 # Number of simulations
t_bar <- 100000 # Steps for each simulation 
phi <- c(0.3, 0.15) # AR parameters
theta <- c(0.3, 0.15, 0.1) # MA parameters
mu <- 0.3 # Intercept 
sigma2 <- 1 # Variance of the residuals 
y0 <- c(0.9, 0.2, 0) # Initial values for y0
eps0 <- c(0.3, -0.2, 0.1) # Initial values for eps0
h <- 200 # Number of steps ahead
# *************************************************
#                   Simulations 
# *************************************************
scenarios <- simulate_ARMA(t_bar, nsim, mu, phi, theta, 
                           sigma2, y0, eps0)
# Build companion matrix 
L_AR <- matrix(c(1, 0, 0, 0, 0), nrow = 1)
L_MA <- cbind(c(0, 0), c(0, 0), diag(2), c(0, 0))
A <- rbind(c(phi, theta), L_AR, rep(0, 5), L_MA)
# Build vector b
b <- matrix(c(1, 0, 1, 0, 0), ncol = 1)
# Build vector c
c <- matrix(c(mu, 0, 0, 0, 0), ncol = 1)
# *************************************************
#                      Moments  
# *************************************************
# Compute expectation and variances with Monte Carlo
e_mc <- mean(purrr::map_dbl(scenarios, ~mean(.x)))
v_mc <- mean(purrr::map_dbl(scenarios, ~var(.x)))
cv_mc_L1 <- mean(purrr::map_dbl(scenarios, ~cov(.x[-1], lag(.x, 1)[-1])))
cv_mc_L2 <- mean(purrr::map_dbl(scenarios, ~cov(.x[-c(1,2)], lag(.x, 2)[-c(1,2)])))
cv_mc_L3 <- mean(purrr::map_dbl(scenarios, ~cov(.x[-c(1:3)], lag(.x, 3)[-c(1:3)])))
cv_mc_L4 <- mean(purrr::map_dbl(scenarios, ~cov(.x[-c(1:4)], lag(.x, 4)[-c(1:4)])))
cv_mc_L5 <- mean(purrr::map_dbl(scenarios, ~cov(.x[-c(1:5)], lag(.x, 5)[-c(1:5)])))
# Compute expectation and variances with Formula
# State vector for forecasting 
X0 = c(y0[-3][c(2,1)], eps0[c(3:1)])
e_mod <- expectation_ARMA(X0, h = h, A, b, c)[1,1]
v_mod <- covariance_ARMA(h, h, A, b, sigma2)[1,1]
cv_mod_L1 <- covariance_ARMA(h, h-1, A, b, sigma2 = 1)[1,1]
cv_mod_L2 <- covariance_ARMA(h, h-2, A, b, sigma2 = 1)[1,1]
cv_mod_L3 <- covariance_ARMA(h, h-3, A, b, sigma2 = 1)[1,1]
cv_mod_L4 <- covariance_ARMA(h, h-4, A, b, sigma2 = 1)[1,1]
cv_mod_L5 <- covariance_ARMA(h, h-5, A, b, sigma2 = 1)[1,1]
Covariance Formula MonteCarlo
E{Yt} 0.5454545 0.5451268
V{Yt} 1.7466575 1.7472189
Cv{Yt,Yt1} 1.1317615 1.1322251
Cv{Yt,Yt2} 0.8115271 0.8118819
Cv{Yt,Yt3} 0.5132223 0.5133504
Cv{Yt,Yt4} 0.2756958 0.2758340
Cv{Yt,Yt5} 0.1596921 0.1596755
Table 20.1: Theoric long term moments and moments computed on 200 Monte Carlo simulations (t = 100000).
Figure 20.2: ARMA(2,3) simulations with expected value (red) and confidence intervals with α=0.1 (green), α=0.05 (magenta) and α=0.01 (purple).