White Test
Calculate White’s test for heteroskedasticity of a regression of dependent_ticker on independent_tickers.
A more general version of get_breusch_pagan_test. Instead of regressing the squared residuals on only the original independent tickers, the auxiliary regression uses each ticker, its square and every pairwise cross-product.
The formula is as follows:
\[e_{t} ^{2} = a_{0} + \text{SUM}_{i}(a_{i} \cdot x_{it}) + \text{SUM}_{i}(b_{i} \cdot x_{it} ^{2}) + \text{SUM\_\{i} < \operatorname{j\}}(c_{ij} \cdot x_{it} \cdot x_{jt}) + v_{t}\] \[\text{LM} = n \cdot R ^{\text{2\_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 null hypothesis is homoskedasticity (constant residual variance). A low p-value means the regression’s standard errors are unreliable and a robust cov_type should be used. 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.
For more information about the method, see the following paper:
- White, H. (1980). “A Heteroskedasticity-Consistent Covariance Matrix Estimator and a Direct Test for Heteroskedasticity.” Econometrica, 48(4), 817-838.
Also known as: White’s general test.
White Test in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_white_test as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["GS", "MS"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2025-01-01",
end_date="2025-12-31",
)
# GS (the first ticker) is dependent; MS is independent
toolkit.econometrics.get_white_test()
Or, after setting up the Finance Toolkit MCP, ask:
Was a regression of Goldman Sachs' daily returns on Morgan Stanley's heteroskedastic in 2025, according to White's test?
Which returns:
| Value | |
|---|---|
| White Statistic | 11.5102 |
| P-Value | 0.0032 |
| Reject Homoskedasticity (5%) | 1 |
Using Your Own Data
get_white_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_white_test()
Parameters
get_white_test accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
dependent_ticker | str | None | The dependent (predicted) asset. Defaults to None, meaning the Toolkit instance’s first ticker. | "AAPL" |
independent_tickers | str | list[str] | None | The independent (predictor) asset(s). Defaults to None, meaning every other ticker in the Toolkit instance besides dependent_ticker. | ["MSFT", "Benchmark"] |
include_benchmark | bool | Whether to include “Benchmark” in the default independent ticker(s) (has no effect when independent_tickers is given explicitly). Defaults to False. | True |
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to regress on. Defaults to “Return”. | "Return" |
add_constant | bool | Whether to include an intercept in the underlying regression. Defaults to True. | False |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |