ibov=ts(read.table("../Dados/d-ibv.txt"))
plot.ts(cbind(ibov,diff(ibov)),main="Série de preços e log-retornos Ibovespa", xaxt = "n", col=c("darkblue","darkred"))
Para realizar os testes de raiz unitária, utilizaremos a função ur.df do pacote urca do R. A função print.adftest pode ser encontrada na página do curso: www.est.ufba.br/kim/matd51.
Seus parâmetros são:
# ur.df(y, type = c("none", "drift", "trend"), lags = 1,
# selectlags = c("Fixed", "AIC", "BIC"))
# "none": teste padrão de Dickey-Fuller;
# "drift": teste de Dickey-Fuller aumentado, i.e., com constante diferente de zero;
# "trend": teste de Dickey-Fuller aumentado com tendência e constante;
# lags: número de lags para a diferença $\Delta X_t$, de acordo com a equação:
# selectlags: método para seleção do número de lags no modelo. Pode ser fixado pelo usuário ("fixed"), ou pode-se se utilizar o critério do AIC ou BIC ("AIC" ou "BIC", respectivamente).
Começaremos com o teste de Dickey-Fuller aumentado com tendência para avaliar se existe tendência deterministica ou estocástica nos dados.
test_ibov_adf_trend=ur.df(ibov,type = "trend",lags=0)
print.adftest(test_ibov_adf_trend)
## *** Model: diff(X[t]) = a0 + a2.t + d.x[t-1] + e[t], e[t] ~ WN***
##
## Testing H01: d = 0, there is 1 unit root (tau3).
## Testing H02: d = a2 = 0 (phi2).
## Testing H03: d = a2 = a0 = 0 (phi3).
##
## Statistics tau_5pct Result
## tau3 -2.42551 -3.41 Ac H01
## phi2 2.39718 4.68 Ac H02
## phi3 2.94709 6.25 Ac H03
##
## Signif. codes: '*' Rej H0 (sig=10%) '**' Rej H0 (sig=5%) '***' Rej H0 (sig=1%)
##
## For more details, see ENDERS, W. (2015), Applied Econometric Time Series.
summary(test_ibov_adf_trend)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression trend
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1717.08 -116.61 3.38 120.40 1630.00
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 29.691770 16.034247 1.852 0.0643 .
## z.lag.1 -0.007744 0.003193 -2.426 0.0154 *
## tt 0.067785 0.031026 2.185 0.0291 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 246.5 on 1495 degrees of freedom
## Multiple R-squared: 0.003927, Adjusted R-squared: 0.002595
## F-statistic: 2.947 on 2 and 1495 DF, p-value: 0.0528
##
##
## Value of test-statistic is: -2.4255 2.3972 2.9471
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau3 -3.96 -3.41 -3.12
## phi2 6.09 4.68 4.03
## phi3 8.27 6.25 5.34
Como não identificamos tendência determinística, mas não rejeitamos a hipótese de raiz unitária, vamos realizar um teste de DF aumentado para avaliar se existe drift.
test_ibov_adf=ur.df(ibov,type = "drift",lags=0)
print.adftest(test_ibov_adf)
## *** Model: diff(X[t]) = a0 + d.x[t-1] + e[t], e[t] ~ WN ***
##
## Testing H01: d = 0, there is 1 unit root (tau2).
## Testing H02: d = a0 = 0 (phi1).
##
## Statistics tau_5pct Result
## tau2 -1.05731 -2.86 Ac H01
## phi1 1.206 4.59 Ac H02
##
## Signif. codes: '*' Rej H0 (sig=10%) '**' Rej H0 (sig=5%) '***' Rej H0 (sig=1%)
##
## For more details, see ENDERS, W. (2015), Applied Econometric Time Series.
summary(test_ibov_adf)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1732.91 -117.47 1.23 120.53 1674.68
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 22.429759 15.705725 1.428 0.153
## z.lag.1 -0.001604 0.001517 -1.057 0.291
##
## Residual standard error: 246.8 on 1496 degrees of freedom
## Multiple R-squared: 0.0007467, Adjusted R-squared: 7.876e-05
## F-statistic: 1.118 on 1 and 1496 DF, p-value: 0.2905
##
##
## Value of test-statistic is: -1.0573 1.206
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.43 -2.86 -2.57
## phi1 6.43 4.59 3.78
Novamente, não rejeitamos a hipótese \(H_{02}:\mu=0\), então o teste adequado para esta série é o teste DF clássico:
summary(ur.df(ibov,type = "none",lags=0))
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1733.3 -112.4 8.2 126.8 1687.1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 0.0003760 0.0006163 0.61 0.542
##
## Residual standard error: 246.9 on 1497 degrees of freedom
## Multiple R-squared: 0.0002486, Adjusted R-squared: -0.0004193
## F-statistic: 0.3722 on 1 and 1497 DF, p-value: 0.5419
##
##
## Value of test-statistic is: 0.6101
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.58 -1.95 -1.62
test_ibov_df = ur.df(ibov,type = "none",lags=0)
print.adftest(test_ibov_df)
## *** Model: diff(X[t]) = a0 + d.x[t-1] + e[t], e[t] ~ WN ***
##
## Testing H01: d = 0, there is 1 unit root (tau1).
##
## Statistics tau_5pct Result
## tau1 0.61007 -1.95 Ac H0
##
## Signif. codes: '*' Rej H0 (sig=10%) '**' Rej H0 (sig=5%) '***' Rej H0 (sig=1%)
##
## For more details, see ENDERS, W. (2015), Applied Econometric Time Series.
summary(test_ibov_df)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1733.3 -112.4 8.2 126.8 1687.1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 0.0003760 0.0006163 0.61 0.542
##
## Residual standard error: 246.9 on 1497 degrees of freedom
## Multiple R-squared: 0.0002486, Adjusted R-squared: -0.0004193
## F-statistic: 0.3722 on 1 and 1497 DF, p-value: 0.5419
##
##
## Value of test-statistic is: 0.6101
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.58 -1.95 -1.62
Vamos agora avaliar se uma diferença foi suficiente para tornar a série Ibovespa estacionária, ou se ela possui mais uma raiz unitária. Para isto, devemos analisar a série de diferenças do Ibovespa \(\Delta Ibovespa_t\).
dibov=diff(ibov)
test_dibov_df=ur.df(dibov,type = "none",lags=0)
print.adftest(test_dibov_df)
## *** Model: diff(X[t]) = a0 + d.x[t-1] + e[t], e[t] ~ WN ***
##
## Testing H01: d = 0, there is 1 unit root (tau1).
##
## Statistics tau_5pct Result
## tau1 -36.37337 -1.95 ***
##
## Signif. codes: '*' Rej H0 (sig=10%) '**' Rej H0 (sig=5%) '***' Rej H0 (sig=1%)
##
## For more details, see ENDERS, W. (2015), Applied Econometric Time Series.
Logo, como esta série não possui raiz unitária, concluímos que a série original do Ibovespa possui apenas uma raiz unitária.
Mas o que aconteceria se aplicássemos uma diferenciação em uma série \(X_t\) não estacionária, mas que possuísse tendência deterministica? Vimos em aula que se tivermos \(X_t\) um processo com uma tendência linear da forma:
\[
X_t=T(t)+a_t,
\] com \(T(t)\) uma tendência linear da forma \(T(t)=\beta_0+\beta_1 t\) e \(a_t\) processo estacionário com \(E(a_t)\)=0, então: \[\begin{eqnarray*}
\Delta X_t&=& X_t-X_{t-1}= \beta_0+\beta_1 t +a_t - \beta_0-\beta_1 (t-1)-a_{t-1}\\
&=& \beta_1 +a_t-a_{t-1},
\end{eqnarray*}\] que é estacionário.
Assim, apesar de o processo for não estacionário por conta de uma tendência linear determinística, é possível transformá-lo em um processo estacionário por meio de diferencição. No entanto, é fácil ver que este processo terá maior variância que o processo \(a_t\) resultante da filtragem de \(X_t\) por um filtro linear \(T(t)\).
Para ilustrar isto, vamos agora adicionar artificialmente uma tendência linear \(T(t)=0.5t\) no dibov e avaliar como a série resultante se comporta e qual o resultado do teste neste caso.
t=length(dibov)
# dibov serie com tendencia deterministica adicionada artificialmente:
dibov2=0.5*(1:t)+dibov
Notem pelos gráficos que a série \(dibov2 = T(t) + dibov\) é uma série não estacionária, já que sua média muda ao longo do tempo.
# Graficos das duas series
par(mfrow=c(1,2))
plot.ts(dibov, ylab="dibov", main="Série de diferenças do Ibovespa", cex.main=0.8, col="darkblue")
plot.ts(dibov2, ylab="dibov2=0.5*(1:t)+dibov", main="Série de diferenças do Ibovespa,\n com uma tendência linear T(t) adicionada", cex.main=0.8)
abline(a=0,b=0.5, col="red")
text(1250,2000, "y=0.5*t", col="red", cex=1.5)
Vamos agora realizar o teste para a série \(dibov2\) para verificar se ela possui raiz unitária.
# teste para a serie dibovt
test_dibov2_df=ur.df(dibov2,type = "trend",lags=0)
print.adftest(test_dibov2_df)
## *** Model: diff(X[t]) = a0 + a2.t + d.x[t-1] + e[t], e[t] ~ WN***
##
## Testing H01: d = 0, there is 1 unit root (tau3).
## Testing H02: d = a2 = 0 (phi2).
## Testing H03: d = a2 = a0 = 0 (phi3).
##
## Statistics tau_5pct Result
## tau3 -36.3802 -3.41 ***
## phi2 441.18 4.68 ***
## phi3 661.75982 6.25 ***
##
## Signif. codes: '*' Rej H0 (sig=10%) '**' Rej H0 (sig=5%) '***' Rej H0 (sig=1%)
##
## For more details, see ENDERS, W. (2015), Applied Econometric Time Series.
summary(test_dibov2_df)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression trend
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1714.71 -113.52 2.77 121.68 1715.37
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.80390 12.75246 0.534 0.594
## z.lag.1 -0.94002 0.02584 -36.380 <2e-16 ***
## tt 0.47092 0.01961 24.009 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 246.6 on 1494 degrees of freedom
## Multiple R-squared: 0.4697, Adjusted R-squared: 0.469
## F-statistic: 661.8 on 2 and 1494 DF, p-value: < 2.2e-16
##
##
## Value of test-statistic is: -36.3802 441.18 661.7598
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau3 -3.96 -3.41 -3.12
## phi2 6.09 4.68 4.03
## phi3 8.27 6.25 5.34
Portanto, o teste conclui pela não existência de raiz unitária para a série \(dibov2\), mesmo ela sendo não estacionária. Se, deliberadamente, tomarmos uma diferença para esta série, teríamos a série \(dif.dibov2=\Delta dibov2\)
dif.dibov2=diff(dibov2)
par(mfrow=c(1,2))
plot.ts(dibov, ylab="dibov", main="Série de diferenças do Ibovespa (dibov)", cex.main=0.8, ylim=c(-2000,2000), col="darkblue");
abline(h=c(-1500,1500), lty=2, col="darkgrey")
text(c(50,50),c(-1700,1700),c("-1500","1500"), col="darkgrey", cex=0.8)
plot.ts(dif.dibov2, ylab="dif.dibov2=diff(dibov2)", main="Série de dibov com tendência \n artificial, diferençada", cex.main=0.8, ylim=c(-2000,2000), col="darkred")
text(c(50,50),c(-1700,1700),c("-1500","1500"), col="darkgrey", cex=0.8)
abline(h=c(-1500,1500), lty=2, col="darkgrey")
Spb \(H_0:\ Existe\ uma\ RU\), os testes anteriores supoem que o processo \(\Delta X_t\) é um ruído branco. É possível também supor que o processo \(X_t\) é um \(AR(p)\), e neste caso, \(\Delta X_t\) será um \(AR(p-1)\), como visto em sala de aula:
\[\begin{eqnarray} \Delta X_t=\eta_0+\phi_1^* X_{t-1}+\sum_{i=1}^{p-1}\phi_{i+1}^*\Delta X_{t-i}+\epsilon_t. \end{eqnarray}\]
Para especificar a ordem de \(\Delta X_t\) no teste, utilize parâmetro lags da função ur.df. Assim, para a série do Ibovespa, se quisermos testar a hipótese de existência de raiz unitária na série do Iboespa, dado que ela \(AR(p)\), então a série de diferenças \(\Delta\)Ibovespa será um \(AR(4)\)
test_ibov_adf_ar5=ur.df(ibov,type = "drift",lags=4)
print.adftest(test_ibov_adf_ar5)
## *** Model: diff(X[t]) = a0 + d.x[t-1] + e[t], e[t] ~ WN ***
##
## Testing H01: d = 0, there is 1 unit root (tau2).
## Testing H02: d = a0 = 0 (phi1).
##
## Statistics tau_5pct Result
## tau2 -1.14388 -2.86 Ac H01
## phi1 1.33847 4.59 Ac H02
##
## Signif. codes: '*' Rej H0 (sig=10%) '**' Rej H0 (sig=5%) '***' Rej H0 (sig=1%)
##
## For more details, see ENDERS, W. (2015), Applied Econometric Time Series.
summary(test_ibov_adf_ar5)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1715.85 -115.55 0.33 119.73 1691.32
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 23.959915 15.762412 1.520 0.1287
## z.lag.1 -0.001742 0.001523 -1.144 0.2529
## z.diff.lag1 0.060914 0.025931 2.349 0.0189 *
## z.diff.lag2 -0.008971 0.025976 -0.345 0.7299
## z.diff.lag3 -0.014321 0.025976 -0.551 0.5815
## z.diff.lag4 -0.018464 0.025930 -0.712 0.4765
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 246.8 on 1488 degrees of freedom
## Multiple R-squared: 0.005212, Adjusted R-squared: 0.00187
## F-statistic: 1.559 on 5 and 1488 DF, p-value: 0.1686
##
##
## Value of test-statistic is: -1.1439 1.3385
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.43 -2.86 -2.57
## phi1 6.43 4.59 3.78
par(mar=c(3,2,3,2)) # c(bottom, left, top, right)
plot(test_ibov_adf_ar5)
Vemos então, de acordo com o teste, que \(\Delta X_t\) possui o primeiro lag significante, isto é, \(\Delta X_t\sim AR(1)\).