%% Simulate Response Path
% Simulate a response path from a two-state Markov-switching dynamic regression model for a 1-D response process. This example uses arbitrary parameter values.
%
%% Create Fully Specified Model
% Create a two-state discrete-time Markov chain model that describes the regime switching mechanism. Label the regimes.

P = [0.9 0.1; 0.3 0.7];
mc = dtmc(P,'StateNames',["Expansion" "Recession"]);

% mc is a fully specified dtmc object.
% For each regime, use arima to create an AR model that describes the response process within the regime. Store the submodels in a vector.

mdl1 = arima('Constant',5,'AR',[0.3 0.2],...
    'Variance',2);
mdl2 = arima('Constant',-5,'AR',0.1,...
    'Variance',1);
mdl = [mdl1; mdl2];

% mdl1 and mdl2 are fully specified arima objects.
% Create a Markov-switching dynamic regression model from the switching mechanism mc and the vector of submodels mdl.

Mdl = msVAR(mc,mdl);

% Mdl is a fully specified msVAR object.
%
%% Simulate Response Path
% Generate one random response path of length 50 from the model.

rng(1); % For reproducibility
y = simulate(Mdl,50);

% y is a 50-by-1 vector of one response path.
% Plot the response path.

figure
plot(y)
xlabel("Time")
ylabel("Response")

% Copyright 2019 The MathWorks, Inc.
%