For this task we should obtain monthly data for federal funds rate FRED/FEDFUNDS and for Moody’s AAA rated corporate bonds FED/RIMLPAAAR_N_M. And the task is to identify whether these two series are cointegrated or not.
library(Quandl)
library(vars)
Now first let’s load the data from Quandl website:
ffr <- Quandl("FRED/FEDFUNDS", type="ts")
cb <- Quandl("FED/RIMLPAAAR_N_M", type="ts")
str(ffr)
## Time-Series [1:742] from 1954 to 2016: 0.8 1.22 1.06 0.85 0.83 1.28 1.39 1.29 1.35 1.43 ...
str(cb)
## Time-Series [1:1165] from 1919 to 2016: 5.35 5.35 5.39 5.44 5.39 5.4 5.44 5.56 5.6 5.54 ...
Since these series do not start from the same date, let’s take the period from July, 1954 till January, 2016. And plot the graphs of the series in the same diagram:
ffr <- window(ffr,start=c(1954,7), end =c(2016,1))
cb <- window(cb,start=c(1954,7), end =c(2016,1))
ts.plot(ffr, cb, gpars = list(col = c("blue", "red")))
By looking at graph we can see that both of the series move similarly and there is a presence of cointegration. Now we can test the series for the presence of the unit root:
summary( ur.ers(ffr, type="P-test", lag.max=8, model="trend") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept and trend
##
## Value of test-statistic is: 11.7476
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
summary( ur.ers(ffr, type="P-test", lag.max=8, model="constant") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept
##
## Value of test-statistic is: 4.2679
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 1.99 3.26 4.48
summary( ur.ers(cb, type="P-test", lag.max=8, model="trend") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept and trend
##
## Value of test-statistic is: 51.7097
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
summary( ur.ers(cb, type="P-test", lag.max=8, model="constant") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept
##
## Value of test-statistic is: 26.1053
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 1.99 3.26 4.48
Here we fail to rejuct the null hypothesis (non stationary). Now let’s look at first difference and conduct the same test:
dffr<-diff(ffr)
dcb<-diff(cb)
summary( ur.ers(dffr, type="P-test", lag.max=8, model="constant") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept
##
## Value of test-statistic is: 0.1795
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 1.99 3.26 4.48
summary( ur.ers(dcb, type="P-test", lag.max=8, model="constant") )
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept
##
## Value of test-statistic is: 0.0464
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 1.99 3.26 4.48
And now we can reject the null hypothesis. And that first difference of the series is in fact stationary. Therefore, both ffr and aaa are I(1).
In this task we have to perform trace and max eigenvalue tests to determine whether the two series are cointegrated.
Trace test
ffrcb <- cbind(ffr,cb)
ffr.cb<- ca.jo(ffrcb, ecdet="const", type="trace", K=2, spec="transitory", season=4)
summary(ffr.cb)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: trace statistic , without linear trend and constant in cointegration
##
## Eigenvalues (lambda):
## [1] 5.656315e-02 6.238040e-03 8.231694e-19
##
## Values of teststatistic and critical values of test:
##
## test 10pct 5pct 1pct
## r <= 1 | 4.61 7.52 9.24 12.97
## r = 0 | 47.52 17.85 19.96 24.60
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## ffr.l1 cb.l1 constant
## ffr.l1 1.000000 1.00000 1.000000
## cb.l1 -1.156515 70.76426 -1.399357
## constant 3.114892 -500.09370 -55.631528
##
## Weights W:
## (This is the loading matrix)
##
## ffr.l1 cb.l1 constant
## ffr.d -0.03644358 -0.0001496004 -5.954994e-19
## cb.d 0.01592491 -0.0000666063 1.603795e-19
Max eigenvalue test
ffr.cb <- ca.jo(ffrcb, ecdet="const", type="eigen", K=2, spec="transitory", season=4)
summary(ffr.cb)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: maximal eigenvalue statistic (lambda max) , without linear trend and constant in cointegration
##
## Eigenvalues (lambda):
## [1] 5.656315e-02 6.238040e-03 8.231694e-19
##
## Values of teststatistic and critical values of test:
##
## test 10pct 5pct 1pct
## r <= 1 | 4.61 7.52 9.24 12.97
## r = 0 | 42.91 13.75 15.67 20.20
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## ffr.l1 cb.l1 constant
## ffr.l1 1.000000 1.00000 1.000000
## cb.l1 -1.156515 70.76426 -1.399357
## constant 3.114892 -500.09370 -55.631528
##
## Weights W:
## (This is the loading matrix)
##
## ffr.l1 cb.l1 constant
## ffr.d -0.03644358 -0.0001496004 -5.954994e-19
## cb.d 0.01592491 -0.0000666063 1.603795e-19
The results of the Trace and Max eigenvalue tests indicate the presence of cointegration.
Test for the presence of a restricted constant.
lttest(ffr.cb, r=1)
## LR-test for no linear trend
##
## H0: H*2(r<=1)
## H1: H2(r<=1)
##
## Test statistic is distributed as chi-square
## with 1 degress of freedom
## test statistic p-value
## LR test 0 0.98
So tests tells that inclusion of the constant is appropriate.
Now we have to test the restriction \(\beta_2 = -1\)
restrict.beta <- matrix(c(1,-1,0,
0,0,1), c(3,2))
test.beta <- blrtest(ffr.cb, H=restrict.beta, r=1)
summary(test.beta)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Estimation and testing under linear restrictions on beta
##
## The VECM has been estimated subject to:
## beta=H*phi and/or alpha=A*psi
##
## [,1] [,2]
## [1,] 1 0
## [2,] -1 0
## [3,] 0 1
##
## Eigenvalues of restricted VAR (lambda):
## [1] 0.0541 0.0000
##
## The value of the likelihood ratio test statistic:
## 1.9 distributed as chi square with 1 df.
## The p-value of the test statistic is: 0.17
##
## Eigenvectors, normalised to first column
## of the restricted VAR:
##
## [,1] [,2]
## [1,] 1.0000 1.0000
## [2,] -1.0000 -1.0000
## [3,] 2.0263 -58.9553
##
## Weights W of the restricted VAR:
##
## [,1] [,2]
## ffr.d -0.0381 0
## cb.d 0.0137 0
From the test results we can see that restricted model is more appropriate.
Now we have to create a plot comparing the error term.
plotres(ffr.cb)