Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/inst/tests/test_objectives.R
1433 views
1
2
require(testthat)
3
require(PortfolioAnalytics)
4
5
context("objectives")
6
7
N <- 4
8
init.portf <- portfolio.spec(assets=N)
9
init.portf <- add.objective(portfolio=init.portf, type="return", name="mean", target=0.005)
10
init.portf <- add.objective(portfolio=init.portf, type="risk", name="ES", arguments=list(p=0.95))
11
init.portf <- add.objective(portfolio=init.portf, type="risk_budget", name="ES")
12
13
test_that("return objective is consistent", {
14
expect_that(init.portf$objectives[[1]]$name, equals("mean"))
15
expect_that(init.portf$objectives[[1]]$target, equals(0.005))
16
expect_that(init.portf$objectives[[1]]$enabled, is_true())
17
expect_that(init.portf$objectives[[1]]$multiplier, equals(-1))
18
expect_that(class(init.portf$objectives[[1]]), equals(c("return_objective", "objective")))
19
})
20
21
test_that("risk objective is consistent", {
22
expect_that(init.portf$objectives[[2]]$name, equals("ES"))
23
expect_that(is.null(init.portf$objectives[[2]]$target), is_true())
24
expect_that(init.portf$objectives[[2]]$arguments$portfolio_method, equals("single"))
25
expect_that(init.portf$objectives[[2]]$arguments$p, equals(0.95))
26
expect_that(init.portf$objectives[[2]]$enabled, is_true())
27
expect_that(init.portf$objectives[[2]]$multiplier, equals(1))
28
expect_that(class(init.portf$objectives[[2]]), equals(c("portfolio_risk_objective", "objective")))
29
})
30
31
test_that("risk objective is consistent", {
32
expect_that(init.portf$objectives[[3]]$name, equals("ES"))
33
expect_that(is.null(init.portf$objectives[[3]]$target), is_true())
34
expect_that(init.portf$objectives[[3]]$arguments$portfolio_method, equals("component"))
35
expect_that(init.portf$objectives[[3]]$enabled, is_true())
36
expect_that(init.portf$objectives[[3]]$multiplier, equals(1))
37
expect_that(init.portf$objectives[[3]]$min_concentration, is_true())
38
expect_that(init.portf$objectives[[3]]$min_difference, is_false())
39
expect_that(class(init.portf$objectives[[3]]), equals(c("risk_budget_objective", "objective")))
40
})
41
42