inst/testme/test-futurize-rugarch.R

#' @tags pkg-rugarch
if (requireNamespace("rugarch") && getRversion() >= "4.4.0") {
library(futurize)
library(rugarch)
fcns <- tryCatch({
  futurize::futurize_supported_functions("rugarch")
}, error = identity)
print(fcns)
stopifnot(is.character(fcns), length(fcns) > 0L)
options(future.rng.onMisuse = "error")

plan(multisession)

#------------------------------------------------------------------
# ugarchroll()
#------------------------------------------------------------------
message("ugarchroll() ...")

data(sp500ret, package = "rugarch")
spec <- ugarchspec()

## Small example to keep it fast
sp500ret_small <- sp500ret[1:100, , drop = FALSE]
n_start <- 50

set.seed(42)
roll_truth <- ugarchroll(spec, sp500ret_small, n.start = n_start, refit.window = "moving", refit.every = 25)
print(roll_truth)

set.seed(42)
roll <- ugarchroll(spec, sp500ret_small, n.start = n_start, refit.window = "moving", refit.every = 25) |> futurize_and_verify()
print(roll)

## rugarch objects might have some environment or pointer differences, 
## but let's see if all.equal works.
roll@model$elapsed <- NULL
roll_truth@model$elapsed <- NULL
roll@model$con_Args$cluster <- NULL
roll_truth@model$con_Args$cluster <- NULL
stopifnot(all.equal(roll, roll_truth))

message("ugarchroll() ... done")

plan(sequential)
}

Try the futurize package in your browser

Any scripts or data that you put into this service are public.

futurize documentation built on Oct. 20, 2026, 1:06 a.m.