VARMAX Procedure
Example 42.5 Conditional Forecasts and Scenario Analysis
(View the complete code for this example.)
Conditional forecasts incorporate future information and the uncertainty of parameters in the forecasts, and they often provide more accurate forecasts than unconditional forecasts do. Clark and McCracken (2017) evaluate conditional forecasts and focus on tests of bias, efficiency, and equal accuracy applied to conditional forecasts from VAR models. In this example, a Monte Carlo experiment is created in order to compare different types of forecasts; that is, 1,000 data sets are generated and the following forecasts are compared: equation-based unconditional forecasts, simulation-based unconditional forecasts, simulation-based conditional forecasts under hard conditions, and simulation-based conditional forecasts under soft conditions.
Consider the following trivariate VAR(2) model:
where
As indicated in Clark and McCracken (2017), the parameter values are equal to the OLS (ordinary least squares) estimates of a VAR in GDP (gross domestic product) growth, inflation less a survey-based measure of trend inflation, and the federal funds rate less a survey-based measure of trend, over a sample from 1961 to 2007. Many central banks require forecasts conditional on particular paths of policy instruments. This example analyzes different scenarios of some known future information on the third variable that is related to federal funds rate.
Conditional Forecasts and Scenario Analysis under Hard Conditions
This section considers the hard conditions, under which some future dependent variables are fixed to some single values.
The following macro generates the data for analysis:
title 'Conditional Forecasts and Scenario Analysis';
%macro cfSimulateData(dgpi,T,lead,tblDGP,tblSample);
* dgpi: index of DGP;
* T: in-sample sample size;
* lead: future horizons;
* tblDGP: output table name for full-sample data;
* tblSample: output table name for in-sample data;
proc iml;
* simulate the data;
* trivariate VAR(2) model;
seed = 12345 + &dgpi.; * random seed;
n = 3; * dim of dependent variable;
T = &T.; * in-sample sample size;
lead = &lead.; * future horizons;
p = 2; * AR order;
* parameter values;
const = {2.425, 0.054, -0.110};
phi = {0.234 -0.134 -0.057,
0.029 0.575 0.200,
0.059 0.038 1.006,
0.164 -0.150 -0.165,
-0.039 0.138 -0.184,
0.031 0.019 -0.087};
sigma = {9.265 0.296 0.553,
0.296 1.746 0.184,
0.553 0.184 0.752};
call varmasim(y,phi) sigma = sigma n = T+lead seed = seed;
mu = (inv(I(3)-phi[1:3,]-phi[4:6,])*const)`;
y = y + mu;
name={y1 y2 y3};
create &tblDGP. from y[colname=name];
append from y;
close;
quit;
data &tblSample.; set &tblDGP.(obs=&T.); run;
%mend;
The following macro constructs four scenarios that contain hard conditions. In scenario , the first i future values of
y3 are fixed (to their true values). In the real world, the true future values cannot be known. Here, the true future values are used so that you can check later whether using more information results in any advantage in conditional forecasts.
%macro hcConstructScenarios(T,tblDGP,tblScenarios);
* T: in-sample sample size;
* tblDGP: input table name for full-sample data;
* tblScenarios: output table name for scenarios;
data &tblScenarios.;
set &tblDGP.(firstobs=%eval(&T.+1) obs=%eval(&T.+1))
&tblDGP.(firstobs=%eval(&T.+1) obs=%eval(&T.+2))
&tblDGP.(firstobs=%eval(&T.+1) obs=%eval(&T.+3))
&tblDGP.(firstobs=%eval(&T.+1) obs=%eval(&T.+4))
&tblDGP.(firstobs=%eval(&T.+1) obs=%eval(&T.+1));
* scenario 1: y3(1) is known;
if(_N_=1) then do;
y1=.; y2=.; myscenario=1;
end;
* scenario 2: y3(1:2) is known;
if(_N_>1 and _N_<=3) then do;
y1=.; y2=.; myscenario=2;
end;
* scenario 3: y3(1:3) is known;
if(_N_>3 and _N_<=6) then do;
y1=.; y2=.; myscenario=3;
end;
* scenario 4: y3(1:4) is known;
if(_N_>6 and _N_<=10) then do;
y1=.; y2=.; myscenario=4;
end;
* scenario 5: nothing is known (unconditional forecast);
if(_N_>10) then do;
y1=.; y2=.; y3=.; myscenario=5;
end;
run;
%mend;
The following macro estimates and performs several types of forecasts. The equation-based forecasts are output to the OUT= data set that is specified in the OUTPUT statement. The conditional forecasts for scenarios 1 to 4 and the unconditional forecasts (for scenario 5) are output to the OUT= data set that is specified in the CONDFORE statement.
%macro hcEstimateAndForecast(tblSample,tblScenarios,alpha,lead,nmc,
tblF,tblCf,tblCfSim);
* tblSample: input table name for in-sample data;
* tblScenarios: input table name for scenarios;
* alpha: size of the confidence interval or credible interval;
* lead: future horizons;
* nmc: number of Monte Carlo iterations;
* tblF: output table name of equation-based point and interval forecasts;
* tblCf: output table name of conditionial point and interval forecasts;
* tblCfSim: output table name of simulated conditional forecasts;
proc varmax data=&tblSample.;
model y1 - y3 / p=2 prior noprint;
output alpha=&alpha. lead=&lead. out=&tblF. noprint;
condfore alpha=&alpha. lead=&lead. out=&tblCf. outsim=&tblCfSim.
sdata=&tblScenarios. sid=myscenario
parm=sampling(scenario) nbi=1000 nmc=&nmc.;
run;
%mend;
The following macro saves all types of forecasts for one simulated data set to one data set for evaluation:
%macro hcSaveForecasts(dgpi,T,lead,nScenarios,tblDGP,tblF,tblCf,tblAll);
* dgpi: index of DGP;
* T: in-sample sample size;
* lead: future horizons;
* nScenarios: number of scenarios;
* tblDGP: input table name for full-sample data;
* tblF: input table name of equation-based point and interval forecasts;
* tblCf: input table name of conditionial point and interval forecasts;
* tblAll: output table name of point and interval forecasts for all DGPs;
data forecasts;
set &tblDGP.(firstobs=%eval(&T.+1) obs=%eval(&T.+&lead.) keep=Y1 Y2);
* for notation convenience, name equation-based forecasts as S0;
set &tblF.(firstobs=%eval(&T.+1) obs=%eval(&T.+&lead.)
rename=( for1=Y1_S0 for2=Y2_S0
lci1=Y1_LB_S0 uci1=Y1_UB_S0
lci2=Y2_LB_S0 uci2=Y2_UB_S0)
keep=FOR1 LCI1 UCI1 FOR2 LCI2 UCI2);
%do i = 1 %to &nScenarios.;
set &tblCf.(where=(myscenario_S&i.=&i.)
rename=( Y1_MEDIAN=Y1_S&i. Y2_MEDIAN=Y2_S&i.
Y1_LB=Y1_LB_S&i. Y1_UB=Y1_UB_S&i.
Y2_LB=Y2_LB_S&i. Y2_UB=Y2_UB_S&i.
myscenario=myscenario_S&i.)
keep=myscenario Y1_MEDIAN Y2_MEDIAN Y1_LB Y1_UB Y2_LB Y2_UB);
%end;
dgpIndex = &dgpi.;
h = _N_;
drop myscenario_S1 - myscenario_S&nScenarios.;
run;
proc append base=&tblAll. data=forecasts; run;
%mend;
The following macro evaluates the forecasts from different methods and under different conditions. The accuracy of point forecasts is measured through the symmetric mean absolute percentage error (sMAPE), which is used in the M4 Forecasting Competition. The sMAPE is defined as
where T is the in-sample sample size, is the future value at
,
is the ith-step-ahead forecast, and h is the forecasting horizon. The smaller the sMAPE, the better the forecasting method. In order to easily compare the sMAPEs, the relative sMAPEs are calculated. The simulation-based unconditional forecasts are used as the benchmark. As for the interval forecasts (that is, the confidence interval for equation-based forecasts and the credible interval for simulation-based conditional and unconditional forecasts), first the size is checked, and then the lengths of intervals are compared: if the size is correct, the smaller the interval length, the more accurate and better the forecasting method.
%macro cfEvaluate(tblAll,lead,nSim,nScenarios,qScenario0,scenarioBM,tblEval);
* tblAll: input table name of point and interval forecasts for all DGPs;
* lead: future horizons;
* nSim: number of DGPs;
* nScenarios: number of scenarios;
* qScenario0: whether there is S0 for equation-based forecasts,
1 for yes and 0 for no;
* scenarioBM: the index of the benchmark scenario;
* tblEval: output table name for evaluation results;
proc iml;
use &tblAll.;
read all into d;
close;
lead = &lead.;
nSim = &nSim.;
nScenarios = &nScenarios. + &qScenario0.;
scenarioBM = &scenarioBM.;
nVars = 2;
sMAPE = J(lead,nScenarios*nVars,0);
rsMAPE = J(lead,nScenarios*nVars,0);
sizeCI = J(lead,nScenarios*nVars,0);
rLenCI = J(lead,nScenarios*nVars,0);
do iSim = 1 to nSim;
do h = 1 to lead;
do iScenario = 1 to nScenarios;
do iVar = 1 to nVars;
yF=d[(iSim-1)*lead+h,
nVars+((iScenario-1)*nVars+(iVar-1))*3+1];
yFlb=d[(iSim-1)*lead+h,
nVars+((iScenario-1)*nVars+(iVar-1))*3+2];
yFub=d[(iSim-1)*lead+h,
nVars+((iScenario-1)*nVars+(iVar-1))*3+3];
yFlbBM=d[(iSim-1)*lead+h,
nVars+((scenarioBM-1)*nVars+(iVar-1))*3+2];
yFubBM=d[(iSim-1)*lead+h,
nVars+((scenarioBM-1)*nVars+(iVar-1))*3+3];
y =d[(iSim-1)*lead+h,iVar];
* symmetric Mean Absolute Percentage Error (sMAPE);
if(abs(yF)+abs(y)>0) then do;
sMAPE[h,(iVar-1)*nScenarios+iScenario] =
sMAPE[h,(iVar-1)*nScenarios+iScenario]
+ 2*abs(yF-y)/(abs(yF)+abs(y))/nSim;
end;
* size;
if(y>=yFlb & y<=yFub) then do;
sizeCI[h,(iVar-1)*nScenarios+iScenario] =
sizeCI[h,(iVar-1)*nScenarios+iScenario] + 1/nSim;
end;
* relative length;
if(yFubBM-yFlbBM>0) then do;
rLenCI[h,(iVar-1)*nScenarios+iScenario] =
rLenCI[h,(iVar-1)*nScenarios+iScenario]
+ (yFub-yFlb)/(yFubBM-yFlbBM)/nSim;
end;
end;
end;
end;
end;
do h = 2 to lead;
do iScenario = 1 to nScenarios;
do iVar = 1 to nVars;
sMAPE[h,(iVar-1)*nScenarios+iScenario] =
(sMAPE[h,(iVar-1)*nScenarios+iScenario]
+ sMAPE[h-1,(iVar-1)*nScenarios+iScenario]*(h-1))/h;
end;
end;
end;
do h = 1 to lead;
do iScenario = 1 to nScenarios;
do iVar = 1 to nVars;
* relative symmetric Mean Absolute Percentage Error;
rsMAPE[h,(iVar-1)*nScenarios+iScenario] =
sMAPE[h,(iVar-1)*nScenarios+iScenario]
/ sMAPE[h,(iVar-1)*nScenarios+scenarioBM];
end;
end;
end;
* rearrange results;
n = ncol(sMAPE)/nVars;
evalResult = sMAPE[,1:n];
do iVar = 2 to nVars;
evalResult = evalResult // sMAPE[,(iVar-1)*n+1:iVar*n];
end;
do iVar = 1 to nVars;
evalResult = evalResult // rsMAPE[,(iVar-1)*n+1:iVar*n];
end;
do iVar = 1 to nVars;
evalResult = evalResult // sizeCI[,(iVar-1)*n+1:iVar*n];
end;
do iVar = 1 to nVars;
evalResult = evalResult // rLenCI[,(iVar-1)*n+1:iVar*n];
end;
evalResult = ((1:4)`@J(lead*nVars,1,1))
|| (J(4,1,1)@((1:nVars)`@J(lead,1,1)))
|| (J(4*nVars,1,1)@(1:lead)`)
|| evalResult;
create &tblEval. from evalResult;
append from evalResult;
close;
quit;
%mend;
The following macro incorporates all the previous macros to test the forecasts from different methods (equation-based versus simulation-based) for different scenarios (unconditional versus four types of hard conditions). All point and interval forecasts are saved in the data set that is specified by the tblAll argument. All evaluation results are saved in the data set that is specified by the tblEval argument.
%macro hcTest(nSim,T,lead,alpha,nmc,nScenarios,qScenario0,scenarioBM,
tblAll,tblEval);
* nSim: number of DGPs;
* T: in-sample sample size;
* lead: future horizons;
* alpha: size of the confidence interval or credible interval;
* nmc: number of Monte Carlo iterations;
* nScenarios: number of scenarios;
* qScenario0: whether there is scenario 0 for equation-based forecasts,
1 for yes and 0 for no;
* scenarioBM: the index of the benchmark scenario;
* tblAll: output table name of point and interval forecasts for all DGPs;
* tblEval: output table name for evaluation results;
%do iSim = 1 %to &nSim.;
%cfSimulateData(&iSim.,&T.,&lead.,t1,t2);
%hcConstructScenarios(&T.,t1,t3);
%hcEstimateAndForecast(t2,t3,&alpha.,&lead.,&nmc.,of,ocf,ocfsim);
%hcSaveForecasts(&iSim.,&T.,&lead.,&nScenarios.,t1,of,ocf,&tblAll.);
%end;
%cfEvaluate(&tblAll.,&lead.,&nSim.,
&nScenarios.,&qScenario0.,&scenarioBM.,
&tblEval.);
%mend;
The following macro variables and macro set up and perform the test:
%let nSim = 1000;
%let T = 200;
%let lead = 4;
%let alpha = 0.05;
%let nmc = 10000;
%let nScenarios = 5;
%let qScenario0 = 1;
%let scenarioBM = 6;
%hcTest(&nSim.,&T.,&lead.,&alpha.,&nmc.,
&nScenarios.,&qScenario0.,&scenarioBM.,
hcForecasts,hcEval);
In order to show the result in a good style, the following template is created and the macro applies the template to the data set:
proc template;
define table hcEvalTemplate;
column col3 col4 col5 col6 col7 col8 col9;
define header hc;
text "Conditional Forecasts, Hard Conditions";
start=col5; end=col8;
end;
define column col3;
header="Horizon";
end;
define column col4;
header="Equation Based"; format=7.5;
end;
define column col5;
header="Scenario 1"; format=12.5;
end;
define column col6;
header="Scenario 2"; format=12.5;
end;
define column col7;
header="Scenario 3"; format=12.5;
end;
define column col8;
header="Scenario 4"; format=12.5;
end;
define column col9;
header="Unconditional"; format=12.5;
end;
end;
run;
%macro cfPrint(template,data);
data _NULL_;
set &data.;
file print ods=(template="&template.");
put _ODS_;
run;
%mend;
The following macro calls print the sMAPEs for y1 and y2. Output 42.5.1 and Output 42.5.2 show that as more future information from scenario 1 to 4 is used in the conditional forecasts, the sMAPEs get smaller, which means that the accuracy of forecasts gets better.
%cfPrint(hcEvalTemplate, hcEval(where=(col1=1 and col2=1)));
%cfPrint(hcEvalTemplate, hcEval(where=(col1=1 and col2=2)));
Output 42.5.1: The sMAPEs for y1
| Conditional Forecasts and Scenario Analysis |
| Horizon | Equation Based | Conditional Forecasts, Hard Conditions | Unconditional | |||
|---|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | |||
| 1 | 0.90307 | 0.90101 | 0.89794 | 0.89874 | 0.89419 | 0.90146 |
| 2 | 0.88474 | 0.88055 | 0.87737 | 0.87471 | 0.87234 | 0.88451 |
| 3 | 0.87674 | 0.87243 | 0.87309 | 0.86822 | 0.86664 | 0.87632 |
| 4 | 0.86908 | 0.86553 | 0.86553 | 0.86266 | 0.86129 | 0.86954 |
Output 42.5.2: The sMAPEs for y2
| Conditional Forecasts and Scenario Analysis |
| Horizon | Equation Based | Conditional Forecasts, Hard Conditions | Unconditional | |||
|---|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | |||
| 1 | 1.07895 | 1.06867 | 1.07027 | 1.07053 | 1.06977 | 1.07941 |
| 2 | 1.16152 | 1.14704 | 1.15181 | 1.14594 | 1.14441 | 1.16143 |
| 3 | 1.22260 | 1.21487 | 1.21397 | 1.20050 | 1.19548 | 1.22251 |
| 4 | 1.27106 | 1.26842 | 1.26392 | 1.25277 | 1.24037 | 1.27112 |
The following macro calls print the relative sMAPEs for y1 and y2. Output 42.5.3 and Output 42.5.4 show that the relative sMAPE for all conditional point forecasts is less than 1, which means that all of them have better accuracy than the benchmark unconditional forecasts. The relative sMAPE for equation-based point forecasts is very close to 1, which means that the accuracy of the equation-based forecasts is similar to that of unconditional forecasts.
%cfPrint(hcEvalTemplate, hcEval(where=(col1=2 and col2=1)));
%cfPrint(hcEvalTemplate, hcEval(where=(col1=2 and col2=2)));
Output 42.5.3: The Relative sMAPEs for y1
| Conditional Forecasts and Scenario Analysis |
| Horizon | Equation Based | Conditional Forecasts, Hard Conditions | Unconditional | |||
|---|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | |||
| 1 | 1.00179 | 0.99951 | 0.99610 | 0.99698 | 0.99194 | 1.00000 |
| 2 | 1.00026 | 0.99552 | 0.99193 | 0.98892 | 0.98624 | 1.00000 |
| 3 | 1.00048 | 0.99556 | 0.99632 | 0.99076 | 0.98896 | 1.00000 |
| 4 | 0.99948 | 0.99540 | 0.99539 | 0.99209 | 0.99052 | 1.00000 |
Output 42.5.4: The Relative sMAPEs for y2
| Conditional Forecasts and Scenario Analysis |
| Horizon | Equation Based | Conditional Forecasts, Hard Conditions | Unconditional | |||
|---|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | |||
| 1 | 0.99958 | 0.99005 | 0.99153 | 0.99177 | 0.99107 | 1.00000 |
| 2 | 1.00008 | 0.98760 | 0.99172 | 0.98666 | 0.98534 | 1.00000 |
| 3 | 1.00008 | 0.99375 | 0.99302 | 0.98200 | 0.97789 | 1.00000 |
| 4 | 0.99995 | 0.99788 | 0.99434 | 0.98556 | 0.97581 | 1.00000 |
The following macro calls print the sizes for y1 and y2. Output 42.5.5 and Output 42.5.6 show that the sizes for all forecasts are very close to 0.95, which means all forecasts have the correct sizes.
%cfPrint(hcEvalTemplate, hcEval(where=(col1=3 and col2=1)));
%cfPrint(hcEvalTemplate, hcEval(where=(col1=3 and col2=2)));
Output 42.5.5: The Sizes for y1
| Conditional Forecasts and Scenario Analysis |
| Horizon | Equation Based | Conditional Forecasts, Hard Conditions | Unconditional | |||
|---|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | |||
| 1 | 0.94700 | 0.94300 | 0.93600 | 0.94500 | 0.94800 | 0.94400 |
| 2 | 0.94900 | 0.94700 | 0.94100 | 0.94600 | 0.94700 | 0.95000 |
| 3 | 0.95100 | 0.94600 | 0.94300 | 0.95000 | 0.95300 | 0.95200 |
| 4 | 0.94400 | 0.94700 | 0.94500 | 0.94800 | 0.94200 | 0.93800 |
Output 42.5.6: The Sizes for y2
| Conditional Forecasts and Scenario Analysis |
| Horizon | Equation Based | Conditional Forecasts, Hard Conditions | Unconditional | |||
|---|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | |||
| 1 | 0.95400 | 0.95100 | 0.94700 | 0.94400 | 0.94700 | 0.94600 |
| 2 | 0.95000 | 0.94300 | 0.94100 | 0.94200 | 0.93200 | 0.94900 |
| 3 | 0.94900 | 0.94900 | 0.94600 | 0.94400 | 0.94300 | 0.94200 |
| 4 | 0.94100 | 0.94100 | 0.93700 | 0.94200 | 0.94400 | 0.94500 |
The following macro calls print the relative interval lengths for y1 and y2. Output 42.5.7 and Output 42.5.8 show that almost all conditional forecasts show smaller relative interval length than the benchmark unconditional forecasts show, which means that the conditional forecasts have better interval forecasts than unconditional forecasts. The relative interval lengths for equation-based forecasts are all greater than 1, which means that equation-based forecasts have worse interval forecasting ability than unconditional forecasts have. The main reason might be that the unconditional forecasts account for the uncertainty of parameters but equation-based forecasts do not.
%cfPrint(hcEvalTemplate, hcEval(where=(col1=4 and col2=1)));
%cfPrint(hcEvalTemplate, hcEval(where=(col1=4 and col2=2)));
Output 42.5.7: The Relative Interval Lengths for y1
| Conditional Forecasts and Scenario Analysis |
| Horizon | Equation Based | Conditional Forecasts, Hard Conditions | Unconditional | |||
|---|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | |||
| 1 | 1.02290 | 0.99210 | 0.95616 | 0.95064 | 0.96477 | 1.00000 |
| 2 | 1.00814 | 1.00050 | 0.95801 | 0.94982 | 0.94094 | 1.00000 |
| 3 | 1.01348 | 0.98599 | 0.99613 | 0.97029 | 0.95520 | 1.00000 |
| 4 | 1.01754 | 1.00582 | 0.99147 | 1.00897 | 0.96589 | 1.00000 |
Output 42.5.8: The Relative Interval Lengths for y2
| Conditional Forecasts and Scenario Analysis |
| Horizon | Equation Based | Conditional Forecasts, Hard Conditions | Unconditional | |||
|---|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | |||
| 1 | 1.02990 | 1.00010 | 0.99527 | 0.97468 | 0.98016 | 1.00000 |
| 2 | 1.02772 | 0.98791 | 0.96935 | 0.97000 | 0.95431 | 1.00000 |
| 3 | 1.03613 | 1.01415 | 0.97397 | 0.97472 | 0.95715 | 1.00000 |
| 4 | 1.01918 | 0.97980 | 0.96314 | 0.96461 | 0.95298 | 1.00000 |
Conditional Forecasts and Scenario Analysis under Soft Conditions
This section considers the soft conditions, under which some future dependent variables are bounded within certain ranges instead of fixed to some single values.
The following macro estimates the model and outputs the unconditional forecasts. In the case of soft conditions, only the unconditional forecasts are needed. When the SDATA= option in the CONDFORE statement is not specified, unconditional forecasts are generated. The number of Monte Carlo iterations needs to be large because later the simulated forecasts that satisfy the soft conditions are selected from the pool of all unconditional forecasts.
%macro scEstimateAndForecast(tblSample,alpha,lead,nmc,tblUcf,tblUcfSim);
* tblSample: input table name for in-sample data;
* alpha: size of the credible interval;
* lead: future horizons;
* nmc: number of Monte Carlo iterations;
* tblUcf: output table name of unconditional point and interval
forecasts;
* tblUcfSim: output table name of simulated unconditional forecasts;
proc varmax data=&tblSample.;
model y1 - y3 / p=2 prior noprint;
condfore alpha=&alpha. lead=&lead. out=&tblUcf. outsim=&tblUcfSim.
parm=sampling nbi=1000 nmc=&nmc.;
run;
%mend;
The scenarios for four types of soft conditions are constructed from the following macro. To set up the correct bounds, both the true DGP (data-generating process) and unconditional forecasts are used. In the real world, the true DGP is not available, and those bound values reflect the scenarios of interest.
%macro scConstructScenarios(T,lead,tblDGP,tblUcf);
* T: in-sample sample size;
* lead: future horizons;
* tblDGP: input table name for full-sample data;
* tblUcf: input table name of unconditional point and interval
forecasts;
* four scenarios are implicitly output:
scenarios i, i=1 to 4: future y3 is known for
lb_j<=y3_j<=ub_j, j=1 to i, where lb_j and ub_j are lower and
upper bounds whose values are saved in the corresponding macro
variables, and y3_j is the j-step-ahead furture value of y3;
data _NULL_;
set &tblDGP.(firstobs=%eval(&T.+1) obs=%eval(&T.+&lead.) keep=Y3);
set &tblUcf.(keep=step Y3_MEDIAN Y3_LB Y3_UB);
array q[&lead.] q1 - q&lead.;
array lb[&lead.] lb1 - lb&lead.;
array ub[&lead.] ub1 - ub&lead.;
retain q lb ub;
if(Y3<=Y3_LB) then do;
q[step] = 1; ub[step] = Y3_LB;
end;
if (Y3>Y3_LB and Y3<=Y3_MEDIAN) then do;
q[step] = 2; lb[step] = Y3_LB; ub[step] = Y3_MEDIAN;
end;
if (Y3>Y3_MEDIAN and Y3<=Y3_UB) then do;
q[step] = 3; lb[step] = Y3_MEDIAN; ub[step] =Y3_UB;
end;
if (Y3>Y3_UB) then do;
q[step] = 4; lb[step] = Y3_UB;
end;
if(_N_=&lead.) then do;
%do i = 1 %to &lead.;
call symputx("lb&i.",lb&i.,'G');
call symputx("ub&i.",ub&i.,'G');
%end;
end;
run;
%mend;
The simulated forecasts that satisfy each type of soft condition in each scenario are selected in the following macro:
%macro scClassifySimulatedForecasts(lead,tblUcfSim,tblSCSim);
* lead: future horizons;
* tblUcfSim: output table name of simulated unconditional forecasts;
* tblSCSim: output table name of simulated conditional forecasts
under soft conditioins specified in the scenarios;
data &tblSCSim.;
set &tblUcfSim.;
array lb[&lead.] lb1 - lb&lead.;
array ub[&lead.] ub1 - ub&lead.;
array y3f[&lead.] y3_1 - y3_&lead.;
%do j = 1 %to &lead.;
lb[&j.]=&&lb&j.; ub[&j.]=&&ub&j.;
%end;
do myScenario=1 to 4;
outputCond = 1;
do i = 1 to myScenario;
if(outputCond=1) then do;
if(lb[i]=.) then do;
if(y3f[i]<=ub[i]) then outputCond=1;
else outputCond = 0;
end;
else do;
if(ub[i]=.) then do;
if(y3f[i]>lb[i]) then outputCond=1;
else outputCond = 0;
end;
else do;
if(y3f[i]>lb[i] and y3f[i]<=ub[i]) then outputCond=1;
else outputCond = 0;
end;
end;
end;
end;
if(outputCond=1) then output;
end;
run;
proc sort data=&tblSCSim.; by myscenario; run;
%mend;
The point and interval forecasts for each scenario of soft conditions are generated from the following macro:
%macro scGetForecastStats(alpha,lead,tblSCSim,tblSCForecasts);
* alpha: size of the credible interval;
* lead: future horizons;
* tblSCSim: input table name of simulated conditional forecasts
under soft conditioins specified in the scenarios;
* tblSCForecasts: output table name of conditional point and interval
forecasts under soft conditioins specified in the scenarios;
data _NULL_;
lbPctl = &alpha./2*100;
ubPctl = 100-lbPctl;
call symputx("lbPctl",lbPctl,'G');
call symputx("ubPctl",ubPctl,'G');
run;
proc univariate data=&tblSCSim. noprint;
var y1_1 - y1_&lead. y2_1 - y2_&lead.;
output out=oucfx pctlpts=&lbPctl. &ubPctl. 50
pctlpre=%do j=1 %to &lead.; y1_&j. %end;
%do j=1 %to &lead.; y2_&j. %end;
pctlname=_lb _ub _median;
by myscenario;
run;
data &tblSCForecasts.;
set oucfx;
array y1f[&lead.] %do j=1 %to &lead.; Y1_&j._median %end; ;
array y1lb[&lead.] %do j=1 %to &lead.; Y1_&j._lb %end; ;
array y1ub[&lead.] %do j=1 %to &lead.; Y1_&j._ub %end; ;
array y2f[&lead.] %do j=1 %to &lead.; Y2_&j._median %end; ;
array y2lb[&lead.] %do j=1 %to &lead.; Y2_&j._lb %end; ;
array y2ub[&lead.] %do j=1 %to &lead.; Y2_&j._ub %end; ;
do i = 1 to &lead.;
Y1_MEDIAN = y1f[i];
Y1_LB = y1lb[i];
Y1_UB = y1ub[i];
Y2_MEDIAN = y2f[i];
Y2_LB = y2lb[i];
Y2_UB = y2ub[i];
step = i;
output;
end;
keep myscenario step y1_median y1_lb y1_ub y2_median y2_lb y2_ub;
run;
%mend;
The following macro saves all types of forecasts for one simulated data set to one data set for evaluation:
%macro scSaveForecasts(dgpi,T,lead,tblDGP,tblUcf,tblSCForecasts,tblAll);
* dgpi: index of DGP;
* T: in-sample sample size;
* lead: future horizons;
* tblDGP: input table name for full-sample data;
* tblUcf: input table name of unconditional point and interval
forecasts;
* tblSCForecasts: input table name of conditional point and interval
forecasts under soft conditioins specified in the scenarios;
* tblAll: output table name of point and interval forecasts for all DGPs;
data forecasts;
set &tblDGP.(firstobs=%eval(&T.+1) obs=%eval(&T.+&lead.) keep=Y1 Y2);
%do i = 1 %to 4;
set &tblSCForecasts.( where=(myscenario_S&i.=&i.)
rename=( Y1_MEDIAN=Y1_S&i. Y2_MEDIAN=Y2_S&i.
Y1_LB=Y1_LB_S&i. Y1_UB=Y1_UB_S&i.
Y2_LB=Y2_LB_S&i. Y2_UB=Y2_UB_S&i.
myscenario=myscenario_S&i.)
keep=myscenario Y1_MEDIAN Y2_MEDIAN Y1_LB Y1_UB Y2_LB Y2_UB);
%end;
set &tblUcf.(
rename=( Y1_MEDIAN=Y1_S5 Y2_MEDIAN=Y2_S5
Y1_LB=Y1_LB_S5 Y1_UB=Y1_UB_S5
Y2_LB=Y2_LB_S5 Y2_UB=Y2_UB_S5 )
keep=Y1_MEDIAN Y2_MEDIAN Y1_LB Y1_UB Y2_LB Y2_UB);
dgpIndex = &dgpi.;
h = _N_;
drop myscenario_S1 - myscenario_S4;
run;
proc append base=&tblAll. data=forecasts; run;
%mend;
The following macro incorporates all previous macros to test the forecasts for different scenarios (unconditional versus four types of soft conditions). All point and interval forecasts are saved in the data set that is specified in the tblAll argument. All evaluation results are saved in the data set that is specified in the tblEval argument.
%macro scTest(nSim,T,lead,alpha,nmc,nScenarios,qScenario0,scenarioBM,
tblAll,tblEval);
* nSim: number of DGPs;
* T: in-sample sample size;
* lead: future horizons;
* alpha: size of the confidence interval or credible interval;
* nmc: number of Monte Carlo iterations;
* nScenarios: number of scenarios;
* qScenario0: whether there is S0 for equation-based forecasts,
1 for yes and 0 for no;
* scenarioBM: the index of the benchmark scenario;
* tblAll: output table name of point and interval forecasts for all DGPs;
* tblEval: output table name for evaluation results;
%do iSim = 1 %to &nSim.;
%cfSimulateData(&iSim.,&T.,&lead.,t1,t2);
%scEstimateAndForecast(t2,&alpha.,&lead.,&nmc.,oucf,oucfsim);
%scConstructScenarios(&T.,&lead.,t1,oucf);
%scClassifySimulatedForecasts(&lead.,oucfsim,oucfsimx);
%scGetForecastStats(&alpha.,&lead.,oucfsimx,oscf);
%scSaveForecasts(&iSim.,&T.,&lead.,t1,oucf,oscf,&tblAll.);
%end;
%cfEvaluate(&tblAll.,&lead.,&nSim.,
&nScenarios.,&qScenario0.,&scenarioBM.,
&tblEval.);
%mend;
The following macro variables and macro set up and perform the test:
%let nSim = 1000;
%let T = 200;
%let lead = 4;
%let alpha = 0.50;
%let nmc = 100000;
%let nScenarios = 5;
%let qScenario0 = 0;
%let scenarioBM = 5;
%scTest(&nSim., &T.,&lead.,&alpha.,&nmc.,
&nScenarios.,&qScenario0.,&scenarioBM.,
scForecasts,scEval);
In order to show the result in a good style, the following template is created for the evaluation data set:
proc template;
define table scEvalTemplate;
column col3 col4 col5 col6 col7 col8;
define header sc;
text "Conditional Forecasts, Soft Conditions";
start=col4; end=col7;
end;
define column col3;
header="Horizon";
end;
define column col4;
header="Scenario 1"; format=12.5;
end;
define column col5;
header="Scenario 2"; format=12.5;
end;
define column col6;
header="Scenario 3"; format=12.5;
end;
define column col7;
header="Scenario 4"; format=12.5;
end;
define column col8;
header="Unconditional"; format=12.5;
end;
end;
run;
The following macro calls print the sMAPEs for y1 and y2 in Output 42.5.9 and Output 42.5.10, respectively. An interesting fact is that as the horizon increases, the accuracy of forecasts for y1 in each scenario gets better (which is not common) and the accuracy of forecasts for y2 in each scenario gets worse (which is common). However, the forecasting methods can still be compared.
%cfPrint(scEvalTemplate, scEval(where=(col1=1 and col2=1)));
%cfPrint(scEvalTemplate, scEval(where=(col1=1 and col2=2)));
Output 42.5.9: The sMAPEs for y1
| Conditional Forecasts and Scenario Analysis |
| Horizon | Conditional Forecasts, Soft Conditions | Unconditional | |||
|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | ||
| 1 | 0.90733 | 0.89925 | 0.90273 | 0.89949 | 0.90144 |
| 2 | 0.88731 | 0.88271 | 0.88282 | 0.87862 | 0.88429 |
| 3 | 0.87891 | 0.87626 | 0.87505 | 0.86820 | 0.87613 |
| 4 | 0.87062 | 0.86864 | 0.86757 | 0.86206 | 0.86852 |
Output 42.5.10: The sMAPEs for y2
| Conditional Forecasts and Scenario Analysis |
| Horizon | Conditional Forecasts, Soft Conditions | Unconditional | |||
|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | ||
| 1 | 1.06627 | 1.06999 | 1.06861 | 1.06688 | 1.07902 |
| 2 | 1.14420 | 1.14813 | 1.14674 | 1.14376 | 1.16096 |
| 3 | 1.20960 | 1.21150 | 1.20106 | 1.19365 | 1.22223 |
| 4 | 1.26086 | 1.26050 | 1.25022 | 1.24181 | 1.27045 |
The following macro calls print the relative sMAPEs for y1 and y2 in Output 42.5.11 and Output 42.5.12, respectively. Most relative sMAPEs for conditional forecasts under soft conditions are less than 1, which means that those conditional forecasts have a better accuracy than the unconditional forecasts have. The forecasts in scenario 4, compared to other forecasts for each horizon, always have the smallest relative sMAPEs, which means that the conditional forecasts under soft conditions successfully take the advantage of the available future information.
%cfPrint(scEvalTemplate, scEval(where=(col1=2 and col2=1)));
%cfPrint(scEvalTemplate, scEval(where=(col1=2 and col2=2)));
Output 42.5.11: The Relative sMAPEs for y1
| Conditional Forecasts and Scenario Analysis |
| Horizon | Conditional Forecasts, Soft Conditions | Unconditional | |||
|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | ||
| 1 | 1.00654 | 0.99757 | 1.00144 | 0.99784 | 1.00000 |
| 2 | 1.00342 | 0.99821 | 0.99834 | 0.99359 | 1.00000 |
| 3 | 1.00317 | 1.00014 | 0.99877 | 0.99094 | 1.00000 |
| 4 | 1.00242 | 1.00014 | 0.99891 | 0.99257 | 1.00000 |
Output 42.5.12: The Relative sMAPEs for y2
| Conditional Forecasts and Scenario Analysis |
| Horizon | Conditional Forecasts, Soft Conditions | Unconditional | |||
|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | ||
| 1 | 0.98818 | 0.99163 | 0.99035 | 0.98875 | 1.00000 |
| 2 | 0.98556 | 0.98894 | 0.98775 | 0.98518 | 1.00000 |
| 3 | 0.98966 | 0.99122 | 0.98268 | 0.97662 | 1.00000 |
| 4 | 0.99245 | 0.99217 | 0.98408 | 0.97746 | 1.00000 |
The following macro calls print the sizes for y1 and y2 in Output 42.5.13 and Output 42.5.14, respectively. All sizes are around 0.5 (the nominal significance level), which means that all interval forecasts have the correct size.
%cfPrint(scEvalTemplate, scEval(where=(col1=3 and col2=1)));
%cfPrint(scEvalTemplate, scEval(where=(col1=3 and col2=2)));
Output 42.5.13: The Sizes for y1
| Conditional Forecasts and Scenario Analysis |
| Horizon | Conditional Forecasts, Soft Conditions | Unconditional | |||
|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | ||
| 1 | 0.50600 | 0.50900 | 0.51000 | 0.50600 | 0.49700 |
| 2 | 0.50000 | 0.50600 | 0.50300 | 0.51000 | 0.50500 |
| 3 | 0.50200 | 0.50300 | 0.49000 | 0.50100 | 0.50000 |
| 4 | 0.50800 | 0.50700 | 0.51300 | 0.51000 | 0.49900 |
Output 42.5.14: The Sizes for y2
| Conditional Forecasts and Scenario Analysis |
| Horizon | Conditional Forecasts, Soft Conditions | Unconditional | |||
|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | ||
| 1 | 0.48900 | 0.48600 | 0.48800 | 0.48800 | 0.49300 |
| 2 | 0.49500 | 0.46200 | 0.46700 | 0.45900 | 0.49300 |
| 3 | 0.50800 | 0.49300 | 0.49500 | 0.49100 | 0.50600 |
| 4 | 0.47800 | 0.46100 | 0.46400 | 0.45900 | 0.47200 |
The following macro calls print the relative interval lengths for y1 and y2 in Output 42.5.15 and Output 42.5.16, respectively. All conditional forecasts under soft conditions have a relative interval length of less than 1, which means that the conditional forecasts provide better interval forecasts than unconditional forecasts, given that all forecasts have the correct size. The smallest relative interval lengths for each horizon almost always lie in the columns of scenario 4, which indicates that more information results in better interval forecasts.
%cfPrint(scEvalTemplate, scEval(where=(col1=4 and col2=1)));
%cfPrint(scEvalTemplate, scEval(where=(col1=4 and col2=2)));
Output 42.5.15: The Relative Interval Lengths for y1
| Conditional Forecasts and Scenario Analysis |
| Horizon | Conditional Forecasts, Soft Conditions | Unconditional | |||
|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | ||
| 1 | 0.97668 | 0.96309 | 0.95805 | 0.95808 | 1.00000 |
| 2 | 0.99957 | 0.97788 | 0.96682 | 0.95940 | 1.00000 |
| 3 | 0.99829 | 0.99797 | 0.98040 | 0.96568 | 1.00000 |
| 4 | 0.99659 | 0.99479 | 0.99352 | 0.97636 | 1.00000 |
Output 42.5.16: The Relative Interval Lengths for y2
| Conditional Forecasts and Scenario Analysis |
| Horizon | Conditional Forecasts, Soft Conditions | Unconditional | |||
|---|---|---|---|---|---|
| Scenario 1 | Scenario 2 | Scenario 3 | Scenario 4 | ||
| 1 | 0.98772 | 0.98616 | 0.98671 | 0.98540 | 1.00000 |
| 2 | 0.99356 | 0.97818 | 0.97409 | 0.97303 | 1.00000 |
| 3 | 0.99495 | 0.98684 | 0.97211 | 0.96640 | 1.00000 |
| 4 | 0.99775 | 0.99329 | 0.98459 | 0.97166 | 1.00000 |
In summary, you can make the following conclusions from the preceding results:
Compared to simulation-based unconditional forecasts, equation-based unconditional forecasts have similar accuracy for point forecasts but worse accuracy for interval forecasts, perhaps because the equation-based method does not consider the uncertainty of parameters.
Compared to simulation-based unconditional forecasts, simulation-based conditional forecasts under hard or soft conditions have better accuracy for both point and interval forecasts. As more future information becomes available, the conditional forecasts can become more accurate.