Skip to content

FIX: delayed ARMA impulse response and simulation when p > q - #976

Open
nicoloangileri wants to merge 1 commit into
QuantEcon:mainfrom
nicoloangileri:fix/arma-impulse-response-lag
Open

nicoloangileri wants to merge 1 commit into
QuantEcon:mainfrom
nicoloangileri:fix/arma-impulse-response-lag

Conversation

@nicoloangileri

Copy link
Copy Markdown

ARMA.impulse_response and ARMA.simulation are shifted by p - q periods when the AR polynomial is longer than the MA polynomial. This includes every pure AR(p) with p >= 2 built with the default theta=0.

>>> import quantecon as qe
>>> qe.ARMA([0.5, -0.2]).impulse_response(5)
array([ 0.  ,  1.  ,  0.5 ,  0.05, -0.075])   # main
array([ 1.   ,  0.5  ,  0.05 , -0.075, -0.0475])   # this PR

The docstring says psi[0] is unity, and statsmodels' ArmaProcess(...).arma2ma gives the second line. qe.ARMA([0.5, 0.1, 0.05]) is delayed by two periods, and simulation starts with p - q exact zeros for the same reason.

The cause is in set_params: (ma_poly, ar_poly, 1) is passed to scipy.signal.dimpulse and dlsim, which read the coefficients as a transfer function in positive powers of z. When ar_poly is longer, the numerator has a lower degree and the system gets len(ar_poly) - len(ma_poly) pure delays. set_params already padded ar_poly when ma_poly was longer; it now also pads ma_poly with zeros, so both polynomials have the same length. spectral_density and autocovariance use freqz, which is not affected by trailing zeros, and their output is unchanged.

The existing tests use theta = np.zeros(3) with three AR coefficients, so the polynomials already had the same length there. The new tests check, for AR(1), AR(2), AR(3), ARMA(2, 1), ARMA(1, 2) and the existing test model:

  • impulse_response against the MA(inf) coefficients from the recursion psi_j = theta_j + sum_i phi_i psi_{j-i};
  • seeded simulation against sum_j psi_j u_{t-j} built from the same shocks.

Both fail on main and pass here. The full test suite passes locally (745 tests).

Related to #888 (test coverage of the simulation and impulse-response paths in _arma).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant