Accelerating the pace of engineering and science

# Documentation

## Forecast IGD Rate Using ARIMAX Model

This example shows how to forecast an ARIMAX model two ways.

Load the Credit Defaults data set, assign the response IGD to Y and the predictors AGE, CPF, and SPR to the matrix X, and obtain the sample size T. To avoid distraction from the purpose of this example, assume that all predictors are stationary.

```load Data_CreditDefaults
X = Data(:,[1 3:4]);
T = size(X,1);
Y = Data(:,5);
```

Step 2. Process response and predictor data.

Divide the response and predictor data into estimation and holdout series. Assume that each predictor series is AR(1), and fit each one to that model. Forecast the predictor series over a 10-year horizon.

```Yest = Y(2:(T-10)) % Response data for estimation;
Xest = X(1:(T-10),:) % Predictor data for estimation;

modelX = arima(1,0,0); % Model for the predictors
X1fit = estimate(modelX,Xest(:,1),'print',false);
X2fit = estimate(modelX,Xest(:,2),'print',false);
X3fit = estimate(modelX,Xest(:,3),'print',false);

X1fore = forecast(X1fit,10,'Y0',Xest(:,1));
X2fore = forecast(X2fit,10,'Y0',Xest(:,2));
X3fore = forecast(X3fit,10,'Y0',Xest(:,3));
XF = [X1fore X2fore X3fore];
```
```Yest =

0.1496
0
0
0.1429
0.1382
0.2005
0
0
0.0522
0.0466

Xest =

3.6184   -0.0571    1.9700
6.2827    3.4798    2.3100
8.3958    3.5782    2.9000
5.4114   -0.8488    2.4100
13.1429    3.2469    1.5000
7.8093   -4.1607    1.9200
7.5535   -6.3518    2.3200
7.7062    6.6135    2.2800
5.4306    9.7126    2.0700
5.3236    6.5485    1.9400
9.2351    2.6272    1.2700

```

XF holds the forecasts for the three predictor series.

Step 3. Estimate response model and infer residuals.

Assume that the response series is ARX(1), and fit it to that model including the predictor series. Infer the residuals Eest from the fitted response model Yfit.

```modelY = arima(1,0,0);
Yfit = estimate(modelY,Yest,'X',Xest,...
'print',false,'Y0',Y(1));
Eest = infer(Yfit,Yest,'Y0',Y(1),'X',Xest);
```

Step 5. MMSE forecast responses.

Forecast responses using the MMSE method at a 10-year horizon. Calculate prediction intervals for the forecasts assuming that they are normally distributed.

```[Yfore,YMSE] = forecast(Yfit,10,'Y0',Y(1:(T-10)),...
'X0',Xest,'XF',XF);
cil = Yfore - 1.96*sqrt(YMSE);
ciu = Yfore + 1.96*sqrt(YMSE);
```

Step 6. Plot MMSE forecasted responses.

Plot the response series using their MMSE forecasts and prediction intervals.

```figure
l1 = plot(dates,Y,'ko-','LineWidth',2);
xlabel('Year')
ylabel('IGD (%)')
hold on
l2 = plot(dates((T-9):T),cil,'r:','LineWidth',2);
plot(dates((T-9):T),ciu,'r:','LineWidth',2)
l3 = plot(dates((T-9):T),Yfore,'k:','LineWidth',2);

plot(dates([T-10 T-9]),[Y(T-10) Yfore(1)],'k:')
plot(dates([T-10 T-9]),[Y(T-10) cil(1)],'r:')
plot(dates([T-10 T-9]),[Y(T-10) ciu(1)],'r:')

legend([l1 l2 l3],'Observed Time Series','95% Interval',...
'Forecast','Location','NorthWest')
title('Default Rate of Investment Grade Corporate Bonds:,MMSE Forecasts')
axis tight
hold off
```

The forecasts seem reasonable, but there are outlying observations in 2000 and 2001.

Step 7. Monte Carlo forecast responses.

Forecast responses using the Monte Carlo method at a 10-year horizon by simulating 100 paths using the model Yfit. Set the estimation responses to Y0 and the inferred residuals to E0 as preforecast data. Set the forecasted predictors (XF) to X. Calculate simulation statistics.

```nsim = 100;
rng(1);
Ymcfore = simulate(Yfit,10,'NumPaths',nsim,'Y0',...
Y(1:(T-10)),'E0',Eest,'X',XF);
Ymcforebar = mean(Ymcfore,2);
mc_cil = quantile(Ymcfore',0.025);
mc_ciu = quantile(Ymcfore',0.975);
```

Step 8. Plot Monte Carlo forecasted responses.

Plot the response series with their MMSE forecasts and prediction intervals.

```figure
xlabel('Year')
ylabel('IGD (%)')

hold on
l4 = plot(dates((T-9):T),Ymcfore(:,1),'Color',[0.7 0.7 0.7]);
plot(dates((T-9):T),Ymcfore,'Color',[0.7 0.7 0.7]);
l2 = plot(dates((T-9):T),mc_cil,'r:','LineWidth',3);
plot(dates((T-9):T),mc_ciu,'r:','LineWidth',3)
l3 = plot(dates((T-9):T),Ymcforebar,'c:','LineWidth',3);

plot(dates([T-10 T-9]),[repmat(Y(T-10),1,nsim);...
Ymcfore(1,:)],'Color',[0.7 0.7 0.7])
plot(dates([T-10 T-9]),[Y(T-10) Ymcforebar(1)],'c:',...
'LineWidth',3)
plot(dates([T-10 T-9]),[Y(T-10) mc_cil(1)],'r:','LineWidth',3)
plot(dates([T-10 T-9]),[Y(T-10) mc_ciu(1)],'r:','LineWidth',3)
l1 = plot(dates,Y,'ko-','LineWidth',2);

legend([l1 l2 l3 l4],'Observed Series','95% MC Interval',...
'MC Mean Forecast','Simulated Forecasts','Location',...
'NorthWest')
title('Default Rate of Investment Grade Corporate Bonds: Monte Carlo Forecasts')
axis tight
hold off
```

The Monte Carlo forecasts and prediction intervals resemble those from the MMSE forecasting.

References:

Helwege, J., and P. Kleiman. "Understanding Aggregate Default Rates of High Yield Bonds." Current Issues in Economics and Finance. Vol. 2, Number. 6, 1996, pp. 1-6.

Loeffler, G., and P. N. Posch. Credit Risk Modeling Using Excel and VBA. West Sussex, England: Wiley Finance, 2007.