[R-SIG-Finance] var_cp_test in tsmodels/tstests returns subscript out of bounds error
Ayla
@y|@@@ug@t @end|ng |rom goog|em@||@com
Wed Jul 12 09:27:42 CEST 2023
Dear contributors, dear Alexios Galanos,
as suggested by Alexios I'm using the var_cp_test from the tsmodels/tstests
package over the VaRTest in the rugarch package to backtest a calculated
value of risk vector against my log returns.
This works well in most cases.
However, in some situations, the test returns an subscript out of bounds
error. I found an example where the test returns no error for the full
vector of VaRs and log returns but when I perform the test without the
first value in the vector, it returns an error. There is no obvious reason
why.
Data for the example can be found here:
https://drive.google.com/file/d/1na5w-15U70RtRA6Mh2jpytDDCafacYHG/view?usp=sharing
This is my code:
```
if(!("tstests" %in% installed.packages())){
remotes::install_github("tsmodels/tstests", dependencies = TRUE)
}
library(tstests)
## load the data
current_path = rstudioapi::getActiveDocumentContext()$path
project_folder = dirname(current_path) # define the project folder
path
setwd(project_folder) # change current working directory
filename =
paste("report_bug_var_cp_test_subscript_out_of_bounds.csv",sep="")
df_bug = read.csv(file = filename)
rownames(df_bug) = df_bug[,1]
df_bug[,1] = NULL
## select forecast and actuals
forecast = df_bug[1:nrow(df_bug),"VaR"]
actual = df_bug[1:nrow(df_bug),"log_returns"]
## run the var_cp_test with full data
var_cp_test(
actual=as.numeric(actual),
forecast=as.numeric(forecast),
alpha=(1-0.99),
)
## run the var_cp_test with all data but first values
forecast = df_bug[2:nrow(df_bug),"VaR"]
actual = df_bug[2:nrow(df_bug),"log_returns"]
var_cp_test(
actual=as.numeric(actual),
forecast=as.numeric(forecast),
alpha=(1-0.99),
)
## error message:
# Error in `[.default`(tab, 2, 2) : subscript out of bounds
```
Thanks a lot in advance!
Best,
Ayla
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list