Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/inst/tests/test_demo_efficient_frontier.R
1433 views
1
2
##### Load packages #####
3
require(testthat)
4
require(PortfolioAnalytics)
5
6
##### Source Demo Script #####
7
source(system.file("demo/demo_efficient_frontier.R", package="PortfolioAnalytics"))
8
9
context("mean-var efficient frontier")
10
11
test_that("meanvar.ef$frontier has 25 rows",
12
{ expect_equal(nrow(meanvar.ef$frontier), 25) })
13
14
test_that("colnames(meanvar.ef$frontier) are consistent",
15
{ expect_equal(colnames(meanvar.ef$frontier), c("mean", "StdDev", "out", "w.CA", "w.CTAG", "w.DS", "w.EM", "w.EQM")) })
16
17
test_that("first row of meanvar.ef$frontier is consistent",
18
{ 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),
19
tolerance=1e-6) })
20
21
test_that("last row of meanvar.ef$frontier is consistent",
22
{ 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),
23
tolerance=1e-6) })
24
25
context("mean-etl efficient frontier")
26
27
test_that("meanetl.ef$frontier has 25 rows",
28
{ expect_equal(nrow(meanetl.ef$frontier), 25) })
29
30
test_that("colnames(meanetl.ef$frontier) are consistent",
31
{ expect_equal(colnames(meanetl.ef$frontier), c("mean", "ES", "out", "w.CA", "w.CTAG", "w.DS", "w.EM", "w.EQM")) })
32
33
test_that("first row of meanetl.ef$frontier is consistent",
34
{ 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),
35
tolerance=1e-6) })
36
37
test_that("last row of meanetl.ef$frontier is consistent",
38
{ 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),
39
tolerance=1e-6) })
40
41