%% Forecast ARX Model
% Forecast the following known ARX(1) model into a 10-period forecast horizon:
% y_t=1+0.3y_{t-1}+2x_t+\varepsilon_t,
% where \varepsilon_t is a standard Gaussian random variable, and x_t is an exogenous Gaussian random variable with a mean of 1 and a standard deviation of 0.5.
% Create an arima model object that represents the ARX(1) model.

Mdl = arima('Constant',1,'AR',0.3,'Beta',2,'Variance',1);

%
% To forecast responses from the ARX(1) model, forecast requires:
% One presample response y_0 to initialize the autoregressive term
% Future exogenous data to include the effects of the exogenous variable on the forecasted responses
% Set the presample response to the unconditional mean of the stationary process:
% E(y_t)=\frac{1+2(1)}{1-0.3}.
% For the future exogenous data, draw 10 values from the distribution of the exogenous variable.

rng(1);
y0 = (1 + 2)/(1 - 0.3);
xf = 1 + 0.5*randn(10,1);

%
% Forecast the ARX(1) model into a 10-period forecast horizon. Specify the presample response and future exogenous data.

fh = 10;
yf = forecast(Mdl,fh,y0,'XF',xf)

% yf(3) = 3.8232 is the 3-period-ahead forecast of the ARX(1) model.
% Copyright 2018 The MathWorks, Inc.