Load libraries
library(haven)
library(urca)
library(dynlm)
library(rugarch)
First-order autoregressive processes: data series and autocorrelation functions
ar1_aa = list(ar=0.5)
ar1_ab = list(ar=0.9)
mu = 1
set.seed(123)
par(mfrow=c(2,2),cex=0.7, mai=c(0.35,0.35,0.4,0.35))
sim_aa = mu + arima.sim(model=ar1_aa, n=100)
acf_aa = ARMAacf(ar=0.5, ma=0, lag.max=15)
sim_ab = mu + arima.sim(model=ar1_ab, n=100)
acf_ab = ARMAacf(ar=0.9, ma=0, lag.max=15)
ts.plot(sim_aa, main="AR(1) with Theta = 0.5",
xlab="time", ylab="y(t)", ylim=c(-4, 4), col="blue")
ts.plot(sim_ab, main="AR(1) with Theta = 0.9", xlab="time", ylab="y(t)", ylim=c(-4, 4), col="blue")
plot(0:15, acf_aa, type="h", col="blue",
main="Theoretical autocorrelation
function: AR(1), Theta = 0.5", xlab="k", ylab="rho(k)", ylim=c(0.0, 1.0))
plot(0:15, acf_ab, type="h", col="blue",
main="Theoretical autocorrelation
function: AR(1), Theta = 0.9",xlab="k",ylab="rho(k)", ylim=c(0.0, 1.0))
First-order moving average processes: data series and autocorrelation functions
ma1_ma = list(ma=0.5)
ma1_mb = list(ma=0.9)
mu = 0
set.seed(123)
sim_ma = mu + arima.sim(model=ma1_ma, n=100)
sim_mb = mu + arima.sim(model=ma1_mb, n=100)
acf_ma = ARMAacf(ar=0, ma=0.5, lag.max=15)
acf_mb = ARMAacf(ar=0, ma=0.9, lag.max=15)
par(mfrow=c(2,2),cex=0.7, mai=c(0.3,0.3,0.4,0.3))
ts.plot(sim_ma, main="MA(1) with Alpha = 0.5",
xlab="time", ylab="y(t)", ylim=c(-4, 4), col="blue")
ts.plot(sim_mb, main="MA(1) with Alpha = 0.9",
xlab="time", ylab="y(t)",ylim=c(-4, 4), col="blue")
plot(0:15, acf_ma, type="h", col="blue",xlab="k",ylab="rho(k)", main="Theoretical autocorrelation
function: AR(1), Alpha = 0.5", ylim=c(0.0, 1.0))
plot(0:15, acf_mb, type="h", col="blue", xlab="k",ylab="rho(k)", main="Theoretical autocorrelation
function: AR(1), Alpha = 0.9", ylim=c(0.0, 1.0))
df <- read_dta("Data/priceearnings.dta")
dlnp <- diff(df$lnp)
dft <- ts(df)
summary(TS1 <- dynlm(dlnp ~ L(trend(dft),-1) + L(lnp, -2), data=dft))
## Warning in merge.zoo(dlnp, L(trend(dft), -1), L(lnp, -2), retclass = "list", :
## Index vectors are of different classes: integer numeric numeric
##
## Time series regression with "ts" data:
## Start = 1, End = 137
##
## Call:
## dynlm(formula = dlnp ~ L(trend(dft), -1) + L(lnp, -2), data = dft)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.56867 -0.10460 0.01141 0.12158 0.40577
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.4342550 0.1644621 -2.640 0.00926 **
## L(trend(dft), -1) -0.0017426 0.0007426 -2.347 0.02040 *
## L(lnp, -2) 0.1038924 0.0373608 2.781 0.00620 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1757 on 134 degrees of freedom
## (0 observations deleted due to missingness)
## Multiple R-squared: 0.05461, Adjusted R-squared: 0.0405
## F-statistic: 3.87 on 2 and 134 DF, p-value: 0.02323
Figure 8.3 Log stock price and earnings, 1871–2009.
plot(df$lne, type="l", col="blue", pch=19, xaxs="i", ylim=c(1,8),
sub="Figure 8.3 Log stock price and earnings, 1871–2009", xlab="", ylab="", cex.sub=0.8)
lines(df$lnp, lty=2, col="red")
lnp <- na.omit(df$lnp)
DF=ur.df(lnp, type="trend",lag=0)@testreg$coef[2, 3]
ADF1=ur.df(lnp,type="trend",lag=1)@testreg$coef[2, 3]
ADF2=ur.df(lnp,type="trend",lag=2)@testreg$coef[2, 3]
ADF3=ur.df(lnp,type="trend",lag=3)@testreg$coef[2, 3]
ADF4=ur.df(lnp,type="trend",lag=4)@testreg$coef[2, 3]
ADF5=ur.df(lnp,type="trend",lag=5)@testreg$coef[2, 3]
ADF6=ur.df(lnp,type="trend",lag=6)@testreg$coef[2, 3]
ttest <- cbind(DF, ADF1, ADF2,ADF3,ADF4,ADF5,ADF6)
ttest
## DF ADF1 ADF2 ADF3 ADF4 ADF5 ADF6
## [1,] -2.621273 -2.743784 -2.273219 -2.617737 -2.25479 -2.15378 -2.345006
Log price/earnings ratio, 1871–2009.
dY <- na.omit(df$lnp - df$lne)
plot(dY, type="l", xaxs="i", xlab="", ylab="",
sub="Figure 8.4 Log price/earnings ratio, 1871–2009", col="red", cex.sub=0.8, ylim=c(1.5,4))
ur.df(dY, type="drift", lag=0)@testreg
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.60918 -0.16168 -0.00755 0.12571 0.91454
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.68491 0.15526 4.411 2.07e-05 ***
## z.lag.1 -0.25558 0.05777 -4.424 1.97e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2448 on 136 degrees of freedom
## Multiple R-squared: 0.1258, Adjusted R-squared: 0.1194
## F-statistic: 19.57 on 1 and 136 DF, p-value: 1.969e-05
Log consumer price index UK and euro area, Jan 1988–Dec 2010.
df <- read_dta("Data/ppp2.dta")
date <- as.Date(df$dateid01, "%y")
plot(df$logcpieuro, type="l", xlab="", ylab="", sub="Figure 8.5 Log consumer price index UK and euro area, Jan 1988–Dec 2010", cex.sub=0.8, ylim=c(4.6, 5.3), col="blue")
lines(df$logcpiuk,lty=2, col="red")
ur.df(df$logcpieuro, lag=0, type="trend")@testreg
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.0098260 -0.0013041 -0.0000486 0.0013773 0.0092253
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.010e-01 3.480e-02 2.902 0.00401 **
## z.lag.1 -2.106e-02 7.467e-03 -2.821 0.00514 **
## tt 3.306e-05 1.399e-05 2.363 0.01882 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.002523 on 272 degrees of freedom
## Multiple R-squared: 0.06164, Adjusted R-squared: 0.05474
## F-statistic: 8.934 on 2 and 272 DF, p-value: 0.0001746
Unit root tests for log price index euro area and the United Kingdom
Statistic = NULL
for (i in 1:13) {
Statistic=rbind(Statistic,c(ur.df(df$logcpieuro,lag=i-1,type="trend")@testreg$coefficients[2,3], ur.df(df$logcpiuk,lag=i-1,type="trend")@testreg$coefficients[2,3]))
}
rownames(Statistic)=paste0(c(rep("ADF(",13)),0:12,")")
colnames(Statistic)=c("Euro(p_t)","UK(p_t*)")
Statistic
## Euro(p_t) UK(p_t*)
## ADF(0) -2.821088 -3.587345
## ADF(1) -2.809960 -3.534779
## ADF(2) -2.911922 -3.696812
## ADF(3) -3.029092 -3.705573
## ADF(4) -3.241219 -3.785119
## ADF(5) -3.401774 -3.936434
## ADF(6) -3.173426 -3.315912
## ADF(7) -3.368383 -3.439326
## ADF(8) -3.517592 -3.400898
## ADF(9) -3.599796 -3.762537
## ADF(10) -3.704027 -3.816361
## ADF(11) -3.730128 -3.840270
## ADF(12) -3.505968 -3.678451
Unit root tests for log exchange rate euro/UK
Statistic2 = NULL
for (i in 1:7) {
Statistic2<-rbind(Statistic2,c(ur.df(log(df$fxep),lag=i-1,type="drift")@testreg$coefficients[2,3], ur.df(log(df$fxep),lag=i-1,type="trend")@testreg$coefficients[2,3]))
}
rownames(Statistic2)=paste0(c(rep("ADF(",6)), 0:6,")")
colnames(Statistic2)=c("Without Trend", "With Trend")
Statistic2
## Without Trend With Trend
## ADF(0) -1.264037 -1.249210
## ADF(1) -1.214676 -1.194774
## ADF(2) -1.242832 -1.221589
## ADF(3) -1.340457 -1.318916
## ADF(4) -1.524789 -1.505020
## ADF(5) -1.404028 -1.375224
## ADF(6) -1.284309 -1.247541
Log real exchange rate euro area/UK, Jan 1988–Dec 2010.
RFX <- log(df$fxep*df$cpiuk/df$cpieuro)
plot(RFX,type="l",las=1,xaxs="i",xlab="",ylab="", sub="Figure 8.6 Log real exchange rate euro area/UK, Jan 1988–Dec 2010.", col="blue")
Unit root tests for log real exchange rate euro area/UK
Statistic3 = NULL
for (i in c(1:7,13)) {
Statistic3=rbind(Statistic3,c(ur.df(RFX,lag=i-1,type="drift")@testreg$coefficients[2,3],
ur.df(RFX,lag=i-1,type="trend")@testreg$coefficients[2,3]))
}
rownames(Statistic3)=paste0(c(rep("ADF(",7)),c(0:6,12),")")
colnames(Statistic3)=c("Without Trend","With Trend")
Statistic3
## Without Trend With Trend
## ADF(0) -1.492318 -1.490480
## ADF(1) -1.473407 -1.468832
## ADF(2) -1.426805 -1.418191
## ADF(3) -1.476237 -1.466034
## ADF(4) -1.626825 -1.616054
## ADF(5) -1.519709 -1.503725
## ADF(6) -1.389101 -1.367495
## ADF(12) -1.992681 -1.966196
Quarterly inflation in the United States, 1960–2010.
df <- read_dta("Data/inflation.dta")
plot(df$infl, type="l", xlab="",ylab="", las=1, sub="Figure 8.7 Quarterly inflation in the United States, 1960–2010.", col="blue", ylim=c(-15,20))
ar3f <- arfimafit(arfimaspec(mean.model=list(armaOrder=c(3,0),include.mean = FALSE)), scale(df$infl,T,F))
ar3f
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(3,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.29095 0.068028 4.2770 0.000019
## ar2 0.22489 0.069101 3.2545 0.001136
## ar3 0.29829 0.069001 4.3231 0.000015
## sigma 2.36548 0.117098 20.2009 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.29095 0.084915 3.4264 0.000612
## ar2 0.22489 0.069439 3.2387 0.001201
## ar3 0.29829 0.065964 4.5221 0.000006
## sigma 2.36548 0.335525 7.0501 0.000000
##
## LogLikelihood : -465.1161
##
## Information Criteria
## ------------------------------------
##
## Akaike 4.5992
## Bayes 4.6642
## Shibata 4.5984
## Hannan-Quinn 4.6255
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.09817 0.75403
## Lag[2*(p+q)+(p+q)-1][8] 5.18233 0.13409
## Lag[4*(p+q)+(p+q)-1][14] 10.45036 0.08821
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.3602 0.5484
## Lag[2*(p+q)+(p+q)-1][2] 0.3982 0.7434
## Lag[4*(p+q)+(p+q)-1][5] 1.0716 0.8433
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 0.4155 2 0.8124
## ARCH Lag[5] 1.4464 5 0.9192
## ARCH Lag[10] 2.8667 10 0.9844
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.0982
## Individual Statistics:
## ar1 0.5165
## ar2 0.4001
## ar3 0.2386
## sigma 0.4139
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.07 1.24 1.6
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.07180691
Box.test(ar3f@fit$residuals, type="Ljung-Box", 6)
##
## Box-Ljung test
##
## data: ar3f@fit$residuals
## X-squared = 10.135, df = 6, p-value = 0.1191
Box.test(ar3f@fit$residuals, type="Ljung-Box", 12)
##
## Box-Ljung test
##
## data: ar3f@fit$residuals
## X-squared = 16.094, df = 12, p-value = 0.187
Sample autocorrelation function of inflation rate
acf(df$infl,lag=30,las=1, ylim=c(-.4, .6), xlab="Lag", ylab="Autocorrelations of infl", main="", sub="Figure 8.8 Sample autocorrelation function of inflation rate", cex.sub=0.8, col="gray", lwd = 5)
Sample partial autocorrelation function of inflation rate.
pacf(df$infl,lag=30, xlab="", ylab="", las=1, ylim=c(-.4, .6), main="", sub="Figure 8.9 Sample partial autocorrelation function of inflation rate.", cex.sub=0.8, col="gray", lwd = 5)
ar4 <- arfimafit(arfimaspec(mean.model=list(armaOrder=c(4,0),include.mean=F)),
scale(df$infl,T,F))
ar4
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(4,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.30702 0.071251 4.30903 0.000016
## ar2 0.23408 0.071164 3.28923 0.001005
## ar3 0.31279 0.072034 4.34223 0.000014
## ar4 -0.04457 0.072116 -0.61804 0.536551
## sigma 2.36205 0.116952 20.19675 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.30702 0.084295 3.64221 0.000270
## ar2 0.23408 0.075011 3.12054 0.001805
## ar3 0.31279 0.078075 4.00625 0.000062
## ar4 -0.04457 0.064844 -0.68735 0.491864
## sigma 2.36205 0.336372 7.02212 0.000000
##
## LogLikelihood : -464.792
##
## Information Criteria
## ------------------------------------
##
## Akaike 4.6058
## Bayes 4.6871
## Shibata 4.6046
## Hannan-Quinn 4.6387
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1192 0.7299343
## Lag[2*(p+q)+(p+q)-1][11] 8.1645 0.0005505
## Lag[4*(p+q)+(p+q)-1][19] 13.9988 0.0579871
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.5019 0.4787
## Lag[2*(p+q)+(p+q)-1][2] 0.5574 0.6673
## Lag[4*(p+q)+(p+q)-1][5] 1.4281 0.7576
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 0.5799 2 0.7483
## ARCH Lag[5] 1.8847 5 0.8649
## ARCH Lag[10] 3.2757 10 0.9742
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.7035
## Individual Statistics:
## ar1 0.5658
## ar2 0.4314
## ar3 0.2655
## ar4 0.1565
## sigma 0.4370
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.28 1.47 1.88
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.03590298
Box.test(ar4@fit$residuals,type="Ljung-Box",6)
##
## Box-Ljung test
##
## data: ar4@fit$residuals
## X-squared = 10.557, df = 6, p-value = 0.1031
Box.test(ar4@fit$residuals,type="Ljung-Box",12)
##
## Box-Ljung test
##
## data: ar4@fit$residuals
## X-squared = 16.265, df = 12, p-value = 0.1794
arma <- arfimafit(arfimaspec(mean.model=list(armaOrder=c(3,1),include.mean=F)),
scale(df$infl,T,F))
arma
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(3,0,1)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.14540 0.224285 0.64827 0.516808
## ar2 0.28173 0.109283 2.57802 0.009937
## ar3 0.34808 0.093865 3.70834 0.000209
## ma1 0.15888 0.237371 0.66934 0.503278
## sigma 2.36357 0.117014 20.19901 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.14540 0.173517 0.83795 0.402059
## ar2 0.28173 0.089448 3.14969 0.001634
## ar3 0.34808 0.098044 3.55029 0.000385
## ma1 0.15888 0.171865 0.92446 0.355247
## sigma 2.36357 0.334656 7.06269 0.000000
##
## LogLikelihood : -464.9388
##
## Information Criteria
## ------------------------------------
##
## Akaike 4.6072
## Bayes 4.6886
## Shibata 4.6061
## Hannan-Quinn 4.6401
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.02404 0.8767717
## Lag[2*(p+q)+(p+q)-1][11] 8.07646 0.0008341
## Lag[4*(p+q)+(p+q)-1][19] 14.00023 0.0579323
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.4737 0.4913
## Lag[2*(p+q)+(p+q)-1][2] 0.5283 0.6804
## Lag[4*(p+q)+(p+q)-1][5] 1.3662 0.7728
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 0.5519 2 0.7588
## ARCH Lag[5] 1.8047 5 0.8754
## ARCH Lag[10] 3.2531 10 0.9748
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.3213
## Individual Statistics:
## ar1 0.47348
## ar2 0.39870
## ar3 0.23493
## ma1 0.08489
## sigma 0.42692
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.28 1.47 1.88
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.07833385
Box.test(arma@fit$residuals,type="Ljung-Box",6)
##
## Box-Ljung test
##
## data: arma@fit$residuals
## X-squared = 10.282, df = 6, p-value = 0.1133
Box.test(arma@fit$residuals,type="Ljung-Box",12)
##
## Box-Ljung test
##
## data: arma@fit$residuals
## X-squared = 16.281, df = 12, p-value = 0.1787
ar6 <- arfimafit(arfimaspec(mean.model=list(armaOrder=c(6,0),include.mean=F)), scale(df$infl,T,F))
ar6
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(6,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.300145 0.071694 4.18648 0.000028
## ar2 0.214352 0.074862 2.86329 0.004193
## ar3 0.246554 0.077461 3.18295 0.001458
## ar4 -0.106003 0.077302 -1.37128 0.170288
## ar5 0.057321 0.075627 0.75795 0.448483
## ar6 0.130045 0.072728 1.78809 0.073761
## sigma 2.358305 0.116758 20.19828 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.300145 0.088876 3.37714 0.000732
## ar2 0.214352 0.089071 2.40654 0.016105
## ar3 0.246554 0.091795 2.68593 0.007233
## ar4 -0.106003 0.059807 -1.77242 0.076324
## ar5 0.057321 0.094617 0.60583 0.544629
## ar6 0.130045 0.075770 1.71630 0.086108
## sigma 2.358305 0.310521 7.59467 0.000000
##
## LogLikelihood : -464.4789
##
## Information Criteria
## ------------------------------------
##
## Akaike 4.6223
## Bayes 4.7362
## Shibata 4.6201
## Hannan-Quinn 4.6684
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.3983 0.527983
## Lag[2*(p+q)+(p+q)-1][17] 10.5324 0.006797
## Lag[4*(p+q)+(p+q)-1][29] 18.4812 0.117844
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.5134 0.4737
## Lag[2*(p+q)+(p+q)-1][2] 0.5527 0.6694
## Lag[4*(p+q)+(p+q)-1][5] 0.8727 0.8878
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 0.5632 2 0.7546
## ARCH Lag[5] 1.1202 5 0.9523
## ARCH Lag[10] 1.4674 10 0.9990
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 2.6171
## Individual Statistics:
## ar1 0.55138
## ar2 0.33638
## ar3 0.19506
## ar4 0.06198
## ar5 0.17899
## ar6 0.19342
## sigma 0.30036
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.69 1.9 2.35
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.08294606
Box.test(ar6@fit$residuals,type="Ljung-Box",6)
##
## Box-Ljung test
##
## data: ar6@fit$residuals
## X-squared = 4.6414, df = 6, p-value = 0.5906
Box.test(ar6@fit$residuals,type="Ljung-Box",12)
##
## Box-Ljung test
##
## data: ar6@fit$residuals
## X-squared = 13.306, df = 12, p-value = 0.3472
ar6b <- arfimafit(arfimaspec(mean.model=list(armaOrder=c(6,0),include.mean=F),
fixed.pars=list(ar4=0,ar5=0)),scale(df$infl,T,F))
ar6b
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(6,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.27289 0.069360 3.9344 0.000083
## ar2 0.21179 0.069910 3.0295 0.002449
## ar3 0.24007 0.075991 3.1592 0.001582
## ar4 0.00000 NA NA NA
## ar5 0.00000 NA NA NA
## ar6 0.12022 0.066646 1.8039 0.071249
## sigma 2.37043 0.117354 20.1990 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## ar1 0.27289 0.082810 3.2954 0.000983
## ar2 0.21179 0.084472 2.5073 0.012167
## ar3 0.24007 0.090836 2.6429 0.008219
## ar4 0.00000 NA NA NA
## ar5 0.00000 NA NA NA
## ar6 0.12022 0.077343 1.5544 0.120090
## sigma 2.37043 0.296150 8.0041 0.000000
##
## LogLikelihood : -465.53
##
## Information Criteria
## ------------------------------------
##
## Akaike 4.6130
## Bayes 4.6944
## Shibata 4.6119
## Hannan-Quinn 4.6459
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.8124 3.674e-01
## Lag[2*(p+q)+(p+q)-1][17] 12.0127 1.950e-06
## Lag[4*(p+q)+(p+q)-1][29] 20.2963 4.308e-02
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.3317 0.5647
## Lag[2*(p+q)+(p+q)-1][2] 0.3623 0.7620
## Lag[4*(p+q)+(p+q)-1][5] 0.6170 0.9382
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 0.3755 2 0.8288
## ARCH Lag[5] 0.7840 5 0.9780
## ARCH Lag[10] 1.0848 10 0.9998
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.9323
## Individual Statistics:
## ar1 0.5177
## ar2 0.3185
## ar3 0.1797
## ar6 0.2263
## sigma 0.3014
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.28 1.47 1.88
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.08099508
Box.test(ar6b@fit$residuals,type="Ljung-Box",6)
##
## Box-Ljung test
##
## data: ar6b@fit$residuals
## X-squared = 6.7165, df = 6, p-value = 0.3479
Box.test(ar6b@fit$residuals,type="Ljung-Box",12)
##
## Box-Ljung test
##
## data: ar6b@fit$residuals
## X-squared = 14.723, df = 12, p-value = 0.2569
1-month and 5-year interest rates (in %), 1970:1–1991:2.
df <- read_dta("Data/irates5.dta")
df <- subset(df, df$dateid01>"1970-01-01")
plot(df$dateid01,df$r1,type="l",las=1,xlab="",ylab="",sub="Figure 8.10 1-month and 5-year interest rates (in %), 1970:1–1991:2.", cex.sub=0.8,tck=0.02)
lines(df$dateid01,df$r60, lty=2, col="blue")
ar1 = arfimafit(arfimaspec(mean.model=list(armaOrder=c(1,0))),df$r1)
ar1
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(1,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 6.87975 0.661386 10.402 0
## ar1 0.95237 0.019554 48.704 0
## sigma 0.81647 0.036297 22.494 0
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 6.87975 0.343848 20.0081 0
## ar1 0.95237 0.024281 39.2226 0
## sigma 0.81647 0.112651 7.2478 0
##
## LogLikelihood : -307.6925
##
## Information Criteria
## ------------------------------------
##
## Akaike 2.4561
## Bayes 2.4980
## Shibata 2.4558
## Hannan-Quinn 2.4729
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.007 0.3157
## Lag[2*(p+q)+(p+q)-1][2] 1.010 0.7338
## Lag[4*(p+q)+(p+q)-1][5] 3.754 0.2674
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 18.17 2.025e-05
## Lag[2*(p+q)+(p+q)-1][2] 32.27 2.707e-09
## Lag[4*(p+q)+(p+q)-1][5] 53.75 5.329e-15
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 36.14 2 1.419e-08
## ARCH Lag[5] 41.22 5 8.469e-08
## ARCH Lag[10] 50.25 10 2.397e-07
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.1777
## Individual Statistics:
## mu 0.21318
## ar1 0.01804
## sigma 0.68208
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 0.846 1.01 1.35
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.07901692
Residual autocorrelation function, AR(1) model, 1970:1–1991:2.
acf(ar1@fit$residuals,ylim=c(-.2, .2), cex.sub=0.8, sub="Figure 8.11 Residual autocorrelation function, AR(1) model, 1970:1–1991:2.", main="", col="gray", lwd = 5, ylab="Residual autocorrelations")
The term structure of interest rates
theta = 0.95
n = 3
sum(theta^c(0:(n-1)))/n
## [1] 0.9508333
n = 12
sum(theta^c(0:(n-1)))/n
## [1] 0.7660665
n = 60
sum(theta^c(0:(n-1)))/n
## [1] 0.3179767
theta = 1
n = 3
sum(theta^c(0:(n-1)))/n
## [1] 1
n = 12
sum(theta^c(0:(n-1)))/n
## [1] 1
n = 60
sum(theta^c(0:(n-1)))/n
## [1] 1
summary(lm(df$r3~I(df$r1-mean(df$r3))))
##
## Call:
## lm(formula = df$r3 ~ I(df$r1 - mean(df$r3)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.00459 -0.19912 -0.06481 0.10372 1.59722
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.07843 0.02273 355.4 <2e-16 ***
## I(df$r1 - mean(df$r3)) 1.00906 0.00854 118.2 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3577 on 251 degrees of freedom
## Multiple R-squared: 0.9823, Adjusted R-squared: 0.9823
## F-statistic: 1.396e+04 on 1 and 251 DF, p-value: < 2.2e-16
summary(lm(df$r12~I(df$r1-mean(df$r12))))
##
## Call:
## lm(formula = df$r12 ~ I(df$r1 - mean(df$r12)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.95791 -0.42798 -0.07559 0.31714 2.83831
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.06608 0.04600 197.10 <2e-16 ***
## I(df$r1 - mean(df$r12)) 0.94696 0.01652 57.34 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6918 on 251 degrees of freedom
## Multiple R-squared: 0.9291, Adjusted R-squared: 0.9288
## F-statistic: 3288 on 1 and 251 DF, p-value: < 2.2e-16
summary(lm(df$r60~I(df$r1-mean(df$r60))))
##
## Call:
## lm(formula = df$r60 ~ I(df$r1 - mean(df$r60)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.6820 -0.7311 -0.1300 0.6537 3.5606
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.83162 0.08408 116.93 <2e-16 ***
## I(df$r1 - mean(df$r60)) 0.73968 0.02795 26.47 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.171 on 251 degrees of freedom
## Multiple R-squared: 0.7362, Adjusted R-squared: 0.7351
## F-statistic: 700.4 on 1 and 251 DF, p-value: < 2.2e-16
Daily change in log exchange rate $/€, 4 January 1999–18 February 2011
df <- read_dta("Data/usd.dta")
plot(df$dlogusd100,type="l",las=1,xaxs="i",yaxs="i",xlab="",ylab="",sub="Figure 8.12 Daily change in log exchange rate $/€, 4 January 1999–18 February 2011", cex.sub=0.8, ylim=c(-6,6),tck=0.02)
GARCH estimates for change in log exchange rate
df <- na.omit(df$dlogusd100)
arch6 <- ugarchfit(spec=ugarchspec(mean.model=list(armaOrder=c(0,0),include.mean=T), variance.model=list(garchOrder=c(6,0),model="sGARCH")), data=df)
arch6
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(6,0)
## Mean Model : ARFIMA(0,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.017312 0.011091 1.5609 0.118556
## omega 0.235844 0.015311 15.4040 0.000000
## alpha1 0.074596 0.022171 3.3646 0.000767
## alpha2 0.025467 0.020649 1.2333 0.217448
## alpha3 0.085723 0.022767 3.7652 0.000166
## alpha4 0.114542 0.024724 4.6329 0.000004
## alpha5 0.096347 0.022926 4.2025 0.000026
## alpha6 0.078602 0.019404 4.0509 0.000051
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.017312 0.012052 1.4364 0.150888
## omega 0.235844 0.023010 10.2494 0.000000
## alpha1 0.074596 0.033479 2.2282 0.025870
## alpha2 0.025467 0.024919 1.0220 0.306779
## alpha3 0.085723 0.028688 2.9881 0.002807
## alpha4 0.114542 0.030957 3.7001 0.000216
## alpha5 0.096347 0.025440 3.7872 0.000152
## alpha6 0.078602 0.020547 3.8254 0.000131
##
## LogLikelihood : -3044.823
##
## Information Criteria
## ------------------------------------
##
## Akaike 1.9645
## Bayes 1.9800
## Shibata 1.9645
## Hannan-Quinn 1.9701
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.5633 0.4529
## Lag[2*(p+q)+(p+q)-1][2] 0.7713 0.5787
## Lag[4*(p+q)+(p+q)-1][5] 1.2262 0.8067
## d.o.f=0
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.2339 0.62867
## Lag[2*(p+q)+(p+q)-1][17] 11.0945 0.24717
## Lag[4*(p+q)+(p+q)-1][29] 28.6492 0.00611
## d.o.f=6
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[7] 1.304 0.500 2.000 0.2535
## ARCH Lag[9] 3.608 1.485 1.796 0.2554
## ARCH Lag[11] 5.534 2.440 1.677 0.2399
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 2.9074
## Individual Statistics:
## mu 0.1513
## omega 1.0173
## alpha1 0.6155
## alpha2 0.2538
## alpha3 0.2781
## alpha4 0.3701
## alpha5 0.2490
## alpha6 0.2961
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.89 2.11 2.59
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 2.956 0.003142 ***
## Negative Sign Bias 1.427 0.153656
## Positive Sign Bias 2.470 0.013573 **
## Joint Effect 9.983 0.018715 **
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 49.59 0.0001504
## 2 30 62.35 0.0003125
## 3 40 69.25 0.0020238
## 4 50 80.93 0.0027654
##
##
## Elapsed time : 0.922117
garch <- ugarchfit(spec=ugarchspec(mean.model=list(armaOrder=c(0,0),include.mean=T), variance.model=list(garchOrder=c(1,1),model="sGARCH")), data=df)
garch
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : sGARCH(1,1)
## Mean Model : ARFIMA(0,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.016631 0.010583 1.5714 0.116093
## omega 0.001615 0.000626 2.5795 0.009895
## alpha1 0.031114 0.002358 13.1951 0.000000
## beta1 0.965574 0.001703 566.9786 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.016631 0.011212 1.4833 0.137986
## omega 0.001615 0.000765 2.1112 0.034758
## alpha1 0.031114 0.002701 11.5205 0.000000
## beta1 0.965574 0.000724 1334.0948 0.000000
##
## LogLikelihood : -2977.946
##
## Information Criteria
## ------------------------------------
##
## Akaike 1.9189
## Bayes 1.9267
## Shibata 1.9189
## Hannan-Quinn 1.9217
##
## Weighted Ljung-Box Test on Standardized Residuals
## ---------------------