Heteroskedasticity Test

Calculate a test for heteroskedasticity: whether the residual variance of a regression of the dependent ticker on the independent tickers moves with them, with the Breusch-Pagan test or White’s test.

OLS standard errors assume that the residual variance is constant (homoskedasticity). Both tests regress the squared residuals of the regression on functions of the independent tickers and check whether they explain any of the residual variance, by testing whether the R-squared of that auxiliary regression is significantly different from zero. The Breusch-Pagan test uses only the original independent tickers. White’s test is the more general version: its auxiliary regression uses each ticker, its square and every pairwise cross-product, so it also catches non-linear forms of heteroskedasticity.

The formula for the Breusch-Pagan test is as follows:

\[\text{Auxiliary regression:}\;\; e_{t}^{2} = a_{0} + a' \cdot x_{t} + v_{t},\;\; \text{with } e_{t} \text{ the OLS residuals and } x_{t} \text{ the independent tickers' column (Return by default)}\] \[\text{LM} = n \cdot R^{2}_{\text{auxiliary}} \;(\text{Koenker's studentized form},\; \text{the statsmodels default})\]

The formula for White’s test is as follows:

\[e_{t}^{2} = a_{0} + \sum_{i}(a_{i} \cdot x_{it}) + \sum_{i}(b_{i} \cdot x_{it}^{2}) + \sum_{i<j}(c_{ij} \cdot x_{it} \cdot x_{jt}) + v_{t}\] \[\text{LM} = n \cdot R^{2}_{\text{auxiliary}},\;\; \text{chi-squared with as many degrees of freedom as the auxiliary regression has terms besides } a_{0}\]
  • \(e_{t}\) are the OLS residuals and \(x_{it}\) the independent tickers’ column (Return by default)

The Breusch-Pagan statistic is the studentized statistic of Koenker (1981), which does not assume normally distributed errors. It is asymptotically chi-squared distributed with k - 1 degrees of freedom under the null hypothesis of homoskedasticity, where k is the number of parameters of the auxiliary regression. For both tests a low p-value means the residual variance moves with the independent tickers (for example, errors grow when the market moves more), so the regression’s standard errors, t-statistics and p-values are unreliable even though the coefficients themselves remain unbiased. Remedies are a robust covariance in get_ols or get_wls. Because it also detects non-linear patterns in the residual variance, White’s test makes fewer assumptions than Breusch-Pagan, at the cost of power when there are many independent tickers, since the number of auxiliary terms grows quadratically.

Also known as: BP test, Breusch-Pagan test, Breusch-Pagan-Godfrey test, White test, White’s general test, heteroscedasticity test.

Example · CAT, DE · 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_heteroskedasticity_test:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["CAT", "DE"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2025-01-01",
    end_date="2025-12-31",
)

# CAT (the first ticker) is dependent; DE is independent
toolkit.econometrics.get_heteroskedasticity_test()

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

Was the residual variance of a regression of Caterpillar's daily returns on Deere's constant in 2025, according to the Breusch-Pagan test?

Which returns:

Item0
Breusch-Pagan Statistic0.0121
P-Value0.9123
Reject Homoskedasticity (5%)0.0000

3 rows

Using Your Own Data

get_heteroskedasticity_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_heteroskedasticity_test()

Parameters

get_heteroskedasticity_test accepts the following parameters.

ParameterTypeDescriptionExample
dependent_tickerstr | NoneThe dependent (predicted) asset. Defaults to None, meaning the Toolkit instance’s first ticker."AAPL"
independent_tickersstr | list[str] | NoneThe independent (predictor) asset(s). Defaults to None, meaning every other ticker in the Toolkit instance besides dependent_ticker.["MSFT", "Benchmark"]
include_benchmarkboolWhether to include “Benchmark” in the default independent ticker(s) (has no effect when independent_tickers is given explicitly). Defaults to False.True
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
columnstrThe historical data column to regress on. Defaults to “Return”."Return"
add_constantboolWhether to include an intercept in the underlying regression. Defaults to True.False
methodstrThe test. Options are: “breusch_pagan” (Breusch-Pagan test, in Koenker’s studentized form), “white” (White’s test). Defaults to “breusch_pagan”."breusch_pagan"
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
show_columnsstr | list[str] | NoneThe 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

References

  • Paper Breusch, T.S., & Pagan, A.R. (1979). “A Simple Test for Heteroscedasticity and Random Coefficient Variation.” Econometrica, 47(5), 1287-1294.
  • Paper Koenker, R. (1981). “A Note on Studentizing a Test for Heteroscedasticity.” Journal of Econometrics, 17(1), 107-112.
  • Paper White, H. (1980). “A Heteroskedasticity-Consistent Covariance Matrix Estimator and a Direct Test for Heteroskedasticity.” Econometrica, 48(4), 817-838.
  • Library Referenced against statsmodels’ het_breuschpagan (Breusch-Pagan test)
  • Library Referenced against statsmodels’ het_white (White’s test)
Share