library(Quandl)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
Quandl.api_key('4-KG5x_Vo7rXzmZNAHch')
library("tseries")
library("urca")
library("vars")
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: sandwich
## Loading required package: lmtest
library("gdata")
## gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.
##
## gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED.
##
## Attaching package: 'gdata'
## The following objects are masked from 'package:xts':
##
## first, last
## The following object is masked from 'package:stats':
##
## nobs
## The following object is masked from 'package:utils':
##
## object.size
fund <- Quandl("FRED/FEDFUNDS",type="zoo")
aaa <-Quandl("FED/RIMLPAAAR_N_M", type="zoo")
str(fund)
## 'zooreg' series from Jul 1954 to Apr 2016
## Data: num [1:742] 0.8 1.22 1.06 0.85 0.83 1.28 1.39 1.29 1.35 1.43 ...
## Index: Class 'yearmon' num [1:742] 1954 1955 1955 1955 1955 ...
## Frequency: 12
str(aaa)
## 'zooreg' series from Jan 1919 to Jan 2016
## Data: num [1:1165] 5.35 5.35 5.39 5.44 5.39 5.4 5.44 5.56 5.6 5.54 ...
## Index: Class 'yearmon' num [1:1165] 1919 1919 1919 1919 1919 ...
## Frequency: 12
v <- cbind(fund,aaa)
v1 <- window(v,start="July 1954", end = "January 2016")
plot(v1,xlab="period", main="1954-2016")
dfund <- diff(fund)
daaa <- diff(aaa)
vd<-cbind(dfund,daaa)
vd1 <- cbind(vd,start="July 1954", end = "January 2016")
## Warning in merge.zoo(..., all = all, fill = fill, suffixes = suffixes,
## retclass = "zoo", : Index vectors are of different classes: yearmon integer
## integer
summary( ur.ers(fund, 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.765
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
summary( ur.ers(aaa, 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: 27.783
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
summary( ur.ers(dfund, 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: 0.4538
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
summary (ur.ers(daaa, 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: 0.1118
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
B
fundaaa <- ca.jo(v1, ecdet="const", type="trace", K=2, spec="transitory")
fundaaa <- ca.jo(v1, ecdet="const", type="eigen", K=2, spec="transitory")
summary(fundaaa)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: maximal eigenvalue statistic (lambda max) , without linear trend and constant in cointegration
##
## Eigenvalues (lambda):
## [1] 5.656992e-02 6.236329e-03 1.476527e-18
##
## 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.92 13.75 15.67 20.20
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## fund.l1 aaa.l1 constant
## fund.l1 1.000000 1.00000 1.00000
## aaa.l1 -1.156911 66.64856 -1.39404
## constant 3.118329 -471.27749 -54.94366
##
## Weights W:
## (This is the loading matrix)
##
## fund.l1 aaa.l1 constant
## fund.d -0.03650126 -1.586843e-04 7.825856e-19
## aaa.d 0.01595198 -7.063239e-05 -2.116698e-19
C
lttest(fundaaa, 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
D
rest.bettal <- matrix(c(0,-1,0,0,0,1), c(3,2))
a.rbettal <- blrtest(fundaaa, H=rest.bettal, r=1)
summary(a.rbettal)
##
## ######################
## # 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,] 0 0
## [2,] -1 0
## [3,] 0 1
##
## Eigenvalues of restricted VAR (lambda):
## [1] 0.0062 0.0001
##
## The value of the likelihood ratio test statistic:
## 38.3 distributed as chi square with 1 df.
## The p-value of the test statistic is: 0
##
## Eigenvectors, normalised to first column
## of the restricted VAR:
##
## [,1] [,2]
## [1,] NaN NaN
## [2,] -Inf Inf
## [3,] Inf Inf
##
## Weights W of the restricted VAR:
##
## [,1] [,2]
## fund.d NaN NaN
## aaa.d NaN NaN
plotres(fundaaa)