Learn R Programming

gmvarkit (version 1.1.1)

simulateGMVAR: Simulate from GMVAR process

Description

simulateGMVAR simulates observations from a GMVAR process.

Usage

simulateGMVAR(gmvar, nsimu, init_values = NULL, ntimes = 1,
  drop = TRUE)

Arguments

gmvar

object of class 'gmvar' created with fitGMVAR or GMVAR.

nsimu

number of observations to be simulated.

init_values

a size \((pxd)\) matrix specifying the initial values to be used in the simulation, where d is the number of time series in the system. The last row will be used as initial values for the first lag, the second last row for second lag etc. If not specified, initial values will be generated from the stationary distribution.

ntimes

how many sets of simulations should be performed?

drop

if TRUE (default) then the components of the returned list are coerced to lower dimension if ntimes==1, i.e., $sample and $mixing_weights will be matrices, and $component will be vector.

Value

If drop==TRUE and ntimes==1 (default): $sample, $component, and $mixing_weights are matrices. Otherwise, returns a list with...

$sample

a size (nsimu\( x d x \)ntimes) array containing the samples: the dimension [t, , ] is the time index, the dimension [, d, ] indicates the marginal time series, and the dimension [, , i] indicates the i:th set of simulations.

$component

a size (nsimu\( x \)ntimes) matrix containing the information from which mixture component each value was generated from.

$mixing_weights

a size (nsimu\( x M x \)ntimes) array containing the mixing weights corresponding to the sample: the dimension [t, , ] is the time index, the dimension [, m, ] indicates the regime, and the dimension [, , i] indicates the i:th set of simulations.

Details

The argument ntimes is intended for forecasting: a GMVAR process can be forecasted by simulating it's possible future values. One can easily perform a large number simulations and calculate the sample quantiles from the simulated values to obtain prediction intervals (see the forecasting example).

References

  • Kalliovirta L., Meitz M. and Saikkonen P. 2016. Gaussian mixture vector autoregression. Journal of Econometrics, 192, 485-498.

Examples

Run this code
# NOT RUN {
 
# }
# NOT RUN {
 # These examples use the data 'eurusd' which comes with the
 # package, but in a scaled form.
 data <- cbind(10*eurusd[,1], 100*eurusd[,2])
 colnames(data) <- colnames(eurusd)

 # GMVAR(1,2), d=2 process, initial values from the stationary
 # distribution
 params122 <- c(0.623, -0.129, 0.959, 0.089, -0.006, 1.006, 1.746,
  0.804, 5.804, 3.245, 7.913, 0.952, -0.037, -0.019, 0.943, 6.926,
  3.982, 12.135, 0.789)
 mod122 <- GMVAR(p=1, M=2, d=2, params=params122)
 set.seed(1)
 sim122 <- simulateGMVAR(mod122, nsimu=500)
 plot.ts(sim122$sample)
 ts.plot(sim122$mixing_weights, col=c("blue", "red"), lty=2)
 plot(sim122$component, type="l")

 ## FORECASTING EXAMPLE
 # Forecast 5-steps-ahead, 10000 sets of simulations with initial
 # values from the data:
 # GMVAR(2,2), d=2 model with mean-parametrization:
 params222 <- c(-11.904, 154.684, 1.314, 0.145, 0.094, 1.292, -0.389,
  -0.070, -0.109, -0.281, 0.920, -0.025, 4.839, 11.633, 124.983, 1.248,
   0.077, -0.040, 1.266, -0.272, -0.074, 0.034, -0.313, 5.855, 3.570,
   9.838, 0.740)
 mod222 <- GMVAR(data, p=2, M=2, params=params222, parametrization="mean")
 sim222 <- simulateGMVAR(mod222, nsimu=5, ntimes=10000)

 # Point forecast + 95% prediction intervals:
 apply(sim222$sample, 1:2, quantile, probs=c(0.025, 0.5, 0.972))

 # Similar forecast for the mixing weights:
 apply(sim222$mixing_weights, 1:2, quantile, probs=c(0.025, 0.5, 0.972))


 # GMVAR(2,2), d=2 model with AR parameters restricted to be
 # the same for both regimes, custom inital values:
 C_mat <- rbind(diag(2*2^2), diag(2*2^2))
 params222c <- c(1.031, 2.356, 1.786, 3.000, 1.250, 0.060, 0.036,
  1.335, -0.290, -0.083, -0.047, -0.356, 0.934, -0.152, 5.201, 5.883,
  3.560, 9.799, 0.368)
 mod222c <- GMVAR(data, p=2, M=2, params=params222c, constraints=C_mat)
 sim222c <- simulateGMVAR(mod222c, nsimu=100,
              init_values=matrix(c(30, 30, 80, 80), nrow=2))
 plot.ts(sim222c$sample)
 ts.plot(sim222c$mixing_weights, col=c("blue", "red"), lty=2)
 plot(sim222c$component, type="l")
 
# }

Run the code above in your browser using DataLab