[Returnanalytics-commits] r3278 - pkg/PortfolioAnalytics/inst/tests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Dec 16 00:00:18 CET 2013
Author: rossbennett34
Date: 2013-12-16 00:00:17 +0100 (Mon, 16 Dec 2013)
New Revision: 3278
Added:
pkg/PortfolioAnalytics/inst/tests/test_demo_efficient_frontier.R
pkg/PortfolioAnalytics/inst/tests/test_demo_group_constraints.R
pkg/PortfolioAnalytics/inst/tests/test_demo_leverage.R
pkg/PortfolioAnalytics/inst/tests/test_demo_max_STARR.R
pkg/PortfolioAnalytics/inst/tests/test_demo_max_qu.R
pkg/PortfolioAnalytics/inst/tests/test_demo_max_return.R
pkg/PortfolioAnalytics/inst/tests/test_demo_min_StdDev.R
pkg/PortfolioAnalytics/inst/tests/test_demo_min_expected_shortfall.R
pkg/PortfolioAnalytics/inst/tests/test_demo_return_target.R
pkg/PortfolioAnalytics/inst/tests/test_demo_risk_budgets.R
pkg/PortfolioAnalytics/inst/tests/test_demo_weight_concentration.R
pkg/PortfolioAnalytics/inst/tests/test_max_Sharpe.R
Modified:
pkg/PortfolioAnalytics/inst/tests/test_backwards_compat.R
Log:
Adding tests for demos
Modified: pkg/PortfolioAnalytics/inst/tests/test_backwards_compat.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_backwards_compat.R 2013-12-15 22:58:27 UTC (rev 3277)
+++ pkg/PortfolioAnalytics/inst/tests/test_backwards_compat.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -10,7 +10,7 @@
# class
test_that("Class of gen.constr is v1_constraint",
- { expect_that(inherits(gen.constr, "v1_constraint", is_true()) })
+ { expect_that(inherits(gen.constr, "v1_constraint"), is_true()) })
# assets
test_that("Initial assets form an equal weight portfolio",
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_efficient_frontier.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_efficient_frontier.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_efficient_frontier.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,35 @@
+
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
+##### Source Demo Script #####
+source("demo/demo_efficient_frontier.R")
+
+context("mean-var efficient frontier")
+
+test_that("meanvar.ef$frontier has 25 rows",
+ { expect_equal(nrow(meanvar.ef$frontier), 25) })
+
+test_that("colnames(meanvar.ef$frontier) are consistent",
+ { expect_equal(colnames(meanvar.ef$frontier), c("mean", "StdDev", "out", "w.CA", "w.CTAG", "w.DS", "w.EM", "w.EQM")) })
+
+test_that("first row of meanvar.ef$frontier is consistent",
+ { expect_equal(as.numeric(meanvar.ef$frontier[1,]), c(0.006765658, 0.01334460, 178.0782, 0.15, 0.15, 0.15, 0.15, 0.4)) })
+
+test_that("last row of meanvar.ef$frontier is consistent",
+ { expect_equal(as.numeric(meanvar.ef$frontier[25,]), c(0.007326513, 0.02070151, 428.5526, 0.15, 0.15, 0.15, 0.4, 0.15)) })
+
+context("mean-etl efficient frontier")
+
+test_that("meanetl.ef$frontier has 25 rows",
+ { expect_equal(nrow(meanetl.ef$frontier), 25) })
+
+test_that("colnames(meanetl.ef$frontier) are consistent",
+ { expect_equal(colnames(meanetl.ef$frontier), c("mean", "ES", "out", "w.CA", "w.CTAG", "w.DS", "w.EM", "w.EQM")) })
+
+test_that("first row of meanetl.ef$frontier is consistent",
+ { expect_equal(as.numeric(meanetl.ef$frontier[1,]), c(0.006887368, 0.02637039, 0.02637039, 0.15, 0.4, 0.15, 0.15, 0.15)) })
+
+test_that("last row of meanetl.ef$frontier is consistent",
+ { expect_equal(as.numeric(meanetl.ef$frontier[25,]), c(0.007326513, 0.04642908, 0.04642908, 0.15, 0.15, 0.15, 0.4, 0.15)) })
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_group_constraints.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_group_constraints.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_group_constraints.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,95 @@
+
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
+##### Source Demo Script #####
+source("demo/demo_group_constraints.R")
+
+##### Test the constraints #####
+context("demo_group_constraints")
+
+group_constr <- init.portf$constraints[[3]]
+
+test_that("init.portf contains groups as a constraint",
+ { expect_that(inherits(group_constr, "group_constraint"), is_true()) })
+
+test_that("group constraint for groupA is c(1, 3, 5)",
+ { expect_equal(group_constr$groups$groupA, c(1, 3, 5)) })
+
+test_that("group constraint for groupB is c(2, 4)",
+ { expect_equal(group_constr$groups$groupB, c(2, 4)) })
+
+test_that("group constraint cLO is c(0.05, 0.15)",
+ { expect_equal(group_constr$cLO, c(0.05, 0.15)) })
+
+test_that("group constraint cUP is c(0.7, 0.5)",
+ { expect_equal(group_constr$cUP, c(0.7, 0.5)) })
+
+cLO <- group_constr$cLO
+cUP <- group_constr$cUP
+
+##### ROI Optimization #####
+context("demo_group_constraints")
+
+test_that("minStdDev.ROI weights equal c(4.593895e-03, 2.540430e-01, -1.387779e-17, 4.595703e-02, 6.954061e-01)",
+ { expect_equal(extractWeights(minStdDev.ROI), c(4.593895e-03, 2.540430e-01, -1.387779e-17, 4.595703e-02, 6.954061e-01)) })
+
+test_that("minStdDev.ROI objective measure StdDev = 0.01042408",
+ { expect_equal(extractObjectiveMeasures(minStdDev.ROI)$StdDev, 0.01042408) })
+
+weights.ROI <- extractWeights(minStdDev.ROI)
+
+test_that("minStdDev.ROI group weights are calculated correctly",
+ { expect_equal(as.numeric(extractGroups(minStdDev.ROI)$group_weights),
+ c(sum(weights.ROI[c(1, 3, 5)]), sum(weights.ROI[c(2, 4)]))) })
+
+test_that("minStdDev.ROI group constraint cLO is not violated",
+ { expect_that(all(extractGroups(minStdDev.ROI)$group_weights >= cLO), is_true()) })
+
+test_that("minStdDev.ROI group constraint cUP is not violated",
+ { expect_that(all(extractGroups(minStdDev.ROI)$group_weights <= cUP), is_true()) })
+
+
+##### RP Optimization #####
+context("minStdDev.RP")
+
+test_that("minStdDev.RP weights is a numeric vector",
+ { expect_that(is.numeric(extractWeights(minStdDev.RP)), is_true()) })
+
+test_that("minStdDev.RP objective measure StdDev is numeric",
+ { expect_that(extractObjectiveMeasures(minStdDev.RP)$StdDev, is_true()) })
+
+weights.RP <- extractWeights(minStdDev.RP)
+
+test_that("minStdDev.RP group weights are calculated correctly",
+ { expect_equal(as.numeric(extractGroups(minStdDev.RP)$group_weights),
+ c(sum(weights.RB[c(1, 3, 5)]), sum(weights.RB[c(2, 4)]))) })
+
+test_that("minStdDev.RP group constraint cLO is not violated",
+ { expect_that(all(extractGroups(minStdDev.RP)$group_weights >= cLO), is_true()) })
+
+test_that("minStdDev.RP group constraint cUP is not violated",
+ { expect_that(all(extractGroups(minStdDev.RP)$group_weights <= cUP), is_true()) })
+
+
+##### DE Optimization #####
+context("minStdDev.DE")
+
+test_that("minStdDev.DE weights is a numeric vector",
+ { expect_equal(extractWeights(minStdDev.DE), is_true()) })
+
+test_that("minStdDev.DE objective measure StdDev is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minStdDev.ROI)$StdDev), is_true()) })
+
+weights.DE <- extractWeights(minStdDev.DE)
+
+test_that("minStdDev.DE group weights are calculated correctly",
+ { expect_equal(as.numeric(extractGroups(minStdDev.DE)$group_weights),
+ c(sum(weights.DE[c(1, 3, 5)]), sum(weights.DE[c(2, 4)]))) })
+
+test_that("minStdDev.DE group constraint cLO is not violated",
+ { expect_that(all(extractGroups(minStdDev.DE)$group_weights >= cLO), is_true()) })
+
+test_that("minStdDev.DE group constraint cUP is not violated",
+ { expect_that(all(extractGroups(minStdDev.DE)$group_weights <= cUP), is_true()) })
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_leverage.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_leverage.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_leverage.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,54 @@
+
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
+##### Source Demo Script #####
+source("demo/demo_leverage_exposure_constraint.R")
+
+context("dollar neutral portfolio")
+
+test_that("dollar.neutral.portf min_sum constraint is -0.01",
+ { expect_equal(dollar.neutral.portf$constraints[[1]]$min_sum, -0.01) })
+
+test_that("dollar.neutral.portf max_sum constraint is 0.01",
+ { expect_equal(dollar.neutral.portf$constraints[[1]]$max_sum, 0.01) })
+
+test_that("dollar.neutral.portf leverage exposure constraint is 2",
+ { expect_equal(dollar.neutral.portf$constraints[[3]]$leverage, 2) })
+
+test_that("dollar.neutral.portf weights is a numeric vector",
+ { expect_that(is.numeric(extractWeights(dollar.neutral.opt)), is_true()) })
+
+test_that("dollar.neutral.portf leverage exposure constraint is not violated",
+ { expect_that(sum(abs(extractWeights(dollar.neutral.opt))) <= 2, is_true()) })
+
+test_that("dollar.neutral.portf objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(dollar.neutral.opt)$mean), is_true()) })
+
+test_that("dollar.neutral.portf objective measure ES is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(dollar.neutral.opt)$ES), is_true()) })
+
+
+context("leveraged portfolio")
+
+test_that("leveraged.portf min_sum constraint is 0.99",
+ { expect_equal(leveraged.portf$constraints[[1]]$min_sum, 0.99) })
+
+test_that("leveraged.portf max_sum constraint is 1.01",
+ { expect_equal(leveraged.portf$constraints[[1]]$max_sum, 1.01) })
+
+test_that("leveraged.portf leverage exposure constraint is 1.6",
+ { expect_equal(leveraged.portf$constraints[[3]]$leverage, 1.6) })
+
+test_that("leveraged.portf weights is a numeric vector",
+ { expect_that(is.numeric(extractWeights(leveraged.portf)), is_true()) })
+
+test_that("leveraged.portf leverage exposure constraint is not violated",
+ { expect_that(sum(abs(extractWeights(leveraged.portf))) <= 1.6, is_true()) })
+
+test_that("leveraged.portf objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(leveraged.portf)$mean), is_true()) })
+
+test_that("leveraged.portf objective measure ES is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(leveraged.portf)$ES), is_true()) })
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_max_STARR.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_max_STARR.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_max_STARR.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,45 @@
+
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
+##### Source Demo Script #####
+source("demo/demo_max_STARR.R")
+
+context("demo_max_STARR")
+
+test_that("init.portf contains mean as an objective",
+ { expect_that(init.portf$objectives[[1]]$name == "mean", is_true()) })
+
+test_that("init.portf contains ES as an objective",
+ { expect_that(init.portf$objectives[[2]]$name == "ES", is_true()) })
+
+test_that("init.portf contains ES as an objective with p=0.925",
+ { expect_that(init.portf$objectives[[2]]$arguments$p == 0.925, is_true()) })
+
+##### maxSR.lo.ROI #####
+context("maxSTARR.lo.ROI")
+
+test_that("maxSTARR.lo.ROI objective measure mean = 0.006657183",
+ { expect_that(all.equal(extractObjectiveMeasures(maxSTARR.lo.ROI)$mean, 0.006657183), is_true()) })
+
+test_that("maxSTARR.lo.ROI objective measure ES = 0.01394436",
+ { expect_that(all.equal(extractObjectiveMeasures(maxSTARR.lo.ROI)$ES, 0.01394436), is_true()) })
+
+##### maxSTARR.lo.RP #####
+context("maxSTARR.lo.RP")
+
+test_that("maxSTARR.lo.RP objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxSTARR.lo.RP)$mean), is_true()) })
+
+test_that("maxSTARR.lo.RP objective measure ES is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxSTARR.lo.RP)$StdDev), is_true()) })
+
+##### maxSTARR.lo.DE #####
+context("maxSTARR.lo.DE")
+
+test_that("maxSTARR.lo.DE objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxSTARR.lo.DE)$mean), is_true()) })
+
+test_that("maxSR.lo.DE objective measure StdDev is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxSTARR.lo.DE)$StdDev), is_true()) })
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_max_qu.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_max_qu.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_max_qu.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,71 @@
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
+##### Source Demo Script #####
+source("demo/demo_max_quadratic_utility.R")
+
+context("demo_max_quadratic_utility")
+
+##### init.portf objectives #####
+context("objectives for quadratic utility")
+
+test_that("init.portf contains mean as an objective",
+ { expect_that(init.portf$objectives[[1]]$name == "mean", is_true()) })
+
+test_that("init.portf contains StdDev as an objective",
+ { expect_that(init.portf$objectives[[2]]$name == "StdDev", is_true()) })
+
+test_that("init.portf contains risk_aversion parameter equal to 4",
+ { expect_that(init.portf$objectives[[2]]$risk_aversion == 4, is_true()) })
+
+##### ROI, full_investment, long only, max qu ######
+context("maxQU.lo.ROI")
+
+test_that("maxQU.lo.ROI objective measure mean = 0.007813251",
+ { expect_that(all.equal(extractObjectiveMeasures(maxQU.lo.ROI)$mean, 0.007813251), is_true()) })
+
+test_that("maxQU.lo.ROI objective measure StdDev = 0.01556929",
+ { expect_that(all.equal(extractObjectiveMeasures(maxQU.lo.ROI)$StdDev, 0.01556929), is_true()) })
+
+test_that("maxQU.lo.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(maxQU.lo.ROI) >= maxQU.lo.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("maxret.lo.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(maxQU.lo.ROI) <= maxQU.lo.ROI$portfolio$constraints[[2]]$max), is_true()) })
+
+##### ROI, full_investment, long only, max qu to approximate max return ######
+context("maxQU.maxret.ROI")
+
+test_that("risk aversion parameter = 1e-6",
+ { expect_that(all.equal(init.portf$objectives[[2]]$risk_aversion, 1e-6), is_true()) })
+
+test_that("maxQU.maxret.ROI objective measure mean = 0.008246053",
+ { expect_that(all.equal(extractObjectiveMeasures(maxQU.maxret.ROI)$mean, 0.008246053), is_true()) })
+
+test_that("maxQU.maxret.ROI objective measure StdDev = 0.03857144",
+ { expect_that(all.equal(extractObjectiveMeasures(maxQU.maxret.ROI)$StdDev, 0.03857144), is_true()) })
+
+test_that("maxQU.maxret.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(maxQU.maxret.ROI) >= maxQU.maxret.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("maxQU.maxret.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(maxQU.maxret.ROI) <= maxQU.maxret.ROI$portfolio$constraints[[2]]$max), is_true()) })
+
+##### ROI, full_investment, long only, max qu to approximate min StdDev ######
+context("maxQU.minvol.ROI")
+
+test_that("risk aversion parameter = 1e6",
+ { expect_that(all.equal(init.portf$objectives[[2]]$risk_aversion, 1e6), is_true()) })
+
+test_that("maxQU.minvol.ROI objective measure mean = 0.00603498",
+ { expect_that(all.equal(extractObjectiveMeasures(maxQU.minvol.ROI)$mean, 0.00603498), is_true()) })
+
+test_that("maxQU.minvol.ROI objective measure StdDev = 0.008251084",
+ { expect_that(all.equal(extractObjectiveMeasures(maxQU.minvol.ROI)$StdDev, 0.008251084), is_true()) })
+
+test_that("maxQU.minvol.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(maxQU.minvol.ROI) >= maxQU.minvol.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("maxQU.minvol.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(maxQU.minvol.ROI) <= maxQU.minvol.ROI$portfolio$constraints[[2]]$max), is_true()) })
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_max_return.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_max_return.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_max_return.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,102 @@
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
+##### Source Demo Script #####
+source("demo/demo_max_return.R")
+
+context("demo_max_return")
+
+###### ROI, full_investment, long only, max return ######
+context("maxret.lo.ROI")
+
+test_that("maxret.lo.ROI contains mean as an objective",
+ { expect_that(maxret.lo.ROI$portfolio$objectives[[1]]$name == "mean", is_true()) })
+
+test_that("maxret.lo.ROI objective measure mean = 0.008246053",
+ { expect_that(all.equal(extractObjectiveMeasures(maxret.lo.ROI)$mean, 0.008246053), is_true()) })
+
+test_that("maxret.lo.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.lo.ROI) >= maxret.lo.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("maxret.lo.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.lo.ROI) <= maxret.lo.ROI$portfolio$constraints[[2]]$max), is_true()) })
+
+
+###### ROI, full_investment, box, max return ######
+context("maxret.box.ROI")
+
+test_that("maxret.box.ROI contains mean as an objective",
+ { expect_that(maxret.box.ROI$portfolio$objectives[[1]]$name == "mean", is_true()) })
+
+test_that("maxret.box.ROI objective measure mean = 0.007508355",
+ { expect_that(all.equal(extractObjectiveMeasures(maxret.box.ROI)$mean, 0.007508355), is_true()) })
+
+test_that("maxret.box.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.box.ROI) >= maxret.box.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("maxret.lo.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.box.ROI) <= maxret.box.ROI$portfolio$constraints[[2]]$max), is_true()) })
+
+###### RP, full_investment, box with shorting, max return ######
+context("maxret.box1.RP")
+
+test_that("maxret.box1.RP contains StdDev as an objective",
+ { expect_that(maxret.box1.RP$portfolio$objectives[[2]]$name == "StdDev", is_true()) })
+
+test_that("maxret.box1.RP contains mean as an objective",
+ { expect_that(maxret.box1.RP$portfolio$objectives[[1]]$name == "mean", is_true()) })
+
+test_that("maxret.box1.RP objective measure StdDev is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxret.box1.RP)$StdDev), is_true()) })
+
+test_that("maxret.box1.RP objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxret.box1.RP)$mean), is_true()) })
+
+test_that("maxret.box1.RP min box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.box1.RP) >= maxret.box1.RP$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.box1.RP max box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.box1.RP) <= maxret.box1.RP$portfolio$constraints[[2]]$max), is_true()) })
+
+###### RP, full_investment, box, max return ######
+context("maxret.box2.RP")
+
+test_that("maxret.box2.RP contains StdDev as an objective",
+ { expect_that(maxret.box2.RP$portfolio$objectives[[2]]$name == "StdDev", is_true()) })
+
+test_that("maxret.box2.RP contains mean as an objective",
+ { expect_that(maxret.box2.RP$portfolio$objectives[[1]]$name == "mean", is_true()) })
+
+test_that("maxret.box2.RP objective measure StdDev is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxret.box2.RP)$StdDev), is_true()) })
+
+test_that("maxret.box2.RP objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxret.box2.RP)$mean), is_true()) })
+
+test_that("maxret.box2.RP min box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.box2.RP) >= maxret.box2.RP$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("maxret.box2.RP max box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.box2.RP) <= maxret.box2.RP$portfolio$constraints[[2]]$max), is_true()) })
+
+###### DE, full_investment, box, max return ######
+context("maxret.box.DE")
+
+test_that("maxret.box.DE contains StdDev as an objective",
+ { expect_that(maxret.box.DE$portfolio$objectives[[2]]$name == "StdDev", is_true()) })
+
+test_that("maxret.box.DE contains mean as an objective",
+ { expect_that(maxret.box.DE$portfolio$objectives[[1]]$name == "mean", is_true()) })
+
+test_that("maxret.box.DE objective measure StdDev is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxret.box.DE)$StdDev), is_true()) })
+
+test_that("maxret.box.DE objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(maxret.box.DE)$mean), is_true()) })
+
+test_that("maxret.box.DE min box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.box.DE) >= maxret.box.DE$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("maxret.box.DE max box constraints are not violated",
+ { expect_that(all(extractWeights(maxret.box.DE) <= maxret.box.DE$portfolio$constraints[[2]]$max), is_true()) })
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_min_StdDev.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_min_StdDev.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_min_StdDev.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,102 @@
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
+##### Source Demo Script #####
+source("demo/demo_min_StdDev.R")
+
+context("demo_min_StdDev")
+
+###### ROI, full_investment, long only, min StdDev ######
+context("minStdDev.lo.ROI")
+
+test_that("minStdDev.lo.ROI contains StdDev as an objective",
+ { expect_that(minStdDev.lo.ROI$portfolio$objectives[[1]]$name == "StdDev", is_true()) })
+
+test_that("minStdDev.lo.ROI objective measure StdDev = 0.008251084",
+ { expect_that(all.equal(extractObjectiveMeasures(minStdDev.lo.ROI)$StdDev, 0.008251084), is_true()) })
+
+test_that("minStdDev.lo.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.lo.ROI) >= minStdDev.lo.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minStdDev.lo.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.lo.ROI) <= minStdDev.lo.ROI$portfolio$constraints[[2]]$max), is_true()) })
+
+###### ROI, full_investment, box, min StdDev ######
+context("minStdDev.box.ROI")
+
+test_that("minStdDev.box.ROI contains StdDev as an objective",
+ { expect_that(minStdDev.box.ROI$portfolio$objectives[[1]]$name == "StdDev", is_true()) })
+
+test_that("minStdDev.box.ROI objective measure StdDev = 0.01096122",
+ { expect_that(all.equal(extractObjectiveMeasures(minStdDev.box.ROI)$StdDev, 0.01096122), is_true()) })
+
+test_that("minStdDev.box.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.box.ROI) >= minStdDev.box.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minStdDev.box.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.box.ROI) <= minStdDev.box.ROI$portfolio$constraints[[2]]$max), is_true()) })
+
+###### RP, full_investment, box, min ES ######
+context("minStdDev.box1.RP")
+
+test_that("minStdDev.box1.RP contains StdDev as an objective",
+ { expect_that(minStdDev.box1.RP$portfolio$objectives[[1]]$name == "StdDev", is_true()) })
+
+test_that("minStdDev.box1.RP contains mean as an objective",
+ { expect_that(minStdDev.box1.RP$portfolio$objectives[[2]]$name == "mean", is_true()) })
+
+test_that("minStdDev.box1.RP objective measure StDev is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minStdDev.box1.RP)$StdDev), is_true()) })
+
+test_that("minStdDev.box1.RP objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minStdDev.box1.RP)$mean), is_true()) })
+
+test_that("minStdDev.box1.RP min box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.box1.RP) >= minStdDev.box1.RP$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.box1.RP max box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.box1.RP) <= minStdDev.box1.RP$portfolio$constraints[[2]]$max), is_true()) })
+
+###### RP, full_investment, box, min StdDev ######
+context("minStdDev.box2.RP")
+
+test_that("minStdDev.box2.RP contains StdDev as an objective",
+ { expect_that(minStdDev.box2.RP$portfolio$objectives[[1]]$name == "StdDev", is_true()) })
+
+test_that("minStdDev.box2.RP contains mean as an objective",
+ { expect_that(minStdDev.box2.RP$portfolio$objectives[[2]]$name == "mean", is_true()) })
+
+test_that("minStdDev.box2.RP objective measure StDev is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minStdDev.box2.RP)$StdDev), is_true()) })
+
+test_that("minStdDev.box2.RP objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minStdDev.box2.RP)$mean), is_true()) })
+
+test_that("minStdDev.box2.RP min box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.box2.RP) >= minStdDev.box2.RP$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.box1.RP max box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.box2.RP) <= minStdDev.box2.RP$portfolio$constraints[[2]]$max), is_true()) })
+
+###### DE, full_investment, box, min StdDev ######
+context("minStdDev.box.DE")
+
+test_that("minStdDev.box.DE contains StdDev as an objective",
+ { expect_that(minStdDev.box.DE$portfolio$objectives[[1]]$name == "StdDev", is_true()) })
+
+test_that("minStdDev.box.DE contains mean as an objective",
+ { expect_that(minStdDev.box.DE$portfolio$objectives[[2]]$name == "mean", is_true()) })
+
+test_that("minStdDev.box.DE objective measure StDev is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minStdDev.box.DE)$StdDev), is_true()) })
+
+test_that("minStdDev.box.DE objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minStdDev.box.DE)$mean), is_true()) })
+
+test_that("minStdDev.box.DE min box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.box.DE) >= minStdDev.box.DE$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.box1.RP max box constraints are not violated",
+ { expect_that(all(extractWeights(minStdDev.box.DE) <= minStdDev.box.DE$portfolio$constraints[[2]]$max), is_true()) })
+
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_min_expected_shortfall.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_min_expected_shortfall.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_min_expected_shortfall.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,119 @@
+
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
+##### Source Demo Script #####
+source("demo/demo_min_expected_shortfall.R")
+
+context("demo_min_expected_shortfall")
+
+###### ROI, full_investment, long only, min ES ######
+context("minES.lo.ROI")
+
+test_that("minES.lo.ROI contains ES as an objective",
+ { expect_that(minES.lo.ROI$portfolio$objectives[[1]]$name == "ES", is_true()) })
+
+test_that("minES.lo.ROI ES objective p=0.9",
+ { expect_that(minES.lo.ROI$portfolio$objectives[[1]]$arguments$p == 0.9, is_true()) })
+
+test_that("minES.lo.ROI objective measure ES = 0.01013571",
+ { expect_that(all.equal(extractObjectiveMeasures(minES.lo.ROI)$ES, 0.01013571), is_true()) })
+
+test_that("minES.lo.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(minES.lo.ROI) >= minES.lo.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.lo.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(minES.lo.ROI) <= minES.lo.ROI$portfolio$constraints[[2]]$max), is_true()) })
+
+###### ROI, full_investment, long only, min ES ######
+context("minES.box.ROI")
+
+test_that("minES.box.ROI contains ES as an objective",
+ { expect_that(minES.box.ROI$portfolio$objectives[[1]]$name == "ES", is_true()) })
+
+test_that("minES.box.ROI ES objective p=0.9",
+ { expect_that(minES.box.ROI$portfolio$objectives[[1]]$arguments$p == 0.9, is_true()) })
+
+test_that("minES.box.ROI objective measure ES = 0.01477709",
+ { expect_that(all.equal(extractObjectiveMeasures(minES.box.ROI)$ES, 0.01477709), is_true()) })
+
+test_that("minES.box.ROI min box constraints are not violated",
+ { expect_that(all(extractWeights(minES.box.ROI) >= minES.box.ROI$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.box.ROI max box constraints are not violated",
+ { expect_that(all(extractWeights(minES.box.ROI) <= minES.box.ROI$portfolio$constraints[[2]]$max), is_true()) })
+
+###### RP, full_investment, box, min ES ######
+context("minES.box1.RP")
+
+test_that("minES.box1.RP contains ES as an objective",
+ { expect_that(minES.box1.RP$portfolio$objectives[[1]]$name == "ES", is_true()) })
+
+test_that("minES.box1.RP ES objective p=0.9",
+ { expect_that(minES.box1.RP$portfolio$objectives[[1]]$arguments$p == 0.9, is_true()) })
+
+test_that("minES.box1.RP contains mean as an objective",
+ { expect_that(minES.box1.RP$portfolio$objectives[[2]]$name == "mean", is_true()) })
+
+test_that("minES.box1.RP objective measure ES is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minES.box1.RP)$ES), is_true()) })
+
+test_that("minES.box1.RP objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minES.box1.RP)$mean), is_true()) })
+
+test_that("minES.box1.RP min box constraints are not violated",
+ { expect_that(all(extractWeights(minES.box1.RP) >= minES.box1.RP$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.box1.RP max box constraints are not violated",
+ { expect_that(all(extractWeights(minES.box1.RP) <= minES.box1.RP$portfolio$constraints[[2]]$max), is_true()) })
+
+###### RP, full_investment, box, min ES ######
+context("minES.box2.RP")
+
+test_that("minES.box2.RP contains ES as an objective",
+ { expect_that(minES.box2.RP$portfolio$objectives[[1]]$name == "ES", is_true()) })
+
+test_that("minES.box2.RP ES objective p=0.9",
+ { expect_that(minES.box2.RP$portfolio$objectives[[1]]$arguments$p == 0.9, is_true()) })
+
+test_that("minES.box2.RP contains mean as an objective",
+ { expect_that(minES.box2.RP$portfolio$objectives[[2]]$name == "mean", is_true()) })
+
+test_that("minES.box2.RP objective measure ES is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minES.box2.RP)$ES), is_true()) })
+
+test_that("minES.box2.RP objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minES.box2.RP)$mean), is_true()) })
+
+test_that("minES.box2.RP min box constraints are not violated",
+ { expect_that(all(extractWeights(minES.box2.RP) >= minES.box2.RP$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.box2.RP max box constraints are not violated",
+ { expect_that(all(extractWeights(minES.box2.RP) <= minES.box2.RP$portfolio$constraints[[2]]$max), is_true()) })
+
+###### DE, full_investment, box, min ES ######
+context("minES.box1.DE")
+
+test_that("minES.box.DE contains ES as an objective",
+ { expect_that(minES.box.DE$portfolio$objectives[[1]]$name == "ES", is_true()) })
+
+test_that("minES.box.DE ES objective p=0.9",
+ { expect_that(minES.box.DE$portfolio$objectives[[1]]$arguments$p == 0.9, is_true()) })
+
+test_that("minES.box2.DE contains mean as an objective",
+ { expect_that(minES.box.DE$portfolio$objectives[[2]]$name == "mean", is_true()) })
+
+test_that("minES.box.DE objective measure ES is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minES.box.DE)$ES), is_true()) })
+
+test_that("minES.box.DE objective measure mean is numeric",
+ { expect_that(is.numeric(extractObjectiveMeasures(minES.box.DE)$mean), is_true()) })
+
+test_that("minES.box.DE min box constraints are not violated",
+ { expect_that(all(extractWeights(minES.box.DE) >= minES.box.DE$portfolio$constraints[[2]]$min), is_true()) })
+
+test_that("minES.box.DE max box constraints are not violated",
+ { expect_that(all(extractWeights(minES.box.DE) <= minES.box.DE$portfolio$constraints[[2]]$max), is_true()) })
+
+
Added: pkg/PortfolioAnalytics/inst/tests/test_demo_return_target.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_return_target.R (rev 0)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_return_target.R 2013-12-15 23:00:17 UTC (rev 3278)
@@ -0,0 +1,43 @@
+
+##### Load packages #####
+require(testthat)
+require(PortfolioAnalytics)
+
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/returnanalytics -r 3278
More information about the Returnanalytics-commits
mailing list