Nothing
library(testthat)
context("presentValue")
test_that("presentValue computes simple discounted sum correctly", {
cf <- c(10, 10, 10)
t <- c(1, 2, 3)
i <- 0.03
expected <- sum(cf * (1 + i) ^ (-t))
result <- presentValue(cashFlows = cf, timeIds = t, interestRates = i, probabilities = c(1,1,1))
expect_equal(result, expected)
})
test_that("presentValue works with vector interestRates and missing probabilities", {
cf <- c(5, 15, 20)
t <- c(1, 2, 3)
i_vec <- rep(0.04, length(t))
expected <- sum(cf * (1 + i_vec) ^ (-t))
# omit probabilities (should assume ones)
result <- presentValue(cashFlows = cf, timeIds = t, interestRates = i_vec)
expect_equal(result, expected)
})
test_that("presentValue errors on mismatched lengths", {
cf <- c(10,20)
t <- c(1,2,3)
i <- 0.03
expect_error(presentValue(cashFlows = cf, timeIds = t, interestRates = i))
expect_error(presentValue(cashFlows = c(1,2,3), timeIds = c(1,2,3), interestRates = i, probabilities = c(1,1)))
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.