%% Create Fully Specified Multivariate Model
% Create a three-state Markov-switching dynamic regression model for a 2-D response process.  Specify all parameter values (this example uses arbitrary values).
%
% Create a three-state discrete-time Markov chain model that describes the regime switching mechanism.

P = [10 1 1; 1 10 1; 1 1 10];
mc = dtmc(P);
mc.P

% mc is a dtmc object.  dtmc normalizes P so that each row sums to 1.
%
% For each regime, use varm to create a VAR model that describes the response process within the regime. Specify all parameter values.

% Constants (numSeries x 1 vectors)
C1 = [1;-1];
C2 = [2;-2];
C3 = [3;-3];

% Autoregression coefficients (numSeries x numSeries matrices)
AR1 = {};                            % 0 lags
AR2 = {[0.5 0.1; 0.5 0.5]};          % 1 lag
AR3 = {[0.25 0; 0 0] [0 0; 0.25 0]}; % 2 lags

% Innovations covariances (numSeries x numSeries matrices)
Sigma1 = [1 -0.1; -0.1 1];
Sigma2 = [2 -0.2; -0.2 2];
Sigma3 = [3 -0.3; -0.3 3];

% VAR Submodels
mdl1 = varm('Constant',C1,'AR',AR1,'Covariance',Sigma1);
mdl2 = varm('Constant',C2,'AR',AR2,'Covariance',Sigma2);
mdl3 = varm('Constant',C3,'AR',AR3,'Covariance',Sigma3);

% mdl1, mdl2, and mdl3 are fully specified varm objects.
% Store the submodels in a vector with order corresponding to the regimes in mc.StateNames.

mdl = [mdl1; mdl2; mdl3];

%
% Use msVAR to create a Markov-switching dynamic regression model from the switching mechanism mc and the state-specific submodels mdl.

Mdl = msVAR(mc,mdl)
Mdl.Submodels(1)
Mdl.Submodels(2)
Mdl.Submodels(3)

% Mdl is a fully specified msVAR object representing a multivariate three-state Markov-switching dynamic regression model.
% Copyright 2019 The MathWorks, Inc.
%
%
%