context("Monthly periods")
load_data <- function() {
h <- new.env()
load("testdata/history.RData",envir=h)
return(get("history",envir=h))
}
test_that("monthly adjusted works", {
h <- load_data()
XLE <- get("XLE",envir=h)
rv <- monthly_ad(XLE)
fv <- as.numeric(xts::last(rv))
expect_gt(fv,74.5)
expect_lt(fv,74.6)
})
test_that("monthly adjusted errors",{
expect_error(monthly_ad(NA))
})
test_that("monthly returns defaults",{
h <- load_data()
rv <- monthly_returns(c("XLE","XLK"),env=h,n_roc=1)
expect_equal(ncol(rv),2)
expect_equal(nrow(rv),25)
rv <- xts::last(rv)
fv <- as.numeric(rv[1,2])
expect_gt(fv,0.037)
expect_lt(fv,0.039)
})
test_that("monthly returns paramter",{
h <- load_data()
rv <- monthly_returns(c("XLE","XLK"),env=h,n_roc=3)
expect_equal(ncol(rv),2)
expect_equal(nrow(rv),25)
rv <- xts::last(rv)
fv <- as.numeric(rv[1,2])
expect_gt(fv,0.0)
expect_lt(fv,0.064)
})
test_that("monthly returns environment",{
expect_error(monthly_returns(c("XLE","XLK"),env="none"))
})
test_that("monthly prices works",{
h <- load_data()
rv <- monthly_prices(c("XLE","XLK"),env=h)
expect_equal(ncol(rv),2)
expect_equal(nrow(rv),25)
rv <- xts::last(rv)
fv <- as.numeric(rv[1,2])
expect_gt(fv,50.1)
expect_lt(fv,50.3)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.