Econometria Financeira (ARIMA + GARCH)

Análise de Dados Financeiros e Econômicos com o R

Marcelo S. Perlin

EA-UFRGS

18/11/2026

Introduction

Please read the references!

Arima Models

Introduction to Arima Models

Arima is a special type of model that uses the past to explain its own future.

Example of a ARIMA(AR = 1, D = 0, MA = 1):

\[y _t = 0.5 y_{t-1} - 0.2 \epsilon _{t-1} + \epsilon _t\]

  • AR indicates the maximum lag used in \(y_t\) in the right hand side of the equation.
  • D indicates the level of differentiation of the time series (Hamilton 1994)
  • MA defines the maximum lag used for the error of the model.

Interesting properties

  • A AR(1) is simply a ARIMA(1, 0, 0) model

\[y _t = 0.15 y_{t-1} + \epsilon _t\]

  • if \(\theta = 1\) in a AR(1) model, then we have the simplest case of a Random walk model: \(y_t = y_{t-1} + \epsilon _t\)
  • if \(abs(\theta) > 1\), the stochastic process is explosive:

\[y_t = 1.5y_{t-1} + \epsilon _t\]

  • A ARMA model is a parsimonious representation of a AR model with infinite lags \(AR(\infty)\)

Simulating Arima Models

library(ggplot2)

set.seed(1)

# set number of observations
n_T <- 500

# set model's parameters
arima_param <- list(ar = 0.5, 
                    ma = -0.1)
my_sd <- 1

# simulate model
my_ts <- stats::arima.sim(
  n = n_T, 
  model = arima_param, 
  sd = my_sd
)

# set df
temp_df <- dplyr::tibble(
  y = unclass(my_ts), 
  date = Sys.Date() + 1:n_T
)

p <- ggplot(temp_df, aes(x = date, y = y)) + 
  geom_line(size=0.5)

print(p)                 

Estimating Arima Models

my_arima <- stats::arima(
  my_ts, 
  order = c(1,0,1))

Simulated Model:

\[y _t = 0.5 y_{t-1} + -0.1 \epsilon_{t-1} \\ + \epsilon_{t}\]

Estimated values


Call:
stats::arima(x = my_ts, order = c(1, 0, 1))

Coefficients:
         ar1      ma1  intercept
      0.4284  -0.0527     0.0248
s.e.  0.1006   0.1102     0.0754

sigma^2 estimated as 1.038:  log likelihood = -718.84,  aic = 1445.69

Estimating ARIMA for real data

  1. make sure data is stationary (dick fuller test) and whether it needs differentiation
  2. differentiate the time series (or not) – this sets parameter D
  3. estimate ARMA model on resulting series
  4. make predictions and applications

Example for SP500

df_SP500 <- yfR::yf_get(
  "^GSPC", 
  "2015-01-01") |>
  na.omit()

Dickey-Fuller for Returns:

tseries::adf.test(df_SP500$ret_adjusted_prices)

    Augmented Dickey-Fuller Test

data:  df_SP500$ret_adjusted_prices
Dickey-Fuller = -14.936, Lag order = 14, p-value = 0.01
alternative hypothesis: stationary

Dickey-Fuller for Prices:

tseries::adf.test(df_SP500$price_adjusted)

    Augmented Dickey-Fuller Test

data:  df_SP500$price_adjusted
Dickey-Fuller = -2.0252, Lag order = 14, p-value = 0.5676
alternative hypothesis: stationary

The lazy man approach – Auto-ARIMA

We can use computer power to find and estimate the best ARIMA model for the current data. It uses a fitting criteria to select models

# estimate arima model with automatic identification
my_autoarima <- forecast::auto.arima(
  x = df_SP500$ret_adjusted_prices)

my_autoarima
Series:  
ARIMA(2,0,2) with non-zero mean 

Coefficients:
          ar1      ar2     ma1     ma2    mean
      -1.7329  -0.8726  1.6394  0.7615  0.0005
s.e.   0.0255   0.0242  0.0340  0.0321  0.0002

sigma^2 = 0.0001174:  log likelihood = 9276.35
AIC=-18540.7   AICc=-18540.67   BIC=-18504.69

Forecasting Arima Models

# forecast model
forecast::forecast(my_autoarima, h = 5)
     Point Forecast       Lo 80      Hi 80       Lo 95      Hi 95
2987   0.0008412800 -0.01304730 0.01472986 -0.02039947 0.02208203
2988  -0.0009921824 -0.01494137 0.01295700 -0.02232562 0.02034125
2989   0.0027434305 -0.01122367 0.01671053 -0.01861740 0.02410427
2990  -0.0021302266 -0.01609763 0.01183718 -0.02349153 0.01923107
2991   0.0030557359 -0.01091916 0.01703063 -0.01831702 0.02442849

An empirical application of ARIMA Models

“Can We Predict the Financial Markets Based on Google’s Search Queries?” – Journal of Forecasting

Garch Models

Introduction

Garch models relate to the seminal work of Engle (1982) and Bollerslev (1986). The main innovation in this class of models is that the variance (uncertainty) of the residual can change over time.

Benefits:

  • directly models the clustering of volatility, allowing for a better representation of the data generating process

  • allows for the forecast of future volatility

  • main R libraries: fGarch (R-fGarch?), rugarch (R-rugarch?)

A simple GARCH model

A GARCH model is modular. We have a process that sets the conditional mean, and another that defines the variance of the error.

Example for AR(1)-GARCH(1, 1):

\[ \begin{aligned} y _t &= \mu + \theta y_{t-1} + \epsilon _t \\ \epsilon _t &\sim N \left(0, h _t \right ) \\ h _t &= \omega + \alpha \epsilon ^2 _{t-1}+ \beta h_{t-1} \end{aligned} \]

Simulating Garch Models

\[ \begin{aligned} y _t &= 0.02 + 0.1 y_{t-1} + \epsilon _t \\ \epsilon _t &\sim N \left(0, h _t \right ) \\ h _t &= 0.001 + 0.15 \epsilon ^2 _{t-1}+ 0.8 h_{t-1} \end{aligned} \]

Step 01: Set up model’s specifications

# set list with model spec
my_sim_garch = list(
  omega=0.001, 
  alpha=0.15, 
  beta=0.8, 
  mu=0.02, 
  ar = 0.1)

# set garch spec                
spec = fGarch::garchSpec(
  model = my_sim_garch
)

# print it
print(spec)

Formula: 
 ~ ar(1) + garch(1, 1)
Model:
 ar:    0.1
 mu:    0.02
 omega: 0.001
 alpha: 0.15
 beta:  0.8
Distribution: 
 norm
Presample: 
  time          z    h          y
1    0 -0.9672395 0.02 0.02222222

Step 02: Simulate it!

set.seed(20)

# simulate garch model
n_T <- 1000
sim_garch = fGarch::garchSim(spec, n = n_T)

# set df for ggplot
temp_df <- dplyr::tibble(
  sim.ret = sim_garch$garch,
  idx=seq_along(sim_garch$garch))

library(ggplot2)
p <- ggplot(temp_df, aes(x=idx, y=sim.ret)) +
  geom_line()

print(p)

Estimating Garch Models

# estimate garch model
my_garchfit <- fGarch::garchFit(
  data = sim_garch, 
  formula = ~ arma(1,0) + garch(1,1), 
  trace = FALSE
)

print(my_garchfit)

Title:
 GARCH Modelling 

Call:
 fGarch::garchFit(formula = ~arma(1, 0) + garch(1, 1), data = sim_garch, 
    trace = FALSE) 

Mean and Variance Equation:
 data ~ arma(1, 0) + garch(1, 1)
<environment: 0x55fe85c14440>
 [data = sim_garch]

Conditional Distribution:
 norm 

Coefficient(s):
       mu        ar1      omega     alpha1      beta1  
0.0164569  0.0695428  0.0010592  0.1292772  0.8175430  

Std. Errors:
 based on Hessian 

Error Analysis:
        Estimate  Std. Error  t value             Pr(>|t|)    
mu     0.0164569   0.0039213    4.197            0.0000271 ***
ar1    0.0695428   0.0327651    2.122               0.0338 *  
omega  0.0010592   0.0004267    2.482               0.0131 *  
alpha1 0.1292772   0.0282136    4.582            0.0000046 ***
beta1  0.8175430   0.0405740   20.149 < 0.0000000000000002 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 604.1887    normalized:  0.6041887 

Description:
 Wed Nov 18 11:06:12 2026 by user:  

Example for SP500

Steps:

  1. Check for GARCH effects using LM Arch test
# test for Arch effects
MTS::archTest(
  rt = df_SP500$ret_adjusted_prices
)
Q(m) of squared series(LM test):  
Test statistic:  3287.009  p-value:  0 
Rank-based Test:  
Test statistic:  864.3169  p-value:  0 
  1. Estimate model
# set object for estimation
df_est <- fBasics::as.timeSeries(df_SP500)

# estimate garch model for SP500
my_garchfit_sp500 <- fGarch::garchFit(
  data = df_est , 
  formula = ret_adjusted_prices ~ arma(1,0) + garch(1,1), 
  trace = FALSE)

print(my_garchfit_sp500)

Title:
 GARCH Modelling 

Call:
 fGarch::garchFit(formula = ret_adjusted_prices ~ arma(1, 0) + 
    garch(1, 1), data = df_est, trace = FALSE) 

Mean and Variance Equation:
 ret_adjusted_prices ~ arma(1, 0) + garch(1, 1)
 [data = df_est]

Conditional Distribution:
 norm 

Coefficient(s):
           mu            ar1          omega         alpha1          beta1  
 0.0008231595  -0.0556940361   0.0000040893   0.1706858002   0.7950806050  

Std. Errors:
 based on Hessian 

Error Analysis:
            Estimate    Std. Error  t value             Pr(>|t|)    
mu      0.0008231595  0.0001379881    5.965     0.00000000243978 ***
ar1    -0.0556940361  0.0201213813   -2.768              0.00564 ** 
omega   0.0000040893  0.0000005931    6.895     0.00000000000539 ***
alpha1  0.1706858002  0.0174035138    9.808 < 0.0000000000000002 ***
beta1   0.7950806050  0.0181126451   43.896 < 0.0000000000000002 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log Likelihood:
 9903.137    normalized:  3.316523 

Description:
 Wed Nov 18 11:06:12 2026 by user:  

Forecasting Garch Models

# static forecast for garch
my_forecast <- fGarch::predict(
  my_garchfit_sp500, n.ahead = 3)

# print df
print(my_forecast)
  meanForecast  meanError standardDeviation
1 0.0013943239 0.01415492        0.01415492
2 0.0007455040 0.01407883        0.01405674
3 0.0007816394 0.01398327        0.01396127

An empirical application of Garch Models

“A GARCH Tutorial with R” – RAC

Exercises

  1. Using package yfR (Perlin 2023), download data for the SP500 (ticker ^GSPC) between 2015 and today. Estimate a ARIMA (1, 0, 0) for the adjusted returns. What is the value of the autoregressive parameter?

  2. Using same package, download data for the FTSE between 2010 and today. However, download data for daily, monthly and yeary observations. Estimate a ARIMA(1, 0, 1) for each of the time series of returns. Can you find any difference in the estimated coefficients?

  3. Using same data from exercise 1, use function forecast::auto.arima() to estimate a ARIMA model with automatic selection of lags. What is the chosem model?

  4. Using package fGarch (R-fGarch?), simulate 10000 observations of a GARCH(1,1) model with the following specification:

\[ \begin{aligned} y _t &= 0.015 -0.15 y_{t-1} + \epsilon _t \\ \epsilon _t &\sim N \left(0, h _t \right ) \\ h _t &= 0.001 + 0.1 \epsilon ^2 _{t-1}+ 0.85 h_{t-1} \end{aligned} \]

  1. Using the simulated data from previous exercise, estimate a GARCH(1, 1) model with fGarch::garchFit(). Do the estimated coefficients match the ones from the simulation?

  2. Using package yfR, download data for the IBOVESPA index (ticker ^BVSP) between 2015 and today. Test the existence of arch effects in 1) prices series and 2) in the returns series. Report an discuss both results.

  3. For the same data used in 4, estimate a GARCH(1, 1) for the adjusted returns. Report the model and its coefficients in the screen of R.

References

Bollerslev, Tim. 1986. “Generalized Autoregressive Conditional Heteroskedasticity.” Journal of Econometrics 31 (3): 307–27.
Brooks, Chris. 2014. Introductory Econometrics for Finance. Cambridge university press.
Campbell, John Y, Andrew Wen-Chuan Lo, Archie Craig MacKinlay, et al. 1997. The Econometrics of Financial Markets. Vol. 2. Princeton University press Princeton, NJ.
Engle, Robert F. 1982. “Autoregressive Conditional Heteroscedasticity with Estimates of the Variance of United Kingdom Inflation.” Econometrica: Journal of the Econometric Society, 987–1007.
Greene, William H. 2003. Econometric Analysis. Pearson Education India.
Hamilton, James Douglas. 1994. Time Series Analysis. Vol. 2. Princeton university press Princeton.
Perlin, Marcelo. 2023. yfR: Downloads and Organizes Financial Data from Yahoo Finance. https://github.com/ropensci/yfR.