Path: blob/master/sandbox/riskbudgetpaper(superseded)/illustration/Effect_Feasible_Space.R
1433 views
12setwd("C:\\Documents and Settings\\Administrator\\Desktop\\risk budget programs\\illustration")3# Bivariate normal example of the effect of constraints on percentage CVaR on the feasible space45showweightlines = T;6srt = 0 ;78CVaR = function( w , mu , sigma , alpha )9{10out = -t(w)%*%mu + sqrt( t(w)%*%sigma%*%w )*dnorm(qnorm(alpha))/alpha11return( out );12}1314CompCVaR = function( w , mu , sigma , alpha )15{16out = -mu + as.vector(sigma%*%w)*(1/sqrt( t(w)%*%sigma%*%w))*dnorm(qnorm(alpha))/alpha17return( w*out );18}1920N = 2; rho1 = -0.5 ; rho2 = 0; rho3 = 0.5; alpha = 0.0521mu1 = as.matrix( rep(0,N) ) ; mu2 = as.matrix( c(1, 0 ) ) ;22sigma1 = sigma2 = matrix ( rep(rho1,N^2) , ncol = N )23sigma3 = sigma4 = matrix ( rep(rho2,N^2) , ncol = N )24sigma5 = sigma6 = matrix ( rep(rho3,N^2) , ncol = N )25diag(sigma1) = diag(sigma2) = diag(sigma3) = diag(sigma4) = diag(sigma5) = diag(sigma6) =1;26sigma2[2,2] = sigma4[2,2] = sigma6[2,2] = 4;2728w = as.matrix( rep(0.5,2) )2930percCompCVaR = function( w = w , mu = mu , sigma = sigma , alpha = alpha ){31out1 = CompCVaR( w = w , mu = mu , sigma = sigma , alpha = alpha )32out2 = CVaR( w = w , mu = mu , sigma = sigma , alpha = alpha )33return(out1/as.numeric(out2))34}3536vw1 = seq(0,1,0.01)37constraint = rep(0,length(vw1));38i=0;39vpccvar1 = vpccvar2 = vpccvar3 = vpccvar4 = vpccvar5 = vpccvar6 = vpccvar7 = vpccvar8 = vpccvar9 = c();40for( w1 in vw1 )41{42w2 = 1-w1; i = i+1;43w = as.matrix( c(w1,w2) )44vpccvar1 = rbind( vpccvar1 , percCompCVaR( w = w , mu = mu1 , sigma = sigma1 , alpha = alpha )[1])45vpccvar2 = rbind( vpccvar2 , percCompCVaR( w = w , mu = mu2 , sigma = sigma1 , alpha = alpha )[1])46vpccvar3 = rbind( vpccvar3 , percCompCVaR( w = w , mu = mu1 , sigma = sigma2 , alpha = alpha )[1])47vpccvar4 = rbind( vpccvar4 , percCompCVaR( w = w , mu = mu1 , sigma = sigma3 , alpha = alpha )[1])48vpccvar5 = rbind( vpccvar5 , percCompCVaR( w = w , mu = mu2 , sigma = sigma3 , alpha = alpha )[1])49vpccvar6 = rbind( vpccvar6 , percCompCVaR( w = w , mu = mu1 , sigma = sigma4 , alpha = alpha )[1])50vpccvar7 = rbind( vpccvar7 , percCompCVaR( w = w , mu = mu1 , sigma = sigma5 , alpha = alpha )[1])51vpccvar8 = rbind( vpccvar8 , percCompCVaR( w = w , mu = mu2 , sigma = sigma5 , alpha = alpha )[1])52vpccvar9 = rbind( vpccvar9 , percCompCVaR( w = w , mu = mu1 , sigma = sigma6 , alpha = alpha )[1])53}5455# Plot 9 x 95657if(showweightlines){ postscript('sensitivity.eps') }else{ postscript('sensitivity_noweightlines.eps')}5859par( mfrow = c(3,3) , las = 1 , mar=c(2.2,2.5,2,1.5) , cex=1 , cex.main=1)6061# !!!! Setup 1: mu1, sigma162plot( vw1 , vpccvar1 , main = expression( mu[1]*"="*mu[2]*"=0 and "*sigma[1]*"="*sigma[2]*"=1") ,63type="l",ylab="" )64text( x = 0.1 , y = 0.95*max(vpccvar1) , labels=expression( rho*"="*-0.5) )65# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%66if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 )}67# Indicate ERC portfolio68objective = function( w1 ){69w = as.matrix( c(w1,1-w1) ); return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma1 , alpha = alpha )[1] ) }70h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root71print(ERC); print( 1/2 ) ;72text( x = ERC , y = 0.5 , labels="ERC" , srt = srt )73# uniroot: find value for which it is 0.4 and 0.674h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root75h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root76if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }7778# !!!! Setup 3: mu1, sigma279plot( vw1 , vpccvar3 , main = expression( mu[1]*"="*mu[2]*"=0 and "*sigma[1]*"=1, "*sigma[2]*"=2 "), type="l" )80text( x = 0.1 , y = 0.95*max(vpccvar3) , labels=expression( rho*"="*-0.5) )81if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }82# uniroot: find value for which it is 0.4 and 0.683objective = function( w1 ){84w = as.matrix( c(w1,1-w1) );85return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma2 , alpha = alpha )[1] )86}87h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root88print(ERC); print( 2/(1+2) ) ;89text( x = ERC , y = 0.5 , labels="ERC" )90# uniroot: find value for which it is 0.4 and 0.691h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root92h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root93if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }9495969798# !!!! Setup 2: mu2, sigma199plot( vw1 , vpccvar2 , main = expression( mu[1]*"=1, "*mu[2]*"=0 and "*sigma[1]*"="*sigma[2]*"=1") , type="l" )100text( x = 0.1 , y = 0.95*max(vpccvar2) , labels=expression( rho*"="*-0.5) )101if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }102# uniroot: find value for which it is 0.4 and 0.6103objective = function( w1 ){104w = as.matrix( c(w1,1-w1) );105return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma1 , alpha = alpha )[1] )106}107h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root108text( x = ERC , y = 0.5 , labels="ERC" )109# uniroot: find value for which it is 0.4 and 0.6110h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root111h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root112if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }113114115#---------------------------------------------------------------------116117# !!!! Setup 4: mu1, sigma3118plot( vw1 , vpccvar4 , main = "" , type="l",ylab="" )119text( x = 0.1 , y = 0.95*max(vpccvar4) , labels=expression( rho*"="*0) )120# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%121if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }122# uniroot: find value for which it is 0.4 and 0.6123objective = function( w1 ){124w = as.matrix( c(w1,1-w1) );125return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma3 , alpha = alpha )[1] )126}127h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root128text( x = ERC , y = 0.5 , labels="ERC" )129# uniroot: find value for which it is 0.4 and 0.6130h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root131h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root132if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }133134# !!!! Setup 6: mu1, sigma4135plot( vw1 , vpccvar6 , main = "", type="l" )136text( x = 0.1 , y = 0.95*max(vpccvar6) , labels=expression( rho*"="*0) )137if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }138# uniroot: find value for which it is 0.4 and 0.6139objective = function( w1 ){140w = as.matrix( c(w1,1-w1) );141return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma4 , alpha = alpha )[1] )142}143h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root144text( x = ERC , y = 0.5 , labels="ERC" )145# uniroot: find value for which it is 0.4 and 0.6146h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root147h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root148if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }149150# !!!! Setup 5: mu2, sigma3151plot( vw1 , vpccvar5 , main = "" , type="l" )152text( x = 0.1 , y = 0.95*max(vpccvar5) , labels=expression( rho*"="*0) )153if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }154# uniroot: find value for which it is 0.4 and 0.6155objective = function( w1 ){156w = as.matrix( c(w1,1-w1) );157return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma3 , alpha = alpha )[1] )158}159h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root160text( x = ERC , y = 0.5 , labels="ERC" )161# uniroot: find value for which it is 0.4 and 0.6162h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root163h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root164if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }165166167168#----169170# !!!! Setup 7: mu1, sigma5171plot( vw1 , vpccvar1 , main = expression( mu[1]*"="*mu[2]*"=0 and "*sigma[1]*"="*sigma[2]*"=1") ,172type="l",ylab="" )173text( x = 0.1 , y = 0.95*max(vpccvar1) , labels=expression( rho*"="*0.5) )174# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%175if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 )}176# Indicate ERC portfolio177objective = function( w1 ){178w = as.matrix( c(w1,1-w1) ); return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma1 , alpha = alpha )[1] ) }179h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root180print(ERC); print( 1/2 ) ;181text( x = ERC , y = 0.5 , labels="ERC" , srt = srt )182# uniroot: find value for which it is 0.4 and 0.6183h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root184h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root185if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }186187188# !!!! Setup 9: mu1, sigma6189plot( vw1 , vpccvar9 , main = "" , type="l" )190text( x = 0.1 , y = 0.95*max(vpccvar9) , labels=expression( rho*"="*0.5) )191if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }192# uniroot: find value for which it is 0.4 and 0.6193objective = function( w1 ){194w = as.matrix( c(w1,1-w1) );195return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma6 , alpha = alpha )[1] )196}197h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root198text( x = ERC , y = 0.5 , labels="ERC" )199# uniroot: find value for which it is 0.4 and 0.6200h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root201h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root202if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }203204205# !!!! Setup 8: mu2, sigma5206plot( vw1 , vpccvar8 , main = "", type="l" )207text( x = 0.1 , y = 0.95*max(vpccvar8) , labels=expression( rho*"="*0.5) )208if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }209# uniroot: find value for which it is 0.4 and 0.6210objective = function( w1 ){211w = as.matrix( c(w1,1-w1) );212return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma5 , alpha = alpha )[1] )213}214h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root215text( x = ERC , y = 0.5 , labels="ERC" )216# uniroot: find value for which it is 0.4 and 0.6217h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root218h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root219if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }220221222223#----------------------------------------------------------------------------------------224225226227dev.off()228229230231####################### Focus on effect of mu and sigma232233234235postscript('sensitivity_rho50.eps')236237par( mfrow = c(3,1) , las = 1 , mar=c(2.2,6.5,2,1.5) , cex=1 , cex.main=1.2)238239#---------------------------------------------------------------------240241showweightlines = TRUE;242243244# !!!! Setup 7: mu1, sigma5245plot( vw1 , vpccvar7 , main = expression( mu[1]*"="*mu[2]*"=0 and "*sigma[1]*"="*sigma[2]*"=1") , type="l",246ylab="Perc CVaR asset 1 \n in function of its weight" )247#text( x = 0.1 , y = 0.95*max(vpccvar7) , labels=expression( rho*"="*0.5) )248# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%249if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 )}250# Indicate ERC portfolio251objective = function( w1 ){252w = as.matrix( c(w1,1-w1) ); return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma5 , alpha = alpha )[1] ) }253h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root254print(ERC); print( 1/2 ) ;255#text( x = ERC , y = 0.5 , labels="ERC" , srt = srt )256# uniroot: find value for which it is 0.4 and 0.6257h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root258h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root259if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }260261262# !!!! Setup 9: mu1, sigma6263plot( vw1 , vpccvar9 , main = expression( mu[1]*"="*mu[2]*"=0, "*rho*"=0, "* sigma[1]*"=1, "*sigma[2]*"=2 ") , type="l" ,264ylab="Perc CVaR asset 1 \n in function of its weight" )265#text( x = 0.1 , y = 0.95*max(vpccvar9) , labels=expression( rho*"="*0.5) )266if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }267# uniroot: find value for which it is 0.4 and 0.6268objective = function( w1 ){269w = as.matrix( c(w1,1-w1) );270return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma6 , alpha = alpha )[1] )271}272#h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root273#text( x = ERC , y = 0.5 , labels="ERC" )274# uniroot: find value for which it is 0.4 and 0.6275h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root276h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root277if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }278279280# !!!! Setup 8: mu2, sigma5281plot( vw1 , vpccvar8 , main = expression( mu[1]*"=1, "*mu[2]*"=0, "*sigma[1]*"="*sigma[2]*"=1"), type="l" ,282ylab="Perc CVaR asset 1 \n in function of its weight")283#text( x = 0.1 , y = 0.95*max(vpccvar8) , labels=expression( rho*"="*0.5) )284if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }285# uniroot: find value for which it is 0.4 and 0.6286objective = function( w1 ){287w = as.matrix( c(w1,1-w1) );288return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma5 , alpha = alpha )[1] )289}290h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root291#text( x = ERC , y = 0.5 , labels="ERC" )292# uniroot: find value for which it is 0.4 and 0.6293h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root294h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root295if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }296297dev.off()298299300301302303304305306307308309310311312313314315316# Plot 1 x 3317318postscript('sensitivity_rho50.eps')319showweightlines = TRUE320par( mfrow = c(1,3) , las = 1 , mar=c(2.2,2.5,2,1.5) , cex=1 , cex.main=1)321322# !!!! Setup 7: mu1, sigma5323plot( vw1 , vpccvar7 , main = expression( mu[1]*"="*mu[2]*"=0, "*rho*"="*0*", "*sigma[1]*"="*sigma[2]*"=1") , type="l" )324text( x = 0.1 , y = 0.95*max(vpccvar7) , labels=expression( rho*"="*0.5) )325# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%326if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }327# uniroot: find value for which it is 0.4 and 0.6328objective = function( w1 ){329w = as.matrix( c(w1,1-w1) );330return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma5 , alpha = alpha )[1] )331}332h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root333text( x = ERC , y = 0.5 , labels="ERC" )334# uniroot: find value for which it is 0.4 and 0.6335h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root336h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root337if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) ;338abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }339340# !!!! Setup 9: mu1, sigma6341plot( vw1 , vpccvar9 , main = main = expression( mu[1]*"=1, "*mu[2]*"=0, "*rho*"="*0*", "*sigma[1]*"="*sigma[2]*"=1") , type="l" )342text( x = 0.1 , y = 0.95*max(vpccvar9) , labels=expression( rho*"="*0.5) )343if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }344# uniroot: find value for which it is 0.4 and 0.6345objective = function( w1 ){346w = as.matrix( c(w1,1-w1) );347return( h - percCompCVaR( w = w , mu = mu1 , sigma = sigma6 , alpha = alpha )[1] )348}349h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root350text( x = ERC , y = 0.5 , labels="ERC" )351# uniroot: find value for which it is 0.4 and 0.6352h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root353h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root354if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) ;355abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }356357358# !!!! Setup 8: mu2, sigma5359plot( vw1 , vpccvar8 , main = "", type="l" )360text( x = 0.1 , y = 0.95*max(vpccvar8) , labels=expression( rho*"="*0.5) )361if(showweightlines){ abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }362# uniroot: find value for which it is 0.4 and 0.6363objective = function( w1 ){364w = as.matrix( c(w1,1-w1) );365return( h - percCompCVaR( w = w , mu = mu2 , sigma = sigma5 , alpha = alpha )[1] )366}367h=0.5; ERC = uniroot( objective , lower = 0 , upper = 1)$root368text( x = ERC , y = 0.5 , labels="ERC" )369# uniroot: find value for which it is 0.4 and 0.6370h=0.4 ; v1 = uniroot( objective , lower = 0 , upper = 1)$root371h=0.6; v2 = uniroot( objective , lower = 0 , upper = 1)$root372if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) ;373abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }374375# !!!! Setup 4: mu1, sigma3376plot( vw1 , vpccvar4 , main = expression( mu[1]*"="*mu[2]*"=0, "*rho*"="*0*", "*sigma[1]*"="*sigma[2]*"=1") ,377type="l",ylab="Perc CVaR asset 1 \n in function of its weight" )378# %C[2]CVaR <= 60% implies %C[1]CVaR >= 40%379# uniroot: find value for which it is 0.4 and 0.6380objective = function( w1 ){381w = as.matrix( c(w1,1-w1) );382return( 0.5 - percCompCVaR( w = w , mu = mu1 , sigma = sigma3 , alpha = alpha )[1] )383}384v1 = uniroot( objective , lower = 0 , upper = 1)$root385objective = function( w1 ){386w = as.matrix( c(w1,1-w1) );387return( 0.5 - percCompCVaR( w = w , mu = mu1 , sigma = sigma3 , alpha = alpha )[1] )388}389v2 = uniroot( objective , lower = 0 , upper = 1)$root390if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) ;391abline( h = 0.4 , lty = 3) ; abline( h = 0.6 , lty = 3 ) }392abline( h=0.5 , lty = 3 )393394# !!!! Setup 5: mu2, sigma3395plot( vw1 , vpccvar5 , main = expression( mu[1]*"=1, "*mu[2]*"=0, "*rho*"="*0*", "*sigma[1]*"="*sigma[2]*"=1") ,396type="l" , ylab = "Perc CVaR asset 1 \n in function of its weight" )397# uniroot: find value for which it is 0.4 and 0.6398objective = function( w1 ){399w = as.matrix( c(w1,1-w1) );400return( 0.5 - percCompCVaR( w = w , mu = mu2 , sigma = sigma3 , alpha = alpha )[1] )401}402v1 = uniroot( objective , lower = 0 , upper = 1)$root403objective = function( w1 ){404w = as.matrix( c(w1,1-w1) );405return( 0.5 - percCompCVaR( w = w , mu = mu2 , sigma = sigma3 , alpha = alpha )[1] )406}407v2 = uniroot( objective , lower = 0 , upper = 1)$root408if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }409abline( h=0.5 , lty = 3 )410411# !!!! Setup 6: mu1, sigma4412plot( vw1 , vpccvar6 , main = expression( mu[1]*"="*mu[2]*"=0, "*rho*"=0, "* sigma[1]*"=1, "*sigma[2]*"=2 "),413type="l" , ylab = "Perc CVaR asset 1 \n in function of its weight" )414# uniroot: find value for which it is 0.4 and 0.6415objective = function( w1 ){416w = as.matrix( c(w1,1-w1) );417return( 0.5 - percCompCVaR( w = w , mu = mu1 , sigma = sigma4 , alpha = alpha )[1] )418}419v1 = uniroot( objective , lower = 0 , upper = 1)$root420objective = function( w1 ){421w = as.matrix( c(w1,1-w1) );422return( 0.5 - percCompCVaR( w = w , mu = mu1 , sigma = sigma4 , alpha = alpha )[1] )423}424v2 = uniroot( objective , lower = 0 , upper = 1)$root425if(showweightlines){ abline( v = v1 , lty = 3) ; abline( v = v2 , lty = 3 ) }426abline( h=0.5 , lty = 3 )427428dev.off()429430431