4

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 ...

samooch
  • 81
  • 1
  • 1
  • 5

1 Answers1

5

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.

Metrics
  • 15,172
  • 7
  • 54
  • 83
  • ok, so I need to have both returns in one file then as I have them in separate files at the moment. I will read up some more on this manual to get my bearings. Thanks for your help. – samooch Jul 08 '13 at 17:21
  • It will be easy if you have everything in one file. – Metrics Jul 08 '13 at 21:50
  • 1
    So, I have been running through the manual of package urca, and it seems that package is extremely useful for VECM. However, I am unclear about how it deals with the VECM for both variables together. So, there seems to be an application for dealing with a single variable and its lags, such as deltaXt = pi1deltaXt-1 + pi2deltaXt-2 + ... pik-1deltaXt-k+1 + gammadeltaXt-k + error. I am unclear as to how it deals with the application of two variables, x and y in the same model statement, such as deltaXt = pi1(Xt-1 - Yt-1)+ pi2deltaXt-1 + pi3deltaXt-2 + pi4deltaYt-1 + pi5deltaYt-2 + error. – samooch Jul 09 '13 at 02:45
  • First you need to get the long run relationship (which occurs only when there is cointegration), let's say this is xt=alpha+betaYt+et. Now, in the vector error correction model, you include the lagged of et which is x(t-1)-alpha-betaY(t-1) to understand how it adjusts to long run equilibrium. Please have a look at this [notes](http://davegiles.blogspot.com/2012/06/integrated-cointegrated-data.html) – Metrics Jul 09 '13 at 21:53
  • First, I want to thank you for those notes - really awesome in breaking co-integration and error correction down. I don't think it has ever been explained that simply to me before. Second, I know the two series are co-integrated based on the results from ADF. I think what threw me off with cajols is definitely the symbols that are use d in lm() that aren't explained and I am left to guessing what they are. Thanks for all your help, you have been a grrrrrrrreat help! – samooch Jul 10 '13 at 18:42
  • why did you use an index on sample? isn't sample() a function in r? I was wondering why I got an error of "object of type "closure" is not subsettable". Until I realize that was the issue. Should that be subset() function instead of sample? – samooch Jul 16 '13 at 19:05
  • I see; I assume sample as dataframe which conflicted with the sample function.I will update the answer. – Metrics Jul 16 '13 at 19:56
  • you can just change the name of dataframe and it should work; yes you can use subset function, but they are doing the same thing. – Metrics Jul 16 '13 at 19:58