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,
18
################################################################################
20
# test.portfolioFrontier.MV.Short
21
# test.portfolioFrontier.MV.LongOnly
22
# test.portfolioFrontier.MV.LongOnly.twoAssets
23
# test.portfolioFrontier.MV.LongOnly.Rdonlp2
24
# test.portfolioFrontier.MV.LongOnly.boxGroupConstraints
25
# test.portfolioFrontier.MV.LongOnly.covRiskBudgetConstraints
27
# test.portfolioFrontier.CVaR.Short
28
# test.portfolioFrontier.CVaR.LongOnly
29
# test.portfolioFrontier.CVaR.LongOnly.TwoAssets
30
################################################################################
33
test.portfolioFrontier.MV.Short <-
37
data = as.timeSeries(data(smallcap.ts))
38
data = data[, c("BKE", "GG", "GYMB", "KRON")]
42
spec = portfolioSpec()
43
setSolver(spec) = "solveRshortExact"
44
setNFrontierPoints(spec) = 10
52
Frontier = portfolioFrontier(data, spec, constraints)
60
# ------------------------------------------------------------------------------
63
test.portfolioFrontier.MV.LongOnly <-
67
data = as.timeSeries(data(smallcap.ts))
68
data = data[, c("BKE", "GG", "GYMB", "KRON")]
72
spec = portfolioSpec()
73
setNFrontierPoints(spec) = 5
77
constraints = "LongOnly"
81
Frontier = portfolioFrontier(data, spec, constraints)
89
# ------------------------------------------------------------------------------
92
test.portfolioFrontier.MV.LongOnly.twoAssets <-
96
data = as.timeSeries(data(smallcap.ts))
97
data = data[, c("BKE", "GG")]
100
# CVaR Specification:
101
spec = portfolioSpec()
106
constraints = "LongOnly"
110
Frontier = portfolioFrontier(data, spec, constraints)
118
# ------------------------------------------------------------------------------
121
test.portfolioFrontier.MV.LongOnly.Rdonlp2 <-
126
if (require(Rdonlp2)) {
129
data = as.timeSeries(data(smallcap.ts))
130
data = data[, c("BKE", "GG", "GYMB", "KRON")]
134
spec = portfolioSpec()
135
setSolver(spec) = "solveRdonlp2"
136
setNFrontierPoints(spec) = 5
140
constraints = "LongOnly"
143
# Portfolio Frontier:
144
Frontier = portfolioFrontier(data, spec, constraints)
157
# ------------------------------------------------------------------------------
160
test.portfolioFrontier.MV.LongOnly.boxGroupConstraints <-
164
Data = as.timeSeries(data(smallcap.ts))
165
Data = Data[, c("BKE", "GG", "GYMB", "KRON")]
168
# Set Specifications:
169
Spec = portfolioSpec()
170
setNFrontierPoints(Spec) <- 10
178
ans = portfolioFrontier(Data, Spec, Constraints)
181
par(mfrow = c(2, 2), cex = 0.7)
183
weightedReturnsPlot(ans)
184
covRiskBudgetsPlot(ans)
190
# getRiskBudgets(ans)
197
# ------------------------------------------------------------------------------
200
test.portfolioFrontier.MV.LongOnly.covRiskBudgetConstraints.Rdonlp2 <-
205
if (require(Rdonlp2)) {
208
data = as.timeSeries(data(smallcap.ts))
209
data = data[, c("BKE", "GG", "GYMB", "KRON")]
213
spec = portfolioSpec()
214
setSolver(spec) = "solveRdonlp2"
215
setNFrontierPoints(spec) = 10
219
constraints = c("minW[1:4]=0", "maxB[1:4]=0.8")
223
Frontier = portfolioFrontier(data, spec, constraints)
236
# ------------------------------------------------------------------------------
239
test.portfolioFrontier.MV.LongOnly.covRiskBudgetConstraints <-
244
if (require(Rdonlp2)) {
247
Data = as.timeSeries(data(smallcap.ts))
248
Data = Data[, c("BKE", "GG", "GYMB", "KRON")]
251
# Set Specifications:
252
Spec = portfolioSpec()
253
setSolver(Spec) = "solveRdonlp2"
254
setNFrontierPoints(Spec) <- 10
265
# still to be done ...
267
## setTargetReturn(Spec) <- mean(series(Data))
268
## solveRdonlp2(Data, Spec, Constraints)
270
## ans = .efficientConstrainedMVPortfolio(Data, Spec, Constraints)
272
## efficientPortfolio(Data, Spec, Constraints)
274
## ans = portfolioFrontier(Data, Spec, Constraints)
277
## par(mfrow = c(2, 2), cex = 0.7)
279
## attributesPlot(ans)
280
## covRiskBudgetsPlot(ans)
286
# getRiskBudgets(ans) # Does not work !!!!
298
################################################################################
301
test.portfolioFrontier.CVaR.Short <-
311
# ------------------------------------------------------------------------------
314
test.portfolioFrontier.CVaR.LongOnly <-
318
data = as.timeSeries(data(smallcap.ts))
319
data = data[, c("BKE", "GG", "GYMB", "KRON")]
322
# CVaR Specification:
323
spec = portfolioSpec()
324
setType(spec) = "CVaR"
325
setNFrontierPoints(spec) = 10
329
constraints = "LongOnly"
332
# CVaR Portfolio Optimization:
333
Frontier = portfolioFrontier(data, spec, constraints)
341
# ------------------------------------------------------------------------------
344
test.portfolioFrontier.CVaR.LongOnly.TwoAssets <-
348
data = as.timeSeries(data(smallcap.ts))
349
data = data[, c("BKE", "GG")]
352
# CVaR Specification:
353
spec = portfolioSpec()
354
setType(spec) = "CVaR"
358
constraints = "LongOnly"
362
Frontier = portfolioFrontier(data, spec, constraints)
370
################################################################################