suppressPackageStartupMessages(require(quantmod))
context("Average 3ROC")
load_data <- function() {
h <- new.env()
load("testdata/history.RData",envir=h)
return(get("history",envir=h))
}
test_that("default parameters work", {
h <- load_data()
XLE <- get("XLE",envir=h)
rv <- xts::last(ave_3ROC(XLE))
expect_equal(as.numeric(Op(rv)), 6)
expect_equal(as.numeric(Ad(rv)), 2.5)
})
test_that("modified parameters work", {
h <- load_data()
XLE <- get("XLE",envir=h)
rv <- xts::last(ave_3ROC(XLE, n = c(2, 4, 6)))
expect_equal(as.numeric(Op(rv)), 6)
})
test_that("flipped parameters work", {
h <- load_data()
XLE <- get("XLE",envir=h)
rv <- xts::last(ave_3ROC(XLE, n = c(6, 4, 2)))
expect_equal(as.numeric(Op(rv)), 6)
})
test_that("combined symbols work", {
h <- load_data()
XLE <- get("XLE",envir=h)
XLK <- get("XLK",envir=h)
cs <- merge(Ad(XLE), Ad(XLK))
rv <- xts::last(ave_3ROC(cs))
colnames(rv) <- gsub(".Adjusted", "", colnames(rv))
expect_equal(as.numeric(rv[1, "XLE"]), 2)
expect_equal(as.numeric(rv[1, "XLK"]), 1)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.