Path: blob/master/inst/tests/test_demo_efficient_frontier.R
1433 views
1##### Load packages #####2require(testthat)3require(PortfolioAnalytics)45##### Source Demo Script #####6source(system.file("demo/demo_efficient_frontier.R", package="PortfolioAnalytics"))78context("mean-var efficient frontier")910test_that("meanvar.ef$frontier has 25 rows",11{ expect_equal(nrow(meanvar.ef$frontier), 25) })1213test_that("colnames(meanvar.ef$frontier) are consistent",14{ expect_equal(colnames(meanvar.ef$frontier), c("mean", "StdDev", "out", "w.CA", "w.CTAG", "w.DS", "w.EM", "w.EQM")) })1516test_that("first row of meanvar.ef$frontier is consistent",17{ 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),18tolerance=1e-6) })1920test_that("last row of meanvar.ef$frontier is consistent",21{ 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),22tolerance=1e-6) })2324context("mean-etl efficient frontier")2526test_that("meanetl.ef$frontier has 25 rows",27{ expect_equal(nrow(meanetl.ef$frontier), 25) })2829test_that("colnames(meanetl.ef$frontier) are consistent",30{ expect_equal(colnames(meanetl.ef$frontier), c("mean", "ES", "out", "w.CA", "w.CTAG", "w.DS", "w.EM", "w.EQM")) })3132test_that("first row of meanetl.ef$frontier is consistent",33{ 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),34tolerance=1e-6) })3536test_that("last row of meanetl.ef$frontier is consistent",37{ 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),38tolerance=1e-6) })394041