MatthieuStigler / tsDyn

tsDyn
tsdyn.googlecode.com
GNU General Public License v2.0
34 stars 20 forks source link

Issue with predict_rolling(VAR) for n.ahead >1 #31

Open MatthieuStigler opened 3 years ago

MatthieuStigler commented 3 years ago

predict_rolling(VAR) for n.ahead >1 does not give expected result...

library(tsDyn)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
data(zeroyld)

fit_var <- lineVar(zeroyld, lag = 1, include = "const", model = "VAR")
predicted_values_h1 <- predict_rolling(fit_var, nroll = 20, refit = 1, n.ahead = 1)$pred
predicted_values_h2 <- predict_rolling(fit_var, nroll = 20, refit = 1, n.ahead = 2)$ pred

pre_manu_h1 <- predict(lineVar(zeroyld[1:(nrow(zeroyld)-20),], lag = 1, include = "const", model = "VAR"), n.ahead=1)
pre_manu_h2 <- predict(lineVar(zeroyld[1:(nrow(zeroyld)-20),], lag = 2, include = "const", model = "VAR"), n.ahead=1)

## Ok for n.ahead=1
all.equal(predicted_values_h1[1,],
          as.data.frame(pre_manu_h1), check.attributes=FALSE)
#> [1] TRUE

## NOT Ok for n.ahead=2 !?
all.equal(predicted_values_h2[1,],
          as.data.frame(pre_manu_h2), check.attributes=FALSE)
#> [1] "Component \"short.run\": Mean relative difference: 0.05865474"
#> [2] "Component \"long.run\": Mean relative difference: 0.09535"

Created on 2021-03-15 by the reprex package (v1.0.0)

Rfileforme88 commented 3 years ago

I am unable to get TVAR GIRF . Kindly help . Thanks and Regards.

head(cakanew) ka ca ir er 1996 Q1 0.03037077 -0.022070407 0.6773027 0.09978520 1996 Q2 0.03109329 -0.011231042 1.0431002 0.12984630 1996 Q3 0.02848449 -0.011109047 0.7786335 0.10633241 1996 Q4 0.02383186 -0.000525194 0.9014583 0.10599754 1997 Q1 0.04063935 -0.013199869 1.1963604 0.09695199 1997 Q2 0.01605832 0.001871578 0.6120771 0.11383574 exampleTVAR <- TVAR(cakanew, lag=2, nthresh=1, thDelay=1, mTh=1, plot=FALSE) Best unique threshold 0.02656121 saved_girfs <- GIRF(exampleTVAR, c(0,0,0,4), H = 10, R = 10) summary(saved_girfs) Length Class Mode 0 NULL NULL plot(saved_girfs) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf