%% Simulate Multiple Paths
% Consider the model in docid:econ_ug.mw_1aa4fc27-78a7-43f5-9bb9-cb2f8e4962bc.
% Create the Markov-switching dynamic regression model.

P = [0.9 0.1; 0.3 0.7];
mc = dtmc(P,'StateNames',["Expansion" "Recession"]);
mdl1 = arima('Constant',5,'AR',[0.3 0.2],...
    'Variance',2);
mdl2 = arima('Constant',-5,'AR',0.1,...
    'Variance',1);
mdl = [mdl1; mdl2];
Mdl = msVAR(mc,mdl);

%
% Simulate 3 response, innovations, and state-index paths of 5 observations from the model.

rng('default') % For reproducibility
[Y,E,SP] = simulate(Mdl,5,'NumPaths',3)

% Y, E, and SP are 5-by-3 matrices.  Columns represent separate,  independent paths.
% Simulate a single path of responses, innovations, and states into a  simulation horizon of length 50. Then plot each path separately.

[y,e,sp] = simulate(Mdl,50);

figure
subplot(3,1,1) 
plot(y)
ylabel('Response')
grid on
subplot(3,1,2)
plot(e)
ylabel('Innovation')
grid on
subplot(3,1,3)
plot(sp,'m')
ylabel('State')
yticks([1 2])
yticklabels(Mdl.StateNames)

% Copyright 2019 The MathWorks, Inc.