计算经验 VaR
在本练习中,您将用经验方法估计日频的动态 5% VaR。
参数法 VaR 与经验法 VaR 的区别在于分位数的估计方式。参数法从预设的分布假设中估计分位数,而经验法则从标准化残差的观测分布中估计分位数。
您将继续使用上一个练习中的同一 GARCH 模型。均值与方差预测分别保存在 mean_forecast 和 variance_forecast 中。经验标准化残差已计算完毕并保存在 std_resid 中。
本练习是课程的一部分
Python 中的 GARCH 模型
练习说明
- 从 GARCH 标准化残差
std_resid计算 0.05 分位数。 - 使用 GARCH 模型给出的
mean_forecast、variance_forecast以及上一步得到的分位数计算 VaR。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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()