Aan de slagGa gratis aan de slag

Compute empirical VaR

In this exercise, you will practice estimating dynamic 5% daily VaRs with an empirical approach.

The difference between parametric VaR and empirical VaR is how the quantiles are estimated. The parametric approach estimates quantiles from an assumed distribution assumption, while the empirical approach estimates quantiles from an observed distribution of the standardized residuals.

You will use the same GARCH model as the previous exercise. The mean and variance forecasts are saved in mean_forecast and variance_forecast respectively. The empirical standardized residuals have also been calculated and saved in std_resid.

Deze oefening maakt deel uit van de cursus

GARCH Models in Python

Cursus bekijken

Oefeninstructies

  • Compute 0.05 quantile from the GARCH standardized residuals std_resid.
  • Calculate VaR using mean_forecast, variance_forecast from the GARCH model and the quantile from the previous step.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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()
Code bewerken en uitvoeren