Testing for Normality

A simple Python function to use whenever we are interested in assessing normality. It provides both visual tools and a hypothesis tests.

normality_general.png

You can find the complete script here. This function provides:

Visualisations

  • Histogram of the returns compared with a normal density plot with parameters equal to the empirical mean and variance
  • Quantile – Quantile (Q-Q) plot
  • Cumulative Distribution Function (CDF) plot against the normal CDF with parameters given by the empirical mean and variance

Hypothesis Test

  • Shapiro Wilk
  • D’ Angostino
  • Kolmogorov-Smirnov
  • Anderson-Darling

Let’s test the function with some normal data.

example_normal_data

normal_example_result

and now with a sample from a standard t-distribution with 3 degrees of freedom:

t_example (1)

t_image.png

Testing Normality: Returns and Log-Returns

It is well-known that many financial models assume that returns or log-returns follow a normal distribution. In these cases, it is a good practice to do some analysis in order to assess departures from normality. Modifying slightly our first function we get a new function which calculates the returns (standard or log-returns) first and then proceeds with the normality assessment.

normality_test

We tested a number of returns for financial time series and none of them passed a single normality test… which is not surprising after looking at the visualisations. You can find more examples in the Python Notebook.  In a future post I will discuss every test more in detail.

Quant Girl

I write about Mathematics, Statistics, Finance, Programming, and the relationships among them. I enjoy learning, listening to music and podcasts, practicing yoga, reading magazines, and watching documentaries.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.