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

« back to all changes in this revision

Viewing changes to inst/unitTests/runit.weightsPie.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.weightsPie.portfolio
 
29
#  test.weightsPie.frontier
 
30
################################################################################
 
31
 
 
32
 
 
33
test.weightsPie.portfolio <-  
 
34
    function()
 
35
{  
 
36
    # Data:
 
37
    data = as.timeSeries(data(smallcap.ts))
 
38
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
 
39
    
 
40
    # Specification:
 
41
    spec = portfolioSpec()
 
42
    
 
43
    # Constraints:
 
44
    constraints = "LongOnly"
 
45
    
 
46
    # Portfolio:
 
47
    portfolio = tangencyPortfolio(data, spec, constraints)
 
48
    portfolio
 
49
    
 
50
    # Graph Frame:
 
51
    par(mfrow = c(2, 2))
 
52
    
 
53
    # Pie Plot 1:
 
54
    weightsPie(portfolio)
 
55
    
 
56
    # Pie Plot 2:
 
57
    weightsPie(portfolio, col = seqPalette(4, "Blues"), box = FALSE)
 
58
    boxL()
 
59
    
 
60
    # Pie Plot 3:
 
61
    weightsPie(portfolio, labels = letters[1:4], init.angle = -17, 
 
62
        col = qualiPalette(4, "Accent"), radius = 0.7, box = FALSE)
 
63
    mtext("Portfolio Weights", line = 1, adj = 0, font = 4)
 
64
    box_()
 
65
    copyright()
 
66
    
 
67
    # Return Value:
 
68
    return()
 
69
}
 
70
 
 
71
 
 
72
# ------------------------------------------------------------------------------
 
73
 
 
74
 
 
75
test.weightsPie.frontier <-  
 
76
    function()
 
77
{  
 
78
    # Data:
 
79
    data = as.timeSeries(data(smallcap.ts))
 
80
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
 
81
    
 
82
    # Specification:
 
83
    spec = portfolioSpec()
 
84
    
 
85
    # Constraints:
 
86
    constraints = "LongOnly"
 
87
    
 
88
    # Portfolio:
 
89
    frontier = portfolioFrontier(data, spec, constraints)
 
90
    frontier
 
91
    
 
92
    # Graph Frame:
 
93
    par(mfrow = c(2, 2))
 
94
    
 
95
    # Pie Plot 2:
 
96
    for (pos in 10*(1:4)) {
 
97
        weightsPie(frontier, labels = FALSE, pos = pos, 
 
98
            col = qualiPalette(4, "Pastel1"), 
 
99
            box = FALSE, radius = 0.6, cex = 0.8, font = 4) 
 
100
        copyright()
 
101
        Return = round(100*getTargetReturn(frontier)[pos,], 2)
 
102
        mtext(paste("Return", Return, "%"), 
 
103
            side = 3, line = 0.5, adj= 0, font = 2)
 
104
        abline(h = 1.07, lwd = 2)
 
105
        box_()
 
106
    }
 
107
    
 
108
    # Return Value:
 
109
    return()
 
110
}
 
111
 
 
112
 
 
113
################################################################################
 
114