開始使用免費開始

計算參數式 VaR

在這個練習中,你將以參數式方法,實作動態的每日 5% VaR 估計。

回顧向前估計 VaR 的三個步驟。第 1 步,使用 GARCH 模型做變異數預測。第 2 步,取得 GARCH 的前瞻性平均數與波動度。第 3 步,依指定的信賴水準計算分位數。參數式方法會在假設的機率分配下估計分位數。

已使用比特幣歷史報酬資料擬合 GARCH 模型至 2019/1/1,並已產生平均數與變異數預測,分別儲存在 mean_forecastvariance_forecast。GARCH 模型假設服從 Student's t 分配,其 $\nu$(自由度)儲存在 nu

本練習屬於課程

Python 中的 GARCH 模型

檢視課程

練習說明

  • 從假設的 Student's t 分配計算 0.05 分位數。
  • 使用 GARCH 模型的 mean_forecastvariance_forecast 以及前一步的分位數計算 VaR。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Obtain the parametric quantile
q_parametric = basic_gm.____.____(____, nu)
print('5% parametric quantile: ', q_parametric)
    
# Calculate the VaR
VaR_parametric = ____.values + np.sqrt(____).values * ____
# Save VaR in a DataFrame
VaR_parametric = pd.DataFrame(VaR_parametric, columns = ['5%'], index = variance_forecast.index)

# Plot the 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()
編輯並執行程式碼