Path: blob/master/inst/tests/test_demo_weight_concentration.R
1433 views
1##### Load packages #####2require(testthat)3require(PortfolioAnalytics)45##### Source Demo Script #####6source(system.file("demo/demo_weight_concentration.R", package="PortfolioAnalytics"))78context("weight concentration objective")910test_that("conc.portf contains weight_concentration as an objective",11{ expect_that(inherits(conc.portf$objectives[[2]], "weight_concentration_objective"), is_true()) })1213test_that("conc.portf contains weight_concentration as an objective",14{ expect_that(conc.portf$objectives[[2]]$name == "HHI", is_true()) })1516test_that("conc.portf contains weight_concentration as an objective with conc_aversion=0",17{ expect_equal(opt2$portfolio$objectives[[2]]$conc_aversion, rep(0, 4)) })1819test_that("minimum variance and conc.portf weights are equal with conc_aversion=0",20{ expect_equal(opt1$weights, opt2$weights) })2122test_that("conc.portf with conc_aversion=1e6 results in an equal weight portfolio",23{ expect_equal(as.numeric(opt4$weights), rep(1 / 8, 8)) })24252627