Cointegration

Zhentao Shi

Oct 6, 2021

Spurious regression

\[ \begin{align} y_{1,t } & = y_{1,t-1} + u_{1,t} \\ y_{2,t } & = y_{2,t-1} + u_{2,t} \\ \end{align} \]

where \((u_{1,t},u_{2,t})\) are mutually independent and independent across time

Demonstrative example

n = 200
y1 <- cumsum(rnorm(n))
y2 <- cumsum(rnorm(n))

reg <- lm(y1 ~ y2)
summary( reg )$coefficients
##              Estimate Std. Error  t value     Pr(>|t|)
## (Intercept) 3.7582818 0.34242161 10.97560 3.369574e-22
## y2          0.5893765 0.02943782 20.02107 1.798968e-49
plot( x = y2, y = y1, type = "l")

Simulation example

AR = function(b,T){
    y = rep(0,T)
    for (t in 1:T){
        if (t > 1) {
            y[t] = b * y[t - 1] + rnorm(1)
        }
    }
    return(ts(y) )
}

spurious <- function(i, a, T){
  y1 <- AR(a, T)
  y2 <- AR(a, T)
  
  reg <- lm(y1 ~ y2)
  p.val <- summary(reg)[[4]][2,4]
  # save the p-value of the estimate of y2's coefficient
  return(p.val)
}
out <- ldply(.data = 1:1000, .fun = spurious, a = 0.3 , T = 1000)
print( mean(out < 0.05) )
## [1] 0.066
out <- ldply(.data = 1:1000, .fun = spurious, a = 1.0 , T = 1000)
print( mean(out < 0.05) )
## [1] 0.937

Real data example

set.seed(2021-9-28)

BTC <- quantmod::getSymbols("BTC-USD",auto.assign = FALSE)[,4]
plot(BTC)

N <- length(BTC)
y <- cumsum(rnorm(N))
plot(y, type = "l")

lm(BTC ~ y) %>% summary %>% print( )
## 
## Call:
## lm(formula = BTC ~ y)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -15996  -8115  -5102   -975  55897 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   168.50     721.80   0.233    0.815    
## y            -270.22      16.51 -16.368   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 15150 on 2678 degrees of freedom
## Multiple R-squared:  0.09094,    Adjusted R-squared:  0.09061 
## F-statistic: 267.9 on 1 and 2678 DF,  p-value: < 2.2e-16

Consequence

Cointegration

Example

TT = 200
e1 <- rnorm(TT) 
y1 <- cumsum(e1) %>% ts()

y2 <- 0.5 * y1 + rnorm(TT)
matplot(cbind(y1, y2), type = "l")

matplot(cbind(0.5 * y1, y2), type = "l")

Equilibrium dynamics

plot( x = y1, y = y2, type = "l")
abline(a = 0, b = 0.5, col = "red")

Real example 1: exchange rates

library(quantmod)
getFX("USD/JPY")
## [1] "USD/JPY"
getFX("HKD/JPY")
## [1] "HKD/JPY"
matplot( y = cbind(USDJPY, HKDJPY*7.8), x = index(USDJPY),
         type = "l", xlab = "time"  )

plot( y = as.vector(USDJPY), x = as.vector(HKDJPY), type = "l")

Pairs trading

Real example 2: bitcoin-ethereum

BTC <- quantmod::getSymbols("BTC-USD",auto.assign = FALSE, from = "2021-01-01")[,4]
plot(BTC)

ETH <- quantmod::getSymbols("ETH-USD",auto.assign = FALSE, from = "2021-01-01")[,4]
plot(ETH)

plot( x = as.vector(ETH), y = as.vector(BTC), type = "l")

Long-run and short-run

\[ \begin{align} \Delta y_{1,t} & = \beta y_{2,t} - y_{1,t-1} + e_t \\ & = \beta \Delta y_{2,t} + \beta y_{2,t-1} - y_{1,t-1} + e_t \\ & = \beta \Delta y_{2,t} - (y_{1,t-1} - \beta y_{2,t-1}) + e_t \\ & = \beta \Delta y_{2,t} - e_{t-1} + e_t \end{align} \]

\[e_t = \theta_1 e_{t-1} + w_t\]

where \(w_t\) and \(e_{t-1}\) are uncorrelated. Moreover, decompose

\[\Delta y_{2,t} = \theta_2 + \theta_3 e_{t-1} + \eta_t\]

where \(\eta_t\) and \(e_{t-1}\) are uncorrelated.

\[ \begin{align} \Delta y_{1,t} & = \beta (\theta_2 + \theta_3 e_{t-1} + \eta_t) - e_{t-1} + (\theta_1 e_{t-1} + w_t) \\ & = \beta \theta_2 + (\beta \theta_3 + \theta_1 - 1) e_{t-1} + (\beta \eta_t + w_t) \\ & = \mu + \alpha (y_{1,t-1} - \beta y_{2,t-1}) + v_t \end{align} \] where \(v_t = \beta \eta_t + w_t\) is orthogonal to \(e_{t-1}\) by construction

Endogeneity

\[ y_{1,t} = \beta y_{2,t} + e_t, \]

the reverse regression of \(y_{2,t}\) on \(y_{1,t}\) is inconsistent for the coefficient \(1/\beta\).

VECM

\[ \begin{align} \Delta y_{1,t} & = \mu_1 + \alpha_1 e_{t-1} + v_{1,t} \\ \Delta y_{2,t} & = \mu_2 + \alpha_2 e_{t-1} + v_{2,t} \end{align} \] where \(e_{t-1} = y_{1,t-1} - \beta y_{2,t-1}\).

\[ \begin{align} \Delta \mathbf{y}_t & = \boldsymbol{\mu} + \boldsymbol{\alpha} \cdot e_{t-1} + \mathbf{v}_{t} \\ & = \boldsymbol{\mu} + \boldsymbol{\alpha} \cdot \boldsymbol{\beta}' \mathbf{y}_{t-1} + \mathbf{v}_{t} \end{align} \]

Additional features

\[ \begin{align} \Delta \mathbf{y}_t & = & \boldsymbol{\mu} + \boldsymbol{\alpha} ( \boldsymbol{\beta}' \mathbf{y}_{t-1} - \beta_1 - \beta_2 (t-1)) \\ & & + \sum_{j=1}^{p-1} \Gamma_j (\Delta \mathbf{y}_{t-j}) + \sum_{j=0}^q \Phi_j \mathbf{x}_{t-j} + \mathbf{v}_{t} \end{align} \]

where \(\Gamma_j\) and \(\Phi_j\) are \(K\times K\) coefficient matrices

Cointegration versus VAR

\[ \begin{align} \mathbf{y}_t & = \mathbf {D} \mathbf{y}_{t-1} + \mathbf{v}_{t} \end{align} \]

If \(\mathbf{y}_t \sim I(1)\), there are unit roots in the coefficient matrix \(\mathbf{D}\)

\[ \begin{align} \Delta \mathbf{y}_t & = \mathbf {A} \mathbf{y}_{t-1} + \mathbf{v}_{t} \end{align} \] where \(\mathbf {A} = \mathbf {D} - \mathbf {I}_K\)

Reduced rank

\[ \begin{align} \boldsymbol{\gamma}' \Delta \mathbf{y}_t & = \boldsymbol{\gamma}' \mathbf {A} \mathbf{y}_{t-1} + \boldsymbol{\gamma} '\mathbf{v}_{t} = \boldsymbol{\gamma} '\mathbf{v}_{t}. \end{align} \]

\[ \begin{pmatrix} \Delta y_{1,t} \\ \Delta y_{2,t} \end{pmatrix} = \begin{pmatrix} \alpha_1 \\ \alpha_2 \end{pmatrix} e_{1,t-1} + \begin{pmatrix} v_{1,t} \\ v_{2,t} \end{pmatrix} = \begin{pmatrix} \alpha_1 \\ \alpha_2 \end{pmatrix} \begin{pmatrix} 1, \beta \\ \end{pmatrix} \begin{pmatrix} y_{1,t-1} \\ y_{2,t-1} \end{pmatrix} + \begin{pmatrix} v_{1,t} \\ v_{2,t} \end{pmatrix} \]

In this case, the \(2 \times 2\) coefficient matrix is of rank 1

\[ \begin{pmatrix} \Delta y_{1,t} \\ \Delta y_{2,t} \end{pmatrix} = \begin{pmatrix} 0,0 \\ 0,0 \end{pmatrix} \begin{pmatrix} y_{1,t-1} \\ y_{2,t-1} \end{pmatrix} + \begin{pmatrix} v_{1,t} \\ v_{2,t} \end{pmatrix} = \begin{pmatrix} v_{1,t} \\ v_{2,t} \end{pmatrix} \]

Reduced rank for \(K\)-equation system

Estimation

\[ \begin{align} y_{1,t} & = \mu + \beta y_{2,t} + e_t \\ \Delta y_{2,t} & = u_{2,t} \end{align} \]

Fully modified OLS

\[ \hat{\beta}_{FM} = \begin{pmatrix} T & \sum y_{2,t} \\ \sum y_{2,t} & \sum y_{2,t}^2 \end{pmatrix}^{-1} \begin{pmatrix} \sum y_{1,t}^+ \\ \sum( y_{1, t}^+ y_{2,t} - \hat{c}) \end{pmatrix} \]

Reduced Rank Regression

\[ \begin{align} \begin{pmatrix} \Delta y_{1,t} \\ \Delta y_{2,t} \end{pmatrix} & = & \begin{pmatrix} \mu_1 \\ \mu_2 \end{pmatrix} + \begin{pmatrix} \alpha_1 \\ \alpha_2 \end{pmatrix} (y_{1,t-1} - \beta_1 - \beta_2 y_{2,t-1}) \\ & & + \begin{pmatrix} \gamma_{11} & \gamma_{12} \\ \gamma_{21} & \gamma_{22} \end{pmatrix} \begin{pmatrix} \Delta y_{1,t-1} \\ \Delta y_{2,t-1} \end{pmatrix} + \begin{pmatrix} v_{1,t} \\ v_{2,t} \end{pmatrix} \end{align} \]

Engle-Granger estimation

Attention!

Engle-Granger test

Reduced-rank-regression test

\[ J = -(T-p) \sum_{j= r + 1}^K \log(1-\hat{\lambda}_j) = (T-p) \sum_{j= r + 1}^K \log\left (\frac{1}{1-\hat{\lambda}_j}\right) \]

where \(r\) is the number of cointegration rank under the null, \(p\) is the order of lagged diff terms, \((\hat{\lambda}_j)_{j=1}^K\) is the generalized eigenvalues (from highest to lowest).

Parameter testing

Example

library(urca)
data(finland)
fl <- finland
fl.vecm <- ca.jo(fl, ecdet = "none", spec = "transitory", K = 2)
summary(fl.vecm)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: maximal eigenvalue statistic (lambda max) , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.31890665 0.24501279 0.07213939 0.02140750
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 3 |  2.25  6.50  8.18 11.65
## r <= 2 |  7.79 12.91 14.90 19.19
## r <= 1 | 29.23 18.90 21.07 25.75
## r = 0  | 39.94 24.78 27.14 32.14
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##           lrm1.l1     lny.l1    lnmr.l1   difp.l1
## lrm1.l1  1.000000  1.0000000  1.0000000  1.000000
## lny.l1  -1.117163 -1.6206016 -0.9074816  1.507580
## lnmr.l1 -4.682914  0.6434857  0.3116962 -1.535948
## difp.l1  5.467442 38.3345426 -2.0157542 -8.090441
## 
## Weights W:
## (This is the loading matrix)
## 
##             lrm1.l1       lny.l1       lnmr.l1       difp.l1
## lrm1.d  0.056932283 -0.023040222 -0.1421986421 -0.0045795123
## lny.d   0.062776880  0.001260473  0.0008129485 -0.0080064088
## lnmr.d  0.106594339  0.004316392 -0.0134648230  0.0020914177
## difp.d -0.002854965 -0.013111002  0.0172870125  0.0009611353

Summary