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.
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.
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,
18
################################################################################
19
# FUNCTION: PRINT AND PLOT METHODS:
20
# plot.fPORTFOLIO S3 Plot method for 'fPORTFOLIO' objects
21
################################################################################
25
function(x, which = "ask", control = list(), ...)
27
# A function implemented by Rmetrics
30
# Plot method for an object of class 'fPORTFOLIO'
33
# This method can also be used for plotting graphs fitted by
34
# the function 'garch' from the contributed R package 'tseries'.
39
Statistics = getStatistics(x)
41
# Use default, if xlim and ylim is not specified ...
43
Sigma = Statistics$Sigma
45
yLim = range(mu) + 0.25*c(-diff(range(mu)), diff(range(mu)))
47
# First, take care that all assets appear on the plot ...
48
# sqrtSig = sqrt(diag(Sigma))
51
# max(sqrtSig))+ c(-0.4*diff(range(sqrtSig)), 0.1*diff(range(sqrtSig)))
52
xRange = range(frontierPoints(x)[, 1])
54
xLimAssets = c(xRange[1] - 2.5*xDiff/10, xRange[2] + xDiff/10)
56
# ... second take care that the whole frontier appears on the plot:
57
fullFrontier = frontierPoints(x)
58
xLimFrontier = range(fullFrontier[, 1])
59
xLim = range(c(xLimAssets, xLimFrontier))
62
# YC: merge with user control list
63
con <- c(control, frontierPlotControl())
64
# YC: remove double entries and keep user args
65
con <- con[unique(names(con))]
66
attr(x, "control") <- con
72
"Plot Efficient Frontier",
73
"Add Minimum Risk Portfolio",
74
"Add Tangency Portfolio",
75
"Add Risk/Return of Single Assets",
76
"Add Equal Weights Portfolio",
77
"Add Two Asset Frontiers [LongOnly Only]",
78
"Add Monte Carlo Portfolios",
79
"Add Sharpe Ratio [Markowitz PF Only]"),
81
".fportfolio.plot.1", ".fportfolio.plot.2", ".fportfolio.plot.3",
82
".fportfolio.plot.4", ".fportfolio.plot.5", ".fportfolio.plot.6",
83
".fportfolio.plot.7", ".fportfolio.plot.8"),
91
# ------------------------------------------------------------------------------
98
# Plot Efficient Frontier
103
con = attr(x, "control")
106
xLab = "Mean-Var Target Risk"
107
} else if (Type == "CVaR") {
108
xLab = "-CVaR Target Risk"
113
object = x, xlim = con$xlim, ylim = con$ylim,
114
pch = 19, cex = 0.75, title = FALSE,
115
las = ifelse(is.null(con$las), 0, con$las))
117
main = ifelse(is.null(con$main), "Efficient Frontier", con$main),
118
xlab = ifelse(is.null(con$xlab), xLab, con$xlab),
119
ylab = ifelse(is.null(con$ylab), "Target Return", con$ylab))
124
# ------------------------------------------------------------------------------
127
.fportfolio.plot.2 <-
131
# Add Minimum Risk Portfolio
136
con = attr(x, "control")
141
col = con$minvariance.col,
142
cex = con$minvariance.cex,
147
# ------------------------------------------------------------------------------
150
.fportfolio.plot.3 <-
154
# Add Tangency Portfolio
159
con = attr(x, "control")
164
col = con$tangency.col,
165
cex = con$tangency.cex,
169
col = con$tangency.col,
170
cex = con$tangency.cex)
174
# ------------------------------------------------------------------------------
177
.fportfolio.plot.4 <-
181
# Add Risk/Return of Single Assets
186
con = attr(x, "control")
189
Palette = match.fun(con$singleAsset.col)
190
col = Palette(getNAssets(x))
194
cex = con$singleAsset.cex,
199
# ------------------------------------------------------------------------------
202
.fportfolio.plot.5 <-
206
# Add Equal Weights Portfolio
211
con = attr(x, "control")
216
col = con$equalWeights.col,
217
cex = con$equalWeights.cex,
222
# ------------------------------------------------------------------------------
225
.fportfolio.plot.6 <-
229
# Add Two Asset Frontiers [0-1 PF Only]
234
con = attr(x, "control")
237
lines(frontierPoints(object = x), col = "grey")
238
twoAssetsLines(object = x, col = con$twoAssets.col)
241
Palette = match.fun(con$singleAsset.col)
242
col = Palette(getNAssets(x))
246
cex = con$singleAsset.cex,
251
# ------------------------------------------------------------------------------
254
.fportfolio.plot.7 <-
258
# Add Monte Carlo Portfolios
263
con = attr(x, "control")
268
col = con$monteCarlo.col,
269
cex = con$monteCarlo.cex,
270
mcSteps = con$mcSteps)
274
# ------------------------------------------------------------------------------
277
.fportfolio.plot.8 <-
281
# Add Sharpe Ratio [MV PF Only]
285
con = attr(x, "control")
290
col = con$sharpeRatio.col,
291
cex = con$sharpeRatio.cex,
296
################################################################################