CVaR 與風險曝險
回顧一下,CVaR 是在「給定最低損失門檻」下的損失期望值。所以 CVaR 本身就是一種風險曝險的表徵——它等於分配尾端中損失機率與損失金額相乘後的總和(或積分)。
為了推導 99% 的 CVaR,你會先用 t.fit() 方法,對 2008–2009 年的 crisis_losses 投資組合資料擬合一個 T 分配。這會回傳 T 分配參數 p,並用 .ppf() 方法找出 VaR。
接著你會計算 99% 的 VaR,因為之後會用到它來求 CVaR。
最後,你會使用 t.expect() 方法計算 99% 的 CVaR 指標;這和你先前用於常態分配計算 CVaR 的方法相同。
已匯入來自 scipy.stats 的 t 分配可供使用。
本練習屬於課程
Python 量化風險管理
練習說明
- 使用
.fit()套用在crisis_losses上,找出分配參數p。 - 使用擬合出的參數
p與t的 percent point function 計算VaR_99。 - 使用
t.expect()方法與參數p計算CVaR_99,並印出結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Fit the Student's t distribution to crisis losses
p = t.____(crisis_losses)
# Compute the VaR_99 for the fitted distribution
VaR_99 = t.____(____, *p)
# Use the fitted parameters and VaR_99 to compute CVaR_99
tail_loss = t.expect(____ y: y, args = (p[0],), loc = p[1], scale = p[2], lb = VaR_99 )
CVaR_99 = (1 / (1 - ____)) * tail_loss
print(CVaR_99)