%% IRF of ARMA Model
% This example shows how to plot the IRF of an ARMA model by using impulse and armairf.
% The equation of an ARMA(p,q) model is
% {y_t} = c  + \phi(L)^{-1}\theta (L){\varepsilon _t},
% where:
% \phi(L) is the p-degree AR lag operator polynomial (1 - {\phi _1}L -  \ldots  - {\phi _p}{L^p}).
% \theta(L) is the q-degree MA lag operator polynomial (1 + {\theta _1}L +  \ldots  + {\theta _q}{L^q}).
% An ARMA process is stationary when the AR lag operator polynomial is stable, which means all its roots lie outside the unit circle. In this case, the infinite-degree inverse polynomial \psi (L) = \phi(L)^{-1}\theta (L) has absolutely summable coefficients, and the IRF decays to zero.
%
%% Plot IRF Using impluse
% Create an ARMA(2,1) model with coefficients \phi_1 = 0.6, \phi_2 = -0.3, and \theta_1 = 0.4, a model constant of 0, and an innovation variance of 1.

ar = [0.6 -0.3];
ma = 0.4;
Mdl = arima('AR',ar,'MA',ma,'Constant',0,'Variance',1);

% Plot the IRF of the ARMA(2,1) model for 11 periods, from periods 0 through 10.

numObs = 11;
impulse(Mdl,numObs)

% The IRF decays in a sinusoidal pattern.
%
%% Plot IRF Using armairf
% Plot the IRF of the ARMA(2,1) model by passing ar as the AR coefficients (first input) and ma as the MA coefficients (second input).   Specify 11 periods.

armairf(ar,ma,'NumObs',numObs)

% Copyright 2021 The MathWorks, Inc.