VARsim: Simulates vector autoregressive (VAR) series

Description Usage Arguments Value Examples

View source: R/VARsim.R

Description

This function simulates VAR(p) series. For quick use, the function can use the estimated model returned by VARfit or VAR as the DGP (Data Generating Process), if passed to the fittedModel argument.

Usage

1
2
VARsim(N = 200, K = 2, p = 1, const = TRUE, trend = FALSE, exogen = NULL, 
       coef = NULL, dist = "normal", Ystart = NULL, errors = NULL, fittedModel = NULL)

Arguments

N

The length of the series.

K

The number of series/equations.

p

The lag length of the VAR(p).

const

if TRUE, a constant will be used.

trend

if TRUE, a trend will be used.

exogen

a matrix of exogenous variables. Should either have N or (N - p number of rows. If the latter, the last row will be matched with the last row of the simulated series y.

coef

a matrix of coefficients. E.g. a 2 dimensional VAR(2) with a constant, a trend and one exogenous variable must be entered in the following order (the same as returned by VARfit):

___y1_______y2___ | const | const | | trend | trend | | exo1 | exo1 | | y1[-1] | y1[-1] | | y2[-1] | y2[-1] | | y1[-2] | y1[-2] | | y2[-2] | y2[-2] | -----------------

dist

the distribution of the error terms (currently only "normal" for i.i.d. standard normal.)

Ystart

a p x K matrix of the start values. These will be present in the simulated series. If NULL, the start values will be set to zero.

errors

(optional) a matrix of error terms. If supplied, VARsim() will use those instead of sampling the errors. Must have K columns and either N or (N - p) number of rows. If the latter, the last row will be matched with the last row of the simulated series y.

fittedModel

(optional) either an object of class "vars", as returned by VAR, or an object of class "VARfit", as returned by VARfit. If used, the estimated model of the fittedModel will be used as a DGP (Data Generating Process). Unless the arguments N, exogen and/or Ystart were supplied, they too will be taken from the fittedModel object.

Value

an N x K matrix of the simulated VAR(p).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Simulates from a fitted DGP:
fit <- VARfit(y = VodafoneCDS, p = 1, const = TRUE)
y <- VARsim(fittedModel = fit)
VARfit(y = y, p = 1, const = TRUE)

# Simulates from user given parameters. 
#  Includes an exogenous variable:
VARcoef <- matrix(c(1,     2,
                    1,   0.5,
                    0.1,  0.3,
                    0.2,  0.5), 
                  ncol = 2, byrow = TRUE)
exo <- matrix(rnorm(500))
y <- VARsim(N = 500, K = 2, p = 1, const = TRUE, 
            trend = FALSE, exogen = exo,
            coef = VARcoef, dist = "normal")
VARfit(y = y, p = 1, const = TRUE, exogen = exo)

## Not run: 



## End(Not run)

VARtests documentation built on May 2, 2019, 5:03 a.m.

Related to VARsim in VARtests...