R/XFcstTrueSimple.R

Defines functions XTrueSimple

Documented in XTrueSimple

#' Forecast for covariate matrix: using true generating process (uncorrelated series)
#'
#' @description Given the true generating process (uncorrelated 10 series), generate on into the future.
#'
#' @details Compared to the original \code{Xgen*} which used vectorised VAR(1), here I use VAR(3) to iteratively produce future points.
#'
#'
#' @param horizon a number. Forecast horizon.
#' @param sigmax a number. Standard deviation of noise of x.
#' @param p a number. Number of covariates x.
#' @param ARmatrix a list of 3 matrices.
#' @param Xinput a matrix. The original training X matrix for forecast, DAT$X.for.fcst (10 series)
#' @param nsize a number. Size (nrow(Xinput)). Essentially the length of training period, used to get the end points (or starting points)
#' of the future period.
#'
#' @return a matrix
#'
#' \item{X.trueforecast}{a matrix. Forecast values for each series produced by true method, simple scenario.}
#'
#' @export
#'
#' @examples
#' ##

XTrueSimple <- function(horizon,
                        sigmax,
                        p,
                        ARmatrix,
                        Xinput,
                        nsize){

  initialX <- matrix(rep(0, (horizon + 3)*p), (horizon+3), p)  # 7+3 rows, 10 col
  initialX[1:3, ] <- Xinput[((nsize-2):nsize), ]

  for (m in 1:horizon){


    # -------- no shock
    x.last <- list(x1 = initialX[(m+2), ],
                   x2 = initialX[(m+1), ],
                   x3 = initialX[m, ])

    tempX <- ARmatrix$A1 %*% x.last$x1 + ARmatrix$A2 %*% x.last$x2 + ARmatrix$A3 %*% x.last$x3 + sigmax
    initialX[(m+3), ] <- tempX

  }


  X.trueforecast <- initialX[(4:10), ]
  return(X.trueforecast = X.trueforecast)


}
yymmhaha/PackPaper1 documentation built on May 24, 2019, 8:55 a.m.