Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/sandbox/riskbudgetpaper(superseded)/R_Allocation/bondequity.R
1433 views
1
setwd("c:/Documents and Settings/Administrator/Desktop/risk budget programs")
2
3
# Equal risk portfolio
4
cAssets = 2;
5
p = priskbudget = 0.95;
6
7
mincriterion = "mES" ; percriskcontribcriterion = "mES";
8
9
# Load programs
10
11
source("R_Allocation/Risk_budget_functions.R");
12
library(zoo); library(fGarch); library("PerformanceAnalytics"); library("DEoptim")
13
14
# Load the data
15
16
firstyear = 1976 ; firstquarter = 1; lastyear = 2010; lastquarter = 2;
17
18
data = read.table( file= paste("data/","/data.txt",sep="") ,header=T)
19
date = as.Date(data[,1],format="%Y-%m-%d")
20
monthlyR = indexes = zoo( data[,2:5] , order.by = date )
21
22
clean = TRUE
23
if(clean){ # multivariate cleaning, on all assets s.t. same value in efficient frontier
24
monthlyR = clean.boudt2(monthlyR,alpha=0.05)[[1]]
25
}
26
monthlyR = indexes = monthlyR[,1:2]
27
28
mu = apply(indexes,2,'mean')
29
# > mu*12
30
# Bond SP500
31
# 0.0754596 0.1024934
32
sigma = cov(indexes)
33
M3 = PerformanceAnalytics:::M3.MM(indexes)
34
M4 = PerformanceAnalytics:::M4.MM(indexes)
35
36
# Summary stats individual assets
37
38
head(indexes[,1:2],2); tail(indexes[,1:2],2)
39
apply(indexes[,1:2],2,'mean')*12
40
apply(indexes[,1:2],2,'sd')
41
ES(indexes[,1],method="modified")
42
ES(indexes[,2],method="modified")
43
44
45
46
#################################################################################
47
# Make Exhibit 2 Risk budget paper: weight and CVaR allocation static portfolios
48
#################################################################################
49
50
# Equal-weight portfolio
51
w5050 <- c(0.5,0.5)
52
sum( w5050*mu*12 ) ;
53
#VaR(R=indexes[,1:2], weights=w5050, portfolio_method="component")
54
ES(R=indexes[,1:2], weights=w5050, portfolio_method="component", mu = mu, sigma = sigma, m3=M3, m4=M4,invert=FALSE)
55
56
# 60/40 bond equity allocation
57
w6040 <- c(0.6,0.4);
58
sum( w6040*mu*12 ) ;
59
#VaR(R=indexes[,1:2], weights=w6040, portfolio_method="component")
60
ES(R=indexes[,1:2], weights=w6040, portfolio_method="component", mu = mu, sigma = sigma, m3=M3, m4=M4,invert=FALSE)
61
62
63
# Min CVaR portfolio
64
65
66
library(DEoptim)
67
obj <- function(w) {
68
if (sum(w) == 0) { w <- w + 1e-2 }
69
w <- w / sum(w)
70
ES(R=indexes[,1:2],weights = matrix(w,ncol=1), mu = mu, sigma = sigma, m3=M3, m4=M4,invert=FALSE)
71
}
72
out <- DEoptim(fn = obj, lower = rep(0, 2), upper = rep(1, 2),
73
DEoptim.control(itermax=100))
74
wstar <- out$optim$bestmem
75
wMinCVaR <- wstar / sum(wstar)
76
print(wMinCVaR)
77
# par1 par2
78
#0.96864323 0.03135677
79
# wMinCVaR = c( 0.96864323 , 0.03135677 )
80
print(sum(wMinCVaR*mu*12))
81
ES(R=indexes[,1:2], weights=matrix(wMinCVaR,ncol=1),portfolio_method="component", mu = mu, sigma = sigma, m3=M3, m4=M4)
82
83
84
# Min CVaR Concentration portfolio
85
86
obj <- function(w) {
87
if (sum(w) == 0) { w <- w + 1e-2 }
88
w <- w / sum(w)
89
CVaR <- ES(R=indexes[,1:2], weights=matrix(w,ncol=1),portfolio_method="component", mu = mu, sigma = sigma, m3=M3, m4=M4)
90
out <- max(CVaR$contribution)
91
}
92
out <- DEoptim(fn = obj, lower = rep(0, 2), upper = rep(1, 2),
93
DEoptim.control(itermax=100))
94
wstar <- out$optim$bestmem
95
wMinCVaRConc <- wstar / sum(wstar)
96
print(wMinCVaRConc)
97
#> print(wMinCVaRConc)
98
# par1 par2
99
#0.7700542 0.2299458
100
# wMinCVaRConc = c( 00.7700542 , 0.2299458 )
101
print(sum(wMinCVaRConc*mu*12))
102
ES(R=indexes[,1:2], weights=wMinCVaRConc, portfolio_method="component")
103
104
105
# 60/40 Risk allocation portfolio
106
obj <- function(w) {
107
if (sum(w) == 0) { w <- w + 1e-2 }
108
w <- w / sum(w)
109
CVaR <- ES(R=indexes[,1:2], weights=matrix(w,ncol=1),portfolio_method="component", mu = mu, sigma = sigma, m3=M3, m4=M4)
110
tmp1 <- CVaR$MES
111
tmp2 <- max(CVaR$pct_contrib_MES - c(0.601,0.401 ) , 0)
112
tmp3 <- max(c(0.599,0.399 ) - CVaR$pct_contrib_MES , 0)
113
out <- tmp1 + 1e3 * tmp2 + 1e3 * tmp3
114
}
115
out <- DEoptim(fn = obj, lower = rep(0, 2), upper = rep(1, 2),
116
DEoptim.control(itermax=100))
117
wstar <- out$optim$bestmem
118
w6040riskalloc <- wstar / sum(wstar)
119
print(w6040riskalloc)
120
# par1 par2
121
#0.8123427 0.1876573
122
print(sum(w6040riskalloc*mu*12))
123
# w6040riskalloc = c( 0.7290461 , 0.2709539 )
124
ES(R=indexes[,1:2], weights=w6040riskalloc, portfolio_method="component", mu = mu, sigma = sigma, m3=M3, m4=M4)
125
126
#################################################################################
127
# Make Exhibit 3 Risk budget paper: Efficient frontier plot
128
#################################################################################
129
130
# Construct efficient frontier: given a return target minimize the largest percentage CVaR in the portfolio
131
132
mESfun = function( series ){ return( operMES( series , alpha = 0.05 , r = 2 ) ) }
133
assetmu = apply( monthlyR , 2 , 'mean' )
134
assetCVaR = apply( monthlyR , 2 , 'mESfun' )
135
minmu = min(assetmu); maxmu = max(assetmu); print(minmu*12); print(maxmu*12);
136
137
# unconstrained solution is Minimum CVaR Concentration portfolio (having the equal risk contribution property):
138
# sol = MinMaxCompCVaRconportfolio(R=monthlyR, Riskupper = Inf ,Returnlower= -Inf )
139
minmu = min( apply(monthlyR,2,'mean' ));
140
sol = PortfolioOptim( minriskcriterion = "mES" , MinMaxComp = T, percriskcontribcriterion = "mES" ,
141
Riskupper = Inf ,Returnlower= minmu,
142
mu = mu, sigma = sigma, M3=M3, M4=M4)
143
144
W = as.vector( sol[[1]] ) ; vmu = as.vector( sol[[2]] )
145
vrisk = as.vector( sol[[3]] ) ; vmaxpercrisk = max( sol[[4]] )
146
vmaxriskcontrib = max( sol[[5]] )
147
148
# mutarget = 0.0047478;
149
150
for( mutarget in seq(minmu+0.00001,maxmu,0.00001) ){
151
sol = PortfolioOptim( minriskcriterion = "mES" , MinMaxComp = T, percriskcontribcriterion = "mES" ,
152
Riskupper = Inf ,Returnlower= mutarget,
153
mu = mu, sigma = sigma, M3=M3, M4=M4)
154
W = rbind( W, as.vector( sol[[1]] ) )
155
vmu = c( vmu , as.vector( sol[[2]] ))
156
vrisk = c( vrisk , as.vector( sol[[3]] ) )
157
vmaxpercrisk = c( vmaxpercrisk , max( sol[[4]] ) )
158
vmaxriskcontrib = c( vmaxriskcontrib , max( sol[[5]] ) )
159
}
160
161
# For the highest return targets, a very high penalty parameter is needed
162
163
for( mutarget in c(seq( max(vmu) , maxmu, 0.000001),maxmu) ){
164
print( c("mutarget equal to",mutarget) )
165
sol = PortfolioOptim( minriskcriterion = "mES" , MinMaxComp = T, percriskcontribcriterion = "mES" ,
166
Riskupper = Inf ,Returnlower= mutarget, penalty = 1e9,
167
mu = mu, sigma = sigma, M3=M3, M4=M4)
168
W = rbind( W, as.vector( sol[[1]] ) )
169
vmu = c( vmu , as.vector( sol[[2]] ))
170
vrisk = c( vrisk , as.vector( sol[[3]] ) )
171
vmaxpercrisk = c( vmaxpercrisk , max( sol[[4]] ) )
172
vmaxriskcontrib = c( vmaxriskcontrib , max( sol[[5]] ) )
173
}
174
175
176
177
178
write.csv( W , file = "EffFrontierMinCVaRConc _weights_biv.csv" )
179
EffFrontier_stats = cbind( vmu , vrisk , vmaxpercrisk , vmaxriskcontrib)
180
write.csv( EffFrontier_stats , file = "EffFrontierMinCVaRConc_stats_biv.csv" )
181
182
# Min CVaR portfolio
183
sol = PortfolioOptim( minriskcriterion = "mES" , MinMaxComp = F, percriskcontribcriterion = "mES" ,
184
R=monthlyR, Riskupper = Inf ,Returnlower= minmu)
185
186
W = as.vector( sol[[1]] )
187
vmu = as.vector( sol[[2]] )
188
vrisk = as.vector( sol[[3]] )
189
vmaxpercrisk = max( sol[[4]] )
190
vmaxriskcontrib = max( sol[[5]] )
191
192
for( mutarget in seq(minmu+0.00001,maxmu,0.00001) ){
193
print( c("mutarget equal to",mutarget) )
194
sol = PortfolioOptim( minriskcriterion = "mES" , MinMaxComp = F, percriskcontribcriterion = "mES" ,
195
Riskupper = Inf ,Returnlower= mutarget,
196
mu = mu, sigma = sigma, M3=M3, M4=M4)
197
W = rbind( W, as.vector( sol[[1]] ) )
198
vmu = c( vmu , as.vector( sol[[2]] ))
199
vrisk = c( vrisk , as.vector( sol[[3]] ) )
200
vmaxpercrisk = c( vmaxpercrisk , max( sol[[4]] ) )
201
vmaxriskcontrib = c( vmaxriskcontrib , max( sol[[5]] ) )
202
}
203
204
205
# For the highest return targets, a very high penalty parameter is needed
206
207
for( mutarget in c(seq( max(vmu) , maxmu, 0.000001),maxmu) ){
208
print( c("mutarget equal to",mutarget) )
209
sol = PortfolioOptim( minriskcriterion = "mES" , MinMaxComp = F, percriskcontribcriterion = "mES" ,
210
Riskupper = Inf ,Returnlower= mutarget , penalty = 1e9,
211
mu = mu, sigma = sigma, M3=M3, M4=M4)
212
W = rbind( W, as.vector( sol[[1]] ) )
213
vmu = c( vmu , as.vector( sol[[2]] ))
214
vrisk = c( vrisk , as.vector( sol[[3]] ) )
215
vmaxpercrisk = c( vmaxpercrisk , max( sol[[4]] ) )
216
vmaxriskcontrib = c( vmaxriskcontrib , max( sol[[5]] ) )
217
}
218
219
220
write.csv( W , file = "EffFrontierMinCVaR _weights_biv.csv" )
221
EffFrontier_stats = cbind( vmu , vrisk , vmaxpercrisk , vmaxriskcontrib)
222
write.csv( EffFrontier_stats , file = "EffFrontierMinCVaR_stats_biv.csv" )
223
224
225
# Plotting
226
227
228
postscript('frontier_bondequity.eps')
229
layout( matrix( c(1,2,3), ncol = 1 ) , height= c(4,3.6,0.4), width=1)
230
####################################
231
# Min CVaR Concentration
232
####################################
233
labelnames = c( "US bond" , "S&P 500" )
234
W = read.csv(file = "EffFrontierMinCVaRConc _weights_biv.csv")[,2:3]
235
EffFrontier_stats = read.csv(file = "EffFrontierMinCVaRConc_stats_biv.csv")[,2:5]
236
vmu = EffFrontier_stats[,1] ;
237
vrisk = EffFrontier_stats[,2] ;
238
vmaxpercrisk = EffFrontier_stats[,3] ;
239
vriskconc = EffFrontier_stats[,4] ;
240
241
Wsel = vmusel = vrisksel = vriskconcsel = c();
242
lm = minmu = min(vmu) ; maxmu = max(vmu);
243
ylim = c( min(assetmu) - 0.0003 , max(assetmu) + 0.0003 )
244
xlim = c( 0 , max(assetCVaR) + 0.01 )
245
246
# seq( minmu + 0.00005 , maxmu , 0.00005 )
247
for( rm in seq( minmu + 0.00005 , maxmu , 0.00005 ) ){
248
selection = c(vmu >= lm & vmu < rm) ;
249
if( any(selection) ){
250
vmusel = c( vmusel , mean(vmu[ selection ] ));
251
Wsel = rbind( Wsel , apply( W[selection,] ,2,'mean' ))
252
vrisksel = c( vrisksel , mean(vrisk[ selection ]) );
253
vriskconcsel = c( vriskconcsel , mean(vriskconc[ selection ]) )
254
}
255
lm = rm;
256
}
257
258
cAssets = ncol(monthlyR)
259
colorset = gray( seq(0,(cAssets-1),1)/cAssets ) ;
260
colnames( Wsel ) = c("US bond", "S&P 500")
261
rownames( Wsel ) = vmusel;
262
263
par( mar = c(4,5,3,1), las=1 ,cex=0.9 , cex.axis=0.9)
264
plot( vriskconcsel, vmusel*12 , type="l", lty = 2 ,
265
main = "Minimum CVaR concentration efficient frontier" ,
266
ylab="Annualized mean return" , xlab="" ,
267
lwd=2, xlim = xlim , ylim = ylim*12 )
268
lines( vrisksel , vmusel*12, lty = 1, lwd=2 ) # , col="darkgray" )
269
legend("bottomright",legend=c("Total Portfolio CVaR" , "Largest Component CVaR" ),lty=c(1,2), cex=0.8,ncol=1,lwd=2)
270
271
for( c in 1:2 ){ text(y=assetmu[c]*12,x= assetCVaR[c] , label=labelnames[c] , cex = 0.8) };
272
273
par( mar = c(5,5,3,1) , las=1 )
274
275
barplot( t(Wsel) , axisnames=T ,col=colorset,space=0 , names.arg = round(vmusel*12,3), xlab="Annualized mean return" ,
276
ylab="Weight allocation" , main = "Minimum CVaR concentration efficient portfolios" )
277
278
par( mar = c(0,5,0,1) )
279
plot.new()
280
legend("center",legend=c("US bond", "S&P 500"),fill=colorset[1:2],cex=0.8,ncol=2)
281
282
dev.off()
283
284
# Other layout
285
286
287
postscript('frontier_bondequity.eps')
288
layout( matrix( c(1,2,3,4), ncol = 2 ) , height= c(4,0.4,4,0.4), width=1 )
289
####################################
290
# Min CVaR Concentration
291
####################################
292
labelnames = c( "US bond" , "S&P 500" )
293
W = read.csv(file = "EffFrontierMinCVaRConc _weights_biv.csv")[,2:3]
294
EffFrontier_stats = read.csv(file = "EffFrontierMinCVaRConc_stats_biv.csv")[,2:5]
295
vmu = EffFrontier_stats[,1] ;
296
vrisk = EffFrontier_stats[,2] ;
297
vmaxpercrisk = EffFrontier_stats[,3] ;
298
vriskconc = EffFrontier_stats[,4] ;
299
300
Wsel = vmusel = vrisksel = vriskconcsel = c();
301
lm = minmu = min(vmu) ; maxmu = max(vmu);
302
ylim = c( min(assetmu) - 0.0003 , max(assetmu) + 0.0003 )
303
xlim = c( 0 , max(assetCVaR) + 0.01 )
304
305
# seq( minmu + 0.00005 , maxmu , 0.00005 )
306
for( rm in seq( minmu + 0.000005 , maxmu , 0.000005 ) ){
307
selection = c(vmu >= lm & vmu < rm) ;
308
if( any(selection) ){
309
vmusel = c( vmusel , mean(vmu[ selection ] ));
310
Wsel = rbind( Wsel , apply( W[selection,] ,2,'mean' ))
311
vrisksel = c( vrisksel , mean(vrisk[ selection ]) );
312
vriskconcsel = c( vriskconcsel , mean(vriskconc[ selection ]) )
313
}
314
lm = rm;
315
}
316
317
318
# add the full investment in the S&P500 NEW ATTENTION
319
vmusel = c( vmusel , max(assetmu) )
320
Wsel = rbind( Wsel , c(0,1) )
321
vrisksel = c( vrisksel , max(assetCVaR) )
322
vriskconcsel = c( vriskconcsel , max(assetCVaR) )
323
324
cAssets = ncol(monthlyR)
325
colorset = gray( seq(0,(cAssets-1),1)/cAssets ) ;
326
colnames( Wsel ) = c("US bond", "S&P 500")
327
rownames( Wsel ) = vmusel;
328
329
par( mar = c(4,5,5,1), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
330
plot( vriskconcsel, vmusel*12 , type="l", lty = 2 ,
331
main = "Ann. Return vs total CVaR and Largest Component CVaR \n for minimum CVaR concentration efficient portfolios" ,
332
ylab="Annualized mean return" , xlab="" ,
333
lwd=2, xlim = xlim , ylim = ylim*12 )
334
lines( vrisksel , vmusel*12, lty = 1, lwd=2 ) # , col="darkgray" )
335
for( c in 1:2 ){ text(y=assetmu[c]*12,x= assetCVaR[c] , label=labelnames[c] , cex = 0.8, offset = 0) };
336
337
par( mar = c(0,5,0,1) )
338
plot.new()
339
legend("center",legend=c("Total Portfolio CVaR" , "Largest Component CVaR" ),lty=c(1,2), cex=0.8,ncol=1,lwd=2)
340
341
342
par( mar = c(5,5,5,1) , las=1 )
343
344
barplot( t(Wsel) , axisnames=T ,col=colorset,space=0 , names.arg = round(vmusel*12,3), xlab="Annualized mean return" ,
345
ylab="Weight allocation" , main = "Weight allocation of\n minimum CVaR concentration efficient portfolios" )
346
347
par( mar = c(0,5,0,1) )
348
plot.new()
349
legend("center",legend=c("US bond", "S&P 500"),fill=colorset[1:2],cex=0.8,ncol=1)
350
351
dev.off()
352
353
354
# Layout 3
355
source("R_interpretation/chart.StackedBar.R");
356
357
mESfun = function( series ){ return( operMES( series , alpha = 0.05 , r = 2 ) ) }
358
assetmu = apply( monthlyR , 2 , 'mean' )
359
assetCVaR = apply( monthlyR , 2 , 'mESfun' )
360
minmu = min(assetmu); maxmu = max(assetmu); print(minmu*12); print(maxmu*12);
361
362
363
postscript('frontier_bondequity.eps')
364
layout( matrix( c(1,2,3,4,5,6), ncol = 3 ) , height= c(4,0.4,4.25,0.15,4.25,0.15), width=c(1,0.78,0.78) )
365
####################################
366
# Min CVaR Concentration
367
####################################
368
labelnames = c( "US bond" , "S&P 500" )
369
W = read.csv(file = "EffFrontierMinCVaRConc _weights_biv.csv")[,2:3]
370
EffFrontier_stats = read.csv(file = "EffFrontierMinCVaRConc_stats_biv.csv")[,2:5]
371
vmu = EffFrontier_stats[,1] ;
372
vrisk = EffFrontier_stats[,2] ;
373
vmaxpercrisk = EffFrontier_stats[,3] ;
374
vmaxriskcontrib = vriskconc = EffFrontier_stats[,4] ;
375
376
order = sort(vmu,index.return=T)$ix
377
vmu = vmu[order]
378
vrisk = vrisk[order]
379
vmaxpercrisk = vmaxpercrisk[order]
380
vmaxriskcontrib = vmaxriskcontrib[order]
381
W = W[order,]
382
a = duplicated(vmu)
383
vmu = vmu[!a]
384
vrisk = vrisk[!a]
385
vmaxpercrisk = vmaxpercrisk[!a]
386
vriskconc = vmaxriskcontrib = vmaxriskcontrib[!a]
387
W = W[!a,]
388
389
# Discontinuity in the frontier: For return targets in between
390
# vmu[41:42]*12
391
# the solution is no longer on the frontier of the feasible space
392
393
394
Wsel = vmusel = vrisksel = vriskconcsel = CVaRsel = c();
395
lm = minmu = min(vmu) ; maxmu = max(vmu);
396
ylim = c( min(assetmu) - 0.0003 , max(assetmu) + 0.0003 )
397
xlim = c( 0 , max(assetCVaR) + 0.01 )
398
399
binning = T # for the weight plots, binned data such that no visual misinterpretation is possible
400
step = 0.000015
401
if( binning ){
402
for( rm in seq( minmu+step , maxmu , step ) ){
403
selection = c(vmu >= lm & vmu < rm) ;
404
if( any(selection) ){
405
vmusel = c( vmusel , mean(vmu[ selection ] ));
406
Wsel = rbind( Wsel , apply( W[selection,] ,2,'mean' ))
407
vrisksel = c( vrisksel , mean(vrisk[ selection ]) );
408
vriskconcsel = c( vriskconcsel , mean(vriskconc[ selection ]) )
409
CVaRsel = rbind( CVaRsel , c( 1-mean(vriskconc[ selection ]/vrisk[selection]) , mean(vriskconc[ selection ]/vrisk[selection]) ) )
410
}else{
411
vmusel = c( vmusel , NA );
412
Wsel = rbind( Wsel , rep(NA,2) )
413
vrisksel = c( vrisksel , NA );
414
vriskconcsel = c( vriskconcsel , NA )
415
CVaRsel = rbind( CVaRsel , rep(NA,2) )
416
417
}
418
lm = rm;
419
}
420
}else{
421
vmusel = vmu;
422
Wsel = W
423
vrisksel = vrisk
424
vriskconcsel = vriskconc
425
CVaRsel = cbind( 1-vriskconc/vrisk , vriskconc/vrisk )
426
}
427
428
# add the full investment in the S&P500 NEW ATTENTION
429
#vmusel = c( vmusel , max(assetmu) )
430
#Wsel = rbind( Wsel , c(0,1) )
431
#vrisksel = c( vrisksel , max(assetCVaR) )
432
#vriskconcsel = c( vriskconcsel , max(assetCVaR) )
433
#CVaRsel = rbind( CVaRsel , c(0,1) )
434
435
436
cAssets = ncol(monthlyR)
437
colorset = gray( seq(0,(cAssets-1),1)/cAssets ) ;
438
colnames( Wsel ) = c("US bond", "S&P 500")
439
rownames( Wsel ) = vmusel;
440
441
par( mar = c(4,5,5,0), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
442
plot( vriskconc, vmu*12 , type="l", lty = 1,
443
main = "Ann. Return vs CVaR (concentration) " ,
444
ylab="Annualized mean return" , xlab="" ,
445
lwd=2, xlim = xlim , ylim = ylim*12 , col="darkgray" )
446
points( vriskconc, vmu*12 , pch=21 , col="darkgray")
447
lines( vrisk , vmu*12, lty = 1, lwd=2 ) # , col="darkgray" )
448
points( vrisk , vmu*12 , pch=21 )
449
for( c in 1:2 ){ text(y=assetmu[c]*12,x= assetCVaR[c] , label=labelnames[c] , cex = 0.7, offset = 0) };
450
451
par( mar = c(0,5,0,0) )
452
plot.new()
453
legend("center",legend=c("CVaR" , "CVaR concentration" ),lty=c(1,1), cex=0.8,ncol=1,lwd=2,
454
col=c("black","darkgray"))
455
456
457
par( mar = c(5,1,14,0) , las=1 )
458
459
chart.StackedBar2(Wsel , axisnames=T ,col=colorset,space=0 , names.arg = round(vmusel*12,3), xlab="Annualized mean return" ,
460
ylab="" , main = "Weight allocation " ,
461
las=1, l=2.5, r=0, u = 5, legend.loc = NULL,ylim=c(0,1),border = F)
462
abline(h=0);abline(h=1)
463
par( mar = c(0,1,0,0) )
464
plot.new()
465
legend("center",legend=c("US bond", "S&P 500"),fill=colorset[1:2],cex=0.8,ncol=2)
466
467
468
par( mar = c(5,1,14,0) , las=1 ) # top programmeren in chart.StackedBar2
469
470
chart.StackedBar2(CVaRsel , axisnames=T ,col=colorset,space=0 , names.arg = round(vmusel*12,3), xlab="Annualized mean return" ,
471
ylab="" , main = "CVaR allocation " ,
472
las=1, l=2.5, r=0, u = 5, legend.loc = NULL,ylim=c(0,1),border = F)
473
abline(h=0);abline(h=1)
474
475
par( mar = c(0,1,0,0) )
476
plot.new()
477
legend("center",legend=c("US bond", "S&P 500"),fill=colorset[1:2],cex=0.8,ncol=2)
478
479
dev.off()
480
481
482
483