#R : R 3.4.1 # Ex1_interest_rates_R.txt # source("Z:/LV/QF_FinancialEconometrics/CHP1_GARCH_DF_Endo_Caus_IV/EXERCISES/Ex1_interest_rates_R.txt") # setwd("C:/LVs/QF_FinancialEconometrics/R_Test") # setwd("C:/MH/LV/Daten/") library("tseries") library("urca") # lending rate. Switzerland. 1981-2015, World Bank li <- c(5.56, 6.22, 5.52, 5.49, 5.49, 5.46, 5.24, 5.07, 5.85, 7.42, 7.83, 7.80, 6.40, 5.51, 5.48, 4.97, 4.47, 4.07, 3.90, 4.29, 4.30, 3.93, 3.27, 3.20, 3.12, 3.03, 3.15, 3.34, 2.75, 2.73, 2.72, 2.69, 2.69, 2.69, 2.68) li <- ts(li, frequency=1, start=1981); nli <- length(li) d_li <- ts(diff(li), start=1982); nd_li <- length(d_li) ### Plotting univariate data plot( li , main = "lending rate, CH") # plot interest rate plot(d_li , main = "change of lending rate, CH") # plot diff(li) ### Testing for white noise acf(li); # acf: very slow decay nonstat? acf(d_li); # acf: white noise ? Box.test(li, lag = 1, type = "Ljung-Box", fitdf = 0) # Ljung-Box tests Box.test(li, lag = 5, type = "Ljung-Box", fitdf = 0) Box.test(li, lag = 10, type = "Ljung-Box", fitdf = 0) Box.test(d_li, lag = 1, type = "Ljung-Box", fitdf = 0) Box.test(d_li, lag = 5, type = "Ljung-Box", fitdf = 0) Box.test(d_li, lag = 10, type = "Ljung-Box", fitdf = 0) ##Dickey-Fuller Unit root test: level and 1st difference # tau* test for H0: (1-rho) = 0 in various models # phi1 test for H0: const=0 and (1-rho) = 0 in model w const/drift # phi3 test for H0: no trend and (1-rho) = 0 in trend model ## type = "none" or "drift" or "trend" ## selectlags= "Fixed" or "AIC", ... ## relevant statistic: tau # li summary( ur.df(li, type="none", lags=5, selectlags="AIC") ) summary( ur.df(li, type="drift", lags=5, selectlags="AIC") ) summary( ur.df(li, type="trend", lags=5, selectlags="AIC") ) # diff(li) summary( ur.df(d_li, type="none", lags=5, selectlags="AIC") ) summary( ur.df(d_li, type="drift", lags=5, selectlags="AIC") ) summary( ur.df(d_li, type="trend", lags=5, selectlags="AIC") ) ## Testing for GARCH for diff(interest rate) d_li2 <- ( d_li-mean(d_li) )^2 d_li2_v <- as.vector(d_li2) plot(d_li2) acf(d_li2); # (d_li)^2 autocorrelated ? Box.test(d_li2, lag = 1, type = "Ljung-Box", fitdf = 0) # Ljung-Box tests Box.test(d_li2, lag = 5, type = "Ljung-Box", fitdf = 0) Box.test(d_li2, lag = 10, type = "Ljung-Box", fitdf = 0) # GARCH summary( garch(d_li, order=c(0,1) ) ) # ARCH(1) summary( garch(d_li, order=c(1,1) ) ) # GARCH(1,1) ## more elaborate and comprehensive GARCH estimation in pakage rugarch