Skip to content

lucabrugnolini/VectorAutoregressions.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VectorAutoregressions.jl

Vector autoregressive models for Julia

Stable Documenter Build Status Coverage Status codecov

Installation

Pkg.add("https://github.com/lucabrugnolini/VectorAutoregressions.jl")

Introduction

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

Status

  • 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

## 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
plotly()

# 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]
gui(pIRF_asy)

# 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]
gui(pIRF_boot)

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)
end

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