The current version of the package contains 5 public functions: expsmpars(), stheta(), fcast_plot, fcast_ac() and decompcl(). PACKAGE DESCRIPTION =================== The "main" forecasting function is stheta(), which implements the theta method, including a version for seasonal data; expsmpars() outputs auto-selected alpha and y_0 to use for exponential smoothing. fcast_plot() plots series and forecasts in a fashion similar to GUI default options for forecasting after native commands, e.g. arima. (In principle, in the future it might be used after any package or function that outputs forecasts, their standard errors, or confidence bands.) fcast_ac() performs assessment of forecast accuracy using shifting forecast periods; can be used after native commands which allows fcast --out-of-sample without inputting right-hand variables. Developers are invited to supply code segments to be incorporated. decompcl() performs classical decomposition of a time series; NEWS are at the bottom of the file. PUBLIC FUNCTIONS DESCRIPTION ============================ expsmpars --------- Argument: y "series to smooth" Returns: matrix containing alpha and the initial state, which minimize the sum of squared errors for simple exponential smoothing. The Nelder-Mead method is used inside under the following restriction: alpha in [0;1]. The output is intended to be inserted into movavg() for smoothing the series. With today's performance there exists a moderate hope to embrace 30 types of exponential smoothing as in [3]. stheta ------ Arguments: series y "series to forecast", scalar h[NA] "horizon, NA = $pd", string opts[null] "options, see the help file/comment", matrix level[null] "conf. levels d.= {80,95}", scalar wts[NA] "weight for forec. seasonality") Returns: matrix. Theta-method for univariate forecasting. The references are [2], [4], and therein. 'opts' parameter details: opts = "noprint|m, notrend|m, noseas|seas|m, tramo|x-12|simpleM|m" 'm' = missed, the fields can be sorted arbitrarily; 'noprint': not to print forecasts and bounds 'notrend': not to use trend transformation 'noseas': use non-seasonal version 'seas': use seasonal version (if both are absent - auto-detect) 'simpleM' 'tramo' 'x-12' - indicates type of seasonal decomposition: 'simpleM': classical multiplicative decomposition, 'tramo': decomposition based on TRAMO/SEATS (requires TRAMO/SEATS to be installed; if none is given, then uses additive classical decomposition.) E.g. opts = "seas, x-12": uses seasonal version based on X-12-... opts = "x-12": tests seasonality, uses X-12 if seas. is detected wts : currently for experimentation purposes; the default is 1/2 A METHODOLOGICAL NOTE. The variant with 'noseas' (no seasonal correction is applied) was tested against thetaf() function from {forecast} R package. The variant with 'seas' (seasonal correction is applied) is based on {forecTheta} R package. There are several innovations: the seasonal correction can be based on either additive, or multiplicative classical decomposition of time series. This version performs improved forecasting of seasonal indices. Also, a user can indicate using TRAMO/SEATS, or X-12(13)-ARIMA (if installed) to this end. The default option now is to use additive classical decomposition, since the multiplicative one is not applicable if a series changes signs. Also, the default option cannot rely on facultative installations. The quality of the function can be easily compared with arima forecasting using fcast_ac() (see fcast_ac help entry below). decompcl -------- Arguments: series x "series to decompose", bool type[1] "0 -> additive; 1 -> multiplicative" Returns: bundle Classical time series decomposition. The (external) clone of R decompose() function. Its coding was a side effect of coding the theta method. fcast_plot ---------- Arguments: series y "forecasted series", matrix fcasts "forecasts and/or ses/cis", scalar t2[NA] "last obs, NA = xmin($t2,lastobs(y)", scalar setype[NA] "how to read other columns of fcasts", scalar cl[NA] "cl if se are input, NA = 0.9" Returns: nothing. Plots series, continued with out-of-sample forecasts and confidence bands (if available). t2: the last observation of y to use, by default it is the last valid observation, or current $t2 setype: 0 - only forecasts are plotted; 1 - the second column of 'fcasts' interpreted as standard errors, other columns (if any) are ignored; 2 - 2-nd and 3-rd columns are interpreted as confidence bounds; NA: if 'fcasts' has 1 column, setype is set to 0; 2 columns -> setype = 1; 3 or more colums -> setype = 2. The check of consistency of series and forecasts samples is available provided fcasts matrix has row names formed as observations labels. If a user function outputs idiosyncratic forecasts matrix with many non-standard ordered columns, one can form the relevant 2 or 3 columns submatrix. cl: used only for setype = 1; confidence level. fcast_ac -------- Arguments: string cmd "quoted command/function to forecast", int res[0] "reserved obs, 0 = [T/5]", scalar h[NA] "horizon, NA = $pd" Returns: matrix Performs ex-post assessment of forecasts accuracy based on fcstats(). Initially, 'res' observations are reserved. The horizon of each forecast is set to h. The training sets enlarge by one observation, while forecast periods are shifted by one observation accordingly. Accuracy measures are output for each period, and, finally, for the total sequence of errors obtained. Example: 1) arima method open bjg.gdt matrix ma1 = fcast_ac("arima 1 1 0; 0 1 1; lg --nc",12,1) A few leftmost columns of output: ME MSE MAE 1960:01 - 1960:01 0.0151692 0.0151692 0.0151692 1960:02 - 1960:02 -0.0192614 0.0192614 0.0192614 1960:03 - 1960:03 -0.0718495 0.0718495 0.0718495 1960:04 - 1960:04 0.126686 0.126686 0.126686 1960:05 - 1960:05 0.0313662 0.0313662 0.0313662 1960:06 - 1960:06 0.00355668 0.00355668 0.00355668 1960:07 - 1960:07 0.0288614 0.0288614 0.0288614 1960:08 - 1960:08 -0.041736 0.041736 0.041736 1960:09 - 1960:09 -0.045035 0.045035 0.045035 1960:10 - 1960:10 0.0265223 0.0265223 0.0265223 1960:11 - 1960:11 -0.0330183 0.0330183 0.0330183 1960:12 - 1960:12 -0.0251796 0.0251796 0.0251796 1960:01 - 1960:12 -0.0003265 0.0498665 0.0390201 We have the sequence of 12 one-step forecasts. The first one was made based on arima estimated on 1949:01 - 1959:12 sample. The second one is based on 1949:01 - 1960:1 sample, etc. The last row reports overall measures for all 12 forecasts stacked. 2) theta-metod sthtext = sprintf("stheta(lg, 1,\"noprint\")") matrix ma2 = fcast_ac(sthtext,12) Executing sum((ma3[,3] - ma10[,3] .> 0)) and sum((ma10[,2] - ma11[,2] .> 0)) we find that arima gives MSE- and MAE-better forecasts in 9 cases out of 12. It is not easy to beat arima over the favorite Box and Jenkins series. The sample script gives an example when stheta() gives noticeably better forecasts than arima, selected based on information criteria (auto_arima() from lagreg.gfn was used for arima parameters selection). Changelog ========= v0.6, December 2021 ------------------- Since this package is not really maintained anymore (unfortunately!), the gretl team did some internal syntax updates and "house-keeping". This means that now gretl versions >=2020c are required. Please contact the gretl team (preferably via the gretl users mailing list) if any problems arise with this package version. Furthermore: - Functions NMminC, NMmaxC, and along with it hinv have been removed, since they did not seem to bear any relation to the main purpose of the package. - The signature of the functions expsmpars(), decompcl(), and fcast_plot() has been changed from a pointer-to-series to a plain series input. This is a backwards-incompatible change, please adjust your scripts (just remove the ampersand sign '&' before the series argument; also see the sample script). NEWS in v. 0.5 -------------- Time performance is improved both due to hansl new NMmin() function, and better algorithm for computing of exponential smoothing errors. New function: fcast_plot is a universal tool for plotting user-specified forecasts. Also, an improved version of fcast_acc() is moved from lagreg.zip [5] under the name of fcast_ac. fcast_acc() will be deprecated in the incoming update of lagreg. Bug corrections. Improvement. stheta(): now for seasonal decomposition (performed at some stage of the theta-method) TRAMO/SEATS, or X-12(13)-ARIMA can be used; it is fairly slow (hansl deseas() takes about 2/3 time of stheta() execution). Multiplicative classical decomposition is inapplicable when a series changes signs. That's why the new default option is to use the additive classical decomposition. The methods of forecasting of seasonal indices are improved (they are needed to correct forecasts of the adjusted series to get forecasts of the actual series). Recall from the previous release, that the function started as a translation of forecTheta [4]. But now it lives a life of its own. The author's innovations are 1) modified version of hinv() 2) using TRAMO/SEATS, or X-12(13)-ARIMA inside seasonal theta-method instead of classical decomposition 3) including additive version, 4) improving seasonal indices forecasting. References ========== 1. John C. Nash. Compact Numerical Methods for Computers: Linear Algebra and Function Minimization. CRC Press, 1990. 2. Assimakopoulos, V. and Nikolopoulos k. (2000). The theta model: a decomposition approach to forecasting. International Journal of Forecasting 16, 4, 521–530. 3. Hyndman RJ (2016). _forecast: Forecasting functions for time series and linear models_. R package version 7.0, URL: http://github.com/robjhyndman/forecast. 4. Jose Augusto Fiorucci, Francisco Louzada and Bao Yiqi (2016). forecTheta: Forecasting Time Series by Theta Models. R package version 2.1. https://CRAN.R-project.org/package=forecTheta 5. Oleh Komashko. lagreg gretl package