Calculate a regression-based Hausman-Wu test for the endogeneity of suspect_ticker in a regression of dependent_ticker on suspect_ticker (and, optionally, other_independent_tickers), using instrument_tickers as instruments for suspect_ticker.

Also known as: Hausman test, Durbin-Wu-Hausman test, regression test for endogeneity.

For more information about the method, see hypothesis_testing_model.get_hausman_wu_test.

No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Hausman-Wu Test for you. Just ask in plain English.

Calculate the Hausman-Wu Test in Python

The Hausman-Wu Test is available in the Econometrics module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_hausman_wu_test as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")

toolkit.econometrics.get_hausman_wu_test(
    "AAPL", "MSFT", "Benchmark", period="weekly"
)

Which returns:

Metric Value
V-Hat Coefficient -0.7162
T-Statistic -6.6098
Degrees of Freedom 154
P-Value 0.0000
Endogenous (5%) 1

Parameters

get_hausman_wu_test accepts the following parameters:

  • dependent_ticker (str): The dependent (predicted) asset.
  • suspect_ticker (str): The (possibly endogenous) asset being tested.
  • instrument_tickers (str | list[str]): One or more instrument asset(s) for suspect_ticker – assets correlated with suspect_ticker but assumed uncorrelated with dependent_ticker’s error term.
  • other_independent_tickers (str | list[str] | None, optional): Any other (assumed exogenous) independent asset(s) to include. Defaults to None.
  • period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
  • column (str, optional): The historical data column to regress on. Defaults to “Return”.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.

The Econometrics module page introduces the module, and the sidebar lists all of its functions.

Share