Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VECM.sim starting values #34

Open
gergelybat opened this issue Oct 22, 2021 · 3 comments
Open

VECM.sim starting values #34

gergelybat opened this issue Oct 22, 2021 · 3 comments
Labels

Comments

@gergelybat
Copy link

gergelybat commented Oct 22, 2021

Hello,

I am fitting a VECM(lag=1) model with 2 variables, and than I run simulations using parameters of that model.
My starting values for the simulation should be the last values of the original series.

According to the error messages of TVECM.sim starting values "Should have nrow = lag and ncol = number of variables".
So I provide a 1 x 2 matrix as a starting value (I take the last row of the original timeseries).

In the results of the simulation I can see:

  • in the first row my original starting values
  • in the second row: 0, 0
  • from the third row the simulation begins, but that second row with zeros makes the simulation unrealistic.

I've checked the code of TVECM.sim, and it seems, that indeed simulations begins from i=lag+2.
I believe the problem is, that starting values should have rather lag+1 x k dimensions instead of lag x k dimensions.

I was able to make my simulation realistic by changing 2 rows in TVECM.sim function (but please don't assume it's a sure fix, I'm just rather following what dim
VECMsim_unrealistic_simulation.R.txt
ensions of matrices suggest).

The changes are in the initialization of simulation (changing p -> p+1):

if (!is.null(starting)) {
            if (all(dim(as.matrix(starting)) == c(nB, p+1))) 
                y[seq_len(p+1), ] <- starting
            else stop("Bad specification of starting values. Should have nrow = lag+1 and ncol = number of variables")
}

I have no issues simulating VAR models (VAR.sim).
Converting VECM models to VAR (VARrep function) and then using VAR.sim also works.

Attached is an example of fitting VECM than simulating.
EDIT: x4 should be x2 in the attached code (I'm not able to modify attachment).

Than you,
Greg

VECMsim_unrealistic_simulation.R.txt

@MatthieuStigler
Copy link
Owner

Hi, thanks for reporting this. Can you please post instead a reprex, in particular with the TVECM code you have issues with?

Thanks

@gergelybat
Copy link
Author

library(tsDyn)
#> Warning: package 'tsDyn' was built under R version 3.6.3
#> Registered S3 method overwritten by 'xts':
#> method from
#> as.zoo.xts zoo
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
set.seed(1234)
N <- 1000
x1 <- cumsum(rnorm(N))
x2 <- 3*x1 + rnorm(N)
m_lineVar <- tsDyn::lineVar(cbind(x1,x2), lag=1, include="none", model="VECM")
VECM.sim(B=coef(m_lineVar), beta=coefB(m_lineVar), lag=m_lineVar$lag, include=m_lineVar$include, varcov=var(m_lineVar$residuals), starting=(m_lineVar$model[1000,1:2]), n=4)
#> [,1] [,2]
#> [1,] -26.5972 -80.9821
#> [2,] 0.0000 0.0000
#> [3,] -0.2882 -0.4300
#> [4,] -0.3958 -0.0310

@MatthieuStigler
Copy link
Owner

ok, thanks! I'll have ot check this, might take some time unfortunately.
Thanks for reporting!

Repository owner deleted a comment from Rfileforme88 Oct 27, 2021
Repository owner deleted a comment from Rfileforme88 Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants