Plot distribution of standardized residuals
GARCH models make distribution assumptions of the standardized residuals. Recall residuals are the differences between predicted returns and the mean returns. And standardized residuals are the residuals divided by the model estimated volatility.
In this exercise, you will practice computing the standardized residuals from a fitted GARCH model, and then plot its histogram together with a standard normal distribution normal_resid
.
A GARCH model has been defined and fitted with S&P 500 price return data. The fitted result can be accessed as gm_result
. In addition matplotlib
has been preloaded as plt
.
This is a part of the course
“GARCH Models in Python”
Exercise instructions
- Obtain model estimated residuals and save it in
gm_resid
. - Obtain model estimated volatility and save it in
gm_std
. - Calculate the standardized residuals
gm_std_resid
. - Plot a histogram of
gm_std_resid
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Obtain model estimated residuals and volatility
gm_resid = gm_result.____
gm_std = gm_result.____
# Calculate the standardized residuals
gm_std_resid = ____ /____
# Plot the histogram of the standardized residuals
plt.____(____, bins = 50,
facecolor = 'orange', label = 'Standardized residuals')
plt.____(normal_resid, bins = 50,
facecolor = 'tomato', label = 'Normal residuals')
plt.legend(loc = 'upper left')
plt.show()
This exercise is part of the course
GARCH Models in Python
Learn about GARCH Models, how to implement them and calibrate them on financial data from stocks to foreign exchange.
A normal GARCH model is not representative of the real financial data, whose distributions frequently exhibit fat tails, skewness, and asymmetric shocks. In this chapter, you’ll learn how to define better GARCH models with more realistic assumptions. You’ll also learn how to make more sophisticated volatility forecasts with rolling window approaches.
Exercise 1: Distribution assumptionsExercise 2: Fat tails and skewnessExercise 3: Plot distribution of standardized residualsExercise 4: Fit a GARCH with skewed t-distributionExercise 5: Mean model specificationsExercise 6: Check mean model assumptionsExercise 7: Effect of mean model on volatility predictionsExercise 8: Volatility models for asymmetric shocksExercise 9: Modeling of asymmetric responses of volatilityExercise 10: Fit GARCH models to cryptocurrencyExercise 11: Compare GJR-GARCH with EGARCHExercise 12: GARCH rolling window forecastExercise 13: Why use rolling window forecastExercise 14: Fixed rolling window forecastExercise 15: Compare forecast resultsWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.