context("Symbol rank")
load_data <- function() {
h <- new.env()
load("testdata/history.RData",envir=h)
return(get("history",envir=h))
}
test_that("monthly rank works", {
h <- load_data()
mp <- monthly_prices(c("XLE","XLK"),h)
colnames(mp) <- gsub(".Adjusted",".Rank",colnames(mp))
symbol_rank_monthly(c("XLK","XLE"),mp,h)
fv <- as.numeric(xts::last(get("XLE",envir=h)))
expect_gt(fv[1],76.1)
expect_lt(fv[1],76.2)
})
test_that("monthly rank empty list", {
expect_error(symbol_rank_monthly(c()))
expect_error(symbol_rank_monthly(c("XLP"),rank_obj = NA))
})
test_that("daily rank works", {
h <- load_data()
pv <- get("XLE",envir=h)
pv$Rank <- 4
symbol_rank_daily("XLE",pv$Rank,h)
fv <- as.numeric(xts::last(get("XLE",envir=h)))
expect_gt(fv[1],74.0)
expect_lt(fv[1],74.1)
})
test_that("daily rank empty list", {
expect_error(symbol_rank_daily(c()))
expect_error(symbol_rank_daily(c("XLP"),rank_obj = NA))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.