Path: blob/master/inst/tests/test_objectives.R
1433 views
1require(testthat)2require(PortfolioAnalytics)34context("objectives")56N <- 47init.portf <- portfolio.spec(assets=N)8init.portf <- add.objective(portfolio=init.portf, type="return", name="mean", target=0.005)9init.portf <- add.objective(portfolio=init.portf, type="risk", name="ES", arguments=list(p=0.95))10init.portf <- add.objective(portfolio=init.portf, type="risk_budget", name="ES")1112test_that("return objective is consistent", {13expect_that(init.portf$objectives[[1]]$name, equals("mean"))14expect_that(init.portf$objectives[[1]]$target, equals(0.005))15expect_that(init.portf$objectives[[1]]$enabled, is_true())16expect_that(init.portf$objectives[[1]]$multiplier, equals(-1))17expect_that(class(init.portf$objectives[[1]]), equals(c("return_objective", "objective")))18})1920test_that("risk objective is consistent", {21expect_that(init.portf$objectives[[2]]$name, equals("ES"))22expect_that(is.null(init.portf$objectives[[2]]$target), is_true())23expect_that(init.portf$objectives[[2]]$arguments$portfolio_method, equals("single"))24expect_that(init.portf$objectives[[2]]$arguments$p, equals(0.95))25expect_that(init.portf$objectives[[2]]$enabled, is_true())26expect_that(init.portf$objectives[[2]]$multiplier, equals(1))27expect_that(class(init.portf$objectives[[2]]), equals(c("portfolio_risk_objective", "objective")))28})2930test_that("risk objective is consistent", {31expect_that(init.portf$objectives[[3]]$name, equals("ES"))32expect_that(is.null(init.portf$objectives[[3]]$target), is_true())33expect_that(init.portf$objectives[[3]]$arguments$portfolio_method, equals("component"))34expect_that(init.portf$objectives[[3]]$enabled, is_true())35expect_that(init.portf$objectives[[3]]$multiplier, equals(1))36expect_that(init.portf$objectives[[3]]$min_concentration, is_true())37expect_that(init.portf$objectives[[3]]$min_difference, is_false())38expect_that(class(init.portf$objectives[[3]]), equals(c("risk_budget_objective", "objective")))39})404142