20 ARMA processes
20.1 ARMA(p, q)
An Auto Regressive Moving Average processes, or for short ARMA(p,q), is a combination of an MA(q) (Equation 19.1) and an AR(p) (Equation 19.3), i.e.
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]
}20.1.1 Matrix form
An Autoregressive process of order p AR(p) (Equation 19.3) can be written in matrix form as
Let’s consider the vector containing the coefficients of the model, i.e.
Example 20.1 Let’s consider an AR(4) process of the form
For an AR(4) we start with a diagonal matrix with dimension
Let’s now consider the matrix form an ARMA (p,q) process (Equation 20.1), i.e.
Let’s consider the vector
Example 20.2 For example let’s consider an ARMA(2,3):
20.2 Moments
Proposition 20.1 Given the information at time
Proposition 20.2 (
The conditional expectation at time
Proposition 20.3 (
Taking the variance of Equation 20.2 on both sides gives
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
}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]