參數估計:Normal
參數估計 是最有力的 VaR 估計方法,因為它假設損失分配的類別是已知的。接著以參數來讓資料貼合該分配,並據此進行統計推論。
在這個練習中,你要以 2007–2009 年投資銀行資料,擬合一個常態分配,並估計 95% 的 VaR。你會使用 scipy.stats 的 norm 分配,假設它是最合適的分配類別。
常態分配貼合得好嗎?你會用 scipy.stats.anderson 的 Anderson–Darling 檢定來測試。如果檢定結果在統計上顯著地不同於 0,就表示資料不是常態分配。你會在下一個練習中處理這件事。
2005–2010 年期間的投資組合 losses 已提供。
本練習屬於課程
Python 量化風險管理
練習說明
- 從
scipy.stats匯入norm和anderson。 - 使用
.fit()方法將losses資料貼合到常態分配,並將分配參數存到params。 - 由擬合後的分配產生並顯示 95% 的 VaR 估計。
- 使用 Anderson–Darling 檢定
anderson(),在losses上檢定常態分配的虛無假設。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the Normal distribution and skewness test from scipy.stats
from ____ import norm, anderson
# Fit portfolio losses to the Normal distribution
params = ____.fit(____)
# Compute the 95% VaR from the fitted distribution, using parameter estimates
VaR_95 = norm.____(0.95, *params)
print("VaR_95, Normal distribution: ", VaR_95)
# Test the data for Normality
print("Anderson-Darling test result: ", anderson(____))