Calculate Fama and French 5 Factor model scores and residuals for a set of financial assets.

The Fama and French 5 Factor model is a widely used financial model that helps estimate the expected return of financial assets, such as stocks or portfolios, based on five key factors:

  • Market Risk Premium (Mkt-RF): Represents the additional return that investors expect to earn for taking on the risk of investing in the overall market as opposed to a risk-free asset.
  • Size Premium (SMB): Reflects the historical excess return of small-cap stocks over large-cap stocks.
  • Value Premium (HML): Captures the historical excess return of value stocks over growth stocks.
  • Profitability (RMW): Measures the historical excess return of high profitability stocks over low profitability stocks.
  • Investment (CMA): Quantifies the historical excess return of low investment stocks over high investment stocks.

The model can perform both a Simple Linear Regression on each factor as well as a Multi Linear Regression which includes all factors. Generally, a multi linear regression is applied but if you wish to see individual R-squared values for each factor you can select the simple linear regression method.

The model performs a Linear Regression on each factor and defines the regression parameters and residuals for each asset over time based on its exposure to these factors.

The regression formula is as follows for the Multi Linear Regression:

\[\text{Excess Return} = \text{Intercept} + \text{Beta1} \cdot \text{Mkt-RF} + \text{Beta2} \cdot \text{SMB} + \text{Beta3} \cdot \text{HML} + \text{Beta4} \cdot \text{RMW} + \text{Beta5} \cdot \text{CMA} + \text{Residuals}\]

And the following for the Simple Linear Regression:

  • Excess Return = Intercept + Slope * Factor Value + Residuals

So for a given factor, it should hold that the Excess Return equals the entire regression. Note that in this calculation the Excess Return refers to the Asset Return minus the Risk Free Rate as reported in the Fama and French dataset and will not be the same as the defined Excess Return in the historical data given that this is based on the Risk Free Rate defined in the initialization.

The regression is estimated on the daily observations falling inside each period, so its Intercept, Slope and Residuals are all on a daily scale. The Factor Value and Residuals columns reported by the Simple Linear Regression therefore describe the last daily observation within the period, which is the only reading for which the identity above holds - they are not period-aggregated quantities.

What is relevant to look at is the influence these factors have on each stock and how much each factor explains the stock return. E.g. you will generally see a pretty high influence (Beta or Slope) for the Market Risk Premium (Mkt-RF) factor as this is the main factor that explains the stock return (as also prevalent in the CAPM). The other factors can fluctuate greatly between stocks depending on which stocks you look at.

Also known as: Fama-French model, three-factor model, five-factor model, FF3, FF5.

No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Fama and French Model (FF) for you. Just ask in plain English.

Calculate the Fama and French Model (FF) in Python

The Fama and French Model (FF) is available in the Performance module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_fama_and_french_model as shown below.

from financetoolkit import Toolkit

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

# Calculate Fama and French 5 Factor model scores
toolkit.performance.get_fama_and_french_model()["AAPL"]

Parameters

get_fama_and_french_model accepts the following parameters:

  • period (str, optional): The period for the calculation (e.g., “weekly”, “monthly”, “quarterly”, “yearly”). Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”.
  • method (str, optional): The regression method to use for the calculation. Defaults to ‘multi’.
  • factors_to_calculate (list of str, optional): List of factors to calculate scores and residuals for. Defaults to [“Mkt-RF”, “SMB”, “HML”, “RMW”, “CMA”].
  • include_daily_residuals (bool, optional): Whether to also return the pointwise (daily) regression residuals as a second DataFrame. Defaults to False.
  • rounding (int, optional): The number of decimals to round the results to. Defaults to 4.
  • growth (bool, optional): Whether to calculate the growth of the ratio values. Defaults to False.
  • lag (int or list of int, optional): The lag to use for the growth calculation. Defaults to 1.
  • standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
  • show_columns (list of str, optional): Restrict the result to these top level columns. Defaults to None, which returns every column.

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

Share