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 PURPOSE. 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,
19
# 1999 - 2007, Diethelm Wuertz, GPL
20
# Diethelm Wuertz <wuertz@itp.phys.ethz.ch>
23
# for the code accessed (or partly included) from other R-ports:
24
# see R's copyright and license files
25
# for the code accessed (or partly included) from contributed R-ports
27
# see Rmetrics's copyright file
30
################################################################################
31
# FUNCTION: EFFICIENT FRONTIER PLOT AND ADDONS:
32
# frontierPlot Plots efficient Frontier
33
# .minvariancePlot Adds Minimum Variance point
34
# .cmlPlot Adds Market Portfolio and Capital Market Line
35
# .tangencyPlot Adds Tangency Portfolio point and line
36
# .equalWeightsPlot Adds point of equal weights portfolio
37
# .singleAssetPlot Adds points of single asset portfolios
38
# .twoAssetsPlot Adds EF for all combinations of two assets
39
# .wheelPiePlot Adds pie chart of weights on EF
40
# .monteCarloPlot Adds randomly produced feasible portfolios
41
# .sharpeRatioPlot Adds Sharpe Ratio
42
# .notStackedWeightsPlot Plots the not stacked weights of potfolio
43
# .addlegend Adds legend to sliders
44
# FUNCTION: FRONTIER BAR PLOTS:
45
# weightsPlot Plots staggered weights
46
# attributesPlot Plots weighted means
47
# covRiskBudgetsPlot Plots weighted risks
48
# FUNCTION: PORTFOLIO PIE PLOTS:
49
# weightsPie Plots staggered weights
50
# attributesPie Plots weighted means
51
# covRiskBudgetsPie Plots weighted risks
52
# FUNCTION: DESCRIPTION:
53
# covEllipsesPlot Plots covariance ellipses
54
################################################################################
57
test.frontierPlot.ShortMV =
61
data = as.timeSeries(data(smallcap.ts))
62
data = data[, c("BKE", "GG", "GYMB", "KRON")]
65
# Set Default Specifications:
66
spec = portfolioSpec()
73
# Calculation of Long Only Minimum Variance Portfolio:
74
Frontier = portfolioFrontier(data, spec, constraints)
80
frontierPlot(Frontier, pch = 19)
81
.minvariancePlot(Frontier, col = "red", pch = 19, cex = 1.5)
82
.tangencyPlot(Frontier, col = "green")
83
.singleAssetPlot(Frontier, col = "red", cex = 1.5)
84
.equalWeightsPlot(Frontier, col = "blue", pch = 19, cex = 1.5)
85
.twoAssetsPlot(Frontier, col = "grey")
86
.weightsWheel(Frontier)
87
.monteCarloPlot(Frontier, mcSteps = 1000, cex = 0.25, pch = 19)
88
.sharpeRatioPlot(Frontier, pch = 19, col = "blue")
95
# ------------------------------------------------------------------------------
98
test.frontierPlot.ConstrainedMV =
102
data = as.timeSeries(data(smallcap.ts))
103
data = data[, c("BKE", "GG", "GYMB", "KRON")]
106
# Set Default Specifications:
107
spec = portfolioSpec()
114
# Calculation of Long Only Minimum Variance Portfolio:
115
Frontier = portfolioFrontier(data, spec, constraints)
120
frontierPlot(Frontier, pch = 19)
121
.minvariancePlot(Frontier, col = "red", pch = 19, cex = 1.5)
122
.tangencyPlot(Frontier, col = "green")
123
.singleAssetPlot(Frontier, col = "red", cex = 1.5)
124
.equalWeightsPlot(Frontier, col = "blue", pch = 19, cex = 1.5)
125
.twoAssetsPlot(Frontier, col = "grey")
126
.weightsWheel(Frontier)
127
.monteCarloPlot(Frontier, mcSteps = 1000, cex = 0.25, pch = 19)
128
.sharpeRatioPlot(Frontier, pch = 19, col = "blue")
135
# ------------------------------------------------------------------------------
138
test.frontierPlot.ConstrainedCVaR =
142
data = as.timeSeries(data(smallcap.ts))
143
data = data[, c("BKE", "GG", "GYMB", "KRON")]
146
# Set Default Specifications:
147
spec = portfolioSpec()
148
setType(spec) = "CVaR"
155
# Calculation of Long Only Minimum Variance Portfolio:
156
Frontier = portfolioFrontier(data, spec, constraints)
161
frontierPlot(Frontier, pch = 19)
162
.minvariancePlot(Frontier, col = "red", pch = 19, cex = 1.5)
163
.tangencyPlot(Frontier, col = "green")
164
.singleAssetPlot(Frontier, col = "red", cex = 1.5)
165
.equalWeightsPlot(Frontier, col = "blue", pch = 19, cex = 1.5)
166
.twoAssetsPlot(Frontier, col = "grey")
167
.weightsWheel(Frontier)
168
.monteCarloPlot(Frontier, mcSteps = 1000, cex = 0.25, pch = 19)
169
.sharpeRatioPlot(Frontier, pch = 19, col = "blue")
176
################################################################################
179
test.barPlots.ShortMV =
182
# Load Time Series Data:
183
data = as.timeSeries(data(smallcap.ts))
184
data = data[, c("BKE", "GG", "GYMB", "KRON")]
187
spec = portfolioSpec()
190
constraints = "Short"
192
# Portfolio Weights Plot from Time Series Data:
193
Frontier = portfolioFrontier(data, spec, constraints)
196
par(mfrow = c(2, 2), cex = 0.7)
197
weightsPlot(Frontier)
198
attributesPlot(Frontier)
199
covRiskBudgetsPlot(Frontier)
206
# ------------------------------------------------------------------------------
209
test.barPlots.ConstrainedMV =
212
# Load Time Series Data:
213
data = as.timeSeries(data(smallcap.ts))
214
data = data[, c("BKE", "GG", "GYMB", "KRON")]
217
spec = portfolioSpec()
220
constraints = "LongOnly"
222
# Portfolio Weights Plot from Time Series Data:
223
Frontier = portfolioFrontier(data, spec, constraints)
226
par(mfrow = c(2, 2), cex = 0.7)
227
weightsPlot(Frontier)
228
attributesPlot(Frontier)
229
covRiskBudgetsPlot(Frontier)
236
# ------------------------------------------------------------------------------
239
test.barPlots.ConstrainedCVaR =
242
# Load Time Series Data:
243
data = as.timeSeries(data(smallcap.ts))
244
data = data[, c("BKE", "GG", "GYMB", "KRON")]
247
spec = portfolioSpec()
248
setType(spec) = "CVaR"
253
# Portfolio Weights Plot from Time Series Data:
254
Frontier = portfolioFrontier(data, spec, constraints)
257
par(mfrow = c(2, 2), cex = 0.7)
258
weightsPlot(Frontier)
259
attributesPlot(Frontier)
260
covRiskBudgetsPlot(Frontier)
267
################################################################################
270
test.piePlots.ShortMV =
273
# Load Time Series Data:
274
data = as.timeSeries(data(smallcap.ts))
275
data = data[, c("BKE", "GG", "GYMB", "KRON")]
278
spec = portfolioSpec()
281
constraints = "Short"
283
# Portfolio Weights Plot from Time Series Data:
284
Portfolio = minvariancePortfolio(data, spec, constraints)
287
par(mfrow = c(2, 2), cex = 0.7)
288
weightsPie(Portfolio)
289
attributesPie(Portfolio)
290
covRiskBudgetsPie(Portfolio)
297
# ------------------------------------------------------------------------------
300
test.piePlots.ConstrainedMV =
303
# Load Time Series Data:
304
data = as.timeSeries(data(smallcap.ts))
305
data = data[, c("BKE", "GG", "GYMB", "KRON")]
308
spec = portfolioSpec()
311
constraints = "LongOnly"
313
# Portfolio Weights Plot from Time Series Data:
314
Portfolio = minvariancePortfolio(data, spec, constraints)
317
par(mfrow = c(2, 2), cex = 0.7)
318
weightsPie(Portfolio)
319
attributesPie(Portfolio)
320
covRiskBudgetsPie(Portfolio)
327
# ------------------------------------------------------------------------------
330
test.piePlots.ConstrainedCVaR =
333
# Load Time Series Data:
334
data = as.timeSeries(data(smallcap.ts))
335
data = data[, c("BKE", "GG", "GYMB", "KRON")]
338
spec = portfolioSpec()
339
setType(spec) = "CVaR"
344
# Portfolio Weights Plot from Time Series Data:
345
Portfolio = minvariancePortfolio(data, spec, constraints)
348
par(mfrow = c(2, 2), cex = 0.7)
349
weightsPie(Portfolio)
350
attributesPie(Portfolio)
351
covRiskBudgetsPie(Portfolio)
358
################################################################################