项目作者: lucabrugnolini

项目描述 :
Vector autoregressive model in Julia
高级语言: Julia
项目地址: git://github.com/lucabrugnolini/VectorAutoregressions.jl.git
创建时间: 2016-02-20T16:40:39Z
项目社区:https://github.com/lucabrugnolini/VectorAutoregressions.jl

开源协议:MIT License

下载


VectorAutoregressions.jl

Vector autoregressive models for Julia

Stable
Documenter
Build Status
Coverage Status
codecov

Installation

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

  1. ## Example: fit a VAR(`p`) to the data and derive structural IRFs with asymptotic and bootstrap conf. bands.
  2. using VectorAutoregressions
  3. using DelimitedFiles: readdlm
  4. using Plots
  5. plotly()
  6. # Read example data
  7. path = joinpath(dirname(pathof(VectorAutoregressions)), "..") # set base path to load data
  8. y = readdlm(joinpath(path,"test","cholvar_test_data.csv"), ',') #read example file with data
  9. # Set VAR parameters
  10. intercept = false #intercept in the estimation
  11. p = 2 #select lag-length
  12. H = 15 # IRFs horizon
  13. nrep = 500 #bootstrap sample
  14. # Fit VAR(2) to data
  15. V = VAR(y,p,intercept)
  16. # Estimate IRFs - Cholesky identification
  17. mIRFa = IRFs_a(V,H,intercept) #asymptotic conf. bandf
  18. mIRFb = IRFs_b(V,H,nrep,intercept) #bootstrap conf. bands
  19. # Plot irf + asy ci
  20. T,K = size(y)
  21. pIRF_asy = plot(layout = grid(K,K));
  22. [plot!(pIRF_asy, [mIRFa.CI.CIl[i,:] mIRFa.IRF[i,:] mIRFa.CI.CIh[i,:]], color = ["red" "red" "red"],
  23. line = [:dash :solid :dash], legend = false, subplot = i) for i in 1:K^2]
  24. gui(pIRF_asy)
  25. # Plot irf + bootstraped ci
  26. pIRF_boot = plot(layout = grid(K,K));
  27. [plot!(pIRF_boot, [mIRFb.CI.CIl[i,:] mIRFb.IRF[i,:] mIRFb.CI.CIh[i,:]], color = ["blue" "blue" "blue"],
  28. line = [:dash :solid :dash], legend = false, subplot = i) for i in 1:K^2]
  29. 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:

  1. struct VAR
  2. Y::Array # dep. variables
  3. X::Array # covariates
  4. β::Array # parameters
  5. ϵ::Array # residuals
  6. Σ::Array # VCV matrix
  7. p::Int64 # lag-length
  8. i::Bool # true or false for including an intercept (default is true)
  9. end

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