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

« back to all changes in this revision

Viewing changes to inst/unitTests/runitPortfolioPlots.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 - 2007, Diethelm Wuertz, GPL
20
 
#   Diethelm Wuertz <wuertz@itp.phys.ethz.ch>
21
 
#   info@rmetrics.org
22
 
#   www.rmetrics.org
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
26
 
# and other sources
27
 
#   see Rmetrics's copyright file
28
 
 
29
 
 
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
 
################################################################################
55
 
 
56
 
 
57
 
test.frontierPlot.ShortMV =
58
 
function()
59
 
{    
60
 
    # Load Data:
61
 
    data = as.timeSeries(data(smallcap.ts))
62
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
63
 
    head(data)
64
 
   
65
 
    # Set Default Specifications:
66
 
    spec = portfolioSpec()
67
 
    spec
68
 
    
69
 
    # Set Constraints:
70
 
    constraints = "Short"
71
 
    constraints
72
 
   
73
 
    # Calculation of Long Only Minimum Variance Portfolio:
74
 
    Frontier = portfolioFrontier(data, spec, constraints)
75
 
    Frontier
76
 
    
77
 
    # Plot:
78
 
    par(mfrow = c(1, 1))
79
 
    object = Frontier
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") 
89
 
 
90
 
    # Return Value:
91
 
    return()
92
 
}
93
 
 
94
 
 
95
 
# ------------------------------------------------------------------------------
96
 
 
97
 
 
98
 
test.frontierPlot.ConstrainedMV =
99
 
function()
100
 
{    
101
 
    # Load Data:
102
 
    data = as.timeSeries(data(smallcap.ts))
103
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
104
 
    head(data)
105
 
   
106
 
    # Set Default Specifications:
107
 
    spec = portfolioSpec()
108
 
    spec
109
 
    
110
 
    # Set Constraints:
111
 
    constraints = NULL
112
 
    constraints
113
 
   
114
 
    # Calculation of Long Only Minimum Variance Portfolio:
115
 
    Frontier = portfolioFrontier(data, spec, constraints)
116
 
    Frontier
117
 
    
118
 
    # Plot:
119
 
    par(mfrow = c(1, 1))
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") 
129
 
 
130
 
    # Return Value:
131
 
    return()
132
 
}
133
 
 
134
 
 
135
 
# ------------------------------------------------------------------------------
136
 
 
137
 
 
138
 
test.frontierPlot.ConstrainedCVaR =
139
 
function()
140
 
{    
141
 
    # Load Data:
142
 
    data = as.timeSeries(data(smallcap.ts))
143
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
144
 
    head(data)
145
 
   
146
 
    # Set Default Specifications:
147
 
    spec = portfolioSpec()
148
 
    setType(spec) = "CVaR"
149
 
    spec
150
 
    
151
 
    # Set Constraints:
152
 
    constraints = NULL
153
 
    constraints
154
 
   
155
 
    # Calculation of Long Only Minimum Variance Portfolio:
156
 
    Frontier = portfolioFrontier(data, spec, constraints)
157
 
    Frontier
158
 
    
159
 
    # Plot:
160
 
    par(mfrow = c(1, 1))
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") 
170
 
 
171
 
    # Return Value:
172
 
    return()
173
 
}
174
 
 
175
 
 
176
 
################################################################################
177
 
 
178
 
 
179
 
test.barPlots.ShortMV =
180
 
function()
181
 
182
 
    # Load Time Series Data:
183
 
    data = as.timeSeries(data(smallcap.ts))
184
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
185
 
    
186
 
    # Specification:
187
 
    spec = portfolioSpec()
188
 
    
189
 
    # Constraints:
190
 
    constraints = "Short"
191
 
    
192
 
    # Portfolio Weights Plot from Time Series Data:
193
 
    Frontier = portfolioFrontier(data, spec, constraints)
194
 
    
195
 
    # Plot:
196
 
    par(mfrow = c(2, 2), cex = 0.7)
197
 
    weightsPlot(Frontier)
198
 
    attributesPlot(Frontier)
199
 
    covRiskBudgetsPlot(Frontier)
200
 
    
201
 
    # Return Value:
202
 
    return()
203
 
}
204
 
 
205
 
 
206
 
# ------------------------------------------------------------------------------
207
 
 
208
 
 
209
 
test.barPlots.ConstrainedMV =
210
 
function()
211
 
212
 
    # Load Time Series Data:
213
 
    data = as.timeSeries(data(smallcap.ts))
214
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
215
 
    
216
 
    # Specification:
217
 
    spec = portfolioSpec()
218
 
    
219
 
    # Constraints:
220
 
    constraints = "LongOnly"
221
 
    
222
 
    # Portfolio Weights Plot from Time Series Data:
223
 
    Frontier = portfolioFrontier(data, spec, constraints)
224
 
    
225
 
    # Plot:
226
 
    par(mfrow = c(2, 2), cex = 0.7)
227
 
    weightsPlot(Frontier)
228
 
    attributesPlot(Frontier)
229
 
    covRiskBudgetsPlot(Frontier)
230
 
    
231
 
    # Return Value:
232
 
    return()
233
 
}
234
 
 
235
 
 
236
 
# ------------------------------------------------------------------------------
237
 
 
238
 
 
239
 
test.barPlots.ConstrainedCVaR =
240
 
function()
241
 
242
 
    # Load Time Series Data:
243
 
    data = as.timeSeries(data(smallcap.ts))
244
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
245
 
    
246
 
    # Specification:
247
 
    spec = portfolioSpec()
248
 
    setType(spec) = "CVaR"
249
 
    
250
 
    # Constraints:
251
 
    constraints = NULL
252
 
    
253
 
    # Portfolio Weights Plot from Time Series Data:
254
 
    Frontier = portfolioFrontier(data, spec, constraints)
255
 
    
256
 
    # Plot:
257
 
    par(mfrow = c(2, 2), cex = 0.7)
258
 
    weightsPlot(Frontier)
259
 
    attributesPlot(Frontier)
260
 
    covRiskBudgetsPlot(Frontier)
261
 
    
262
 
    # Return Value:
263
 
    return()
264
 
}
265
 
 
266
 
 
267
 
################################################################################
268
 
 
269
 
 
270
 
test.piePlots.ShortMV =
271
 
function()
272
 
273
 
    # Load Time Series Data:
274
 
    data = as.timeSeries(data(smallcap.ts))
275
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
276
 
    
277
 
    # Specification:
278
 
    spec = portfolioSpec()
279
 
    
280
 
    # Constraints:
281
 
    constraints = "Short"
282
 
    
283
 
    # Portfolio Weights Plot from Time Series Data:
284
 
    Portfolio = minvariancePortfolio(data, spec, constraints)
285
 
    
286
 
    # Plot:
287
 
    par(mfrow = c(2, 2), cex = 0.7)
288
 
    weightsPie(Portfolio)
289
 
    attributesPie(Portfolio)
290
 
    covRiskBudgetsPie(Portfolio)
291
 
    
292
 
    # Return Value:
293
 
    return()
294
 
}
295
 
 
296
 
 
297
 
# ------------------------------------------------------------------------------
298
 
 
299
 
 
300
 
test.piePlots.ConstrainedMV =
301
 
function()
302
 
303
 
    # Load Time Series Data:
304
 
    data = as.timeSeries(data(smallcap.ts))
305
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
306
 
    
307
 
    # Specification:
308
 
    spec = portfolioSpec()
309
 
    
310
 
    # Constraints:
311
 
    constraints = "LongOnly"
312
 
    
313
 
    # Portfolio Weights Plot from Time Series Data:
314
 
    Portfolio = minvariancePortfolio(data, spec, constraints)
315
 
    
316
 
    # Plot:
317
 
    par(mfrow = c(2, 2), cex = 0.7)
318
 
    weightsPie(Portfolio)
319
 
    attributesPie(Portfolio)
320
 
    covRiskBudgetsPie(Portfolio)
321
 
    
322
 
    # Return Value:
323
 
    return()
324
 
}
325
 
 
326
 
 
327
 
# ------------------------------------------------------------------------------
328
 
 
329
 
 
330
 
test.piePlots.ConstrainedCVaR =
331
 
function()
332
 
333
 
    # Load Time Series Data:
334
 
    data = as.timeSeries(data(smallcap.ts))
335
 
    data = data[, c("BKE", "GG", "GYMB", "KRON")]
336
 
    
337
 
    # Specification:
338
 
    spec = portfolioSpec()
339
 
    setType(spec) = "CVaR"
340
 
    
341
 
    # Constraints:
342
 
    constraints = NULL
343
 
    
344
 
    # Portfolio Weights Plot from Time Series Data:
345
 
    Portfolio = minvariancePortfolio(data, spec, constraints)
346
 
    
347
 
    # Plot:
348
 
    par(mfrow = c(2, 2), cex = 0.7)
349
 
    weightsPie(Portfolio)
350
 
    attributesPie(Portfolio)
351
 
    covRiskBudgetsPie(Portfolio)
352
 
    
353
 
    # Return Value:
354
 
    return()
355
 
}
356
 
 
357
 
 
358
 
################################################################################
359