%% Forecast Conditional Mean Response
% Forecast the conditional mean response of simulated data over a 30-period horizon.
% Simulate 130 observations from a multiplicative seasonal MA model with known parameter values.

Mdl = arima('MA',{0.5,-0.3},'SMA',0.4,'SMALags',12,...
		'Constant',0.04,'Variance',0.2);
rng(200);
Y = simulate(Mdl,130);

%
% Fit a seasonal MA model to the first 100 observations, and reserve the remaining 30 observations to evaluate forecast performance.

MdlTemplate = arima('MALags',1:2,'SMALags',12);
EstMdl = estimate(MdlTemplate,Y(1:100));

% EstMdl is a new arima model that contains estimated parameters (that is, a fully specified model).
%
% Forecast the fitted model into a 30-period horizon. Specify the estimation period data as a presample.

[YF,YMSE] = forecast(EstMdl,30,Y(1:100));

YF(15)
YMSE(15)

% YF and YMSE are 30-by-1 vectors of forecasted responses and corresponding MSEs, respectively. The 15-period-ahead forecast is 0.2040 and its MSE is 0.2592.
% Visually compare the forecasts to the holdout data.

figure
h1 = plot(Y,'Color',[.7,.7,.7]);
hold on
h2 = plot(101:130,YF,'b','LineWidth',2);
h3 = plot(101:130,YF + 1.96*sqrt(YMSE),'r:',...
		'LineWidth',2);
plot(101:130,YF - 1.96*sqrt(YMSE),'r:','LineWidth',2);
legend([h1 h2 h3],'Observed','Forecast',...
		'95% Confidence Interval','Location','NorthWest');
title(['30-Period Forecasts and Approximate 95% '...
			'Confidence Intervals'])
hold off

% Copyright 2012 The MathWorks, Inc.