# Time Series Forecasting

For time series forecasting, such as moving average and exponential smoothing, we follow the notational conventions below.

## Observations and Estimates

The Forecasting library uses as input observations made in the history. It provides estimates over both the history and the horizon. A single set and index is used to index both the history and the estimates, this set is called the time set. In addition, you will need to specify the number of elements that belong to the history. The corresponding mathematical notation is:

 $$T$$ number of observations $$H$$ length of horizon $$\{1\ldots T+H\}$$ time set $$t$$ index in time set $$y_t, t \in \{1\ldots T\}$$ observation $$e_t, t \in \textrm{ time set }$$ estimate

The forecasts are provided in $$e_t$$, $$t \in \{T+1 \ldots T+H\}$$.

## Residuals

The residual, $$r_t$$ where $$t \in \{1\ldots T\}$$, is the difference between the corresponding observation $$y_t$$ and estimate $$e_t$$. To obtain the residuals, you will need to provide a parameter declared over the time set.

## Error Measures

From the residuals, error measures such as Mean Absolute Deviation (MAD), Mean Absolute Percentage Error (MAPE), and Mean Squared Deviation (MSD) can be computed.

## Predeclared Index ems

Whenever one of the time series forecasting functions communicates the error measures, it uses identifiers declared over the index forecasting::ems, declared as follows:

Set ErrorMeasureSet {
Index: ems;
Definition: {
data {
MAPE, ! Mean Absolute Percentage Error (provided as fraction)
MSE   ! Mean Squared Error
}
}
}


To obtain the error measures, you will need to provide a parameter indexed over forecasting::ems to the time series forecasting functions. Note that the MAPE is a fraction, in order to use it as a percentage, you can use the predeclared quantity SI_unitless. For instance, given the declarations:

Quantity SI_Unitless {
BaseUnit: -;
Conversions: % -> - : # -> # / 100;
Comment: "Expresses a dimensionless value.""}
Parameter myMAPE {
Unit: %;
}
Parameter myErrorMeasures {
IndexDomain: forecasting::ems;
}


The following statements:

1myMAPE := myErrorMeasures('MAPE') ;
2display myErrorMeasures, myMAPE ;


The output may look as follows:

myErrorMeasures := data { MAPE : 0.417092,  MAD : 1.785714,  MSE : 3.982143 } ;
myMAPE := 41.709184 [%] ;