%% Simulate Responses and Innovations
% Simulate response and innovation paths from a multiplicative seasonal model.
% Specify the model
% (1 - L)(1 - L^{12}){y_{t}} = (1 - 0.5L)(1 + 0.3{L^{12}){\varepsilon _{t}},
% where \varepsilon_{t} follows a Gaussian distribution with mean 0 and variance 0.1.

Mdl = arima('MA',-0.5,'SMA',0.3,...
	'SMALags',12,'D',1,'Seasonality',12,...
	'Variance',0.1,'Constant',0);

%
% Simulate 500 paths with 100 observations each.

rng default % For reproducibility
[Y,E] = simulate(Mdl,100,'NumPaths',500);

figure
subplot(2,1,1);
plot(Y)
title('Simulated Response')

subplot(2,1,2);
plot(E)
title('Simulated Innovations')

%
% Plot the 2.5th, 50th (median), and 97.5th percentiles of the simulated response paths.

lower = prctile(Y,2.5,2);
middle = median(Y,2);
upper = prctile(Y,97.5,2);

figure
plot(1:100,lower,'r:',1:100,middle,'k',...
			1:100,upper,'r:')
legend('95% Interval','Median')

% Compute statistics across the second dimension (across paths) to summarize the sample paths.
%
% Plot a histogram of the simulated paths at time 100.

figure
histogram(Y(100,:),10)
title('Response Distribution at Time 100')

% Copyright 2019 The MathWorks, Inc.