VaR in nancial risk
management
GA RCH MODELS IN P YTH ON
Chelsea Yang
Data Science Instructor
Risk management mindset
Rule No.1: Never lose money
Rule No.2 Never forget Rule No.1
-- Warren Buffett
GARCH MODELS IN PYTHON
What is VaR
VaR stands for Value at Risk
Three ingredients:
1. portfolio
2. time horizon
3. probability
GARCH MODELS IN PYTHON
VaR examples
_1-day 5% VaR of $1 million _
5% probability the portfolio will fall in value by 1 million dollars or more over a 1-day period
10-day 1% VaR of $9 million
1% probability the portfolio will fall in value by 9 million dollars or more over a 10-day period
GARCH MODELS IN PYTHON
VaR in risk management
Set risk limits
VaR exceedance: portfolio loss exceeds the VaR
GARCH MODELS IN PYTHON
Dynamic VaR with GARCH
More realistic VaR estimation with GARCH
VaR = mean + (GARCH vol) * quantile
VaR = mean_forecast.values + np.sqrt(variance_forecast).values * quantile
GARCH MODELS IN PYTHON
Dynamic VaR calculation
Step 1: Use GARCH model to make variance forecast
# Specify and fit a GARCH model
basic_gm = arch_model(bitcoin_data['Return'], p = 1, q = 1,
mean = 'constant', vol = 'GARCH', dist = 't')
gm_result = basic_gm.fit()
# Make variance forecast
gm_forecast = gm_result.forecast(start = '2019-01-01')
GARCH MODELS IN PYTHON
Dynamic VaR calculation (cont.)
Step 2: Use GARCH model to obtain forward-looking mean and volatility
mean_forecast = gm_forecast.mean['2019-01-01':]
variance_forecast = gm_forecast.variance['2019-01-01':]
Step 3: Obtain the quantile according to a con dence level
1. Parametric VaR
2. Empirical VaR
GARCH MODELS IN PYTHON
Parametric VaR
Estimate quantiles based on GARCH assumed distribution of the standardized residuals
# Assume a Student's t-distribution
# ppf(): Percent point function
q_parametric = garch_model.distribution.ppf(0.05, nu)
GARCH MODELS IN PYTHON
Empirical VaR
Estimate quantiles based on the observed distribution of the GARCH standardized residuals
q_empirical = std_resid.quantile(0.05)
GARCH MODELS IN PYTHON
Let's practice!
GA RCH MODELS IN P YTH ON
Dynamic covariance
in portfolio
optimization
GA RCH MODELS IN P YTH ON
Chelsea Yang
Data Science Instructor
What is covariance
Describe the relationship between movement of two variables
Positive covariance: move together
Negative covariance; move in the opposite directions
GARCH MODELS IN PYTHON
Dynamic covariance with GARCH
If two asset returns have correlation ρ and time-varying volatility of σ1 and σ2 :
Covariance = ρ ⋅ σ1 ⋅ σ2
covariance = correlation * garch_vol1 * garch_vol2
GARCH MODELS IN PYTHON
Calculate GARCH covariance in Python
Step 1: Fit GARCH models and obtain volatility for each return series
# gm_eur, gm_cad are fitted GARCH models
vol_eur = gm_eur.conditional_volatility
vol_cad = gm_cad.conditional_volatility
Step 2: Compute standardized residuals from the tted GARCH models
resid_eur = gm_eur.resid/vol_eur
resid_cad = gm_cad.resid/vol_cad
GARCH MODELS IN PYTHON
Calculate GARCH covariance in Python (cont.)
Step 3: Compute ρ as simple correlation of standardized residuals
corr = np.corrcoef(resid_eur, resid_cad)[0,1]
Step 4: Compute GARCH covariance by multiplying the correlation and volatility.
covariance = corr * vol_eur * vol_cad
GARCH MODELS IN PYTHON
Modern portfolio theory (MPT)
Pioneered by Harry Markowitz in his paper "Portfolio Selection"(1952)
Take advantage of the diversi cation effect
The optimal portfolio can yield the maximum return with the minimum risk
GARCH MODELS IN PYTHON
MPT intuition
Variance of a simple two-asset portfolio:
_W1∗ Variance1 + W2∗ Variance2 + 2∗W1∗W2∗Covariance _
Diversi cation effect:
Risk can be reduced in a portfolio by pairing assets that have a negative covariance
GARCH MODELS IN PYTHON
Let's practice!
GA RCH MODELS IN P YTH ON
Dynamic Beta in
portfolio
management
GA RCH MODELS IN P YTH ON
Chelsea Yang
Data Science Instructor
What is Beta
Stock Beta:
a measure of stock volatility in relation to the general market
Systematic risk:
the portion of the risk that cannot be diversi ed away
GARCH MODELS IN PYTHON
Beta in portfolio management
_Gauge investment risk _
Market Beta = 1: used as benchmark
Beta > 1: the stock bears more risks than the general market
Beta < 1: the stock bears less risks than the general market
GARCH MODELS IN PYTHON
Beta in CAPM
Estimate risk premium of a stock
CAPM: Capital Asset Pricing Model
E(Rs ) = Rf + β (E(Rm ) − Rf )
E(Rs ): stock required rate of return
Rf : risk-free rate (e.g. Treasuries)
E(Rm ): market expected return (e.g. S&P 500)
E(Rm ) − Rf : Market premium
GARCH MODELS IN PYTHON
Dynamic Beta with GARCH
Beta = ρ * σ _stock / σ __market
GARCH MODELS IN PYTHON
Calculate dynamic Beta in Python
1). Compute correlation between S&P500 and stock
resid_stock = stock_gm.resid / stock_gm.conditional_volatility
resid_sp500 = sp500_gm.resid / sp500_gm.conditional_volatility
correlation = numpy.corrcoef(resid_stock, resid_sp500)[0, 1]
2). Compute dynamic Beta for the stock
stock_beta = correlation * (stock_gm.conditional_volatility /
sp500_gm.conditional_volatility)
GARCH MODELS IN PYTHON
Let's practice!
GA RCH MODELS IN P YTH ON
Congratulations!
GA RCH MODELS IN P YTH ON
Chelsea Yang
Data Science Instructor
You did it
Fit GARCH models
Make volatility forecast
Evaluate model performance
GARCH in action: VaR, covariance, Beta
GARCH MODELS IN PYTHON
Going forward
Time series analysis
ARIMA (AutoRegressive Integrated Moving Average) models
CAPM (Capital Asset Pricing Model)
Portfolio optimization
GARCH MODELS IN PYTHON
Have fun and keep
improving!
GA RCH MODELS IN P YTH ON