FoReco (version 0.1.1)

octrec: Optimal combination cross-temporal forecast reconciliation

Description

Optimal (in least squares sense) combination cross-temporal forecast reconciliation. The reconciled forecasts are calculated either through a projection approach (Byron, 1978), or the equivalent structural approach by Hyndman et al. (2011).

Usage

octrec(basef, m, C, comb, res, Ut, nb, W, Sstruc,
       mse = TRUE, corpcor = FALSE, type = "M", sol = "direct",
       nn = FALSE, keep = "list",
       settings = osqpSettings(verbose = FALSE, eps_abs = 1e-5,
       eps_rel = 1e-5, polish_refine_iter = 100, polish=TRUE))

Arguments

basef

(n x h(k* + m)) matrix of base forecasts to be reconciled; n is the total number of variables, m is the highest frequency, k* is the sum of (p-1) factors of m, excluding m, and h is the forecast horizon. Each row identifies, a time series, and the forecasts are ordered as [lowest_freq' ... highest_freq']'.

m

Highest available sampling frequency per seasonal cycle (max. order of temporal aggregation).

C

(na x nb) cross-sectional (contemporaneous) matrix mapping the bottom level series into the higher level ones.

comb

Type of the reconciliation, it corrispond to a different covariance matrix (n(k* + m) x n(k* + m)), k* is the sum of (p-1) factors of m (exclude m as factors) and n is the number of variables:

  • ols (Identity);

  • struc (Cross-temporal summing matrix, use the Sstruc param to reduce computation time);

  • wlsh (Hierarchy variances matrix);

  • wlsv (Series variances matrix);

  • bdshr (Shrunk cross-covariance matrix, cross-sectional framework);

  • bdsam (Sample cross-covariance matrix, cross-sectional framework);

  • acov (Series auto-covariance matrix);

  • Sshr (Series shrunk cross-covariance matrix);

  • Ssam (Series cross-covariance matrix);

  • shr (Shrunk cross-covariance matrix);

  • sam (Sample cross-covariance matrix);

  • w use your personal matrix W in param W.

res

(n x N(k* + m)) matrix containing the residuals at all the temporal frequencies ordered [lowest_freq' ... highest_freq']' (columns) for each variable (row), needed to estimate the covariance matrix when comb = {"sam", "wlsv", "wlsh", "acov", "Ssam", "Sshr", "Sshr1", "shr"}.

Ut

Zero constraints cross-sectional (contemporaneous) kernel matrix \((\textbf{U}'\textbf{Y} = \mathbf{0})\) spanning the null space valid for the reconciled forecasts. It can be used instead of parameter C, but in this case nb (n = na + nb) is needed. If the hierarchy admits a structural representation, Ut has dimension (na x n).

nb

Number of bottom time series; if C is present, nb is not used.

W

This option permits to directly enter the covariance matrix:

  1. W must be a p.d. (n(k* + m) x n(k* + m)) matrix;

  2. if comb is different from "w", W is not used.

Sstruc

Cross-temporal summing matrix (structural representation)\(,\; \check{\textbf{S}}\); can be obtained through the function ctf_tools.

mse

Logical value: TRUE (default) calculates the covariance matrix of the in-sample residuals (when necessary) according to the original hts and thief formulation: no mean correction, T as denominator.

corpcor

Logical value: TRUE if corpcor (Sch<U+00E4>fer et al., 2017) must be used to shrink the sample covariance matrix according to Sch<U+00E4>fer and Strimmer (2005), otherwise the function uses the same implementation as package hts.

type

Approach used to compute the reconciled forecasts: "M" for the projection approach with matrix M (default), or "S" for the structural approach with summing matrix S.

sol

Solution technique for the reconciliation problem: either "direct" (default) for the direct solution or "osqp" for the numerical solution (solving a linearly constrained quadratic program using solve_osqp).

nn

Logical value: TRUE if non-negative reconciled forecasts are wished.

keep

Return a list object of the reconciled forecasts at all levels.

settings

Settings for osqp (object osqpSettings). The default options are: verbose = FALSE, eps_abs = 1e-5, eps_rel = 1e-5, polish_refine_iter = 100 and polish = TRUE. For details, see the osqp documentation (Stellato et al., 2019).

Value

If the parameter keep is equal to "recf", then the function returns only the (n x h(k* + m)) reconciled forecasts matrix, otherwise (keep="all") it returns a list that mainly depends on what type of representation (type) and methodology (sol) have been used:

recf

(n x h(k* + m)) reconciled forecasts matrix.

Omega

Covariance matrix used for reconciled forecasts (vec(Y') representation).

W

Covariance matrix used for reconciled forecasts (vec(Y) representation).

nn_check

Number of negative values (if zero, there are no values below zero).

rec_check

Logical value: has the hierarchy been respected?

M (type="M" and type="direct")

Projection matrix (projection approach).

G (type="S" and type="direct")

Projection matrix (structural approach).

S (type="S" and type="direct")

Cross-temporal summing matrix\(, \; \textbf{Q}\check{\textbf{S}}\) (vec(Y') representation).

info (type="osqp")

matrix with some useful indicators (columns) for each forecast horizon h (rows): run time (run_time) number of iteration, norm of primal residual (pri_res), status of osqp's solution (status) and polish's status (status_polish).

Details

In case of non-negativity constraints, there are two ways:

  1. sol = "direct" and nn = TRUE: the base forecasts will be reconciled at first without non-negativity constraints, then, if negative reconciled values are present, the "osqp" solver is used.

  2. sol = "osqp" and nn = TRUE: the base forecasts will be reconciled through the "osqp" solver.

References

Byron, R.P. (1978), The estimation of large social accounts matrices, Journal of the Royal Statistical Society A, 141, 3, 359-367.

Di Fonzo, T., Girolimetto, D. (2020), Cross-Temporal Forecast Reconciliation: Optimal Combination Method and Heuristic Alternatives, Department of Statistical Sciences, University of Padua, arXiv:2006.08570.

Sch<U+00E4>fer, J.L., Opgen-Rhein, R., Zuber, V., Ahdesmaki, M., Duarte Silva, A.P., Strimmer, K. (2017), Package `corpcor', R package version 1.6.9 (April 1, 2017), https://CRAN.R-project.org/package= corpcor.

Sch<U+00E4>fer, J.L., Strimmer, K. (2005), A Shrinkage Approach to Large-Scale Covariance Matrix Estimation and Implications for Functional Genomics, Statistical Applications in Genetics and Molecular Biology, 4, 1.

Stellato, B., Banjac, G., Goulart, P., Bemporad, A., Boyd, S. (2018). OSQP: An Operator Splitting Solver for Quadratic Programs, arXiv:1711.08013.

Stellato, B., Banjac, G., Goulart, P., Boyd, S., Anderson, E. (2019), OSQP: Quadratic Programming Solver using the 'OSQP' Library, R package version 0.6.0.3 (October 10, 2019), https://CRAN.R-project.org/package=osqp.

Examples

Run this code
# NOT RUN {
data(FoReco_data)
obj <- octrec(FoReco_data$base, m = 12, C = FoReco_data$C,
              comb = "bdshr", res = FoReco_data$res)

# }

Run the code above in your browser using DataLab