diff options
Diffstat (limited to 'tests/testthat/test_lossdistrib.R')
| -rw-r--r-- | tests/testthat/test_lossdistrib.R | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/tests/testthat/test_lossdistrib.R b/tests/testthat/test_lossdistrib.R index 074cbf2..6550852 100644 --- a/tests/testthat/test_lossdistrib.R +++ b/tests/testthat/test_lossdistrib.R @@ -1,26 +1,36 @@ -library(lossdistrib) -p <- runif(1000) -S <- runif(1000) -issuer.weights <- rep(1/1000,1000) +test_that("gaussian quadrature", { + temp <- GHquad(100) + expect_equal(length(temp$Z), 100) + expect_equal(length(temp$w), 100) + expect_equal(as.numeric(crossprod(temp$w, temp$Z)), 0) + ##expectation of a log normal + expect_equal(as.numeric(crossprod(temp$w, exp(temp$Z))), exp(0.5)) +}) -run1 <- system.time(for(i in 1:1000){ - lossdistC(p, issuer.weights, S, 301) +test_that("loss distribution", { + p <- runif(100) + S <- runif(100) + w <- runif(100) + w <- w/sum(w) + N <- 101 + expect_equal(lossdistC(p, w, S, N), lossdistrib2(p, w, S, N)) + expect_equal(lossdistC(p, w, S, N, TRUE), lossdistrib2(p, w, S, N, TRUE)) + expect_equal(length(lossdistC(p, w, S, N)), N) }) -cat("simple lossdist", run1["elapsed"], "\n") -S <- matrix(runif(1000*500), 1000, 500) -rho <- rep(0.45, 1000) -temp <- GHquad(500) -Z <- temp$Z -w <- temp$w +## S <- matrix(runif(1000*500), 1000, 500) +## rho <- rep(0.45, 1000) +## temp <- GHquad(500) +## Z <- temp$Z +## w <- temp$w -test <- lossdistCZ(p, issuer.weights, S, 301, FALSE, rho, Z) -p <- matrix(runif(100*25), 100, 25) -issuer.weights <- rep(1/100, 100) -S <- runif(100) +## test <- lossdistCZ(p, issuer.weights, S, 301, FALSE, rho, Z) +## p <- matrix(runif(100*25), 100, 25) +## issuer.weights <- rep(1/100, 100) +## S <- runif(100) -cat("I'm here") -rho <- rep(0.45, 100) -test <- BClossdistC(p, issuer.weights, 1-S, rho, temp$Z, temp$w) -# the blas function should be roughly twice as fast -cat("blas lossdist", run2["elapsed"], "\n") +## cat("I'm here") +## rho <- rep(0.45, 100) +## test <- BClossdistC(p, issuer.weights, 1-S, rho, temp$Z, temp$w) +## # the blas function should be roughly twice as fast +## cat("blas lossdist", run2["elapsed"], "\n") |
