Fit a Fama-MacBeth (1973) two-pass cross-sectional regression: asset_tickers is treated as the cross-section of test assets, factor_tickers as the risk factor(s) whose risk premia are estimated – the standard procedure for testing whether a proposed risk factor is actually priced.

Also known as: two-pass regression, Fama-MacBeth procedure.

For more information about the method, see fama_macbeth_model.get_fama_macbeth_regression.

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

Calculate the Fama-MacBeth Regression in Python

The Fama-MacBeth Regression is available in the Econometrics module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_fama_macbeth_regression as shown below.

from financetoolkit import Toolkit

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

# Benchmark (the default factor) is the single risk factor; AAPL and MSFT
# are the test assets. add_constant=False since only 2 assets are available.
toolkit.econometrics.get_fama_macbeth_regression(
    period="weekly", add_constant=False
)

Which returns:

  Risk Premium Std. Error t-Statistic P-Value
Benchmark 0.0032 0.0016 1.9798 0.0486

Parameters

get_fama_macbeth_regression accepts the following parameters:

  • factor_tickers (str | list[str] | None, optional): The ticker(s) whose returns are used as the risk factor(s) (e.g. “Benchmark” for a single-factor/CAPM-style test). Defaults to None, meaning ["Benchmark"].
  • asset_tickers (str | list[str] | None, optional): The ticker(s) forming the cross-section of test assets. Defaults to None, meaning every Toolkit ticker (including “Benchmark”) not already used as a factor.
  • 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 the second-pass cross-sectional regression. Defaults to True.
  • 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