From d472c25c5729a14009d69b265960b0362b62540d Mon Sep 17 00:00:00 2001 From: gravermistakes Date: Sun, 18 Oct 2026 22:48:15 -0700 Subject: [PATCH] M3: add statistical/tests.R --- core/src/economy/sims/statistical/tests.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 core/src/economy/sims/statistical/tests.R diff --git a/core/src/economy/sims/statistical/tests.R b/core/src/economy/sims/statistical/tests.R new file mode 100644 index 0000000..6b050ef --- /dev/null +++ b/core/src/economy/sims/statistical/tests.R @@ -0,0 +1,16 @@ +args <- commandArgs(trailingOnly=FALSE); f <- sub("^--file=", "", args[grep("^--file=", args)]) +source(file.path(dirname(normalizePath(f)), "engine.R")) +x <- gbm_terminal(100,0.05,0.2,1/252,252,20000,7) +expected <- 100*exp(0.05) +stopifnot(abs(mean(x)-expected)/expected < 0.02) +j <- merton_terminal(100,0.05,0.15,2,-0.08,0.15,1/252,252,10000,9) +kurtosis <- mean((j-mean(j))^4)/(var(j)^2) +stopifnot(kurtosis > 3) +h <- heston_terminal(100,0.04,0.03,2,0.04,0.3,-0.6,1/252,252,5000,3) +stopifnot(all(h > 0)) +set.seed(12) +r <- c(rnorm(100,0,.01), rnorm(100,0,.05)); fit <- garch11_fit(r) +stopifnot(fit$alpha >= 0, fit$beta >= 0, fit$alpha+fit$beta < 1) +p <- bounded_price_prediction(100,.03,.2,1/365,30,5000,4,"30d","TEST") +stopifnot(p$lower_bound <= p$value, p$value <= p$upper_bound) +cat("STATISTICAL TESTS PASSED\n")