Skip to content

Commit

Permalink
fix to unit test for M1 mac
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiosg committed May 2, 2024
1 parent 338f9bb commit 4dfa604
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 70 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tsgarch
Type: Package
Title: Univariate GARCH Models
Version: 1.0.1
Version: 1.0.2
Authors@R: c(person("Alexios", "Galanos", role = c("aut", "cre","cph"), email = "alexios@4dscape.com"))
Maintainer: Alexios Galanos <alexios@4dscape.com>
Depends: R (>= 3.5.0), methods, tsmethods
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# tsgarch 1.0.2

* Moved a unit tests back to original folder and added a tolerance
to the expectation per CRAN maintainers directions.

# tsgarch 1.0.1

* Moved a couple of unit tests to other folder to avoid checking on CRAN
Expand Down
69 changes: 0 additions & 69 deletions tests/longtests/test-simulation.R

This file was deleted.

68 changes: 68 additions & 0 deletions tests/testthat/test-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,72 @@ test_that("cgarch(1,1) simulation: validate algoritm",{
expect_equal(sim$sigma[1,], local_mod_cgarch$sigma)
})

test_that("cgarch(2,1) simulation: validate algoritm",{
local_spec_cgarch <- garch_modelspec(y[1:1800,1], constant = TRUE, model = "cgarch",
order = c(2,1), vreg = y[1:1800,2],
distribution = "norm")
local_mod_cgarch <- suppressWarnings(estimate(local_spec_cgarch))
spec <- copy(local_spec_cgarch)
spec$parmatrix <- copy(local_mod_cgarch$parmatrix)
v <- c(as.numeric(y[1:1800,2]) * coef(local_mod_cgarch)["xi1"])
z <- matrix(as.numeric(residuals(local_mod_cgarch, standardize = TRUE)), nrow = 1)
sim <- simulate(spec, nsim = 1, h = length(spec$target$y_orig),
var_init = rep(global_mod_cgarch$var_initial,2),
innov = z, vreg = v)
expect_equal(sim$sigma[1,], local_mod_cgarch$sigma, tolerance = 1e-6)

})

test_that("egarch(1,1) simulation: validate algoritm",{
spec <- copy(global_spec_garch)
spec$parmatrix <- copy(global_mod_garch$parmatrix)
v <- c(as.numeric(y[1:1800,2]) * coef(global_mod_garch)["xi1"])
z <- matrix(as.numeric(residuals(global_mod_garch, standardize = TRUE)), nrow = 1)
# use fixed innovation and replicate the initial conditions to guarantee a deterministic
# simulation which serves to validate the algorithm for correctness and reproducability
sim <- simulate(spec, nsim = 1, h = length(spec$target$y_orig),
var_init = global_mod_garch$var_initial,
innov = z, vreg = v,
arch_initial = global_mod_garch$arch_initial)
expect_equal(sim$sigma[1,], global_mod_garch$sigma, tolerance = 1e-6)
})

test_that("simulate norm: same seed same output",{
spec <- copy(global_spec_garch)
spec$parmatrix <- copy(global_mod_garch$parmatrix)
maxpq <- max(spec$model$order)
v_init <- as.numeric(tail(sigma(global_mod_garch)^2, maxpq))
i_init <- as.numeric(tail(residuals(global_mod_garch),maxpq))
simulate_spec1 <- simulate(spec, nsim = 100, seed = 101, h = 10, var_init = v_init,
innov_init = i_init, vreg = y[1801:1810,2])
simulate_spec2 <- simulate(spec, nsim = 100, seed = 101, h = 10, var_init = v_init,
innov_init = i_init, vreg = y[1801:1810,2])
expect_equal(simulate_spec1$series,simulate_spec2$series, tolerance = 1e-6)
expect_equal(NROW(simulate_spec1$series),100)
expect_equal(NCOL(simulate_spec1$series),10)
expect_s3_class(simulate_spec1, class = "tsgarch.simulate")
expect_s3_class(simulate_spec1$sigma, class = "tsmodel.distribution")
})

test_that("simulate ghst: same seed same output",{
spec <- global_spec_garch_jsu
spec$parmatrix <- copy(global_mod_garch_jsu$parmatrix)
maxpq <- max(spec$model$order)
v_init <- as.numeric(tail(sigma(global_mod_garch_jsu)^2, maxpq))
i_init <- as.numeric(tail(residuals(global_mod_garch_jsu),maxpq))
simulate_spec1 <- simulate(spec, nsim = 100, seed = 101, h = 10, var_init = v_init,
innov_init = i_init, vreg = y[1801:1810,2])
simulate_spec2 <- simulate(spec, nsim = 100, seed = 101, h = 10, var_init = v_init,
innov_init = i_init, vreg = y[1801:1810,2])
expect_equal(simulate_spec1$series,simulate_spec2$series, tolerance = 1e-6)
})

test_that("simulation: long run variance check",{
spec_garch <- garch_modelspec(y = y[1:1800,1], constant = TRUE, model = "garch")
sim <- simulate(spec_garch, nsim = 1, h = 25000, seed = 77, burn = 100)
expect_equal(mean(sim$sigma[1,]^2), unconditional(spec_garch), tolerance = 0.01)
spec_egarch <- garch_modelspec(y = y[1:1800,1], constant = TRUE, model = "egarch")
sim <- simulate(spec_egarch, nsim = 1, h = 25000, seed = 727, burn = 100)
expect_equal(mean(sim$sigma[1,]^2), unconditional(spec_egarch), tolerance = 0.1)

})

0 comments on commit 4dfa604

Please sign in to comment.