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

« back to all changes in this revision

Viewing changes to R/methods-show.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 Description. 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
 
 
18
################################################################################
 
19
# FUNCTION:                     DESCRIPTION:
 
20
#  show.fPORTFOLIO               S4 Print method for 'fPPORTFOLIO' objects
 
21
#  show.fPFOLIODATA              Print method for 'fPFOLIODATA' objects
 
22
#  show.fPFOLIOSPEC              Print method for 'fPFOLIOSPEC' objects
 
23
#  show.fPFOLIOCON               Print method for 'fPFOLIOCON' objects
 
24
 
 
25
################################################################################
 
26
 
 
27
 
 
28
setMethod("show", "fPORTFOLIO",
 
29
    function(object)
 
30
{
 
31
    # Description:
 
32
    #   S4 Print Method for an object of class "fPORTFOLIO"
 
33
 
 
34
    # Arguments:
 
35
    #   object - an object of class "fPORTFOLIO"
 
36
 
 
37
    # FUNCTION:
 
38
 
 
39
    # Print Title:
 
40
    cat("\nTitle:\n ")
 
41
        cat(getType(object),  getTitle(object),     "\n")
 
42
        cat(" Estimator:   ", getEstimator(object), "\n")
 
43
        cat(" Solver:      ", getSolver(object),    "\n")
 
44
        cat(" Optimize:    ", getOptimize(object),  "\n")
 
45
        cat(" Constraints: ", getConstraintsTypes(object), "\n")
 
46
    if(getType(object) == "CVaR")
 
47
        cat(" VaR Alpha:   ", getAlpha(object),     "\n")
 
48
        #at(" Objective:   ", getObjective(object), "\n")
 
49
 
 
50
    # Print Call:
 
51
    # cat("\nCall:\n ")
 
52
    # print.default(getCall(object))
 
53
 
 
54
    # Print Target Weights:
 
55
    cat("\nPortfolio Weights:\n")
 
56
    weights = data.frame(round(getWeights(object), digits = 4))
 
57
    if (NROW(weights) == 1) rownames(weights) = ""
 
58
    print(weights)
 
59
 
 
60
    # Print Covariance Risk Budgets:
 
61
    cat("\nCovariance Risk Budgets:\n")
 
62
    covRiskBudgets = data.frame(round(getCovRiskBudgets(object), digits = 4))
 
63
    if (NROW(covRiskBudgets) == 1) rownames(covRiskBudgets) = ""
 
64
    print(covRiskBudgets)
 
65
 
 
66
    # Print Tail Risk Budgets:
 
67
    if (FALSE) {
 
68
        if (!is.na(getTailRiskBudgets(object))) {
 
69
            cat("\nRiskBudget(s):\n")
 
70
            riskBudgets = round(getTailRiskBudgets(object), digits = 4)
 
71
            print.table(riskBudgets)
 
72
        }
 
73
    }
 
74
 
 
75
    # Print Target Return and Risks:
 
76
    cat("\nTarget Return and Risks:\n")
 
77
    targetReturn = getTargetReturn(object)
 
78
    targetRisk = getTargetRisk(object)
 
79
    target = data.frame(targetReturn, targetRisk)
 
80
    if (NROW(target) == 1) rownames(target) = ""
 
81
    print(round(target, digits = 4))
 
82
 
 
83
    # Print Description:
 
84
    cat("\nDescription:\n ")
 
85
    cat(getDescription(object), "\n")
 
86
 
 
87
    # Return Value:
 
88
    invisible(object)
 
89
})
 
90
 
 
91
 
 
92
# ------------------------------------------------------------------------------
 
93
 
 
94
 
 
95
setMethod("show", "fPFOLIODATA",
 
96
    function(object)
 
97
{
 
98
    # Description:
 
99
    #   S4 Print Method for an object of class "fPFOLIODATA"
 
100
 
 
101
    # Arguments:
 
102
    #   object - an object of class "fPFOLIOSPEC"
 
103
 
 
104
    # FUNCTION:
 
105
 
 
106
    # Series:
 
107
    cat("\nSeries Data:\n\n")
 
108
    print(object@data$series)
 
109
 
 
110
    # Statistics:
 
111
    cat("\nStatistics:\n\n")
 
112
    print(object@statistics)
 
113
 
 
114
    # Tailrisk:
 
115
    # NYI
 
116
 
 
117
    # Return Value:
 
118
    invisible(object)
 
119
})
 
120
 
 
121
 
 
122
# ------------------------------------------------------------------------------
 
123
 
 
124
 
 
125
setMethod("show", "fPFOLIOSPEC",
 
126
    function(object)
 
127
{
 
128
    # Description:
 
129
    #   S4 Print Method for an object of class "fPFOLIOSPEC"
 
130
 
 
131
    # Arguments:
 
132
    #   object - an object of class "fPFOLIOSPEC"
 
133
 
 
134
    # FUNCTION:
 
135
 
 
136
    # Model:
 
137
        cat("\nPortfolio Specification:\t")
 
138
        cat("\n Portfolio Type:           ",
 
139
            object@model$type)
 
140
        cat("\n Optimize:                 ",
 
141
            object@model$optimize)
 
142
        cat("\n Covariance Estimator:     ",
 
143
            object@model$estimator)
 
144
 
 
145
    # Portfolio:
 
146
    if (!is.null(object@portfolio$weights)) {
 
147
        cat("\n Portfolio Weights:    ",
 
148
            object@portfolio$weights)
 
149
    }
 
150
    if (!is.null(object@portfolio$targetReturn)) {
 
151
        cat("\n Target Return:            ",
 
152
            object@portfolio$targetReturn)
 
153
    }
 
154
    if (!is.null(object@portfolio$targetAlpha)) {
 
155
        cat("\n Target Alpha:             ",
 
156
        as.character(object@portfolio$targetAlpha))
 
157
    }
 
158
    if (!is.null(object@portfolio$riskFreeRate)) {
 
159
        cat("\n Portfolio Risk-Free Rate: ",
 
160
        as.character(object@portfolio$riskFreeRate))
 
161
    }
 
162
    if (!is.null(object@portfolio$nFrontierPoints)) {
 
163
        cat("\n Number of Frontier Points:",
 
164
        as.character(object@portfolio$nFrontierPoints))
 
165
    }
 
166
 
 
167
    # Optimization:
 
168
        cat("\n Optimizer:                ",
 
169
            object@optim$solver, "\n")
 
170
 
 
171
    # Return Value:
 
172
    invisible(object)
 
173
})
 
174
 
 
175
 
 
176
# ------------------------------------------------------------------------------
 
177
 
 
178
if(FALSE) {
 
179
setMethod("show", "fPFOLIOCON",
 
180
    function(object)
 
181
{
 
182
    # Description:
 
183
    #   S4 Print Method for an object of class "fPFOLIODATA"
 
184
 
 
185
    # Arguments:
 
186
    #   object - an object of class "fPFOLIOSPEC"
 
187
 
 
188
    # FUNCTION:
 
189
 
 
190
    # Print Title:
 
191
    cat("\nTitle:\n ")
 
192
    cat("Portfolio Constraints\n")
 
193
 
 
194
    cat("\nConstraint String:\n")
 
195
    print(object@stringConstraints)
 
196
 
 
197
    cat("\nBox Constraints:\n")
 
198
    print(object@boxConstraints)
 
199
 
 
200
    cat("Group-Equal Constraints:\n")
 
201
    print(object@groupEqConstraints)
 
202
 
 
203
    cat("Group-Matrix Constraints:\n")
 
204
    print(object@groupMatConstraints)
 
205
 
 
206
    cat("Cov Risk Budget Constraints:\n")
 
207
    print(object@riskBudgetConstraints)
 
208
    
 
209
    cat("Box/Group Constraints:\n")
 
210
    print(object@boxGroupConstraints)
 
211
 
 
212
    # Return Value:
 
213
    invisible(object)
 
214
})
 
215
}
 
216
 
 
217
 
 
218
# ------------------------------------------------------------------------------
 
219
 
 
220
 
 
221
setMethod("show", "fPFOLIOCON",
 
222
    function(object)
 
223
{
 
224
    # Description:
 
225
    #   S4 Print Method for an object of class "fPFOLIODATA"
 
226
 
 
227
    # Arguments:
 
228
    #   object - an object of class "fPFOLIOSPEC"
 
229
 
 
230
    # FUNCTION:
 
231
 
 
232
    # Print Title:
 
233
    cat("\nTitle:\n ")
 
234
    cat("Portfolio Constraints\n")
 
235
 
 
236
    minmaxW = rbind(object@minWConstraints, object@maxWConstraints)
 
237
    if (length(minmaxW)) {
 
238
        cat("\nLower/Upper Bounds:\n")
 
239
        print(minmaxW)
 
240
    }
 
241
 
 
242
    eqsumW = object@eqsumWConstraints
 
243
    if (sum(dim(eqsumW)) > 2) {
 
244
        cat("\nEqual Matrix Constraints:\n")
 
245
        print(eqsumW)
 
246
    }
 
247
    
 
248
    minsumW = object@minsumWConstraints
 
249
    if (sum(dim(minsumW)) > 2) {
 
250
        cat("\nLower Matrix Constraints:\n")
 
251
        print(minsumW)
 
252
    }
 
253
    
 
254
    maxsumW = object@maxsumWConstraints
 
255
    if (sum(dim(minsumW)) > 2) {
 
256
        cat("\nUpper Matrix Constraints:\n")
 
257
        print(maxsumW)
 
258
    }
 
259
    
 
260
    minmaxB = rbind(object@minBConstraints, object@maxBConstraints)
 
261
    if (length(minmaxB) > 0) {
 
262
        cat("\nLower/Upper Cov Risk Budget Bounds:\n")
 
263
        rownames(minmaxB) = c("Lower", "Upper")
 
264
        print(minmaxB)
 
265
    }
 
266
    
 
267
    # Return Value:
 
268
    invisible(object)
 
269
})
 
270
 
 
271
 
 
272
################################################################################
 
273