Hi all,

I am a recent R converter so please bare with me if I ask any stupid
questions. I am open to both constructive criticism and blatant mockery. I
have been working on converting the Joel Hasbrouck Information share code
originally for SAS and Implementing it into R. I have a working code but
for some reason I am about 10% of the actual values, if there is anyone
more experienced in this area I would much appreciate any advice availlable.

I know there is a better method in a previous post by Niddhi Aggarwaul with
a very coherent code for calculating a 2 dimensional case but I really need
an n dimensional case which should be represented by my code being ideally
the same as Hasbrouk's. My code is below, x refers to a matrix of parallel
midpoint stock quotes of n markets.

#find the optimal lag length
lags <- VARselect(x, lag.max=100)$selection[1]

#Johansens Cointegration test is applied and then estimates the VECM with
the estimated Beta
cointest <- ca.jo(x, K=lags, type="eigen", ecdet="const",
spec="transitory")
#summary(cointest)
    vecm <- cajorls(cointest)

#Breaks the VECM down into VAR by levels as in Hasbrouck
    var <- vec2var(cointest)
#covariance of forecast error response
FER <- fevd(var, n.ahead=ImpulseResponse,cumulative=TRUE, boot=FALSE)


#covariance matrix of innovations
d <- dim(FER[[1]])
for (i in 1:n) {
errvar <- FER[[i]]
if (i == 1) {CovIn <- errvar[(d[1]),]}
if (i != 1) {CovIn <- rbind(CovIn, errvar[(d[1]),])}
}
#long run cumulative response functions
CRF <- irf(var, n.ahead=ImpulseResponse, ortho=TRUE, cumulative=FALSE,
boot=FALSE)
#matrix of long run cumulative response functions
d <- dim(CRF$irf[[1]])
for (i in 1:n) {
lrcrf <- CRF$irf[[i]]
if (i == 1) {LRCoeffs <- lrcrf[(d[1]),]}
if (i != 1) {LRCoeffs <- rbind(LRCoeffs, lrcrf[(d[1]),])}
}
 Cdiag  <- diag(CovIn)
sqrtd <- sqrt(Cdiag)
sd  <- diag(sqrt(sqrtd))
cor   <- sd %*% CovIn %*% sd
cd  <- t(chol(cor))
VarContrib     <- LRCoeffs %*% cd
VarTotal       <- colSums(VarContrib)
VarTotalMatrix <- VarTotal
 for (i in 1:(VectorCount-1)) {
VarTotalMatrix <- rbind(VarTotalMatrix,VarTotal)}
PC <- VarContrib / (VarTotalMatrix)
 if (j == 1) {
PropCont <- colMeans(t(PC))}
if (j != 1) {
PropCont <- rbind(PropCont, colMeans(t(PC)))}
}
rm(InformationShares)
colnames(PropCont) <- InputVectors
InformationShares  <-colMeans(PropCont)

	[[alternative HTML version deleted]]

