wbnicholson / BigVAR

Dimension Reduction Methods for Multivariate Time Series
56 stars 17 forks source link

generateIRF #5

Closed joshualeond closed 6 years ago

joshualeond commented 7 years ago

Hi, first I'd like to say thanks for this package. I was reading the BigVAR paper on arXiv and noticed the mentioned generateIRF function on page 18. I don't see this function in this repo though. Are there plans to incorporate this or is it imported from a different package?

Thanks!

wbnicholson commented 7 years ago

I haven't added generateIRF to the package since it requires the package expm and I didn't want to add another dependency. It is available below for anyone to use.

suppressMessages(library(expm))
generateIRF <- function(Phi,Sigma,n,k,p,Y0)
    {

if(p>1){

    A <-VarptoVar1MC(Phi,p,k) 

    }else{

        A <- Phi

    }
J <- matrix(0,nrow=k,ncol=k*p)
diag(J) <- 1
P <- t(chol(Sigma))
IRF <- matrix(0,nrow=k,ncol=n+1)
for(i in 0:n)
{

    phi1 <- J%*%(A%^%i)%*%t(J)

    theta20 <- phi1%*%P

    IRF[,i+1] <- (theta20%*%Y0)    

    }

return(IRF)

}
joshualeond commented 7 years ago

Great! Thanks for this.

nutle commented 1 year ago

Would it be possible to extend this function such that it would take an exogenous shock (from VARX part)? How would the code look like then, or maybe there is an example already available?