# [R-SIG-Finance] Problem understanding the code of dse::simulate

Paul Gilbert pgilbert902 at gmail.com
Sun Jan 24 14:33:47 CET 2016

```On 01/22/2016 11:17 AM, Degang WU wrote:
> Hi, I want to simulate a VAR process using the following code
> library(dse) AR   <- array(c(1, .5, .3, 0, .2, .1, 0, .2, .05, 1, .5,
> .3) ,c(3,2,2)) VAR  <- ARMA(A=AR, B=diag(1,2)) print(VAR) simData <-
> simulate(VAR) Inside dse::simulate:
>
> if (p == 1) invA0 <- matrix(1/A[1, , ], 1, 1) else invA0 <-
> solve(A[1, , ]) for (l in 1:a) A[l, , ] <- invA0 %*% A[l, , ] for (l
> in 1:b) B[l, , ] <- invA0 %*% B[l, , ]
>
> Where A[,,,] are the coefficient matrix for the process. I have no
> idea why the inverse of A[1, ,] is involved in the simulation.

Degang

In response to your previous question I said the dse specification is

y_t + A_1 y_{t-1} + A_2 y_{t-2} + .. A_p y_{t-p} = e_t (2)

but that is the form corresponding to your specification. In general,
VAR models can be written

A_0 y_t + A_1 y_{t-1} + A_2 y_{t-2} + .. A_p y_{t-p} = e_t (3)

In your specification A_0 is the identity matrix. For simulation it is
convenient to re-write (3) as

y_t = (A_0)^-1 (-A_1 y_{t-1} - A_2 y_{t-2} - ... - A_p y_{t-p} + e_t)

R indexes arrays starting with 1, so A_0 is stored in A[1,,]. If A_0 is
the identity, as in your specification, the inverse will also be
identity and the multiplication is not necessary.

Paul
>
> Thanks!
>
> Regards, Degang [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance --
> Subscriber-posting only. If you want to post, subscribe first. --
> Also note that this is not the r-help list where general R questions
> should go.
>

```

More information about the R-SIG-Finance mailing list