Calculate a Wald test of q general linear restriction(s) on the coefficients of an OLS regression of dependent_ticker on independent_tickers.

A single OLS regression is fitted internally and the test checks the null hypothesis H0: R @ beta = r, where R (restriction_matrix) encodes q linear restrictions on the coefficients and r (restriction_values) holds their hypothesised values (zero by default). This generalises the t-test reported for each coefficient to combinations of coefficients, for example that two coefficients are jointly zero, that a coefficient equals a specific value (such as a beta of exactly 1), or that two tickers have the same coefficient.

The formula is as follows:

\[W = (R \text{@} \beta_{hat} - r) \text{'} \text{@} (R \text{@} \;\text{Cov} (\beta_{hat}) \text{@} R') ^{-1} \operatorname{@}(R \text{@} \beta_{hat} - r)\] \[F = W / q,\;\; \text{F-distributed with (q, n - k) degrees of freedom}\] \[\beta_{hat} \;\text{and the classical Cov} (\beta_{hat}) = \text{sigmâ} ^{2} \cdot (\text{X'X}) \text{⁻¹} \;\text{come from the OLS regression of the dependent ticker's}\; \text{column} (\text{Return by default}),\;\; \text{with a constant when add\_constant=True}\]

Which is asymptotically chi-squared distributed with q degrees of freedom. W / q is reported alongside it as an F-statistic for small samples; for a single restriction it equals the squared t-statistic of that coefficient. A low p-value means the data reject the restriction(s).

For more information about the method, see the following paper:

  • Wald, A. (1943). “Tests of Statistical Hypotheses Concerning Several Parameters When the Number of Observations is Large.” Transactions of the American Mathematical Society, 54(3), 426-482.

Also known as: Wald chi-squared test.

Wald Test in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_wald_test as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

# H0: the coefficients on both MSFT and Benchmark are jointly zero.
toolkit.econometrics.get_wald_test(
    restriction_matrix=[[0, 1, 0], [0, 0, 1]],
    independent_tickers=["MSFT", "Benchmark"],
    period="weekly",
)

Or, after setting up the Finance Toolkit MCP, ask:

Are the coefficients on Microsoft and the S&P 500 jointly zero in a regression of Apple's weekly returns from 2021 to 2025, according to a Wald test?

Which returns:

  0
Wald Statistic (Chi2) 269.191
Chi2 P-Value 0
F-Statistic 134.595
F P-Value 0
Restrictions (q) 2
Reject Restrictions (5%) 1

Using Your Own Data

get_wald_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, where each country is a column:

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")

Then call econometrics.get_wald_test with restriction_matrix.

Parameters

get_wald_test accepts the following parameters.

ParameterTypeDescriptionExample
restriction_matrixpd.DataFrame | np.ndarray | list[list[float]]The (q, k) restriction matrix R, one row per restriction, one column per coefficient in the same order as add_constant (if True, “Intercept” first) followed by the independent ticker(s), e.g. [[0, 1, 0], [0, 0, 1]].
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), in the order the restriction matrix’s columns (after “Intercept”, if add_constant) refer to them. 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
restriction_valuespd.Series | np.ndarray | list[float] | NoneThe length-q vector of hypothesized values. Defaults to None, i.e. all restrictions equal zero.
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. Defaults to True.False
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
Share