Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/sandbox/riskbudgetpaper(superseded)/illustration/CVaRvsVaRsstbis.R
1433 views
1
2
3
setwd( "C:/Documents and Settings/Administrator/Desktop/risk budget programs/illustration" )
4
5
library( skewt )
6
n = 5000 ;
7
df = 5 ;
8
gamma = 0.8 ;
9
simret = rskt( n = n , df = df , gamma = gamma ) ;
10
11
postscript( "CVaR.eps" )
12
13
par( cex = 1.2 , cex.main = 1.2)
14
hist( simret , freq = F , breaks = 20 , ylim =c(0,0.4), col="gray" ,
15
main = "95% Value at Risk and 95% Conditional VaR \n for a Skewed Student t" , xlab = "Portfolio returns" , ylab = "Density" )
16
mi = min( simret ) ; ma = max( simret );
17
lines( seq(mi,ma,0.01) , dskt( seq(mi,ma,0.01), df = df , gamma = gamma ),lwd=2 )
18
19
abline ( v = qskt( 0.05 , df = df , gamma = gamma ) , lty = 3, lwd = 2 , col = "red" )
20
text( x = qskt( 0.05 , df = df , gamma = gamma ) , y = 0.38 , labels = "95% VaR" , col = "red" , lwd = 2 , cex = 1.1)
21
22
library(graphics)
23
arrows( x0 = min(simret) , x1 = qskt( 0.05 , df = df , gamma = gamma ) ,
24
y0 = 0.1 , y1 = 0.1 , code = 3 , col = "blue" , lwd = 2 )
25
text( x = 0.5*(min(simret)+qskt( 0.05 , df = df , gamma = gamma ) ) , y = 0.12 ,
26
labels = "95% CVaR" , col = "blue" , lwd = 2 , cex = 1.1)
27
28
dev.off()
29
30