Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to Portfolio Risk Management in Python

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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)
Code bewerken en uitvoeren