Skip to content

Commit

Permalink
some fixed to clear cran warnings for Mac M1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiosg committed Apr 28, 2024
1 parent 8552ebc commit 338f9bb
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 73 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: tsgarch
Type: Package
Title: Univariate GARCH Models
Version: 1.0.0
Version: 1.0.1
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
LinkingTo: Rcpp (>= 0.10.6), RcppArmadillo, TMB(>= 1.7.20), RcppEigen
Imports: TMB (>= 1.7.20), Rcpp, nloptr, Rdpack, numDeriv, xts, zoo, future.apply, future, progressr, flextable, stats, utils, data.table, tsdistributions, lubridate, sandwich
Description: Multiple flavors of the Generalized Autoregressive Conditional Heteroscedascity (GARCH) model with a large choice of conditional distributions. Methods for specification, estimation, prediction, filtering, statistical testing and much more. Represents a partial re-write and re-think of 'rugarch', making use of automatic differentiation for estimation.
Description: Multiple flavors of the Generalized Autoregressive Conditional Heteroskedasticity (GARCH) model with a large choice of conditional distributions. Methods for specification, estimation, prediction, filtering, simulation, statistical testing and more. Represents a partial re-write and re-think of 'rugarch', making use of automatic differentiation for estimation.
License: GPL-2
Encoding: UTF-8
LazyData: true
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# tsgarch 1.0.1

* Moved a couple of unit tests to other folder to avoid checking on CRAN
since the M1 mac had different rounding errors than other architectures
for simulation tests.


# tsgarch 1.0.0

* Initial CRAN submission.
Expand Down
3 changes: 3 additions & 0 deletions man/plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/plot.tsgarch.estimate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/tsgarch-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/TMB/tsgarch_TMBExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Type objective_function<Type>::operator() () {
} else if(model == "fgarchjacobian"){
return fgarchjac(this);
} else {
Rf_error("Unknown model.");
Rf_error("Unknown model.");
}
return 0;
}
69 changes: 69 additions & 0 deletions tests/longtests/test-simulation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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)

})

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)
})

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)
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)
})

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)

})
69 changes: 0 additions & 69 deletions tests/testthat/test-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ test_that("cgarch(1,1) simulation: validate algoritm",{
order = c(1,1), vreg = y[1:1800,2], multiplicative = TRUE,
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"])
Expand All @@ -142,72 +141,4 @@ 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)

})

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)
})

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)
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)
})

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 338f9bb

Please sign in to comment.