%% Specify Number of Paths
% forecast estimates forecasts and corresponding forecast error variances by performing Monte Carlo simulation.  You can adjust the number of paths to sample by specifying the 'NumPaths' name-value pair argument. Consider the model in Compute Optimal Point Forecasts.
% Create the fully specified 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 100 observations from the DGP.

rng(10); % For reproducibility
y = simulate(Mdl,100);

% Compute 1- through 20-step-ahead Monte Carlo point forecasts by returning the estimated forecast error variances. Specify 1000 sample paths for the Monte Carlo simulation. Treat the observations y as the presample for the forecast.

[yf,estVar] = forecast(Mdl,y,20,'NumPaths',1000);

% yf is a 20-by-1 vector of Monte Carlo point forecasts. estVAR is a 20-by-1 vector of corresponding estimated forecast error variances.
% Copyright 2019 The MathWorks, Inc.
%