คำนวณ VaR เชิง Empirical
ในแบบฝึกหัดนี้ จะได้ฝึกประมาณค่า VaR รายวันแบบ dynamic ที่ระดับ 5% โดยใช้แนวทาง empirical
ความแตกต่างระหว่าง VaR แบบ parametric และแบบ empirical อยู่ที่วิธีการประมาณ quantile โดยแบบ parametric ประมาณ quantile จากการสมมติการแจกแจง ในขณะที่แบบ empirical ประมาณ quantile จากการแจกแจงที่สังเกตได้จริงของ standardized residuals
จะใช้โมเดล GARCH เดิมจากแบบฝึกหัดก่อนหน้า โดยผลพยากรณ์ค่า mean และค่าความแปรปรวนถูกบันทึกไว้ใน mean_forecast และ variance_forecast ตามลำดับ ส่วน standardized residuals เชิง empirical ได้คำนวณและบันทึกไว้ใน std_resid แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
GARCH Models ใน Python
คำแนะนำการฝึกหัด
- คำนวณ quantile ที่ 0.05 จาก standardized residuals ของ GARCH ใน
std_resid - คำนวณ VaR โดยใช้
mean_forecastและvariance_forecastจากโมเดล GARCH ร่วมกับค่า quantile ที่ได้จากขั้นตอนก่อนหน้า
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Obtain the empirical quantile
q_empirical = ____.____(____)
print('5% empirical quantile: ', q_empirical)
# Calculate the VaR
VaR_empirical = ____.values + np.sqrt(____).values * ____
# Save VaR in a DataFrame
VaR_empirical = pd.DataFrame(VaR_empirical, columns = ['5%'], index = variance_forecast.index)
# Plot the VaRs
plt.plot(VaR_empirical, color = 'brown', label = '5% Empirical VaR')
plt.plot(VaR_parametric, color = 'red', label = '5% Parametric VaR')
plt.scatter(variance_forecast.index,bitcoin_data.Return['2019-1-1':], color = 'orange', label = 'Bitcoin Daily Returns' )
plt.legend(loc = 'upper right')
plt.show()