Skewness and kurtosis

Introduction to Portfolio Risk Management in Python

Dakota Wixom

Quantitative Analyst | QuantCourse.com

Skewness is the third moment of a distribution.

  • Negative Skew: The mass of the distribution is concentrated on the right. Usually a right-leaning curve
  • Positive Skew: The mass of the distribution is concentrated on the left. Usually a left-leaning curve
  • In finance, you would tend to want positive skewness

 

Introduction to Portfolio Risk Management in Python

Skewness in Python

Assume you have pre-loaded stock returns data in the StockData object.

To calculate the skewness of returns:

from scipy.stats import skew
skew(StockData["Returns"].dropna())
0.225

Note that the skewness is higher than 0 in this example, suggesting non-normality.

Introduction to Portfolio Risk Management in Python

Kurtosis is a measure of the thickness of the tails of a distribution

  • Most financial returns are leptokurtic
  • Leptokurtic: When a distribution has positive excess kurtosis (kurtosis greater than 3)
  • Excess Kurtosis: Subtract 3 from the sample kurtosis to calculate "Excess Kurtosis"

 

Introduction to Portfolio Risk Management in Python

Excess kurtosis in Python

Assume you have pre-loaded stock returns data in the StockData object. To calculate the excess kurtosis of returns:

from scipy.stats import kurtosis
kurtosis(StockData["Returns"].dropna())
2.44

Note the excess kurtosis greater than 0 in this example, suggesting non-normality.

Introduction to Portfolio Risk Management in Python

Testing for normality in Python

How do you perform a statistical test for normality?

The null hypothesis of the Shapiro-Wilk test is that the data are normally distributed.

# Run the Shapiro-Wilk normality test in Python 
from scipy import stats
p_value = stats.shapiro(StockData["Returns"].dropna())[1]
if p_value <= 0.05:
     print("Null hypothesis of normality is rejected.")
else:
     print("Null hypothesis of normality is accepted.")

The p-value is the second variable returned in the list. If the p-value is less than 0.05, the null hypothesis is rejected because the data are most likely non-normal.

Introduction to Portfolio Risk Management in Python

Let's practice!

Introduction to Portfolio Risk Management in Python

Preparing Video For Download...