Get Started

Statistical tests for normality

In order to truly be confident in your judgement of the normality of the stock's return distribution, you will want to use a true statistical test rather than simply examining the kurtosis or skewness.

You can use the shapiro() function from scipy.stats to run a Shapiro-Wilk test of normality on the stock returns. The function will return two values in a list. The first value is the t-stat of the test, and the second value is the p-value. You can use the p-value to make a judgement about the normality of the data. If the p-value is less than or equal to 0.05, you can safely reject the null hypothesis of normality and assume that the data are non-normally distributed.

clean_returns from the previous exercise is available in your workspace.

This is a part of the course

“Introduction to Portfolio Risk Management in Python”

View Course

Exercise instructions

  • Import shapiro from scipy.stats.
  • Run the Shapiro-Wilk test on clean_returns.
  • Extract the p-value from the shapiro_results tuple.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import shapiro from scipy.stats
from ____ import ____

# Run the Shapiro-Wilk test on the stock returns
shapiro_results = ____
print("Shapiro results:", shapiro_results)

# Extract the p-value from the shapiro_results
p_value = ____
print("P-value: ", p_value)
Edit and Run Code