Python For Finance: Risk Measurement
Python For Finance: Risk Measurement
Risk Measurement
Andras Niedermayer
Outline
1 Risk Measures
2 Parametric VaR, ES
4 Historical method
Formal definitions:
1 Value at Risk:
1 Risk Measures
2 Parametric VaR, ES
4 Historical method
3 Use the closed form solution to calculate the VaR and ES:
1 var = - scs . norm . ppf ( alpha , loc = mu ,
2 scale = sigma )
3 es = scs . norm . pdf ( scs . norm . ppf ( alpha ))*
4 1/ alpha * sigma - mu
Wednesday, April, 2019 Python for Finance - Lecture 9
Andras Niedermayer - Université Paris-Dauphine 8/36
Normality assumption
2 QQ (quantile-quantile) plots.
1 sm . qqplot ( log_returns . flatten ())
We want to see whether the S&P 500 returns are also normally
distributed.
1 plt . hist ( sp_returns , bins =50 , density = True )
2 sm . qqplot ( sp_returns )
The S&P 500 data have negative skewness (i.e., the returns are not
symmetric around the mean), and they also have excess kurtosis (fat
tails: excessive extreme returns). Therefore, it fails the normality test.
1 Risk Measures
2 Parametric VaR, ES
4 Historical method
Especially in small samples, the sample mean and variance will not be
zero and one!
1 X . mean ()= -0.128
2 X . std ()=1.015
Mean adjustment
First, we can normalize the mean by subtracting it from each element:
1 X1 =X - X . mean ()
2 X1 . mean ()=5.16 e -17
3 X1 . std ()=1.015
Variance adjustment
Second, we can normalize the variance by dividing each element with
the standard deviation:
1 X2 = X1 / X . std ()
2 X2 . mean ()=5.16 e -17
3 X2 . std ()=1.000
Or, directly:
1 X3 =( X - X . mean ())/ X . std ()
rt = µ + t , where t ∼ N 0, σt2
(4)
GARCH Normal
VaR95 0.0387 0.0248
1 Risk Measures
2 Parametric VaR, ES
4 Historical method