Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/inst/tests/test_demo_weight_concentration.R
1433 views
1
2
##### Load packages #####
3
require(testthat)
4
require(PortfolioAnalytics)
5
6
##### Source Demo Script #####
7
source(system.file("demo/demo_weight_concentration.R", package="PortfolioAnalytics"))
8
9
context("weight concentration objective")
10
11
test_that("conc.portf contains weight_concentration as an objective",
12
{ expect_that(inherits(conc.portf$objectives[[2]], "weight_concentration_objective"), is_true()) })
13
14
test_that("conc.portf contains weight_concentration as an objective",
15
{ expect_that(conc.portf$objectives[[2]]$name == "HHI", is_true()) })
16
17
test_that("conc.portf contains weight_concentration as an objective with conc_aversion=0",
18
{ expect_equal(opt2$portfolio$objectives[[2]]$conc_aversion, rep(0, 4)) })
19
20
test_that("minimum variance and conc.portf weights are equal with conc_aversion=0",
21
{ expect_equal(opt1$weights, opt2$weights) })
22
23
test_that("conc.portf with conc_aversion=1e6 results in an equal weight portfolio",
24
{ expect_equal(as.numeric(opt4$weights), rep(1 / 8, 8)) })
25
26
27