Vector autoregressive model in Julia
Author lucabrugnolini
28 Stars
Updated Last
6 Months Ago
Started In
February 2016


Vector autoregressive models for Julia

Stable Documenter Build Status Coverage Status codecov




This package is a work in progress for the estimation and identification of Vector Autoregressive (VAR) models.


  • VAR
    • VAR(1) form
    • Lag-length selection
      • AIC
      • AICC
      • BIC
      • HQC
    • VAR impulse response function (IRFs)
      • Identification
        • Reduce form
        • Cholesky
        • Long-run restrictions
        • Sign restrictions
        • Heteroskedasticity
        • External instruments (ex. high-frequency,narrative)
          • Wild bootstrap
      • Confidence bands
        • Asymptotic
        • Bootstrap
        • Bootstrap-after-bootstrap
    • Forecasting
      • BVAR
      • FAVAR
  • Local projection IRFs
    • Lag-length selection
    • Confidence bands
      • Standard
      • Bootstrap
    • Bayesian Local Projection


## Example: fit a VAR(`p`) to the data and derive structural IRFs with asymptotic and bootstrap conf. bands.
using VectorAutoregressions
using DelimitedFiles: readdlm
using Plots

# Read example data
path = joinpath(dirname(pathof(VectorAutoregressions)), "..") # set base path to load data
y = readdlm(joinpath(path,"test","cholvar_test_data.csv"), ',') #read example file with data

# Set VAR parameters
intercept = false #intercept in the estimation
p = 2 #select lag-length
H = 15 # IRFs horizon
nrep = 500 #bootstrap sample

# Fit VAR(2) to data
V = VAR(y,p,intercept)

# Estimate IRFs - Cholesky identification
mIRFa = IRFs_a(V,H,intercept) #asymptotic conf. bandf
mIRFb = IRFs_b(V,H,nrep,intercept) #bootstrap conf. bands

# Plot irf + asy ci
T,K = size(y)
pIRF_asy = plot(layout = grid(K,K));
[plot!(pIRF_asy, [mIRFa.CI.CIl[i,:] mIRFa.IRF[i,:] mIRFa.CI.CIh[i,:]], color = ["red" "red" "red"],
line = [:dash :solid :dash], legend = false, subplot = i) for i in 1:K^2]

# Plot irf + bootstraped ci
pIRF_boot = plot(layout = grid(K,K));
[plot!(pIRF_boot, [mIRFb.CI.CIl[i,:] mIRFb.IRF[i,:] mIRFb.CI.CIh[i,:]], color = ["blue" "blue" "blue"],
line = [:dash :solid :dash], legend = false, subplot = i) for i in 1:K^2]

More in details, y is a matrix with data, p is the lag-length of the VAR we fit to the data and i is a Boolean for including an intercept (default is true). VAR(y,p,intercept) returns a fitted VAR(p) model in V with the following structure:

struct VAR
  Y::Array # dep. variables
  X::Array # covariates
  β::Array # parameters
  ϵ::Array # residuals
  Σ::Array # VCV matrix
  p::Int64 # lag-length
  i::Bool # true or false for including an intercept (default is true)

You can access to each element writing V. and than the element you are interested in (for example for the covariates V.X).