This function performs optimal (in least squares sense) forecast reconciliation for a multiple time series with \(C\) linear and non-linear constraints.
Usage
csnlc(base, g_fun, g_grad = NULL, comb = "ols", res = NULL, start = NULL,
nn = FALSE, settings = NULL, ...)Arguments
- base
A (\(h \times n\)) numeric matrix or multivariate time series (
mtsclass) containing the base forecasts to be reconciled; \(h\) is the forecast horizon, and \(n\) is the total number of time series.- g_fun
A multivariate constraint function \(g:\mathbb{R}^n \rightarrow \mathbb{R}^{C}\). It may consist of both linear and non-linear constraints.
- g_grad
Gradient of the constraints function \(g\).
- comb
A string specifying the reconciliation method:
ols,wlsorshr. (see for more detailsFoReco::cscov).- res
An (\(N \times n\)) optional numeric matrix containing the in-sample residuals/validation errors. This matrix is used to compute some covariance matrices.
- start
Optional starting values of the non-linear optimisation.
- nn
Logical value:
TRUE(default) if non-negative reconciled forecasts are wished.- settings
Settings for (nloptr). The default options are:
algorithm = "NLOPT_LD_SLSQP",xtol_rel = 1.0e-6,xtol_abs = 1.0e-6. For details, see the (nloptr) documentation.- ...
Arguments passed on to
FoReco::cscov.
References
Girolimetto, D., Panagiotelis, A., Di Fonzo, T., Li, H. (2024), Forecast reconciliation with non-linear constraints, arXiv. doi:10.48550/arXiv.2510.21249
Johnson, S. (2008), The NLopt non-linear optimization package. https://github.com/stevengj/nlopt
Examples
bf <- c(1, 2, 4)
g_fun <- function(x) x[1]-x[2]/x[3]
g_grad <- function(x){
c(1, -1/x[3], x[2]/(x[3]^2))
}
reco <- csnlc(base = bf, g_fun = g_fun, g_grad = g_grad, comb = "ols")
#> Warning: Argument `res` is ignored.
#> ℹ When `res` is provided, `comb = 'shr'` is suggested.
FoReco::recoinfo(reco)$info
#> ✔ Cross-sectional Forecast Reconciliation
#> ℹ FoReco function: `csnlc`
#> ℹ Covariance approximation: `ols`
#> ℹ Non-negative forecasts: `TRUE`
#> obj_val iter ineq_cons eq_cons status
#> 1 0.1156807 5 0 1 4