tests/testthat/test-strength-roc.R

suppressPackageStartupMessages(require(quantmod))

context("Strength ROC")

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(strength_ROC(XLE))
  expect_equal(as.numeric(Op(rv)), 6)
  expect_equal(as.numeric(Ad(rv)), 1.5)
})

test_that("modified parameters work", {
  h <- load_data()
  XLE <- get("XLE",envir=h)
  rv <- xts::last(strength_ROC(XLE, roc_n = 6, sd_n = 4))
  expect_equal(as.numeric(Op(rv)), 6)
})

test_that("flipped parameters work", {
  h <- load_data()
  XLE <- get("XLE",envir=h)
  rv <- xts::last(strength_ROC(XLE, sd_n = 4, roc_n = 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(strength_ROC(cs))
  colnames(rv) <- gsub(".Adjusted", "", colnames(rv))
  expect_equal(as.numeric(rv[1, "XLE"]), 2)
  expect_equal(as.numeric(rv[1, "XLK"]), 1)
})
greatgray/scorecard documentation built on Feb. 14, 2018, 4:28 a.m.