Modelli Econometrici per il Dowjones

Beniamino Sartini

25/5/2021

dowjones = read_csv("dowjones.csv")

r_DJ = xts::xts(dowjones$r_DJ, order.by = dowjones$obs)

plot(r_DJ)

AR(8) Model for DowJones

Il primo modello che specifichiamo per i rendimenti del DowJones è un modello autoregressivo di ordine 8. La specificazione del modello:

\[y_t = \alpha_0 + \alpha_1 y_{t-1} + \alpha_2 y_{t-2} + \alpha_3 y_{t-3} + \alpha_4 y_{t-4} + \\ + \alpha_5 y_{t-5} + \alpha_6 y_{t-6} + \alpha_7 y_{t-7} + \alpha_8 y_{t-8} + u_t \]

Le assunzioni sul termine di errore:

  • \(E(u_t) = 0\)
  • \(E(u_t u_{t-k} ) = 0\)
  • \(E(u_t^2 ) = \sigma^2 \, costant\)
lag1 = Lag(r_DJ, 1)
lag2 = Lag(r_DJ, 2)
lag3 = Lag(r_DJ, 3)
lag4 = Lag(r_DJ, 4)
lag5 = Lag(r_DJ, 5)
lag6 = Lag(r_DJ, 6)
lag7 = Lag(r_DJ, 7)
lag8 = Lag(r_DJ, 8)

df = cbind(r_DJ, lag1, lag2, lag3, lag4, lag5, lag6, lag7, lag8) %>% na.omit()

ar8 = lm(r_DJ ~ Lag.1 + Lag.2 + Lag.3 + Lag.4 + Lag.5 + Lag.6 + Lag.7 + Lag.8, data = df)

broom::tidy(ar8) %>% mutate_if(is.numeric, round, 2) %>% knitr::kable(caption = "Modello AR(8) Dowjones") %>% 
    kableExtra::kable_classic() %>% kable_styling() %>% row_spec(c(1), font_size = 14) %>% 
    row_spec(c(1), bold = T, color = "black", background = "yellow") %>% column_spec(c(1, 
    2, 3, 4, 5), background = "white", color = "black")
Modello AR(8) Dowjones
term estimate std.error statistic p.value
(Intercept) 0.03 0.01 3.22 0.00
Lag.1 -0.02 0.01 -2.21 0.03
Lag.2 -0.01 0.01 -1.07 0.28
Lag.3 0.00 0.01 -0.52 0.60
Lag.4 -0.02 0.01 -2.77 0.01
Lag.5 0.00 0.01 0.52 0.60
Lag.6 -0.04 0.01 -4.34 0.00
Lag.7 0.01 0.01 1.65 0.10
Lag.8 -0.02 0.01 -1.77 0.08
broom::glance(ar8)[, -c(11, 12)] %>% knitr::kable(caption = "Modello AR(8) Dowjones") %>% 
    kableExtra::kable_classic() %>% kable_styling() %>% row_spec(c(1), font_size = 14) %>% 
    row_spec(c(1), bold = T, color = "black", background = "yellow") %>% column_spec(c(1:10), 
    background = "white", color = "black")
Modello AR(8) Dowjones
r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance
0.0029278 0.0023275 1.070122 4.877377 5e-06 8 -19764.3 39548.6 39623.55 15216.9

Test sulla significatività di tutti i coefficenti

Usiamo gli errori corretti per l’eteroschedasicità.

car::linearHypothesis(ar8, c("Lag.1=0", "Lag.2=0", "Lag.3=0", "Lag.4=0", "Lag.5=0", 
    "Lag.6=0", "Lag.7=0", "Lag.8=0"), white.adjust = "hc0") %>% broom::tidy() %>% 
    knitr::kable(caption = "Test F sui Coefficenti AR(8)") %>% kableExtra::kable_classic() %>% 
    kable_styling() %>% row_spec(c(1, 2), font_size = 14) %>% row_spec(c(2), bold = T, 
    color = "black", background = "yellow") %>% column_spec(c(1, 2, 4), background = "white", 
    color = "black")
Test F sui Coefficenti AR(8)
res.df df statistic p.value
13296 NA NA NA
13288 8 0.734854 0.6607994

Come possiamo vedere usando gli errori corretti abbiamo un non rifiuto dell’ipotesi nulla, di conseguenza i coefficenti sono uguali a zero e dobbiamo ricercare un modello migliore.

Test autocorrelazione dei residui fino al 8 ordine

Construction of a Breush Godfrey

u_hat_ar8 = residuals(ar8)

lag1_u_hat_ar8 = Lag(u_hat_ar8, 1)
lag2_u_hat_ar8 = Lag(u_hat_ar8, 2)
lag3_u_hat_ar8 = Lag(u_hat_ar8, 3)
lag4_u_hat_ar8 = Lag(u_hat_ar8, 4)
lag5_u_hat_ar8 = Lag(u_hat_ar8, 5)
lag6_u_hat_ar8 = Lag(u_hat_ar8, 6)
lag7_u_hat_ar8 = Lag(u_hat_ar8, 7)
lag8_u_hat_ar8 = Lag(u_hat_ar8, 8)


df_u_hat_ar8 = cbind(u_hat_ar8, lag1_u_hat_ar8, lag2_u_hat_ar8, lag3_u_hat_ar8, lag4_u_hat_ar8, 
    lag5_u_hat_ar8, lag6_u_hat_ar8, lag7_u_hat_ar8, lag8_u_hat_ar8) %>% na.omit() %>% 
    as_tibble()


mod1_u_hat_ar8 = lm(u_hat_ar8 ~ Lag.1 + Lag.2, data = df_u_hat_ar8)

mod2_u_hat_ar8 = lm(u_hat_ar8 ~ Lag.1 + Lag.2 + Lag.3 + Lag.4 + Lag.5, data = df_u_hat_ar8)

mod3_u_hat_ar8 = lm(u_hat_ar8 ~ Lag.1 + Lag.2 + Lag.3 + Lag.4 + Lag.5 + Lag.6 + Lag.7 + 
    Lag.8, data = df_u_hat_ar8)

car::linearHypothesis(mod1_u_hat_ar8, c("Lag.1=0", "Lag.2=0")) %>% broom::tidy() %>% 
    knitr::kable(caption = "Test F residui Breush Godfrey AR(8) 2 Lag") %>% kableExtra::kable_classic() %>% 
    kable_styling() %>% row_spec(c(1, 2), font_size = 14) %>% row_spec(c(2), bold = T, 
    color = "black", background = "yellow") %>% column_spec(c(1, 2, 3, 4), background = "white", 
    color = "black")
Test F residui Breush Godfrey AR(8) 2 Lag
res.df rss df sumsq statistic p.value
13288 15213.37 NA NA NA NA
13286 15213.37 2 0.0013394 0.0005849 0.9994153
car::linearHypothesis(mod2_u_hat_ar8, c("Lag.1=0", "Lag.2=0", "Lag.3=0", "Lag.4=0", 
    "Lag.5=0")) %>% knitr::kable(caption = "Test F residui Breush Godfrey AR(8) 5 Lag") %>% 
    kableExtra::kable_classic() %>% kable_styling() %>% row_spec(c(1, 2), font_size = 14) %>% 
    row_spec(c(2), bold = T, color = "black", background = "yellow") %>% column_spec(c(1, 
    2, 3, 4), background = "white", color = "black")
Test F residui Breush Godfrey AR(8) 5 Lag
Res.Df RSS Df Sum of Sq F Pr(>F)
13288 15213.37 NA NA NA NA
13283 15213.36 5 0.0116396 0.0020325 0.9999994
car::linearHypothesis(mod3_u_hat_ar8, c("Lag.1=0", "Lag.2=0", "Lag.3=0", "Lag.4=0", 
    "Lag.5=0", "Lag.6=0", "Lag.7=0", "Lag.8=0")) %>% knitr::kable(caption = "Test F residui Breush Godfrey AR(8) 8 Lag") %>% 
    kableExtra::kable_classic() %>% kable_styling() %>% row_spec(c(1, 2), font_size = 14) %>% 
    row_spec(c(2), bold = T, color = "black", background = "yellow") %>% column_spec(c(1, 
    2, 3, 4), background = "white", color = "black")
Test F residui Breush Godfrey AR(8) 8 Lag
Res.Df RSS Df Sum of Sq F Pr(>F)
13288 15213.37 NA NA NA NA
13280 15213.32 8 0.0450503 0.0049157 1

Come possiamo vedere da tutti e tre i test sembra che i residui non siano serialmente autocorrelati, tuttavia dovremmo ripetere il test considerando i quadrati dei residui.

u2_hat_ar8 = residuals(ar8)^2

lag1_u2_hat_ar8 = Lag(u2_hat_ar8, 1)
lag2_u2_hat_ar8 = Lag(u2_hat_ar8, 2)
lag3_u2_hat_ar8 = Lag(u2_hat_ar8, 3)
lag4_u2_hat_ar8 = Lag(u2_hat_ar8, 4)
lag5_u2_hat_ar8 = Lag(u2_hat_ar8, 5)
lag6_u2_hat_ar8 = Lag(u2_hat_ar8, 6)
lag7_u2_hat_ar8 = Lag(u2_hat_ar8, 7)
lag8_u2_hat_ar8 = Lag(u2_hat_ar8, 8)


df_u2_hat_ar8 = cbind(u2_hat_ar8, lag1_u2_hat_ar8, lag2_u2_hat_ar8, lag3_u2_hat_ar8, 
    lag4_u2_hat_ar8, lag5_u2_hat_ar8, lag6_u2_hat_ar8, lag7_u2_hat_ar8, lag8_u2_hat_ar8) %>% 
    na.omit() %>% as_tibble()


mod1_u2_hat_ar8 = lm(u2_hat_ar8 ~ Lag.1 + Lag.2, data = df_u2_hat_ar8)

mod2_u2_hat_ar8 = lm(u2_hat_ar8 ~ Lag.1 + Lag.2 + Lag.3 + Lag.4 + Lag.5, data = df_u2_hat_ar8)

mod3_u2_hat_ar8 = lm(u2_hat_ar8 ~ Lag.1 + Lag.2 + Lag.3 + Lag.4 + Lag.5 + Lag.6 + 
    Lag.7 + Lag.8, data = df_u2_hat_ar8)

car::linearHypothesis(mod1_u2_hat_ar8, c("Lag.1=0", "Lag.2=0")) %>% broom::tidy() %>% 
    knitr::kable(caption = "Test F quadrati Breush Godfrey AR(8) 2 Lag") %>% kableExtra::kable_classic() %>% 
    kable_styling() %>% row_spec(c(1, 2), font_size = 14) %>% row_spec(c(2), bold = T, 
    color = "black", background = "yellow") %>% column_spec(c(1, 2, 3, 4), background = "white", 
    color = "black")
Test F quadrati Breush Godfrey AR(8) 2 Lag
res.df rss df sumsq statistic p.value
13288 646971.8 NA NA NA NA
13286 607223.9 2 39747.88 434.8399 0
car::linearHypothesis(mod2_u2_hat_ar8, c("Lag.1=0", "Lag.2=0", "Lag.3=0", "Lag.4=0", 
    "Lag.5=0")) %>% knitr::kable(caption = "Test F quadrati Breush Godfrey AR(8) 5 Lag") %>% 
    kableExtra::kable_classic() %>% kable_styling() %>% row_spec(c(1, 2), font_size = 14) %>% 
    row_spec(c(2), bold = T, color = "black", background = "yellow") %>% column_spec(c(1, 
    2, 3, 4), background = "white", color = "black")
Test F quadrati Breush Godfrey AR(8) 5 Lag
Res.Df RSS Df Sum of Sq F Pr(>F)
13288 646971.8 NA NA NA NA
13283 596242.4 5 50729.39 226.0284 0
car::linearHypothesis(mod3_u2_hat_ar8, c("Lag.1=0", "Lag.2=0", "Lag.3=0", "Lag.4=0", 
    "Lag.5=0", "Lag.6=0", "Lag.7=0", "Lag.8=0")) %>% knitr::kable(caption = "Test F quadrati Breush Godfrey AR(8) 8 Lag") %>% 
    kableExtra::kable_classic() %>% kable_styling() %>% row_spec(c(1, 2), font_size = 14) %>% 
    row_spec(c(2), bold = T, color = "black", background = "yellow") %>% column_spec(c(1, 
    2, 3, 4), background = "white", color = "black")
Test F quadrati Breush Godfrey AR(8) 8 Lag
Res.Df RSS Df Sum of Sq F Pr(>F)
13288 646971.8 NA NA NA NA
13280 593759.5 8 53212.24 148.7678 0

Come possiamo vedere dai test i quadrati dei residui risultano correlati, il che rappresenta un ulteriore problema di mispecificazione del modello.

Modelli per la varianza Condizionata: Arch, Garch

Modello AR(1)-GARCH(1,1)

garchSpec1 <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 
    1)), mean.model = list(armaOrder = c(1, 0)), distribution.model = "norm")


garch11 <- ugarchfit(spec = garchSpec1, data = na.omit(r_DJ))
garch11

*---------------------------------*
*          GARCH Model Fit        *
*---------------------------------*

Conditional Variance Dynamics   
-----------------------------------
GARCH Model : sGARCH(1,1)
Mean Model  : ARFIMA(1,0,0)
Distribution    : norm 

Optimal Parameters
------------------------------------
        Estimate  Std. Error  t value Pr(>|t|)
mu      0.051834    0.007094   7.3072 0.000000
ar1     0.036227    0.009405   3.8520 0.000117
omega   0.016037    0.001730   9.2677 0.000000
alpha1  0.086025    0.004654  18.4827 0.000000
beta1   0.899858    0.005326 168.9472 0.000000

Robust Standard Errors:
        Estimate  Std. Error  t value Pr(>|t|)
mu      0.051834    0.007351   7.0509 0.000000
ar1     0.036227    0.009880   3.6666 0.000246
omega   0.016037    0.003393   4.7264 0.000002
alpha1  0.086025    0.014422   5.9647 0.000000
beta1   0.899858    0.014312  62.8731 0.000000

LogLikelihood : -17311.27 

Information Criteria
------------------------------------
                   
Akaike       2.6030
Bayes        2.6058
Shibata      2.6030
Hannan-Quinn 2.6039

Weighted Ljung-Box Test on Standardized Residuals
------------------------------------
                        statistic p-value
Lag[1]                      2.419 0.11985
Lag[2*(p+q)+(p+q)-1][2]     2.514 0.08863
Lag[4*(p+q)+(p+q)-1][5]     3.608 0.29490
d.o.f=1
H0 : No serial correlation

Weighted Ljung-Box Test on Standardized Squared Residuals
------------------------------------
                        statistic p-value
Lag[1]                     0.2171  0.6413
Lag[2*(p+q)+(p+q)-1][5]    1.3313  0.7813
Lag[4*(p+q)+(p+q)-1][9]    2.2795  0.8691
d.o.f=2

Weighted ARCH LM Tests
------------------------------------
            Statistic Shape Scale P-Value
ARCH Lag[3]     1.273 0.500 2.000  0.2593
ARCH Lag[5]     1.315 1.440 1.667  0.6424
ARCH Lag[7]     1.685 2.315 1.543  0.7835

Nyblom stability test
------------------------------------
Joint Statistic:  9.6128
Individual Statistics:             
mu     0.3536
ar1    8.0362
omega  0.3397
alpha1 0.1090
beta1  0.4880

Asymptotic Critical Values (10% 5% 1%)
Joint Statistic:         1.28 1.47 1.88
Individual Statistic:    0.35 0.47 0.75

Sign Bias Test
------------------------------------
                   t-value      prob sig
Sign Bias           0.9773 3.285e-01    
Negative Sign Bias  2.6815 7.339e-03 ***
Positive Sign Bias  2.4800 1.315e-02  **
Joint Effect       34.1055 1.882e-07 ***


Adjusted Pearson Goodness-of-Fit Test:
------------------------------------
  group statistic p-value(g-1)
1    20     583.1   1.825e-111
2    30     561.6   5.810e-100
3    40     650.9   5.308e-112
4    50     656.1   3.867e-107


Elapsed time : 1.49227 
# residui modello garch
u_hat_garch = residuals(garch11)

# varianza condizionata stimata
h = garch11@fit$var

# residui standardizzati
std_uhat = u_hat_garch/sqrt(h)

Test per l’autocorrelazione dei redesidui

# regressors
hh = 1/h
uu = Lag(u_hat_garch, 1)^2/h
colnames(uu) = "uu"

# epsilon^2 - 1
eps2 = (std_uhat)^2 - 1

lag1_eps2 = Lag(eps2, 1)
lag2_eps2 = Lag(eps2, 2)
lag3_eps2 = Lag(eps2, 3)
lag4_eps2 = Lag(eps2, 4)
lag5_eps2 = Lag(eps2, 5)

df_eps = cbind(eps2, hh, uu, lag1_eps2, lag2_eps2, lag3_eps2, lag4_eps2, lag5_eps2) %>% 
    na.omit() %>% as_tibble()


mod_garch_eps = lm(eps2 ~ hh + uu + Lag.1 + Lag.2 + Lag.3 + Lag.4 + Lag.5 - 1, data = df_eps)

car::linearHypothesis(mod_garch_eps, c("Lag.1=0", "Lag.2=0", "Lag.3=0", "Lag.4=0", 
    "Lag.5=0"), white.adjust = "hc0") %>% knitr::kable(caption = "Test F autocorrelazione residui garch(1,1) 5 Lag") %>% 
    kableExtra::kable_classic() %>% kable_styling() %>% row_spec(c(1, 2), font_size = 14) %>% 
    row_spec(c(2), bold = T, color = "black", background = "yellow") %>% column_spec(c(1, 
    2, 3, 4), background = "white", color = "black")
Test F autocorrelazione residui garch(1,1) 5 Lag
Res.Df Df F Pr(>F)
13298 NA NA NA
13293 5 0.8945529 0.483569