tests/testthat/test_for_stoch_oscilator_strategy_back_test.R

library(PawelKawskiPackage)
context("stoch_oscilator_strategy_back_test properties")

test_that(" investment_size <= 0 results in an error", {
  expect_error(stoch_oscilator_strategy_back_test("GOOG", 10000, -0.04, "2010-01-01", "2017-05-01"),
               "investment_size has to be positive number")
})
test_that(" investment_size > 0.05 results in an error", {
  expect_error(stoch_oscilator_strategy_back_test("GOOG", 10000, 0.051, "2010-01-01", "2017-05-01"),
               "investment_size has to be less then 5% of initial_portfolio because the strategy could lead to almost instant bankruptcy")
})
A <- grepl("Error in sprintf",try(stoch_oscilator_strategy_back_test("GOOG", 10000, 0.03, "2017-03", "2017-05-01"),
                       silent = TRUE)[1])
test_that(" start_date in wrong format like \"2017-03\" results in an error", {
  expect_equal(A, TRUE)
})
test_that(" symbol which is not character value results in an error", {
  expect_error(stoch_oscilator_strategy_back_test(7, 10000, 0.03, "2017-03-03", "2017-05-01"),
               "symbol is not a character vector")
})
test_that(" initial_portfolio < 5000 results in an error", {
  expect_error(stoch_oscilator_strategy_back_test("GOOG", 4999, 0.04, "2010-01-01", "2017-05-01"),
               "initial_portfolio has to to be greater then 5000 USD because(.|\n)*with less capital we should not invest on the US stock market")
})

B <-  grepl("During the investment period, the portfolio achieves the highest value at the level of:",
            stoch_oscilator_strategy_back_test("YHOO", 10000, 0.007, "2006-01-01", "2016-12-30"))
test_that(" The statement is displayed", {
  expect_equal(B, TRUE)
})
mrepsilon/PawelKawskiPackage documentation built on May 21, 2019, 2:22 p.m.