Análise de Dados Financeiros e Econômicos com o R
EA-UFRGS
18/11/2026
The econometrics of financial markets (Campbell et al. 1997)
Introductory econometrics for finance (Brooks 2014)
Time series analysis (Hamilton 1994)
Econometric analysis (Greene 2003)
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\]
\[y _t = 0.15 y_{t-1} + \epsilon _t\]
\[y_t = 1.5y_{t-1} + \epsilon _t\]
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) 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
Dickey-Fuller for Returns:
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
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
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
“Can We Predict the Financial Markets Based on Google’s Search Queries?” – Journal of Forecasting
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 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} \]
\[ \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
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!
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:
Steps:
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:
“A GARCH Tutorial with R” – RAC
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?
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?
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?
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} \]
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?
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.
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.
ADFER - UFRGS