CVaR と VaR を比較する
条件付きリスク価値(CVaR、または expected shortfall: ES)は、特定の信頼水準において、ある閾値を超える損失が発生した「条件の下」で、平均損失がどれくらいになるかを問う指標です。VaR を出発点にしますが、損失分布の「テール」を考慮に入れるため、より多くの情報を含みます。
まず、2005〜2010 年の投資銀行の portfolio_losses と同じ平均と標準偏差を持つ正規分布に対して、95% VaR を計算します。続いて、その VaR を用いて 95% CVaR を算出し、両方を正規分布と並べてプロットします。
作業スペースには portfolio_losses と、scipy.stats の正規分布 norm が用意されています。
この演習はコースの一部です
Pythonで学ぶ定量的リスク管理
演習の手順
portfolio_lossesの平均と標準偏差を計算し、それぞれpmとpsに代入します。normの.ppf()メソッドを使って 95% VaR を求めます。これは平均にloc、標準偏差にscaleを指定します。- 95% VaR と
normの.expect()メソッドを使ってtail_lossを求め、同じ信頼水準での CVaR を計算します。 - 正規分布のヒストグラムに、VaR(赤)と CVaR(緑)を示す縦線を追加します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Compute the mean and standard deviation of the portfolio returns
pm = portfolio_losses.____
ps = portfolio_losses.____
# Compute the 95% VaR using the .ppf()
VaR_95 = norm.ppf(0.95, loc = ____, scale = ____)
# Compute the expected tail loss and the CVaR in the worst 5% of cases
tail_loss = norm.____(lambda x: x, loc = ____, scale = ____, lb = VaR_95)
CVaR_95 = (1 / (1 - 0.95)) * ____
# Plot the normal distribution histogram and add lines for the VaR and CVaR
plt.hist(norm.rvs(size = 100000, loc = pm, scale = ____), bins = 100)
plt.axvline(x = VaR_95, c='r', label = "VaR, 95% confidence level")
plt.axvline(x = ____, c='g', label = "CVaR, worst 5% of outcomes")
plt.legend(); plt.show()