# DiebMar Perform the Diebold-Mariano (1995) test for predictive accuracy for different loss functions. The DiebMar has the following features: * Compare time series with the same sample size * GUI access through gretl menuDiebold-Mariano (1995) test for predictive accuracy # GUI Access Access via: Variable/Diebold-Mariano test # Public Function ``` function matrix DiebMar (series y, series f1, series f2, int loss, scalar LLorder, scalar LXshape, int m, bool prewhit, bool HLN) ``` # Parameters `y`: series - actual data, time series of interest `f1`: series - 1st time series available for forecasting `f2`: series - 2st time series available for forecasting `loss`: int - loss function type (see Giacomini and White, 2006; Pesaran and Timmerman, 1992) options: * 0: the DM test is performed for all loss functions; **this is the default**. * 1: U-shape loss function (symmetric) * 2: V-shape loss function (symmetric) * 3: Lin-Lin loss function (asymmetric) with order parameter given in Argument 5 * 4: Linex loss function (asymmetric) with shape parameter given in Argument 6 * 5: Direction-of-Change loss function (asymmetric) * 6: Forecast-direction loss function (asymmetric) `LLorder`: scalar - order parameter for Lin-Lin loss function: this value must be in the interval [0,1]; **the default value is 0.5** which assigns the same weight to positive and negative forecast errors `LXshape`: scalar - shape parameter for Linex loss functio: this value must be non zero. In general, with a shape parameter greater than 2, the Linex function could return explosive values; ** the default value is 1** `m`: int - Bartlett window size: the **default** value is the largest integer less than or equal to T^(1/3), where T is number of observations in both forecast time series `prewhit`: bool - prewhitening correction for long-run variance robust to heteroskedasticity and autocorrelation (see Andrews and Monahan, 1992) `HLN`: bool - HLN: correction for small samples (see Harvey, Leybourne and Newbold, 1997) # Returns The package returns a matrix with 4 columns. The 1st column contains an integer id number from 1 to 10. * id=1: U-shape loss function * id=2: V-shape loss function * id=3: Lin-Lin loss function with order parameter given in Argument 5 * id=4: Linex loss function with shape parameter given in Argument 6 * id=5: Direction-of-Change loss function * id=6: Forecast-direction loss function * id=7: Maximum p-value Lin-Lin whose order parameter is achieved via a grid search in the interval [0,1] * id=8: Minimum p-value Lin-Lin whose order parameter is achieved via a grid search in the interval [0,1] * id=9: Maximum p-value Linex whose shape parameter is achieved via a grid search in the interval [-M,M], where M=max{2,|p|} and |p| is the absolute value of the shape parameter assigned by Argument 6 (it is reasonable to set |p|<2). * id=10: Minimum p-value Linex whose shape parameter is achieved via a grid search in the interval [-M,M], where M=max{2,|p|} and |p| is the absolute value of the shape parameter assigned by Argument 6 (it is reasonable to set |p|<2). The 2nd column contains the Diebold-Mariano test-statistic. If two forecast models have exactly the same predictive accuracy (the loss function returns a time series of zeros), the test-statistic is automatically zero. In this case, the following message appear: "This test is not performed: both forecast series have exactly the same predictive accuracy." The same is for Linex loss function when some numerical problems are met in the exponential function. The message here is "The test with Linex loss function is not performed: numerical results out of range for exp{p*e}", where p is the shape parameter value and e is the residual series (difference between forecast and actual). The 3rd column contains the p-values from a normal standard distribution. When the HLN option is used the p-values are those of a t distribution with (T-1) d.o.f., where T is number of observations in both forecast time series. Obviously, when the test- statistic is zero, the corresponding p-value is 1. If id={3,4,7,8,9,10} the 4th column contains the parameters for the Lin-Lin and the Linex loss functions. Otherwise it returns zero. * 1 row if Argument 4 is 1, 2, 5 or 6 (id={1,2,5,6}) * 3 rows if Argument 4 is 3 (id={3,7,8}) or 4 (id={4,9,10}) * 10 rows if Argument 4 is 0 (id={1,2,3,4,5,6,7,8,9,10}) The number of rows in the output matrix depend on the selection of the loss function: # Diebold-Mariano test Given the actual times series y and two forecast time series f1 and f2, the forecast errors is defined as e1=f1-y and e2=f1-y. The loss associated with the two forecasts is assumed to be a function of the forecast error and is denoted by L(e), with e={e1,e2}. The function L(e) is a loss function, that is a function such that (a) takes the value zero when no error is made; (b) is never negative; (c) is increasing in size as the errors become larger in magnitude. The loss differential between the two forecasts is d=L(e1)-L(e2); the two forecasts have equal accuracy if and only if the above loss differential has zero expectation for all t. Available loss functions: 1. U-shape L(e)=e^2 2. V-shape L(e)=|e| 3. Lin-Lin L(e)=[p-(e<0)]e (p is order the parameter) 4. Linex L(e)=p exp(e)-1-p e (p is the shape parameter) 5. Direction-of-Change L(e)=|1(y-y(-1)>0)-1(f-y(-1)>0)| where y(-1) is the lagged actual time series and 1(.) is the indicator function 6. Forecast-Direction L(e)=1(y f<0), where f is the forecast time series # Bibliography Andrews D.W.K. and Monahan J.C. (1992), _An improved heteroskedasticity and autocorrelation consistent covariance matrix estimation_, Econometrica 59, pp. 818-858. Diebold F.X. and Mariano R. (1995), _Comparing predictive accuracy_, Journal of Business Economic Statistics 13, pp. 253-265. Giacomini R. and White H. (2006), _Tests of Conditional Predictive Ability_, Econometrica 74(6), pp. 1545-1578. Harvey D., Leybourne S. and Newbold P (1997), _Testing the Equality of Prediction Mean Squared Error_, International Journal of Forecasting 13(2), pp. 281-291. Pesaran H. and Timmermann A. (1992), _A Simple Nonparametric Test of Predictive Performance_, Journal of Business & Economic Statistics, 10(4), pp. 461-465. # Changelog * **v1.0 (September 1, 2016)** * Initial release * **v.1.1 (December 18, 2016)** * In the "DiebMar 1.0" package, sqrt(T) is missing from the calculation of the Diebold-Mariano test statistic, where T is the number of observations in both predicted time series * **v.1.2 (January 28, 2017)** * Added internal function Matching(f1,f2), which checks whether both predicted time series f1 and f2 have the same start date and end date * Added the HLNcorrect(T,h) function, which consists of the Harvey, Leybourne and Newbold correction for small samples (h is the number of the steps-ahead forecasts) * **v.1.3 (March 22, 2019)** * small update: use of "==" instead of "=" in the if command * small update: use of "loop" instead of "loop for" * **v.1.4 (May 1, 2025)** * The printout has been revised to report the input time series. * Added row and column labels to the result matrix * The info file has been re-edited