Calculate a nested-model Likelihood Ratio (LR) test, the Maximum Likelihood analogue of get_f_test, for the joint significance of the regressors in unrestricted_independent_tickers that are not already in restricted_independent_tickers.

As with get_f_test, a “restricted” and an “unrestricted” OLS regression of dependent_ticker are fitted internally and the null hypothesis is that the q extra tickers are jointly zero. Instead of an F-statistic, the two models are compared through the ratio of their likelihoods, which for linear models with normal errors reduces to a function of the two Residual Sums of Squares (RSS).

The formula is as follows:

\[\text{LR} = - 2 \cdot (\text{ln}\; L_{\text{restricted}} - \text{ln}\; L_{\text{unrestricted}}) = n \cdot \ln(\text{RSS\_restricted} / \text{RSS\_unrestricted})\]
  • Both models are OLS regressions of the dependent ticker’s column (Return by default), with a constant when add_constant=True

Under the null this is asymptotically chi-squared distributed with q degrees of freedom. Where the F-test is exact in small samples under the classical assumptions, the LR test relies on a large-sample approximation: both agree for long return histories and can differ somewhat for short ones. A low p-value means the extra tickers meaningfully improve the model.

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

  • Wilks, S.S. (1938). “The Large-Sample Distribution of the Likelihood Ratio for Testing Composite Hypotheses.” Annals of Mathematical Statistics, 9(1), 60-62.

Also known as: LR test, Wilks’ likelihood ratio test.

Likelihood Ratio Test in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_likelihood_ratio_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",
)

toolkit.econometrics.get_likelihood_ratio_test(
    "AAPL", "MSFT", ["MSFT", "Benchmark"], period="weekly"
)

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

Did adding the S&P 500 to a regression of Apple's weekly returns on Microsoft's improve the fit from 2021 to 2025, according to a likelihood ratio test?

Which returns:

  0
LR Statistic 88.8863
Degrees of Freedom 1
P-Value 0
Reject Restrictions (5%) 1

Using Your Own Data

get_likelihood_ratio_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_likelihood_ratio_test with dependent_ticker, restricted_independent_tickers and unrestricted_independent_tickers, using the column names of the data as tickers.

Parameters

get_likelihood_ratio_test accepts the following parameters.

ParameterTypeDescriptionExample
dependent_tickerstrThe dependent (predicted) asset."AAPL"
restricted_independent_tickersstr | list[str]The independent asset(s) in the restricted (smaller) model."MSFT"
unrestricted_independent_tickersstr | list[str]The independent asset(s) in the unrestricted (larger) model – must be a superset of restricted_independent_tickers.["MSFT", "Benchmark"]
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 both models. Defaults to True.False
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
Share