Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/sandbox/paper_analysis/insample/EfficientFrontier_MakePlots.R
1433 views
1
# Paper: Portfolio Optimization with Conditional Value-at-Risk Budgets
2
# Boudt, Carl, Peterson (2010)
3
# This R script serves to make the exhibits regarding the four asset efficient frontier
4
5
setwd("c:/Documents and Settings/Administrator/Desktop/risk budget programs/insample")
6
7
cAssets = 4; p = priskbudget = 0.95;
8
mincriterion = "mES" ; percriskcontribcriterion = "mES";
9
10
# Load programs
11
12
source("Risk_budget_functions.R");
13
library(zoo); library(fGarch); library("PerformanceAnalytics"); library("PortfolioAnalytics")
14
clean = TRUE; CC = T
15
16
# Load the data
17
firstyear = 1976 ; firstquarter = 1; lastyear = 2010; lastquarter = 2;
18
data = read.table( file= paste(getwd(),"/data.txt",sep="") ,header=T)
19
date = as.Date(data[,1],format="%Y-%m-%d")
20
21
monthlyR = zoo( data[,2:(1+cAssets)] , order.by = date )
22
set.seed(1234)
23
if(clean){ monthlyR = clean.boudt2(monthlyR,alpha=0.05)[[1]] }
24
mu = apply(monthlyR,2,'mean')
25
sigma = cov(monthlyR)
26
if(!CC){
27
M3 = PerformanceAnalytics:::M3.MM(monthlyR-matrix( rep(as.numeric(mu),nrow(monthlyR)) , nrow=nrow(monthlyR) , byrow=TRUE) );
28
M4 = PerformanceAnalytics:::M4.MM(monthlyR-matrix( rep(as.numeric(mu),nrow(monthlyR)) , nrow=nrow(monthlyR) , byrow=TRUE) )
29
}else{
30
source( "coskewkurtosis.R" )
31
M3 = coskewCC(monthlyR-matrix( rep(as.numeric(mu),nrow(monthlyR)) , nrow=nrow(monthlyR) , byrow=TRUE) );
32
M4 = cokurtCC(monthlyR-matrix( rep(as.numeric(mu),nrow(monthlyR)) , nrow=nrow(monthlyR) , byrow=TRUE) );
33
}
34
N = ncol(monthlyR)
35
36
# Summary stats individual assets
37
apply(monthlyR,2,'mean')*12
38
apply(monthlyR,2,'sd')*sqrt(12)
39
apply(monthlyR,2,'skewness')
40
apply(monthlyR,2,'kurtosis')
41
ES(monthlyR[,1],method="modified"); ES(monthlyR[,2],method="modified")
42
ES(monthlyR[,3],method="modified"); ES(monthlyR[,4],method="modified")
43
44
#################################################################################
45
# Make Exhibit 3 Risk budget paper: Efficient frontier plot
46
#################################################################################
47
48
# Layout 3
49
source("chart.StackedBar.R");
50
51
mESfun = function( series ){ return( operMES( series , alpha = 0.05 , r = 2 ) ) }
52
assetmu = apply( monthlyR , 2 , 'mean' )
53
assetCVaR = apply( monthlyR , 2 , 'mESfun' )
54
55
mESfun2 = function( w ){ return( operPortMES(w,mu=mu,alpha=0.05,sigma=sigma,M3=M3,M4=M4)[[1]] ) }
56
assetCVaR = rep(0,4);
57
for( i in 1:4 ){
58
w = rep(0,4); w[i]=1;
59
assetCVaR[i] = mESfun2( as.matrix(w) )
60
}
61
62
#> assetCVaR
63
#[1] 0.01235899 0.12465759 0.27755656 0.20558527
64
65
minmu = min(assetmu); maxmu = max(assetmu); print(minmu*12); print(maxmu*12);
66
67
# Load the data
68
69
labelnames = c( "US bond" , "S&P 500" , "NAREIT" , "GSCI" )
70
71
72
if(clean){
73
# Portfolio weights
74
W_MCC = read.csv( file = "EffFrontierMinCVaRConc_weights_clean_CC.csv" )[,2:(1+cAssets)]
75
W_minCVaR = read.csv( file = "EffFrontierMinCVaR_weights_clean_CC.csv" )[,2:(1+cAssets)]
76
W_minVar = read.csv( file = "EffFrontierMinVar_weights_clean.csv" )[,2:(1+cAssets)]
77
# Percentage CVaR contributions
78
PercCVaR_MCC = read.csv( file = "EffFrontierMinCVaRConc_percrisk_clean_CC.csv" )[,2:(1+cAssets)]
79
PercCVaR_minCVaR = read.csv( file = "EffFrontierMinCVaR_percrisk_clean_CC.csv" )[,2:(1+cAssets)]
80
PercCVaR_minVar = read.csv( file = "EffFrontierMinVar_percrisk_clean.csv" )[,2:(1+cAssets)]
81
# Summary stats
82
EffFrontier_stats_MCC = read.csv(file = "EffFrontierMinCVaRConc_stats_clean_CC.csv")[,2:5]
83
EffFrontier_stats_minCVaR = read.csv(file = "EffFrontierMinCVar_stats_clean_CC.csv")[,2:5]
84
EffFrontier_stats_minVar = read.csv(file = "EffFrontierMinVar_stats_clean.csv")[,2:5]
85
86
}else{
87
# Portfolio weights
88
W_MCC = read.csv(file = "EffFrontierMinCVaRConc_weights_CC.csv")[,2:(1+cAssets)]
89
W_minCVaR = read.csv(file = "EffFrontierMinCVaR_weights_CC.csv")[,2:(1+cAssets)]
90
W_minVar = read.csv(file = "EffFrontierMinVar_weights.csv")[,2:(1+cAssets)]
91
# Percentage CVaR contributions
92
PercCVaR_MCC = read.csv( file = "EffFrontierMinCVaRConc_percrisk_CC.csv" )[,2:(1+cAssets)]
93
PercCVaR_minCVaR = read.csv( file = "EffFrontierMinCVaR_percrisk_CC.csv" )[,2:(1+cAssets)]
94
PercCVaR_minVar = read.csv(file = "EffFrontierMinVar_percrisk.csv")[,2:(1+cAssets)]
95
# Summary stats
96
EffFrontier_stats_MCC = read.csv(file = "EffFrontierMinCVaRConc_stats_CC.csv")[,2:5]
97
EffFrontier_stats_minCVaR = read.csv(file = "EffFrontierMinCVar_stats_CC.csv")[,2:5]
98
EffFrontier_stats_minVar = read.csv(file = "EffFrontierMinVar_stats.csv")[,2:5]
99
}
100
101
vmu_MCC = EffFrontier_stats_MCC[,1] ; vmu_minCVaR = EffFrontier_stats_minCVaR[,1] ; vmu_minVar = EffFrontier_stats_minVar[,1] ;
102
vrisk_MCC = EffFrontier_stats_MCC[,2] ; vrisk_minCVaR = EffFrontier_stats_minCVaR[,2] ; vrisk_minVar = EffFrontier_stats_minVar[,2] ;
103
vmaxpercrisk_MCC = EffFrontier_stats_MCC[,3] ; vmaxpercrisk_minCVaR = EffFrontier_stats_minCVaR[,3] ;
104
vriskconc_MCC = EffFrontier_stats_MCC[,4] ; vriskconc_minCVaR = EffFrontier_stats_minCVaR[,4] ; vriskconc_minVar = EffFrontier_stats_minVar[,4] ;
105
106
vstdev_MCC = c();
107
for( r in 1:nrow(W_MCC) ){ wr = matrix( as.numeric(W_MCC[r,]) , ncol = 1 ) ;
108
vstdev_MCC = c( vstdev_MCC , sqrt( t(wr)%*%sigma%*%wr ) ) }
109
vstdev_minVar = c();
110
for( r in 1:nrow(W_minVar) ){ wr = matrix( as.numeric(W_minVar[r,]) , ncol = 1 ) ;
111
vstdev_minVar = c( vstdev_minVar , sqrt( t(wr)%*%sigma%*%wr ) ) }
112
113
vstdev_minCVaR = c();
114
for( r in 1:nrow(W_minCVaR) ){ wr = matrix( as.numeric(W_minCVaR[r,]) , ncol = 1 ) ;
115
vstdev_minCVaR = c( vstdev_minCVaR , sqrt( t(wr)%*%sigma%*%wr ) ) }
116
117
# The MCC and Min CVaR were obtained with DEoptim. The solutions are not always optimal. Correct for this:
118
119
order_MCC = sort(vmu_MCC,index.return=T)$ix ; order_minCVaR = sort(vmu_minCVaR,index.return=T)$ix
120
vmu_MCC = vmu_MCC[order_MCC] ; vmu_minCVaR = vmu_minCVaR[order_minCVaR]
121
vrisk_MCC = vrisk_MCC[order_MCC] ; vrisk_minCVaR = vrisk_minCVaR[order_minCVaR]
122
vstdev_MCC = vstdev_MCC[order_MCC] ; vstdev_minCVaR = vstdev_minCVaR[order_minCVaR]
123
vmaxpercrisk_MCC = vmaxpercrisk_MCC[order_MCC] ; vmaxpercrisk_minCVaR = vmaxpercrisk_MCC[order_minCVaR]
124
vriskconc_MCC = vriskconc_MCC[order_MCC] ; vriskconc_minCVaR = vriskconc_minCVaR[order_minCVaR]
125
W_MCC = W_MCC[order_MCC,] ; W_minCVaR = W_minCVaR[order_minCVaR,]
126
PercCVaR_MCC = PercCVaR_MCC[order_MCC,] ; PercCVaR_minCVaR = PercCVaR_minCVaR[order_minCVaR,]
127
128
# eliminate duplicates in mu
129
# Determines which elements of a vector or data frame are duplicates of elements with smaller subscripts,
130
# and returns a logical vector indicating which elements (rows) are duplicates.
131
a_MCC = duplicated(vmu_MCC) ; a_minCVaR = duplicated(vmu_minCVaR)
132
vmu_MCC = vmu_MCC[!a_MCC] ; vmu_minCVaR = vmu_minCVaR[!a_minCVaR]
133
vrisk_MCC = vrisk_MCC[!a_MCC] ; vrisk_minCVaR = vrisk_minCVaR[!a_minCVaR]
134
vstdev_MCC = vstdev_MCC[!a_MCC] ; vstdev_minCVaR = vstdev_minCVaR[!a_minCVaR]
135
vmaxpercrisk_MCC = vmaxpercrisk_MCC[!a_MCC] ; vmaxpercrisk_minCVaR = vmaxpercrisk_minCVaR[!a_minCVaR]
136
vriskconc_MCC = vriskconc_MCC[!a_MCC] ; vriskconc_minCVaR = vriskconc_minCVaR[!a_minCVaR]
137
W_MCC = W_MCC[!a_MCC,] ; W_minCVaR = W_minCVaR[!a_minCVaR,]
138
PercCVaR_MCC = PercCVaR_MCC[!a_MCC,] ; PercCVaR_minCVaR = PercCVaR_minCVaR[!a_minCVaR,]
139
140
# eliminate (efficiency: lower mu, higher CVaR alloc
141
142
sel_MCC = sel_minCVaR = c(); nmu_MCC = length(vmu_MCC); nmu_minCVaR = length(vmu_minCVaR);
143
for( i in 1:(nmu_MCC-1) ){
144
if( any(vriskconc_MCC[(i+1):nmu_MCC]<=vriskconc_MCC[i]) ){ }else{sel_MCC = c(sel_MCC, i) }
145
}
146
for( i in 1:(nmu_minCVaR-1) ){
147
if( any(vrisk_minCVaR[(i+1):nmu_minCVaR]<=vrisk_minCVaR[i]) ){ }else{sel_minCVaR = c(sel_minCVaR, i) }
148
}
149
vmu_MCC = vmu_MCC[sel_MCC] ; vmu_minCVaR = vmu_minCVaR[sel_minCVaR]
150
vrisk_MCC = vrisk_MCC[sel_MCC] ; vrisk_minCVaR = vrisk_minCVaR[sel_minCVaR]
151
vstdev_MCC = vstdev_MCC[sel_MCC] ; vstdev_minCVaR = vstdev_minCVaR[sel_minCVaR]
152
vmaxpercrisk_MCC = vmaxpercrisk_MCC[sel_MCC] ; vmaxpercrisk_minCVaR = vmaxpercrisk_minCVaR[sel_minCVaR]
153
vriskconc_MCC = vriskconc_MCC[sel_MCC] ; vriskconc_minCVaR = vriskconc_minCVaR[sel_minCVaR]
154
W_MCC = W_MCC[sel_MCC,] ; W_minCVaR = W_minCVaR[sel_minCVaR,]
155
PercCVaR_MCC = PercCVaR_MCC[sel_MCC,] ; PercCVaR_minCVaR = PercCVaR_minCVaR[sel_minCVaR,]
156
157
wEW <- rep(1/4,4)
158
muEW = mean(assetmu*12)
159
outES = ES(weights=wEW, portfolio_method="component", mu = mu, sigma = sigma, m3=M3, m4=M4,invert=FALSE)
160
riskEW = outES$MES; riskconcEW = max(outES$contribution)
161
162
if(clean){
163
postscript('frontier_fourassets_clean.eps')
164
}else{ postscript('frontier_fourassets.eps') }
165
166
layout( matrix( c(1,2,3,1,2,3), ncol = 2 ) , height= c(5,5,1), width=c(1,1) )
167
ylim = c( min(assetmu) , max(assetmu) )
168
par( mar = c(4.5,5,2,2), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
169
plot( vrisk_MCC , vmu_MCC*12 , type="l", lty = 1, main = "" ,
170
ylab="Annualized mean return" , xlab="Monthly 95% Portfolio CVaR" ,
171
lwd=2, xlim = c(0.01,0.13) , ylim = (ylim*12+c(0,0.01)) , col="black" )
172
lines( vrisk_minCVaR , vmu_minCVaR*12, lty = 1, lwd=2, col="darkgray" )
173
lines( vrisk_minVar , vmu_minVar*12, lty = 3, lwd=2, col="black" )
174
175
c = 1; text(y=assetmu[c]*12,x= assetCVaR[c]-0.005 , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3); points(y=assetmu[c]*12,x= assetCVaR[c] )
176
for( c in 2:cAssets ){
177
text(y=assetmu[c]*12,x= assetCVaR[c] , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3)
178
points(y=assetmu[c]*12,x= assetCVaR[c] )
179
};
180
# Plot also EW portfolio
181
text(y=muEW,x=riskEW, label="EW" , cex = 0.7, offset = 0.2, pos = 3)
182
points(y=muEW,x= riskEW , pch=22 )
183
text(y=vmu_MCC[1]*12,x=vrisk_MCC[1], label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 1)
184
points(y=vmu_MCC[1]*12,x=vrisk_MCC[1], pch=22 )
185
text(y=vmu_minCVaR[1]*12,x=vrisk_minCVaR[1]-0.0035, label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 1)
186
points(y=vmu_minCVaR[1]*12,x=vrisk_minCVaR[1], pch=22 )
187
text(y=vmu_minVar[1]*12-0.001,x=vrisk_minVar[1]+0.0035, label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 1)
188
points(y=vmu_minVar[1]*12,x=vrisk_minVar[1], pch=22 )
189
190
par( mar = c(4.5,5,2,2), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
191
plot( vriskconc_MCC/vrisk_MCC , vmu_MCC*12 , type="l", lty = 1, main = "" ,
192
ylab="Annualized mean return" , xlab="Largest Perc. CVaR contribution" ,
193
lwd=2, xlim = c(0.2,1.1), ylim = c(ylim*12+c(0,0.01)) , col="black" )
194
lines( vriskconc_minCVaR/vrisk_minCVaR , vmu_minCVaR*12, lty = 1, lwd=2, col="darkgray" )
195
lines( vriskconc_minVar/vrisk_minVar , vmu_minVar*12 , lty = 3, lwd=2, col="black" )
196
197
text(y=muEW,x=riskconcEW/riskEW, label="EW" , cex = 0.7, offset = 0.2, pos = 1)
198
points(y=muEW,x= riskconcEW/riskEW , pch=22 )
199
text(y=vmu_MCC[1]*12,x=vriskconc_MCC[1]/vrisk_MCC[1], label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 1)
200
points(y=vmu_MCC[1]*12,x=vriskconc_MCC[1]/vrisk_MCC[1], pch=22 )
201
text(y=vmu_minCVaR[1]*12,x=vriskconc_minCVaR[1]/vrisk_minCVaR[1], label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 1)
202
points(y=vmu_minCVaR[1]*12,x=vriskconc_minCVaR[1]/vrisk_minCVaR[1], pch=22 )
203
text(y=vmu_minVar[1]*12,x=vriskconc_minVar[1]/vrisk_minVar[1], label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 1)
204
points(y=vmu_minVar[1]*12,x=vriskconc_minVar[1]/vrisk_minVar[1], pch=22 )
205
206
for( c in 1:cAssets ){
207
text(y=assetmu[c]*12,x= 1 , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 4)
208
points(y=assetmu[c]*12,x= 1 )
209
};
210
211
par( mar = c(0,1,1,0) )
212
plot.new()
213
legend("center",legend=c("Mean-CVaR concentration", "Mean-CVaR","Mean-StdDev" ),
214
lty=c("solid","solid","dashed"), cex=0.8,ncol=3,lwd=c(4,4,2),col=c("black","darkgray","black"))
215
216
dev.off()
217
218
if(clean){
219
postscript('frontier_fourassets_bis_clean.eps')
220
}else{ postscript('frontier_fourassets_bis.eps') }
221
222
layout( matrix( c(1,2,3,1,2,3), ncol = 2 ) , height= c(5,5,1), width=c(1,1) )
223
ylim = c( min(assetmu) , max(assetmu) )
224
par( mar = c(4.5,5,2,2), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
225
plot( vrisk_MCC , vmu_MCC*12 , type="l", lty = 1, main = "" ,
226
ylab="Annualized mean return" , xlab="Monthly 95% Portfolio CVaR" ,
227
lwd=2, xlim = c(0,0.13) , ylim = (ylim*12+c(0,0.02)) , col="black" )
228
lines( vrisk_minCVaR , vmu_minCVaR*12, lty = 1, lwd=2, col="darkgray" )
229
lines( vrisk_minVar , vmu_minVar*12, lty = 3, lwd=2, col="black" )
230
231
c = 1; text(y=assetmu[c]*12,x= assetCVaR[c]-0.005 , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3); points(y=assetmu[c]*12,x= assetCVaR[c] )
232
for( c in 2:cAssets ){
233
text(y=assetmu[c]*12,x= assetCVaR[c] , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3)
234
points(y=assetmu[c]*12,x= assetCVaR[c] )
235
};
236
# Plot also EW portfolio
237
text(y=muEW,x=riskEW, label="EW" , cex = 0.7, offset = 0.2, pos = 3)
238
points(y=muEW,x= riskEW , pch=22 )
239
text(y=vmu_MCC[1]*12,x=vrisk_MCC[1], label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 4)
240
points(y=vmu_MCC[1]*12,x=vrisk_MCC[1], pch=22 )
241
text(y=vmu_minCVaR[1]*12,x=vrisk_minCVaR[1]-0.0035, label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 1)
242
points(y=vmu_minCVaR[1]*12,x=vrisk_minCVaR[1], pch=22 )
243
text(y=vmu_minVar[1]*12-0.0035,x=vrisk_minVar[1], label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 1)
244
points(y=vmu_minVar[1]*12,x=vrisk_minVar[1], pch=22 )
245
246
par( mar = c(4.5,5,2,2), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
247
248
plot( vriskconc_MCC, vmu_MCC*12 , type="l", lty = 1, main = "" ,
249
ylab="Annualized mean return" , xlab="Largest CVaR contribution" ,
250
lwd=2, xlim = c(0,0.13), ylim = c(ylim*12+c(0,0.02)) , col="black" )
251
lines( vriskconc_minCVaR , vmu_minCVaR*12, lty = 1, lwd=2, col="darkgray" )
252
lines( vriskconc_minVar , vmu_minVar*12 , lty = 3, lwd=2, col="black" )
253
254
text(y=muEW,x=riskconcEW, label="EW" , cex = 0.7, offset = 0.2, pos = 1)
255
points(y=muEW,x= riskconcEW , pch=22 )
256
text(y=vmu_MCC[1]*12,x=vriskconc_MCC[1], label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 2)
257
points(y=vmu_MCC[1]*12,x=vriskconc_MCC[1], pch=22 )
258
text(y=vmu_minCVaR[1]*12,x=vriskconc_minCVaR[1], label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 4)
259
points(y=vmu_minCVaR[1]*12,x=vriskconc_minCVaR[1], pch=22 )
260
text(y=vmu_minVar[1]*12-0.003,x=vriskconc_minVar[1], label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 1)
261
points(y=vmu_minVar[1]*12,x=vriskconc_minVar[1], pch=22 )
262
263
#for( c in 1:cAssets ){
264
# text(y=assetmu[c]*12,x= 1 , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 4)
265
# points(y=assetmu[c]*12,x= 1 )
266
#};
267
268
par( mar = c(0,1,1,0) )
269
plot.new()
270
legend("center",legend=c("Mean-CVaR concentration", "Mean-CVaR","Mean-StdDev" ),
271
lty=c("solid","solid","dashed"), cex=0.8,ncol=3,lwd=c(4,4,2),col=c("black","darkgray","black"))
272
273
dev.off()
274
275
276
277
if(clean){
278
postscript('frontier_fourassets_bis_clean.eps')
279
}else{ postscript('frontier_fourassets_bis.eps') }
280
281
layout( matrix( c(1,2,3,1,2,3), ncol = 2 ) , height= c(5,5,1), width=c(1,1) )
282
ylim = c( min(assetmu) , max(assetmu) )
283
par( mar = c(4.5,5,2,2), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
284
plot( vrisk_MCC , vmu_MCC*12 , type="l", lty = 1, main = "" ,
285
ylab="Annualized mean return" , xlab="Monthly 95% Portfolio CVaR" ,
286
lwd=2, xlim = c(0,0.13) , ylim = (ylim*12+c(0,0.02)) , col="black" )
287
lines( vrisk_minCVaR , vmu_minCVaR*12, lty = 1, lwd=2, col="darkgray" )
288
lines( vrisk_minVar , vmu_minVar*12, lty = 3, lwd=2, col="black" )
289
290
c = 1; text(y=assetmu[c]*12,x= assetCVaR[c]-0.005 , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3);
291
points(y=assetmu[c]*12,x= assetCVaR[c] )
292
for( c in 2:cAssets ){
293
text(y=assetmu[c]*12,x= assetCVaR[c] , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3)
294
points(y=assetmu[c]*12,x= assetCVaR[c] )
295
};
296
# Plot also EW portfolio
297
text(y=muEW,x=riskEW, label="EW" , cex = 0.7, offset = 0.2, pos = 3)
298
points(y=muEW,x= riskEW , pch=22 )
299
text(y=vmu_MCC[1]*12,x=vrisk_MCC[1], label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 4)
300
points(y=vmu_MCC[1]*12,x=vrisk_MCC[1], pch=22 )
301
text(y=vmu_minCVaR[1]*12,x=vrisk_minCVaR[1]-0.0035, label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 1)
302
points(y=vmu_minCVaR[1]*12,x=vrisk_minCVaR[1], pch=22 )
303
text(y=vmu_minVar[1]*12-0.0035,x=vrisk_minVar[1], label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 1)
304
points(y=vmu_minVar[1]*12,x=vrisk_minVar[1], pch=22 )
305
306
par( mar = c(4.5,5,2,2), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
307
308
plot( vriskconc_MCC, vmu_MCC*12 , type="l", lty = 1, main = "" ,
309
ylab="Annualized mean return" , xlab="Largest CVaR contribution" ,
310
lwd=2, xlim = c(0,0.13), ylim = c(ylim*12+c(0,0.02)) , col="black" )
311
lines( vriskconc_minCVaR , vmu_minCVaR*12, lty = 1, lwd=2, col="darkgray" )
312
lines( vriskconc_minVar , vmu_minVar*12 , lty = 3, lwd=2, col="black" )
313
314
text(y=muEW,x=riskconcEW, label="EW" , cex = 0.7, offset = 0.2, pos = 1)
315
points(y=muEW,x= riskconcEW , pch=22 )
316
text(y=vmu_MCC[1]*12,x=vriskconc_MCC[1], label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 2)
317
points(y=vmu_MCC[1]*12,x=vriskconc_MCC[1], pch=22 )
318
text(y=vmu_minCVaR[1]*12,x=vriskconc_minCVaR[1], label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 4)
319
points(y=vmu_minCVaR[1]*12,x=vriskconc_minCVaR[1], pch=22 )
320
text(y=vmu_minVar[1]*12-0.003,x=vriskconc_minVar[1], label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 1)
321
points(y=vmu_minVar[1]*12,x=vriskconc_minVar[1], pch=22 )
322
323
#for( c in 1:cAssets ){
324
# text(y=assetmu[c]*12,x= 1 , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 4)
325
# points(y=assetmu[c]*12,x= 1 )
326
#};
327
328
par( mar = c(0,1,1,0) )
329
plot.new()
330
legend("center",legend=c("Mean-CVaR concentration", "Mean-CVaR","Mean-StdDev" ),
331
lty=c("solid","solid","dashed"), cex=0.8,ncol=3,lwd=c(4,4,2),col=c("black","darkgray","black"))
332
333
dev.off()
334
335
assetStdDev = sqrt(diag(sigma))
336
StdDevEW = sqrt(matrix( rep(1/4,4) , ncol = 4 )%*%sigma%*%matrix( rep(1/4,4) , ncol = 1 ))
337
if(clean){
338
postscript('frontier_fourassets_tris_clean.eps')
339
}else{ postscript('frontier_fourassets_tris.eps') }
340
341
layout( matrix( c(1,2,3,4,1,2,3,4), ncol = 2 , nrow=4 ) , height= c(5,5,5,1), width=c(1,1) )
342
343
layout( matrix( c(1,2,3,4), ncol = 2 , nrow=2 ) , height= c(5,5), width=c(1,1) )
344
345
ylim = c( min(assetmu) , max(assetmu) )
346
par( mar = c(4.5,5,2,0.1), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
347
plot( vstdev_MCC*sqrt(12) , vmu_MCC*12 , type="l", lty = 1, main = "" ,
348
ylab="Annualized mean return" , xlab="Annualized Portfolio StdDev" ,
349
lwd=2, xlim = c(-0.01,0.2) , ylim = (ylim*12+c(0,0.01)) , col="black" )
350
lines( vstdev_minCVaR*sqrt(12) , vmu_minCVaR*12, lty = 1, lwd=1, col="darkgray" )
351
lines( vstdev_minVar*sqrt(12) , vmu_minVar*12, lty = 3, lwd=2, col="black" )
352
353
c = 1; text(y=assetmu[c]*12+0.0005,x= assetStdDev[c]*sqrt(12) , label=labelnames[c] ,
354
cex = 0.7, offset = 0.2, pos = 4);
355
points(y=assetmu[c]*12,x= assetStdDev[c]*sqrt(12) )
356
for( c in 2:cAssets ){
357
text(y=assetmu[c]*12,x= assetStdDev[c]*sqrt(12) , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3)
358
points(y=assetmu[c]*12,x= assetStdDev[c]*sqrt(12) )
359
};
360
# Plot also EW portfolio
361
text(y=muEW,x=StdDevEW*sqrt(12), label="EW" , cex = 0.7, offset = 0.2, pos = 3)
362
points(y=muEW,x= StdDevEW*sqrt(12) , pch=22 )
363
text(y=vmu_MCC[1]*12,x=vstdev_MCC[1]*sqrt(12), label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 4)
364
points(y=vmu_MCC[1]*12,x=vstdev_MCC[1]*sqrt(12), pch=22 )
365
text(y=vmu_minCVaR[1]*12-0.0035,x=vstdev_minCVaR[1]*sqrt(12)-0.0035, label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 4)
366
points(y=vmu_minCVaR[1]*12,x=vstdev_minCVaR[1]*sqrt(12), pch=22 )
367
text(y=vmu_minVar[1]*12+0.0035,x=vstdev_minVar[1]*sqrt(12), label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 2)
368
points(y=vmu_minVar[1]*12,x=vstdev_minVar[1]*sqrt(12), pch=22 )
369
370
# Values of 1, 2, 3 and 4, respectively indicate positions below, to the left of, above and to the right
371
372
373
374
375
par( mar = c(0,1,1,0.1) )
376
plot.new()
377
legend("center",legend=c("Mean-CVaR concentration", "Mean-CVaR","Mean-StdDev" ),
378
lty=c("solid","solid","dashed"), cex=0.8,ncol=1,lwd=c(4,2,2),col=c("black","darkgray","black"))
379
380
381
ylim = c( min(assetmu) , max(assetmu) )
382
par( mar = c(4.5,5,2,0.1), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
383
plot( vrisk_MCC , vmu_MCC*12 , type="l", lty = 1, main = "" ,
384
ylab="Annualized mean return" , xlab="Monthly 95% Portfolio CVaR" ,
385
lwd=2, xlim = c(-0.01,0.13) , ylim = (ylim*12+c(0,0.01)) , col="black" )
386
lines( vrisk_minCVaR , vmu_minCVaR*12, lty = 1, lwd=1, col="darkgray" )
387
lines( vrisk_minVar , vmu_minVar*12, lty = 3, lwd=2, col="black" )
388
389
c = 1; text(y=assetmu[c]*12,x= assetCVaR[c]-0.005 , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3); points(y=assetmu[c]*12,x= assetCVaR[c] )
390
for( c in 2:cAssets ){
391
text(y=assetmu[c]*12,x= assetCVaR[c] , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 3)
392
points(y=assetmu[c]*12,x= assetCVaR[c] )
393
};
394
# Plot also EW portfolio
395
text(y=muEW,x=riskEW, label="EW" , cex = 0.7, offset = 0.2, pos = 3)
396
points(y=muEW,x= riskEW , pch=22 )
397
text(y=vmu_MCC[1]*12,x=vrisk_MCC[1], label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 4)
398
points(y=vmu_MCC[1]*12,x=vrisk_MCC[1], pch=22 )
399
text(y=vmu_minCVaR[1]*12,x=vrisk_minCVaR[1]-0.0035, label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 1)
400
points(y=vmu_minCVaR[1]*12,x=vrisk_minCVaR[1], pch=22 )
401
text(y=vmu_minVar[1]*12,x=vrisk_minVar[1], label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 4)
402
points(y=vmu_minVar[1]*12,x=vrisk_minVar[1], pch=22 )
403
404
405
406
par( mar = c(4.5,5,2,0.1), las=1 ,cex=0.9 , cex.axis=0.9, cex.main=0.95)
407
408
plot( vriskconc_MCC, vmu_MCC*12 , type="l", lty = 1, main = "" ,
409
ylab="Annualized mean return" , xlab="Largest contribution to monthly 95% CVaR" ,
410
lwd=2, xlim = c(-0.01,0.13), ylim = c(ylim*12+c(0,0.01)) , col="black" )
411
lines( vriskconc_minCVaR , vmu_minCVaR*12, lty = 1, lwd=1, col="darkgray" )
412
lines( vriskconc_minVar , vmu_minVar*12 , lty = 3, lwd=2, col="black" )
413
414
text(y=muEW,x=riskconcEW, label="EW" , cex = 0.7, offset = 0.2, pos = 1)
415
points(y=muEW,x= riskconcEW , pch=22 )
416
text(y=vmu_MCC[1]*12,x=vriskconc_MCC[1], label="MCC=ERC" , cex = 0.7, offset = 0.2, pos = 2)
417
points(y=vmu_MCC[1]*12,x=vriskconc_MCC[1], pch=22 )
418
text(y=vmu_minCVaR[1]*12,x=vriskconc_minCVaR[1], label="Min CVaR" , cex = 0.7, offset = 0.2, pos = 4)
419
points(y=vmu_minCVaR[1]*12,x=vriskconc_minCVaR[1], pch=22 )
420
text(y=vmu_minVar[1]*12,x=vriskconc_minVar[1], label="Min StdDev" , cex = 0.7, offset = 0.2, pos = 2)
421
points(y=vmu_minVar[1]*12,x=vriskconc_minVar[1], pch=22 )
422
423
424
425
#for( c in 1:cAssets ){
426
# text(y=assetmu[c]*12,x= 1 , label=labelnames[c] , cex = 0.7, offset = 0.2, pos = 4)
427
# points(y=assetmu[c]*12,x= 1 )
428
#};
429
430
431
432
dev.off()
433
434
435
# Make the weight/CVaR allocation plots
436
#---------------------------------------
437
438
Wsel_MCC = PercCVaRsel_MCC = Wsel_minCVaR = PercCVaRsel_minCVaR = Wsel_minVar = PercCVaRsel_minVar = c();
439
vmusel_MCC = vrisksel_MCC = vriskconcsel_MCC = vmusel_minCVaR = vrisksel_minCVaR = vriskconcsel_minCVaR = vmusel_minVar = vrisksel_minVar = vriskconcsel_minVar = c();
440
lm = minmu = min( c(vmu_MCC,vmu_minCVaR) ) ; maxmu = max( c(vmu_MCC,vmu_minCVaR) );
441
ylim = c( min(assetmu) - 0.0003 , max(assetmu) + 0.0003 )
442
xlim = c( 0 , max(assetCVaR) + 0.01 )
443
444
binning = T # for the weight plots, binned data such that no visual misinterpretation is possible
445
step = quantile( diff(vmu_MCC) , 0.1 )
446
if( binning ){
447
for( rm in seq( minmu+step , maxmu , step ) ){
448
selection = c(vmu_MCC >= lm & vmu_MCC < rm) ;
449
if( any(selection) ){
450
selection = c(1:length(selection))[selection]
451
selone = sort(vriskconc_MCC[ selection ],index.return=T)$ix[1]
452
selone = selection[selone]
453
vmusel_MCC = c( vmusel_MCC , mean(vmu_MCC[selone ] ));
454
Wsel_MCC = rbind( Wsel_MCC , apply( W_MCC[selone,] ,2,'mean' ))
455
PercCVaRsel_MCC = rbind( PercCVaRsel_MCC , apply( PercCVaR_MCC[selone,] ,2,'mean' ))
456
vrisksel_MCC = c( vrisksel_MCC , mean(vrisk_MCC[ selone ]) );
457
vriskconcsel_MCC = c( vriskconcsel_MCC , mean(vriskconc_MCC[ selone ]) )
458
}else{
459
vmusel_MCC = c( vmusel_MCC , NA );
460
Wsel_MCC = rbind( Wsel_MCC , rep(NA,cAssets) )
461
PercCVaRsel_MCC = rbind( PercCVaRsel_MCC , rep(NA,cAssets) )
462
vrisksel_MCC = c( vrisksel_MCC , NA );
463
vriskconcsel_MCC = c( vriskconcsel_MCC , NA )
464
}
465
selection = c(vmu_minCVaR >= lm & vmu_minCVaR < rm) ;
466
if( any(selection) ){
467
selection = c(1:length(selection))[selection]; selone = sort(vrisk_minCVaR[ selection ],index.return=T)$ix[1]
468
selone = selection[selone]
469
vmusel_minCVaR = c( vmusel_minCVaR , mean(vmu_minCVaR[selone ] ));
470
Wsel_minCVaR = rbind( Wsel_minCVaR , apply( W_minCVaR[selone,] ,2,'mean' ))
471
PercCVaRsel_minCVaR = rbind( PercCVaRsel_minCVaR , apply( PercCVaR_minCVaR[selone,] ,2,'mean' ))
472
vrisksel_minCVaR = c( vrisksel_minCVaR , mean(vrisk_minCVaR[ selone ]) );
473
vriskconcsel_minCVaR = c( vriskconcsel_minCVaR , mean(vriskconc_minCVaR[ selone ]) )
474
}else{
475
vmusel_minCVaR = c( vmusel_minCVaR , NA );
476
Wsel_minCVaR = rbind( Wsel_minCVaR , rep(NA,cAssets) )
477
PercCVaRsel_minCVaR = rbind( PercCVaRsel_minCVaR , rep(NA,cAssets) )
478
vrisksel_minCVaR = c( vrisksel_minCVaR , NA );
479
vriskconcsel_minCVaR = c( vriskconcsel_minCVaR , NA )
480
}
481
selection = c(vmu_minVar >= lm & vmu_minVar < rm) ;
482
if( any(selection) ){
483
selection = c(1:length(selection))[selection]; selone = sort(vrisk_minVar[ selection ],index.return=T)$ix[1]
484
selone = selection[selone]
485
vmusel_minVar = c( vmusel_minVar , mean(vmu_minVar[selone ] ));
486
Wsel_minVar = rbind( Wsel_minVar , apply( W_minVar[selone,] ,2,'mean' ))
487
PercCVaRsel_minVar = rbind( PercCVaRsel_minVar , apply( PercCVaR_minVar[selone,] ,2,'mean' ))
488
vrisksel_minVar = c( vrisksel_minVar , mean(vrisk_minVar[ selone ]) );
489
vriskconcsel_minVar = c( vriskconcsel_minVar , mean(vriskconc_minVar[ selone ]) )
490
}else{
491
vmusel_minVar = c( vmusel_minVar , NA );
492
Wsel_minVar = rbind( Wsel_minVar , rep(NA,cAssets) )
493
PercCVaRsel_minVar = rbind( PercCVaRsel_minVar , rep(NA,cAssets) )
494
vrisksel_minVar = c( vrisksel_minVar , NA );
495
vriskconcsel_minVar = c( vriskconcsel_minVar , NA )
496
}
497
lm = rm;
498
}
499
}else{
500
vmusel_MCC = vmu_MCC ; vmusel_minCVaR = vmu_minCVaR
501
Wsel_MCC = W_MCC ; Wsel_minCVaR = W_minCVaR ;
502
vrisksel_MCC = vrisk_MCC ; vrisksel_minCVaR = vrisk_minCVaR
503
vriskconcsel_MCC = vriskconc_MCC ; vriskconcsel_minCVar = vriskconc_minCVaR
504
PercCVaRsel_MCC = PercCVaR_MCC ; PercCVaRsel_minCVar = PercCVaR_minCVar ;
505
}
506
507
library(zoo)
508
cAssets = ncol(monthlyR)
509
colorset = sort(gray( 1-(seq(1,cAssets,1)/(cAssets))^1.5 )) ;
510
colnames( Wsel_MCC ) = colnames( Wsel_minCVaR ) = labelnames
511
rownames( Wsel_MCC ) = rownames( PercCVaRsel_MCC ) = round( interpNA(vmusel_MCC)*12,4);
512
rownames( Wsel_minCVaR ) = rownames( PercCVaRsel_minCVaR ) = round( interpNA(vmusel_minCVaR)*12,4) ;
513
514
rownames( Wsel_minVar ) = rownames( PercCVaRsel_minVar ) = round( interpNA(vmusel_minVar)*12,4) ;
515
colnames( Wsel_minVar ) = labelnames
516
517
518
w.names = c( "US bond" , "S&P 500", "NAREIT" , "GSCI" )
519
namelabels = c("Mean-StdDev" , "Mean-CVaR","Mean-CVaR concentration" )
520
l = 2 ; mar1 =c(2,l,2,1.1) ; mar3 = c(3,l+1,3,0.1)
521
522
source("chart.StackedBar.R");
523
524
# Stacked weights plot:
525
if(clean){
526
postscript('stackedweightsriskcont_efficientfrontier_withNA_clean.eps')
527
}else{ postscript('stackedweightsriskcont_efficientfrontier_withNA.eps') }
528
529
layout( matrix( c(1,2,3,4,5,6,7,4), ncol = 2 ) , height= c(1.5,1.5,1.5,0.7), width=1)
530
531
par(mar=mar3 , cex.main=1)
532
chart.StackedBar2(Wsel_minVar ,col=colorset,space=0, main = namelabels[1], ylab="Weight allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
533
chart.StackedBar2(Wsel_minCVaR,col=colorset,space=0, main = namelabels[2], ylab="Weight allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
534
chart.StackedBar2(Wsel_MCC ,col=colorset,space=0, main = namelabels[3], ylab="Weight allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T, legend.loc = NULL,ylim=c(0,1),border = F )
535
536
par(mar=mar1 , cex.main=1)
537
plot.new()
538
legend("center",legend=w.names,fill=colorset,ncol=4)
539
540
par(mar=mar3 , cex.main=1)
541
chart.StackedBar2(PercCVaRsel_minVar,col=colorset,space=0, main = namelabels[1], ylab="CVaR allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
542
chart.StackedBar2(PercCVaRsel_minCVaR,col=colorset,space=0, main = namelabels[2], ylab="CVaR allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
543
chart.StackedBar2(PercCVaRsel_MCC,col=colorset,space=0, main = namelabels[3], ylab="CVaR allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
544
545
dev.off()
546
547
548
if(clean){
549
postscript('stackedweightsriskcont_efficientfrontier_clean.eps')
550
}else{ postscript('stackedweightsriskcont_efficientfrontier.eps') }
551
552
layout( matrix( c(1,2,3,4,5,6,7,4), ncol = 2 ) , height= c(1.5,1.5,1.5,0.7), width=1)
553
554
par(mar=mar3 , cex.main=1)
555
chart.StackedBar2(interpNA(Wsel_minVar) ,col=colorset,space=0, main = namelabels[1], ylab="Weight allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
556
chart.StackedBar2(interpNA(Wsel_minCVaR),col=colorset,space=0, main = namelabels[2], ylab="Weight allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
557
chart.StackedBar2(interpNA(Wsel_MCC) ,col=colorset,space=0, main = namelabels[3], ylab="Weight allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T, legend.loc = NULL,ylim=c(0,1),border = F )
558
559
par(mar=mar1 , cex.main=1)
560
plot.new()
561
legend("center",legend=w.names,col=colorset,ncol=4,lwd=6)
562
563
par(mar=mar3 , cex.main=1)
564
chart.StackedBar2(interpNA(PercCVaRsel_minVar),col=colorset,space=0, main = namelabels[1], ylab="CVaR allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
565
chart.StackedBar2(interpNA(PercCVaRsel_minCVaR),col=colorset,space=0, main = namelabels[2], ylab="CVaR allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
566
chart.StackedBar2(interpNA(PercCVaRsel_MCC),col=colorset,space=0, main = namelabels[3], ylab="CVaR allocation", las=1, l=3.9, r=0, cex.axis=1, cex.lab=1, cex.main=1, axisnames=T,legend.loc = NULL,ylim=c(0,1),border = F )
567
568
dev.off()
569
570
571
572
#----------------------------------------------------------------------------------------------------
573
# DISCUSSION RESULTS
574
575
576
# unconstrained:
577
12*vmu_minVar[1] ; sqrt(12)*vstdev_minVar[1] ; vrisk_minVar[1] ; W_minVar[1,] ; PercCVaR_minVar[1,];
578
12*vmu_minCVaR[1]; sqrt(12)*vstdev_minCVaR[1] ; vrisk_minCVaR[1]; W_minCVaR[1,]; PercCVaR_minCVaR[1,];
579
12*vmu_MCC[1] ; sqrt(12)*vstdev_MCC[1] ; vrisk_MCC[1] ; W_MCC[1,] ; PercCVaR_MCC[1,];
580
581
> # unconstrained:
582
> 12*vmu_minVar[1] ; sqrt(12)*vstdev_minVar[1] ; vrisk_minVar[1] ; W_minVar[1,] ; PercCVaR_minVar[1,];
583
[1] 0.07705461
584
[1] 0.04967331
585
[1] 0.0277955
586
V1 V2 V3 V4
587
1 0.8404353 0.03862133 0.03643427 0.08450912
588
V1 V2 V3 V4
589
1 0.5620443 0.08734358 0.08376784 0.2668442
590
> 12*vmu_minCVaR[1]; sqrt(12)*vstdev_minCVaR[1] ; vrisk_minCVaR[1]; W_minCVaR[1,]; PercCVaR_minCVaR[1,];
591
[1] 0.075321
592
[1] 0.05230409
593
[1] 0.0228343
594
V1 V2 V3 V4
595
2 0.9771176 0 0 0.02288243
596
V1 V2 V3 V4
597
2 0.9771177 0 0 0.02288231
598
> 12*vmu_MCC[1] ; sqrt(12)*vstdev_MCC[1] ; vrisk_MCC[1] ; W_MCC[1,] ; PercCVaR_MCC[1,];
599
[1] 0.08714249
600
[1] 0.06588349
601
[1] 0.038659
602
V1 V2 V3 V4
603
1 0.4733987 0.2070037 0.1843733 0.1352243
604
V1 V2 V3 V4
605
1 0.25064 0.2505296 0.2497479 0.2490826
606
607
608
609
cbind( vmu_minVar*12 , vriskconc_minVar ) :
610
611
cbind( vmu_minCVaR*12 , vriskconc_minCVaR ) : 0.0816 is turning point
612
# [124,] 0.09017165 0.01210119 is turning point
613
614
cbind( vmu_MCC*12 , vrisk_MCC, vriskconc_MCC )
615
616
# Mean/CVaR concentration efficient portfolios
617
618
# On Cleaned Data: Three segments
619
620
> cbind( vmu_MCC*12 , vrisk_MCC, vriskconc_MCC )
621
[1,] 0.08714249 0.03865900 0.009689492
622
[2,] 0.08726420 0.03849615 0.009802639
623
#24
624
[23,] 0.08997886 0.03585947 0.011824072
625
[24,] 0.09010885 0.03585032 0.011871467
626
[25,] 0.09024551 0.03589501 0.011974648
627
[26,] 0.09036701 0.03594272 0.012064923
628
[27,] 0.09050353 0.03610158 0.012242378
629
[28,] 0.09062808 0.03621858 0.012405637
630
[29,] 0.09075394 0.03635143 0.012544703
631
[30,] 0.09087482 0.03674130 0.012857458
632
# 174
633
[170,] 0.10996933 0.06748652 0.039200481
634
[171,] 0.11008934 0.06789785 0.042263237
635
[172,] 0.11020953 0.06842979 0.045351289
636
[173,] 0.11033011 0.06909579 0.048542053
637
[174,] 0.11045013 0.06985814 0.051639874
638
[175,] 0.11057105 0.07075940 0.054836023
639
[176,] 0.11069142 0.07176853 0.057990740
640
641
[193,] 0.11273404 0.10433383 0.104615672
642
[194,] 0.11273413 0.10433618 0.104617643
643
644
> W_MCC
645
V1 V2 V3 V4
646
1 4.733987e-01 0.20700375 0.1843733 1.352243e-01
647
3 4.759377e-01 0.20759359 0.1855799 1.308888e-01
648
#24
649
23 5.561089e-01 0.22228044 0.2020208 1.958989e-02
650
24 5.614145e-01 0.22306274 0.2027785 1.274428e-02
651
25 5.651643e-01 0.22387831 0.2036273 7.330121e-03
652
26 5.664972e-01 0.22511059 0.2048818 3.510355e-03
653
27 5.674492e-01 0.22627029 0.2060026 2.778562e-04
654
28 5.623908e-01 0.22852300 0.2080519 1.034299e-03
655
29 5.595434e-01 0.23008873 0.2098842 4.836782e-04
656
657
# 174
658
170 1.444844e-02 0.51421725 0.4710510 2.833091e-04
659
171 1.074035e-02 0.51609949 0.4727863 3.738407e-04
660
172 7.379454e-03 0.51796198 0.4745030 1.555284e-04
661
173 3.671705e-03 0.51988524 0.4762691 1.739490e-04
662
174 2.930070e-04 0.52170814 0.4779540 4.485562e-05
663
175 2.228161e-05 0.50313662 0.4968072 3.392269e-05
664
176 9.137182e-07 0.48289134 0.5170837 2.405561e-05
665
666
199 1.461185e-06 0.01379234 0.9862059 2.992504e-07
667
200 8.716672e-07 0.01377375 0.9862242 1.214785e-06
668
669
# Unconstrained: Equal Risk Contribution Portfolio:
670
# > W_MCC[1,]
671
# 0.4733987 0.2070037 0.1843733 0.1352243
672
#> PercCVaR_MCC[1,]
673
# 0.25064 0.2505296 0.2497479 0.2490826
674
# > vmu_MCC[1]*12
675
# [1] 0.08714249
676
#> vrisk_MCC[1]
677
#[1] 0.038659
678
#> vriskconc_MCC[1]
679
#[1] 0.009689492
680
# Segment 1: increasing allocation to bonds and decreasing allocation to commodities
681
# Portfolio risk concentration increases, portfolio risk decreases
682
# > W_MCC[25:27,]
683
# 0.7052788 0.1584357 0.1321813 0.0041042550
684
# 0.7085301 0.1597522 0.1313759 0.0003417814
685
# 0.7025028 0.1628656 0.1344935 0.0001380022
686
#> vmu_MCC[26]*12
687
#[1] 0.0812571
688
#> vrisk_MCC[26]
689
#[1] 0.03352778
690
#> vriskconc_MCC[26]
691
#[1] 0.0112
692
# Segment 2: increasing allocation to both US equity and EAFE
693
# Portfolio risk concentration and risk increase together
694
# > W_MCC[138:140,]
695
# 0.0078323664 0.5106416 0.4814090 1.169711e-04
696
# 0.0005986683 0.5136429 0.4856355 1.228907e-04
697
# 0.0002258733 0.5201106 0.4796231 4.051641e-05
698
# > PercCVaR_MCC[138:140,]
699
# 0e+00 0.4999 0.5000 0
700
#> vmu_MCC[139]*12
701
#[1] 0.09483605
702
# > vrisk_MCC[139]
703
# [1] 0.09808784
704
# > vriskconc_MCC[139]
705
# [1] 0.049
706
# Segment 3: increasing alllocation to US equity and decreasing to EAFE
707
# Portfolio risk concentration and risk increase together
708
# > tail(W_MCC,1)
709
# 5.45402e-05 0.9998762 4.340072e-05 2.585630e-05
710
711
712
713