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.

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

Fits both a “restricted” and an “unrestricted” OLS regression of dependent_ticker internally (via regression_model.get_ols) and compares them. For more information about the method, see hypothesis_testing_model.get_likelihood_ratio_test.

Likelihood Ratio Test in Python

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

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

Which returns:

Metric Value
LR Statistic 39.2102
Degrees of Freedom 1
P-Value 0.0000
Reject Restrictions (5%) 1

Parameters

The function accepts the following parameters:

  • dependent_ticker (str): The dependent (predicted) asset.
  • restricted_independent_tickers (str | list[str]): The independent asset(s) in the restricted (smaller) model.
  • unrestricted_independent_tickers (str | list[str]): The independent asset(s) in the unrestricted (larger) model – must be a superset of restricted_independent_tickers.
  • 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”.
  • add_constant (bool, optional): Whether to include an intercept in both models. Defaults to True.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.
Share