[Returnanalytics-commits] r3282 - in pkg/PortfolioAnalytics: demo inst/tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 16 06:26:33 CET 2013


Author: rossbennett34
Date: 2013-12-16 06:26:32 +0100 (Mon, 16 Dec 2013)
New Revision: 3282

Modified:
   pkg/PortfolioAnalytics/demo/demo_max_return.R
   pkg/PortfolioAnalytics/demo/demo_min_StdDev.R
   pkg/PortfolioAnalytics/demo/demo_weight_concentration.R
   pkg/PortfolioAnalytics/inst/tests/test_backwards_compat.R
   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
Log:
Cleaning up some of the demos and improving tests

Modified: pkg/PortfolioAnalytics/demo/demo_max_return.R
===================================================================
--- pkg/PortfolioAnalytics/demo/demo_max_return.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/demo/demo_max_return.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -64,7 +64,7 @@
                                     search_size=2000, 
                                     trace=TRUE)
 maxret.box1.RP
-ploy(maxret.box1.RP, risk.col="StdDev")
+plot(maxret.box1.RP, risk.col="StdDev")
 
 # create a new portfolio called 'port2' by using init.portf and modify the 
 # box constraints

Modified: pkg/PortfolioAnalytics/demo/demo_min_StdDev.R
===================================================================
--- pkg/PortfolioAnalytics/demo/demo_min_StdDev.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/demo/demo_min_StdDev.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -66,7 +66,7 @@
                                         search_size=2000, 
                                         trace=TRUE)
 print(minStdDev.box1.RP)
-ploy(minStdDev.box1.RP, risk.col="StdDev")
+plot(minStdDev.box1.RP, risk.col="StdDev")
 
 # create a new portfolio called 'port2' by using init.portf and modify the 
 # box constraints

Modified: pkg/PortfolioAnalytics/demo/demo_weight_concentration.R
===================================================================
--- pkg/PortfolioAnalytics/demo/demo_weight_concentration.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/demo/demo_weight_concentration.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -28,7 +28,7 @@
 conc.portf <- add.objective(portfolio=init.portf, type="weight_concentration", name="HHI", 
                             conc_aversion=0, conc_groups=init.portf$category_labels)
 
-opt2 <- optimize.portfolio(R=R, portfolio=conc, optimize_method="ROI", trace=TRUE)
+opt2 <- optimize.portfolio(R=R, portfolio=conc.portf, optimize_method="ROI", trace=TRUE)
 opt2
 all.equal(opt1$weights, opt2$weights)
 chart.Weights(opt2)

Modified: pkg/PortfolioAnalytics/inst/tests/test_backwards_compat.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_backwards_compat.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_backwards_compat.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,7 +4,7 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/backwards_compat.R")
+source(system.file("demo/backwards_compat.R", package="PortfolioAnalytics"))
 
 context("Backwards compatibility is maintained")
 
@@ -21,8 +21,8 @@
           { expect_that(all.equal(as.numeric(gen.constr$min), rep(0, 4)), is_true()) })
 
 # max
-test_that("Box constraints max vector is all 1s", 
-          { expect_that(all.equal(as.numeric(gen.constr$max), rep(1, 4)), is_true()) })
+test_that("Box constraints max vector is all 0.55", 
+          { expect_that(all.equal(as.numeric(gen.constr$max), rep(0.55, 4)), is_true()) })
 
 # min_mult
 test_that("min_mult is null", 
@@ -62,7 +62,7 @@
 
 # DEoptim optimization
 test_that("DE optim updated portfolio object", 
-          { expect_that(inherits(optrdev1$portfolio, "portfolio.spec"), is_true()) })
+          { expect_that(inherits(optdev1$portfolio, "portfolio.spec"), is_true()) })
 
 test_that("DE optim returns optimal weights", 
           { expect_that(is.numeric(extractWeights(optdev1)), is_true()) })
@@ -78,5 +78,5 @@
           { expect_equal(as.numeric(extractWeights(optroiv1)), c(0, 0, 0.46, 0.55)) })
 
 test_that("ROI returns an objective measure mean=0.008193842", 
-          { expect_equal(is.numeric(extractObjectiveMeasures(optroiv1)$mean), 0.008193842) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(optroiv1)$mean), 0.008193842) })
 

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_efficient_frontier.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_efficient_frontier.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_efficient_frontier.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,7 +4,7 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_efficient_frontier.R")
+source(system.file("demo/demo_efficient_frontier.R", package="PortfolioAnalytics"))
 
 context("mean-var efficient frontier")
 
@@ -15,10 +15,12 @@
           { 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)) })
+          { 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), 
+                         tolerance=1e-6) })
 
 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)) })
+          { 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),
+                         tolerance=1e-6) })
 
 context("mean-etl efficient frontier")
 
@@ -29,7 +31,9 @@
           { 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)) })
+          { 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),
+                         tolerance=1e-6) })
 
 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)) })
+          { 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),
+                         tolerance=1e-6) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_group_constraints.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_group_constraints.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_group_constraints.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,7 +4,7 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_group_constraints.R")
+source(system.file("demo/demo_group_constraints.R", package="PortfolioAnalytics"))
 
 ##### Test the constraints #####
 context("demo_group_constraints")
@@ -30,13 +30,15 @@
 cUP <- group_constr$cUP
 
 ##### ROI Optimization #####
-context("demo_group_constraints")
+context("demo_group_constraints optimization")
 
 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)) })
+          { expect_equal(as.numeric(extractWeights(minStdDev.ROI)), c(4.593895e-03, 2.540430e-01, -1.387779e-17, 4.595703e-02, 6.954061e-01),
+                         tolerance=1e-6) })
 
 test_that("minStdDev.ROI objective measure StdDev = 0.01042408", 
-          { expect_equal(extractObjectiveMeasures(minStdDev.ROI)$StdDev, 0.01042408) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(minStdDev.ROI)$StdDev), 0.01042408,
+                         tolerance=1e-6) })
 
 weights.ROI <- extractWeights(minStdDev.ROI)
 
@@ -58,13 +60,13 @@
           { 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()) })
+          { expect_that(is.numeric(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)]))) })
+                         c(sum(weights.RP[c(1, 3, 5)]), sum(weights.RP[c(2, 4)]))) })
 
 test_that("minStdDev.RP group constraint cLO is not violated", 
           { expect_that(all(extractGroups(minStdDev.RP)$group_weights >= cLO), is_true()) })
@@ -77,7 +79,7 @@
 context("minStdDev.DE")
 
 test_that("minStdDev.DE weights is a numeric vector", 
-          { expect_equal(extractWeights(minStdDev.DE), is_true()) })
+          { expect_that(is.numeric(extractWeights(minStdDev.DE)), is_true()) })
 
 test_that("minStdDev.DE objective measure StdDev is numeric", 
           { expect_that(is.numeric(extractObjectiveMeasures(minStdDev.ROI)$StdDev), is_true()) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_leverage.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_leverage.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_leverage.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,8 +4,9 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_leverage_exposure_constraint.R")
+source(system.file("demo/demo_leverage_exposure_constraint.R", package="PortfolioAnalytics"))
 
+
 context("dollar neutral portfolio")
 
 test_that("dollar.neutral.portf min_sum constraint is -0.01", 
@@ -41,14 +42,14 @@
 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.opt weights is a numeric vector", 
+          { expect_that(is.numeric(extractWeights(leveraged.opt)), 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.opt leverage exposure constraint is not violated", 
+          { expect_that(sum(abs(extractWeights(leveraged.opt))) <= 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.opt objective measure mean is numeric", 
+          { expect_that(is.numeric(extractObjectiveMeasures(leveraged.opt)$mean), is_true()) })
 
-test_that("leveraged.portf objective measure ES is numeric", 
-          { expect_that(is.numeric(extractObjectiveMeasures(leveraged.portf)$ES), is_true()) })
+test_that("leveraged.opt objective measure ES is numeric", 
+          { expect_that(is.numeric(extractObjectiveMeasures(leveraged.opt)$ES), is_true()) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_max_STARR.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_max_STARR.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_max_STARR.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,8 +4,9 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_max_STARR.R")
+source(system.file("demo/demo_max_STARR.R", package="PortfolioAnalytics"))
 
+
 context("demo_max_STARR")
 
 test_that("init.portf contains mean as an objective", 
@@ -15,16 +16,16 @@
           { 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()) })
+          { expect_equal(init.portf$objectives[[2]]$arguments$p, 0.925) })
 
 ##### 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()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxSTARR.lo.ROI)$mean), 0.006657183, tolerance=1e-6) })
 
 test_that("maxSTARR.lo.ROI objective measure ES = 0.01394436", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxSTARR.lo.ROI)$ES, 0.01394436), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxSTARR.lo.ROI)$ES), 0.01394436, tolerance=1e-6) })
 
 ##### maxSTARR.lo.RP #####
 context("maxSTARR.lo.RP")
@@ -33,7 +34,7 @@
           { 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()) })
+          { expect_that(is.numeric(extractObjectiveMeasures(maxSTARR.lo.RP)$ES), is_true()) })
 
 ##### maxSTARR.lo.DE #####
 context("maxSTARR.lo.DE")
@@ -42,4 +43,4 @@
           { 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()) })
+          { expect_that(is.numeric(extractObjectiveMeasures(maxSTARR.lo.DE)$ES), is_true()) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_max_qu.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_max_qu.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_max_qu.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -3,9 +3,8 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_max_quadratic_utility.R")
+source(system.file("demo/demo_max_quadratic_utility.R", package="PortfolioAnalytics"))
 
-context("demo_max_quadratic_utility")
 
 ##### init.portf objectives #####
 context("objectives for quadratic utility")
@@ -16,17 +15,17 @@
 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("risk aversion parameter = 4", 
+          { expect_equal(maxQU.lo.ROI$portfolio$objectives[[2]]$risk_aversion, 4) })
+
 test_that("maxQU.lo.ROI objective measure mean = 0.007813251", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxQU.lo.ROI)$mean, 0.007813251), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxQU.lo.ROI)$mean), 0.007813251, tolerance=1e-6) })
 
 test_that("maxQU.lo.ROI objective measure StdDev = 0.01556929", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxQU.lo.ROI)$StdDev, 0.01556929), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxQU.lo.ROI)$StdDev), 0.01556929, tolerance=1e-6) })
 
 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()) })
@@ -38,13 +37,13 @@
 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()) })
+          { expect_equal(maxQU.maxret.ROI$portfolio$objectives[[2]]$risk_aversion, 1e-6) })
 
 test_that("maxQU.maxret.ROI objective measure mean = 0.008246053", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxQU.maxret.ROI)$mean, 0.008246053), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxQU.maxret.ROI)$mean), 0.008246053, tolerance=1e-6) })
 
 test_that("maxQU.maxret.ROI objective measure StdDev = 0.03857144", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxQU.maxret.ROI)$StdDev, 0.03857144), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxQU.maxret.ROI)$StdDev), 0.03857144, tolerance=1e-6) })
 
 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()) })
@@ -56,13 +55,13 @@
 context("maxQU.minvol.ROI")
 
 test_that("risk aversion parameter = 1e6", 
-          { expect_that(all.equal(init.portf$objectives[[2]]$risk_aversion, 1e6), is_true()) })
+          { expect_equal(maxQU.minvol.ROI$portfolio$objectives[[2]]$risk_aversion, 1e6) })
 
 test_that("maxQU.minvol.ROI objective measure mean = 0.00603498", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxQU.minvol.ROI)$mean, 0.00603498), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxQU.minvol.ROI)$mean), 0.00603498, tolerance=1e-6) })
 
 test_that("maxQU.minvol.ROI objective measure StdDev = 0.008251084", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxQU.minvol.ROI)$StdDev, 0.008251084), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxQU.minvol.ROI)$StdDev), 0.008251084, tolerance=1e-6) })
 
 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()) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_max_return.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_max_return.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_max_return.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -3,8 +3,9 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_max_return.R")
+source(system.file("demo/demo_max_return.R", package="PortfolioAnalytics"))
 
+
 context("demo_max_return")
 
 ###### ROI, full_investment, long only, max return ######
@@ -14,7 +15,7 @@
           { 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()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxret.lo.ROI)$mean), 0.008246053, tolerance=1e-6) })
 
 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()) })
@@ -30,7 +31,7 @@
           { 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()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxret.box.ROI)$mean), 0.007508355, tolerance=1e-6) })
 
 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()) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_min_StdDev.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_min_StdDev.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_min_StdDev.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -3,8 +3,9 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_min_StdDev.R")
+source(system.file("demo/demo_min_StdDev.R", package="PortfolioAnalytics"))
 
+
 context("demo_min_StdDev")
 
 ###### ROI, full_investment, long only, min StdDev ######
@@ -14,7 +15,7 @@
           { 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()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(minStdDev.lo.ROI)$StdDev), 0.008251084, tolerance=1e-6) })
 
 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()) })
@@ -29,7 +30,7 @@
           { 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()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(minStdDev.box.ROI)$StdDev), 0.01096122, tolerance=1e-6) })
 
 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()) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_min_expected_shortfall.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_min_expected_shortfall.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_min_expected_shortfall.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,7 +4,7 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_min_expected_shortfall.R")
+source(system.file("demo/demo_min_expected_shortfall.R", package="PortfolioAnalytics"))
 
 context("demo_min_expected_shortfall")
 
@@ -15,10 +15,10 @@
           { 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()) })
+          { expect_equal(minES.lo.ROI$portfolio$objectives[[1]]$arguments$p, 0.9) })
 
 test_that("minES.lo.ROI objective measure ES = 0.01013571", 
-          { expect_that(all.equal(extractObjectiveMeasures(minES.lo.ROI)$ES, 0.01013571), is_true()) })
+          { expect_equal(extractObjectiveMeasures(minES.lo.ROI)$ES, 0.01013571, tolerance=1e-6) })
 
 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()) })
@@ -33,10 +33,10 @@
           { 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()) })
+          { expect_equal(minES.box.ROI$portfolio$objectives[[1]]$arguments$p, 0.9) })
 
 test_that("minES.box.ROI objective measure ES = 0.01477709", 
-          { expect_that(all.equal(extractObjectiveMeasures(minES.box.ROI)$ES, 0.01477709), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(minES.box.ROI)$ES), 0.01477709, tolerance=1e-6) })
 
 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()) })
@@ -51,7 +51,7 @@
           { 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()) })
+          { expect_equal(minES.box1.RP$portfolio$objectives[[1]]$arguments$p, 0.9) })
 
 test_that("minES.box1.RP contains mean as an objective", 
           { expect_that(minES.box1.RP$portfolio$objectives[[2]]$name == "mean", is_true()) })
@@ -75,7 +75,7 @@
           { 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()) })
+          { expect_equal(minES.box2.RP$portfolio$objectives[[1]]$arguments$p, 0.9) })
 
 test_that("minES.box2.RP contains mean as an objective", 
           { expect_that(minES.box2.RP$portfolio$objectives[[2]]$name == "mean", is_true()) })
@@ -99,7 +99,7 @@
           { 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()) })
+          { expect_equal(minES.box.DE$portfolio$objectives[[1]]$arguments$p, 0.9) })
 
 test_that("minES.box2.DE contains mean as an objective", 
           { expect_that(minES.box.DE$portfolio$objectives[[2]]$name == "mean", is_true()) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_return_target.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_return_target.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_return_target.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,24 +4,25 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_return_target.R")
+source(system.file("demo/demo_return_target.R", package="PortfolioAnalytics"))
 
+
 context("target return as an objective")
 
 test_that("ret.obj.portf contains mean as an objective", 
           { expect_that(ret.obj.portf$objectives[[1]]$name == "mean", is_true()) })
 
 test_that("ret.obj.portf contains mean as an objective with target = 0.007", 
-          { expect_that(ret.obj.portf$objectives[[1]]$target == 0.007, is_true()) })
+          { expect_equal(ret.obj.portf$objectives[[1]]$target, 0.007) })
 
 test_that("ret.obj.opt objective measure mean = 0.007", 
-          { expect_equal(extractObjectiveMeasures(ret.obj.opt)$mean, 0.007) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(ret.obj.opt)$mean), 0.007, tolerance=0.0001) })
 
 test_that("opt.obj.de objective measure mean = 0.007", 
-          { expect_equal(extractObjectiveMeasures(opt.obj.de)$mean, 0.007, tolerance=0.00001) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(opt.obj.de)$mean), 0.007, tolerance=0.0001) })
 
 test_that("opt.obj.rp objective measure mean = 0.007", 
-          { expect_equal(extractObjectiveMeasures(opt.obj.rp)$mean, 0.007, tolerance=0.00001) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(opt.obj.rp)$mean), 0.007, tolerance=0.0001) })
 
 context("target return as a constraint")
 
@@ -29,15 +30,15 @@
           { expect_that(ret.constr.portf$constraints[[3]]$type == "return", is_true()) })
 
 test_that("ret.obj.portf contains mean as a constraint with target = 0.007", 
-          { expect_that(ret.constr.portf$constraints[[3]]$return_target == 0.007, is_true()) })
+          { expect_equal(ret.constr.portf$constraints[[3]]$return_target, 0.007) })
 
 test_that("ret.constr.opt objective measure mean = 0.007", 
-          { expect_equal(extractObjectiveMeasures(ret.constr.opt)$mean, 0.007) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(ret.constr.opt)$mean), 0.007, tolerance=0.0001) })
 
 test_that("opt.constr.de objective measure mean = 0.007", 
-          { expect_equal(extractObjectiveMeasures(opt.constr.de)$mean, 0.007, tolerance=0.00001) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(opt.constr.de)$mean), 0.007, tolerance=0.0001) })
 
 test_that("opt.constr.rp objective measure mean = 0.007", 
-          { expect_equal(extractObjectiveMeasures(opt.constr.rp)$mean, 0.007, tolerance=0.00001) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(opt.constr.rp)$mean), 0.007, tolerance=0.0001) })
 
 

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_risk_budgets.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_risk_budgets.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_risk_budgets.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,8 +4,9 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_risk_budgets.R")
+source(system.file("demo/demo_risk_budgets.R", package="PortfolioAnalytics"))
 
+
 context("Risk Budget Optimizations")
 
 context("risk budget objective ES max_prisk")

Modified: pkg/PortfolioAnalytics/inst/tests/test_demo_weight_concentration.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_demo_weight_concentration.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_demo_weight_concentration.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,7 +4,7 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_weight_concentration.R")
+source(system.file("demo/demo_weight_concentration.R", package="PortfolioAnalytics"))
 
 context("weight concentration objective")
 
@@ -15,7 +15,7 @@
           { expect_that(conc.portf$objectives[[2]]$name == "HHI", is_true()) })
 
 test_that("conc.portf contains weight_concentration as an objective with conc_aversion=0", 
-          { expect_equal(conc.portf$objectives[[2]]$conc_aversion, rep(0, 4)) })
+          { expect_equal(opt2$portfolio$objectives[[2]]$conc_aversion, rep(0, 4)) })
 
 test_that("minimum variance and conc.portf weights are equal with conc_aversion=0", 
           { expect_equal(opt1$weights, opt2$weights) })

Modified: pkg/PortfolioAnalytics/inst/tests/test_max_Sharpe.R
===================================================================
--- pkg/PortfolioAnalytics/inst/tests/test_max_Sharpe.R	2013-12-15 23:14:09 UTC (rev 3281)
+++ pkg/PortfolioAnalytics/inst/tests/test_max_Sharpe.R	2013-12-16 05:26:32 UTC (rev 3282)
@@ -4,8 +4,9 @@
 require(PortfolioAnalytics)
 
 ##### Source Demo Script #####
-source("demo/demo_max_Sharpe.R")
+source(system.file("demo/demo_max_Sharpe.R", package="PortfolioAnalytics"))
 
+
 context("demo_max_Sharpe")
 
 test_that("init.portf contains mean as an objective", 
@@ -18,10 +19,10 @@
 context("maxSR.lo.ROI")
 
 test_that("maxSR.lo.ROI objective measure mean = 0.006062083", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxSR.lo.ROI)$mean, 0.006062083), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxSR.lo.ROI)$mean), 0.006062083, tolerance=1e-6) })
 
 test_that("maxSR.lo.ROI objective measure StdDev = 0.008843188", 
-          { expect_that(all.equal(extractObjectiveMeasures(maxSR.lo.ROI)$StdDev, 0.008843188), is_true()) })
+          { expect_equal(as.numeric(extractObjectiveMeasures(maxSR.lo.ROI)$StdDev), 0.008843188, tolerance=1e-6) })
 
 ##### maxSR.lo.RP #####
 context("maxSR.lo.RP")



More information about the Returnanalytics-commits mailing list