suppressPackageStartupMessages(require(quantmod))
context("Row rank")
load_data <- function() {
h <- new.env()
load("testdata/history.RData",envir=h)
return(get("history",envir=h))
}
test_that("single column stops", {
h <- load_data()
XLE <- get("XLE",envir=h)
expect_error(xts::last(row_rank(Cl(XLE))))
})
test_that("empty argument stops", {
expect_error(row_rank())
})
test_that("multiple columns", {
h <- load_data()
XLE <- get("XLE",envir=h)
XLK <- get("XLK",envir=h)
series <- merge(Op(XLE), Op(XLK))
rv <- row_rank(series)
rv <- xts::last(coredata(rv))
expect_equal(as.numeric(rv[1]), 1)
expect_equal(as.numeric(rv[2]), 2)
})
test_that("duplicated column equal rank", {
h <- load_data()
XLE <- get("XLE",envir=h)
series <- merge(Op(XLE), Op(XLE))
colnames(series) <- c("X1", "X2")
rv <- row_rank(series)
rv <- xts::last(coredata(rv))
expect_equivalent(rv[1], rv[2])
expect_equal(as.numeric(rv[1]), 1.5)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.