Search code examples
pythonstatsmodels

Statsmodels: vector_ar and IRAnalysis


I'm trying to estimate impulse response functions of a -1 standard-deviation shock to a 3-dimension VAR using statsmodels.tsa, however I'm currently having issues with setting the shock magnitude.

This gives me the IRFs for a 1 s.d. shock, the default:

import numpy as np
import statsmodels.tsa as sm
model = sm.vector_ar.var_model.VAR(endog = data)
fitted = model.fit()
shock= -1*fitted.sigma_u
irf = sm.vector_ar.irf.IRAnalysis(model = fitted)

The function IRAnalysis takes an argument P, an upper diagonal matrix that sets the shocks, I found this looking at the source code. However inputting P as shown below doesn't seem to be doing anything.

irf = statsmodels.tsa.vector_ar.irf.IRAnalysis(model = fitted, P = -np.linalg.cholesky(model.fitted_U))

I would really appreciate some help. Thanks in advance.


Solution

  • I have had the same question and finally found something that works on my end.

    instead of using the IRAnalysis explicitly, I found that transforming the VAR model into it's MA representation was the best way to adjust the size of the shock.

    from statsmodels.tsa.vector_ar.irf import IRAnalysis
    J = fitted.ma_rep(T)
    J = shock*np.array(J)
    

    This will give you the output of the irfs for T periods.

    I also wanted the standard error bands on my plots, so I did something similar to that particular function as well.

    G, H = fitted.irf_errband_mc(orth=False, repl=1000, steps=T, signif=0.05, seed=None, burn=100, cum=False)
    

    Hope this helps