Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/sandbox/riskbudgetpaper(superseded)/illustration/Effect_Feasible_Space.R
1433 views
1
2
3
setwd("C:\\Documents and Settings\\Administrator\\Desktop\\risk budget programs\\illustration")
4
# Bivariate normal example of the effect of constraints on percentage CVaR on the feasible space
5
6
showweightlines = T;
7
srt = 0 ;
8
9
CVaR = function( w , mu , sigma , alpha )
10
{
11
out = -t(w)%*%mu + sqrt( t(w)%*%sigma%*%w )*dnorm(qnorm(alpha))/alpha
12
return( out );
13
}
14
15
CompCVaR = function( w , mu , sigma , alpha )
16
{
17
out = -mu + as.vector(sigma%*%w)*(1/sqrt( t(w)%*%sigma%*%w))*dnorm(qnorm(alpha))/alpha
18
return( w*out );
19
}
20
21
N = 2; rho1 = -0.5 ; rho2 = 0; rho3 = 0.5; alpha = 0.05
22
mu1 = as.matrix( rep(0,N) ) ; mu2 = as.matrix( c(1, 0 ) ) ;
23
sigma1 = sigma2 = matrix ( rep(rho1,N^2) , ncol = N )
24
sigma3 = sigma4 = matrix ( rep(rho2,N^2) , ncol = N )
25
sigma5 = sigma6 = matrix ( rep(rho3,N^2) , ncol = N )
26
diag(sigma1) = diag(sigma2) = diag(sigma3) = diag(sigma4) = diag(sigma5) = diag(sigma6) =1;
27
sigma2[2,2] = sigma4[2,2] = sigma6[2,2] = 4;
28
29
w = as.matrix( rep(0.5,2) )
30
31
percCompCVaR = function( w = w , mu = mu , sigma = sigma , alpha = alpha ){
32
out1 = CompCVaR( w = w , mu = mu , sigma = sigma , alpha = alpha )
33
out2 = CVaR( w = w , mu = mu , sigma = sigma , alpha = alpha )
34
return(out1/as.numeric(out2))
35
}
36
37
vw1 = seq(0,1,0.01)
38
constraint = rep(0,length(vw1));
39
i=0;
40
vpccvar1 = vpccvar2 = vpccvar3 = vpccvar4 = vpccvar5 = vpccvar6 = vpccvar7 = vpccvar8 = vpccvar9 = c();
41
for( w1 in vw1 )
42
{
43
w2 = 1-w1; i = i+1;
44
w = as.matrix( c(w1,w2) )
45
vpccvar1 = rbind( vpccvar1 , percCompCVaR( w = w , mu = mu1 , sigma = sigma1 , alpha = alpha )[1])
46
vpccvar2 = rbind( vpccvar2 , percCompCVaR( w = w , mu = mu2 , sigma = sigma1 , alpha = alpha )[1])
47
vpccvar3 = rbind( vpccvar3 , percCompCVaR( w = w , mu = mu1 , sigma = sigma2 , alpha = alpha )[1])
48
vpccvar4 = rbind( vpccvar4 , percCompCVaR( w = w , mu = mu1 , sigma = sigma3 , alpha = alpha )[1])
49
vpccvar5 = rbind( vpccvar5 , percCompCVaR( w = w , mu = mu2 , sigma = sigma3 , alpha = alpha )[1])
50
vpccvar6 = rbind( vpccvar6 , percCompCVaR( w = w , mu = mu1 , sigma = sigma4 , alpha = alpha )[1])
51
vpccvar7 = rbind( vpccvar7 , percCompCVaR( w = w , mu = mu1 , sigma = sigma5 , alpha = alpha )[1])
52
vpccvar8 = rbind( vpccvar8 , percCompCVaR( w = w , mu = mu2 , sigma = sigma5 , alpha = alpha )[1])
53
vpccvar9 = rbind( vpccvar9 , percCompCVaR( w = w , mu = mu1 , sigma = sigma6 , alpha = alpha )[1])
54
}
55
56
# Plot 9 x 9
57
58
if(showweightlines){ postscript('sensitivity.eps') }else{ postscript('sensitivity_noweightlines.eps')}
59
60
par( mfrow = c(3,3) , las = 1 , mar=c(2.2,2.5,2,1.5) , cex=1 , cex.main=1)
61
62
# !!!! Setup 1: mu1, sigma1
63
plot( vw1 , vpccvar1 , main = expression( mu[1]*"="*mu[2]*"=0 and "*sigma[1]*"="*sigma[2]*"=1") ,
64
type="l",ylab="" )
65
text( x = 0.1 , y = 0.95*max(vpccvar1) , labels=expression( rho*"="*-0.5) )
66
# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%
67
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 )}
68
# Indicate ERC portfolio
69
objective = function( w1 ){
70
w = as.matrix( c(w1,1-w1) ); return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma1 , alpha = alpha )[1] ) }
71
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
72
print(ERC); print( 1/2 ) ;
73
text( x = ERC , y = 0.5 , labels="ERC" , srt = srt )
74
# uniroot: find value for which it is 0.4 and 0.6
75
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
76
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
77
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
78
79
# !!!! Setup 3: mu1, sigma2
80
plot( vw1 , vpccvar3 , main = expression( mu[1]*"="*mu[2]*"=0 and "*sigma[1]*"=1, "*sigma[2]*"=2 "), type="l" )
81
text( x = 0.1 , y = 0.95*max(vpccvar3) , labels=expression( rho*"="*-0.5) )
82
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
83
# uniroot: find value for which it is 0.4 and 0.6
84
objective = function( w1 ){
85
w = as.matrix( c(w1,1-w1) );
86
return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma2 , alpha = alpha )[1] )
87
}
88
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
89
print(ERC); print( 2/(1+2) ) ;
90
text( x = ERC , y = 0.5 , labels="ERC" )
91
# uniroot: find value for which it is 0.4 and 0.6
92
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
93
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
94
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
95
96
97
98
99
# !!!! Setup 2: mu2, sigma1
100
plot( vw1 , vpccvar2 , main = expression( mu[1]*"=1, "*mu[2]*"=0 and "*sigma[1]*"="*sigma[2]*"=1") , type="l" )
101
text( x = 0.1 , y = 0.95*max(vpccvar2) , labels=expression( rho*"="*-0.5) )
102
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
103
# uniroot: find value for which it is 0.4 and 0.6
104
objective = function( w1 ){
105
w = as.matrix( c(w1,1-w1) );
106
return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma1 , alpha = alpha )[1] )
107
}
108
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
109
text( x = ERC , y = 0.5 , labels="ERC" )
110
# uniroot: find value for which it is 0.4 and 0.6
111
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
112
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
113
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
114
115
116
#---------------------------------------------------------------------
117
118
# !!!! Setup 4: mu1, sigma3
119
plot( vw1 , vpccvar4 , main = "" , type="l",ylab="" )
120
text( x = 0.1 , y = 0.95*max(vpccvar4) , labels=expression( rho*"="*0) )
121
# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%
122
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
123
# uniroot: find value for which it is 0.4 and 0.6
124
objective = function( w1 ){
125
w = as.matrix( c(w1,1-w1) );
126
return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma3 , alpha = alpha )[1] )
127
}
128
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
129
text( x = ERC , y = 0.5 , labels="ERC" )
130
# uniroot: find value for which it is 0.4 and 0.6
131
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
132
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
133
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
134
135
# !!!! Setup 6: mu1, sigma4
136
plot( vw1 , vpccvar6 , main = "", type="l" )
137
text( x = 0.1 , y = 0.95*max(vpccvar6) , labels=expression( rho*"="*0) )
138
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
139
# uniroot: find value for which it is 0.4 and 0.6
140
objective = function( w1 ){
141
w = as.matrix( c(w1,1-w1) );
142
return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma4 , alpha = alpha )[1] )
143
}
144
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
145
text( x = ERC , y = 0.5 , labels="ERC" )
146
# uniroot: find value for which it is 0.4 and 0.6
147
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
148
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
149
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
150
151
# !!!! Setup 5: mu2, sigma3
152
plot( vw1 , vpccvar5 , main = "" , type="l" )
153
text( x = 0.1 , y = 0.95*max(vpccvar5) , labels=expression( rho*"="*0) )
154
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
155
# uniroot: find value for which it is 0.4 and 0.6
156
objective = function( w1 ){
157
w = as.matrix( c(w1,1-w1) );
158
return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma3 , alpha = alpha )[1] )
159
}
160
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
161
text( x = ERC , y = 0.5 , labels="ERC" )
162
# uniroot: find value for which it is 0.4 and 0.6
163
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
164
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
165
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
166
167
168
169
#----
170
171
# !!!! Setup 7: mu1, sigma5
172
plot( vw1 , vpccvar1 , main = expression( mu[1]*"="*mu[2]*"=0 and "*sigma[1]*"="*sigma[2]*"=1") ,
173
type="l",ylab="" )
174
text( x = 0.1 , y = 0.95*max(vpccvar1) , labels=expression( rho*"="*0.5) )
175
# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%
176
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 )}
177
# Indicate ERC portfolio
178
objective = function( w1 ){
179
w = as.matrix( c(w1,1-w1) ); return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma1 , alpha = alpha )[1] ) }
180
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
181
print(ERC); print( 1/2 ) ;
182
text( x = ERC , y = 0.5 , labels="ERC" , srt = srt )
183
# uniroot: find value for which it is 0.4 and 0.6
184
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
185
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
186
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
187
188
189
# !!!! Setup 9: mu1, sigma6
190
plot( vw1 , vpccvar9 , main = "" , type="l" )
191
text( x = 0.1 , y = 0.95*max(vpccvar9) , labels=expression( rho*"="*0.5) )
192
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
193
# uniroot: find value for which it is 0.4 and 0.6
194
objective = function( w1 ){
195
w = as.matrix( c(w1,1-w1) );
196
return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma6 , alpha = alpha )[1] )
197
}
198
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
199
text( x = ERC , y = 0.5 , labels="ERC" )
200
# uniroot: find value for which it is 0.4 and 0.6
201
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
202
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
203
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
204
205
206
# !!!! Setup 8: mu2, sigma5
207
plot( vw1 , vpccvar8 , main = "", type="l" )
208
text( x = 0.1 , y = 0.95*max(vpccvar8) , labels=expression( rho*"="*0.5) )
209
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
210
# uniroot: find value for which it is 0.4 and 0.6
211
objective = function( w1 ){
212
w = as.matrix( c(w1,1-w1) );
213
return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma5 , alpha = alpha )[1] )
214
}
215
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
216
text( x = ERC , y = 0.5 , labels="ERC" )
217
# uniroot: find value for which it is 0.4 and 0.6
218
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
219
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
220
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
221
222
223
224
#----------------------------------------------------------------------------------------
225
226
227
228
dev.off()
229
230
231
232
####################### Focus on effect of mu and sigma
233
234
235
236
postscript('sensitivity_rho50.eps')
237
238
par( mfrow = c(3,1) , las = 1 , mar=c(2.2,6.5,2,1.5) , cex=1 , cex.main=1.2)
239
240
#---------------------------------------------------------------------
241
242
showweightlines = TRUE;
243
244
245
# !!!! Setup 7: mu1, sigma5
246
plot( vw1 , vpccvar7 , main = expression( mu[1]*"="*mu[2]*"=0 and "*sigma[1]*"="*sigma[2]*"=1") , type="l",
247
ylab="Perc CVaR asset 1 \n in function of its weight" )
248
#text( x = 0.1 , y = 0.95*max(vpccvar7) , labels=expression( rho*"="*0.5) )
249
# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%
250
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 )}
251
# Indicate ERC portfolio
252
objective = function( w1 ){
253
w = as.matrix( c(w1,1-w1) ); return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma5 , alpha = alpha )[1] ) }
254
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
255
print(ERC); print( 1/2 ) ;
256
#text( x = ERC , y = 0.5 , labels="ERC" , srt = srt )
257
# uniroot: find value for which it is 0.4 and 0.6
258
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
259
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
260
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
261
262
263
# !!!! Setup 9: mu1, sigma6
264
plot( vw1 , vpccvar9 , main = expression( mu[1]*"="*mu[2]*"=0, "*rho*"=0, "* sigma[1]*"=1, "*sigma[2]*"=2 ") , type="l" ,
265
ylab="Perc CVaR asset 1 \n in function of its weight" )
266
#text( x = 0.1 , y = 0.95*max(vpccvar9) , labels=expression( rho*"="*0.5) )
267
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
268
# uniroot: find value for which it is 0.4 and 0.6
269
objective = function( w1 ){
270
w = as.matrix( c(w1,1-w1) );
271
return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma6 , alpha = alpha )[1] )
272
}
273
#h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
274
#text( x = ERC , y = 0.5 , labels="ERC" )
275
# uniroot: find value for which it is 0.4 and 0.6
276
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
277
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
278
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
279
280
281
# !!!! Setup 8: mu2, sigma5
282
plot( vw1 , vpccvar8 , main = expression( mu[1]*"=1, "*mu[2]*"=0, "*sigma[1]*"="*sigma[2]*"=1"), type="l" ,
283
ylab="Perc CVaR asset 1 \n in function of its weight")
284
#text( x = 0.1 , y = 0.95*max(vpccvar8) , labels=expression( rho*"="*0.5) )
285
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
286
# uniroot: find value for which it is 0.4 and 0.6
287
objective = function( w1 ){
288
w = as.matrix( c(w1,1-w1) );
289
return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma5 , alpha = alpha )[1] )
290
}
291
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
292
#text( x = ERC , y = 0.5 , labels="ERC" )
293
# uniroot: find value for which it is 0.4 and 0.6
294
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
295
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
296
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
297
298
dev.off()
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# Plot 1 x 3
318
319
postscript('sensitivity_rho50.eps')
320
showweightlines = TRUE
321
par( mfrow = c(1,3) , las = 1 , mar=c(2.2,2.5,2,1.5) , cex=1 , cex.main=1)
322
323
# !!!! Setup 7: mu1, sigma5
324
plot( vw1 , vpccvar7 , main = expression( mu[1]*"="*mu[2]*"=0, "*rho*"="*0*", "*sigma[1]*"="*sigma[2]*"=1") , type="l" )
325
text( x = 0.1 , y = 0.95*max(vpccvar7) , labels=expression( rho*"="*0.5) )
326
# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%
327
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
328
# uniroot: find value for which it is 0.4 and 0.6
329
objective = function( w1 ){
330
w = as.matrix( c(w1,1-w1) );
331
return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma5 , alpha = alpha )[1] )
332
}
333
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
334
text( x = ERC , y = 0.5 , labels="ERC" )
335
# uniroot: find value for which it is 0.4 and 0.6
336
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
337
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
338
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) ;
339
abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
340
341
# !!!! Setup 9: mu1, sigma6
342
plot( vw1 , vpccvar9 , main = main = expression( mu[1]*"=1, "*mu[2]*"=0, "*rho*"="*0*", "*sigma[1]*"="*sigma[2]*"=1") , type="l" )
343
text( x = 0.1 , y = 0.95*max(vpccvar9) , labels=expression( rho*"="*0.5) )
344
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
345
# uniroot: find value for which it is 0.4 and 0.6
346
objective = function( w1 ){
347
w = as.matrix( c(w1,1-w1) );
348
return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma6 , alpha = alpha )[1] )
349
}
350
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
351
text( x = ERC , y = 0.5 , labels="ERC" )
352
# uniroot: find value for which it is 0.4 and 0.6
353
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
354
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
355
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) ;
356
abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
357
358
359
# !!!! Setup 8: mu2, sigma5
360
plot( vw1 , vpccvar8 , main = "", type="l" )
361
text( x = 0.1 , y = 0.95*max(vpccvar8) , labels=expression( rho*"="*0.5) )
362
if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
363
# uniroot: find value for which it is 0.4 and 0.6
364
objective = function( w1 ){
365
w = as.matrix( c(w1,1-w1) );
366
return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma5 , alpha = alpha )[1] )
367
}
368
h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root
369
text( x = ERC , y = 0.5 , labels="ERC" )
370
# uniroot: find value for which it is 0.4 and 0.6
371
h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root
372
h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root
373
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) ;
374
abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
375
376
# !!!! Setup 4: mu1, sigma3
377
plot( vw1 , vpccvar4 , main = expression( mu[1]*"="*mu[2]*"=0, "*rho*"="*0*", "*sigma[1]*"="*sigma[2]*"=1") ,
378
type="l",ylab="Perc CVaR asset 1 \n in function of its weight" )
379
# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%
380
# uniroot: find value for which it is 0.4 and 0.6
381
objective = function( w1 ){
382
w = as.matrix( c(w1,1-w1) );
383
return( 0.5 - percCompCVaR( w = w , mu = mu1 , sigma = sigma3 , alpha = alpha )[1] )
384
}
385
v1 = uniroot( objective , lower = 0 , upper = 1)$root
386
objective = function( w1 ){
387
w = as.matrix( c(w1,1-w1) );
388
return( 0.5 - percCompCVaR( w = w , mu = mu1 , sigma = sigma3 , alpha = alpha )[1] )
389
}
390
v2 = uniroot( objective , lower = 0 , upper = 1)$root
391
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) ;
392
abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }
393
abline( h=0.5 , lty = 3 )
394
395
# !!!! Setup 5: mu2, sigma3
396
plot( vw1 , vpccvar5 , main = expression( mu[1]*"=1, "*mu[2]*"=0, "*rho*"="*0*", "*sigma[1]*"="*sigma[2]*"=1") ,
397
type="l" , ylab = "Perc CVaR asset 1 \n in function of its weight" )
398
# uniroot: find value for which it is 0.4 and 0.6
399
objective = function( w1 ){
400
w = as.matrix( c(w1,1-w1) );
401
return( 0.5 - percCompCVaR( w = w , mu = mu2 , sigma = sigma3 , alpha = alpha )[1] )
402
}
403
v1 = uniroot( objective , lower = 0 , upper = 1)$root
404
objective = function( w1 ){
405
w = as.matrix( c(w1,1-w1) );
406
return( 0.5 - percCompCVaR( w = w , mu = mu2 , sigma = sigma3 , alpha = alpha )[1] )
407
}
408
v2 = uniroot( objective , lower = 0 , upper = 1)$root
409
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
410
abline( h=0.5 , lty = 3 )
411
412
# !!!! Setup 6: mu1, sigma4
413
plot( vw1 , vpccvar6 , main = expression( mu[1]*"="*mu[2]*"=0, "*rho*"=0, "* sigma[1]*"=1, "*sigma[2]*"=2 "),
414
type="l" , ylab = "Perc CVaR asset 1 \n in function of its weight" )
415
# uniroot: find value for which it is 0.4 and 0.6
416
objective = function( w1 ){
417
w = as.matrix( c(w1,1-w1) );
418
return( 0.5 - percCompCVaR( w = w , mu = mu1 , sigma = sigma4 , alpha = alpha )[1] )
419
}
420
v1 = uniroot( objective , lower = 0 , upper = 1)$root
421
objective = function( w1 ){
422
w = as.matrix( c(w1,1-w1) );
423
return( 0.5 - percCompCVaR( w = w , mu = mu1 , sigma = sigma4 , alpha = alpha )[1] )
424
}
425
v2 = uniroot( objective , lower = 0 , upper = 1)$root
426
if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }
427
abline( h=0.5 , lty = 3 )
428
429
dev.off()
430
431