估計 VaR 與 ES
現在你要利用 hslosses 中歷史模擬的損益,來為國際股票投資人估計 VaR 與 ES。
你會用兩種方法進行。首先,套用一個簡單的非參數法:用樣本分位數來估計 VaR,並以超過該樣本分位數的值之平均來估計 ES。
接著,將這些估計值與在假設 hslosses 服從常態分配時得到的結果做比較。當然,這個假設非常不理想;你應該比較兩組估計,看看哪一組較為保守。
本練習屬於課程
R 的量化風險管理
練習說明
- 使用
quantile()來估計hslosses分配的第 99 個樣本百分位數。 - 透過計算不小於 VaR 估計值的那些
hslosses的平均來估計 99% ES(此步驟已為你完成)。 - 使用適當的函式估計
hslosses的平均與標準差,分別指定給mu與sigma。 - 使用
qnorm()並帶入計算出的平均與標準差,求出常態分配的 99% 分位數。 - 使用
ESnorm()並帶入計算出的平均與標準差,求出常態分配的 99% ES。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Estimate the 99th sample percentile of the distribution of hslosses
# Estimate the 99% ES
mean(hslosses[hslosses >= quantile(hslosses, 0.99)])
# Estimate the mean and standard deviation of hslosses
# Compute the 99% quantile of a normal distribution
# Compute the 99% ES of a normal distribution