Vector Error Correction Model in r

samooch picture samooch · Jul 8, 2013 · Viewed 13.3k times · Source

I have to estimate the relationship between prices in New York(N) and London(L) using a vector error correction model adapted from Joel Hasbrouck. After much research online, I still have not made much headway so I thought that I would ask you experts to see if I can get some direction in getting this model done.

My dataset is a dataframe with date, time, symbol, price.

Return(r_t) is defined as the log difference between price for each fifteen minute interval (p(t) - p(t-1)) for both New York and London (equation 1 and 2).

The model uses r_t in New York to model on 2 lags of returns in new york and London (equation 3).

Then uses in r-t in London to model on 2 lags of returns in new york and london (equation 4).

N and L represent New York and London respectively anywhere seen in the model and t represents time.

r_t^N=∆ log(P_t^N )
r_t^L=∆ log(P_t^L )
r_t^N=α(log(P_(t-1)^N)-log(P_(t-1)^L))+∑_(i=1)to 2(γ_i^(N,N) r_(t-i)^N) + ∑_(i=1)to 2(γ_i^(N,L) r_(t-i)^L)+ ε_t^N
r_t^L=α(log(P_(t-1)^L)-log(P_(t-1)^N))+∑_(i=1)to 2(γ_i^(L,L) r_(t-i)^L) + ∑_(i=1)to 2(γ_i^(L,N) r_(t-i)^N)+ ε_t^L

Any help will be soooooo appreciated. Thank you in advance for your help!!

I am new to R and have a bit more experience using SAS and the time series procedures there. I have seen reference to using vars() but the examples I have looked at do not seem applicable so I am pretty much stuck. I have done the DW statistic and there is co-integration.

I just can't figure out how to write the code for this ...

Answer

Metrics picture Metrics · Jul 8, 2013

You can use urca package in R for this: (say your data is mydf with LN column as stock returns for London stock market and NY as stock returns for NY stock market). Following is the sample code(not tested):

install.packages("urca")
library(urca)
mysample <- mydf[, c("NY", "LN")]
myvecm <- ca.jo(mysample, ecdet = "const", type="eigen", K=2, spec="longrun")
myvecm.ols <- cajools(myvecm)

Note: I am assuming that you have used Johansen co-integration test and eigen statistic; k indicates the lag number which is 2 for your example, ecdet is saying that the cointegration has a constant. Please check the manual here for details.