~ubuntu-branches/ubuntu/trusty/fportfolio/trusty

« back to all changes in this revision

Viewing changes to inst/unitTests/runit.frontierPoints.R

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2008-12-04 11:36:54 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081204113654-gr832nfs44blp5ph
Tags: 280.74-1
* New upstream release
* Finally uploading as r-cran-rglpk is out of NEW after five weeks

* debian/control: Updated (Build-)Depends: and Suggests:

* debian/control: Set (Build-)Depends: to current R version
* debian/control: Set Standards-Version: to current version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# This library is free software; you can redistribute it and/or
 
3
# modify it under the terms of the GNU Library General Public
 
4
# License as published by the Free Software Foundation; either
 
5
# version 2 of the License, or (at your option) any later version.
 
6
#
 
7
# This library is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
10
# GNU Library General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU Library General
 
13
# Public License along with this library; if not, write to the
 
14
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
15
# MA  02111-1307  USA
 
16
 
 
17
# Copyrights (C)
 
18
# for this R-port: 
 
19
#   1999 - Diethelm Wuertz, GPL
 
20
#   2007 - Rmetrics Foundation, GPL
 
21
#   Diethelm Wuertz <wuertz@itp.phys.ethz.ch>
 
22
# for code accessed (or partly included) from other sources:
 
23
#   see Rmetric's copyright and license files
 
24
 
 
25
 
 
26
################################################################################
 
27
# FUNCTION:                     
 
28
#  test.frontierPoints.feasiblePortfolio 
 
29
#  test.frontierPoints.portfolioFrontier               
 
30
################################################################################
 
31
 
 
32
 
 
33
test.frontierPoints.feasiblePortfolio <- 
 
34
    function()
 
35
{  
 
36
    # Data:
 
37
    data = as.timeSeries(data(smallcap.ts))
 
38
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
 
39
    print(head(data))
 
40
    
 
41
    # Specification:
 
42
    spec = portfolioSpec()
 
43
    setWeights(spec) = rep(1/ncol(data), ncol(data))
 
44
    print(spec)
 
45
    
 
46
    # Constraints:
 
47
    constraints = "LongOnly"
 
48
    print(constraints)
 
49
    
 
50
    # Feasible Portfolio:
 
51
    portfolio = feasiblePortfolio(data, spec, constraints)
 
52
    print(portfolio)
 
53
    
 
54
    # Frontier Points:
 
55
    points = frontierPoints(portfolio)
 
56
    print(points)
 
57
    
 
58
    # Specify Return/Risk Measures, explicitely:
 
59
    print(frontierPoints(portfolio, auto = TRUE))
 
60
    print(frontierPoints(portfolio, 
 
61
        risk = "Cov", auto = FALSE))
 
62
    print(frontierPoints(portfolio, 
 
63
        risk = "Sigma", auto = FALSE))
 
64
    print(frontierPoints(portfolio, 
 
65
        risk = "CVaR", auto = FALSE))
 
66
    print(frontierPoints(portfolio, 
 
67
        risk = "VaR", auto = FALSE))
 
68
    print(frontierPoints(portfolio, 
 
69
        return = "mu", risk = "CVaR", auto = FALSE))
 
70
  
 
71
    # Return Value:
 
72
    return()
 
73
}
 
74
 
 
75
 
 
76
# ------------------------------------------------------------------------------
 
77
 
 
78
 
 
79
test.frontierPoints.portfolioFrontier <- 
 
80
    function()
 
81
{  
 
82
    # Data:
 
83
    data = as.timeSeries(data(smallcap.ts))
 
84
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
 
85
    print(head(data))
 
86
    
 
87
    # Specification:
 
88
    spec = portfolioSpec()
 
89
    print(spec)
 
90
    
 
91
    # Constraints:
 
92
    constraints = "LongOnly"
 
93
    print(constraints)
 
94
    
 
95
    # Portfolio Frontier:
 
96
    frontier = portfolioFrontier(data)
 
97
    print(frontier)
 
98
    
 
99
    # Frontier Points:
 
100
    points = frontierPoints(frontier)
 
101
    print(points)
 
102
    
 
103
    # Specify Return/Risk Measures, explicitely:
 
104
    print(frontierPoints(frontier, auto = TRUE))
 
105
    print(frontierPoints(frontier, 
 
106
        return = "mean", risk = "Cov", auto = FALSE))
 
107
    print(frontierPoints(frontier, 
 
108
        return = "mean", risk = "Sigma", auto = FALSE))
 
109
    print(frontierPoints(frontier, 
 
110
        return = "mean", risk = "CVaR", auto = FALSE))
 
111
    print(frontierPoints(frontier, 
 
112
        return = "mean", risk = "VaR", auto = FALSE))
 
113
    
 
114
    # Return Value:
 
115
    return()
 
116
}
 
117
 
 
118
 
 
119
################################################################################
 
120