tests/testthat/test-strength-sma.R

suppressPackageStartupMessages(require(quantmod))

context("Strength SMA")


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

test_that("modified parameters work", {
  h <- load_data()
  XLE <- get("XLE",envir=h)
  rv <- xts::last(strength_SMA(XLE, roc_n = 6, sigma_n = 6, sma_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_SMA(XLE, sma_n = 4, sigma_n = 10))
  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_SMA(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.