Lilliefors Test
The Lilliefors Test (Lilliefors, 1967) is the Kolmogorov-Smirnov test for normality when the mean and the variance are estimated from the sample. The Kolmogorov-Smirnov test assumes a fully specified distribution; with estimated parameters the fitted normal lies closer to the data than the true one, its critical values are far too large and it rarely rejects. Lilliefors tabulated the distribution of the statistic for this case by simulation.
The formula for the Lilliefors Test standardizes the sorted returns \(y_{1}\) to \(y_{n}\) with the mean of the returns r and their sample standard deviation s (with n - 1 in the denominator):
\[z_{i} = \frac{y_{i} - \operatorname{mean}\left(r\right)}{s}\]The statistic D is the largest gap between the empirical distribution function, which steps from (i - 1) / n to i / n at the i-th smallest return, and the normal distribution function Phi:
\[D = \max\left(\max\left(\frac{i}{n} - \Phi(z_{i})\right), \max\left(\Phi(z_{i}) - \frac{i - 1}{n}\right)\right)\]A large D, with a p-value below the significance level, rejects normality. The p-value comes from the approximation of Dallal and Wilkinson (1986) where that is at most 0.10 and from simulated normal samples otherwise. The largest gap tends to lie in the middle of the distribution, so the test gives fat tails no extra weight and detects them later than the Anderson-Darling Test.
A normality test asks whether a sample could come from a normal distribution: the null hypothesis is that it does, the alternative that it comes from any other distribution. The question matters because the Gaussian Value at Risk, the Black-Scholes model and many statistical tests assume normally distributed returns, while returns tend to be skewed and fat-tailed. The tests differ in the departure from normality they are most sensitive to. Every one of them reads the same way: a p-value below the chosen significance level (such as 0.05) rejects normality, while a higher p-value only means the sample gives no evidence against it, not that the returns are normal. In a long sample a test rejects even a departure too small to matter, and in a short one it misses a large one.
Also known as: Kolmogorov-Smirnov normality test, KS normality test.
In the Finance Toolkit this is get_normality_test with method="lilliefors", the same function as Normality Test.
Example · ^GSPC, BTCUSD, TLT · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_normality_test:
from financetoolkit import Toolkit
toolkit = Toolkit(
["^GSPC", "BTCUSD", "TLT"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.econometrics.get_normality_test(method="lilliefors", period="monthly")
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency for returns (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
within_period | bool | Whether to calculate the test within the specified period or for the entire period. Thus whether to look at the test within a specific year (if period = ‘yearly’) or look at the entirety of all years. Defaults to False. Note that this requires intraday data when period = ‘daily’, since a single day only nests observations when intraday data was fetched. | True |
method | str | The test. Options are: “shapiro_wilk” (Shapiro-Wilk Test), “anderson_darling” (Anderson-Darling Test), “lilliefors” (Lilliefors Test), “dagostino_pearson” (D’Agostino-Pearson Test). Defaults to “shapiro_wilk”. | "shapiro_wilk" |
include_benchmark | bool | Whether to include “Benchmark” among the assets tested. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
Which returns:
| Item | ^GSPC | BTCUSD | TLT |
|---|---|---|---|
| Lilliefors Statistic | 0.1121 | 0.0809 | 0.0599 |
| P-Value | 0.0625 | 0.4293 | 0.8696 |
2 rows
Using Your Own Data
get_normality_test runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:
from financetoolkit import Economics, Econometrics
economics = Economics(start_date="2000-01-01")
unemployment = economics.get_unemployment_rate(
countries=["United States", "Germany"], period="monthly"
)
econometrics = Econometrics(data=unemployment, changes="difference")
econometrics.get_normality_test()
References
- Paper Lilliefors, H.W. (1967). “On the Kolmogorov-Smirnov Test for Normality with Mean and Variance Unknown.” Journal of the American Statistical Association, 62(318), 399-402.
- Paper Dallal, G.E. and Wilkinson, L. (1986). “An Analytic Approximation to the Distribution of Lilliefors’s Test Statistic for Normality.” The American Statistician, 40(4), 294-296.
- Library Referenced against statsmodels’ lilliefors (Lilliefors Test)