Factor Attribution

Attribute the return of a portfolio in every period to factors, by default the five factors of Fama and French (market, size, value, profitability and investment).

It shows the part of the return its exposure to each factor explains, and the specific return that is left. The loadings of the assets on the factors come from a regression over the whole period (see get_factor_loadings), and the portfolio’s exposure to a factor is the weighted sum of its assets’ loadings.

  • Exposure_f,t = \(\sum_{i} w_{i,t} \beta_{i,f}\)
  • Contribution_f,t = Exposure_f,t × Factor Return_f,t
  • Common Return = \(\sum_{f}\) Contribution_f,t
  • Specific Return = Total Return - Common Return
  • Tilt Return = \(\sum_{f}\) Average Exposure_f × Factor Return_f,t
  • Timing Return = Common Return - Tilt Return

The Specific Return holds the alphas of the assets (and the risk free rate, as the Fama and French factors are excess returns) and their residual returns. The Tilt Return is what the average exposure earned and the Timing Return what moving the exposures around it added, which is zero for weights that stay the same.

The weights are those of the Portfolio the Toolkit came from at the end of the period before, or, when weights are given (or there is no Portfolio), those weights restored every period.

Also known as: performance attribution to risk factors, factor return attribution, returns-based attribution, common and specific returns.

Example · AAPL, MSFT, JNJ, XOM · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_factor_attribution:

from financetoolkit import Toolkit

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

toolkit.portfolio.get_factor_attribution(
    weights={"AAPL": 0.4, "MSFT": 0.3, "JNJ": 0.2, "XOM": 0.1}, period="monthly"
).tail(4).T

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

How much of the monthly return of a portfolio of 40% Apple, 30% Microsoft, 20% Johnson & Johnson and 10% ExxonMobil came from the Fama and French factors in the last four months of 2025?

Which returns:

Parameters

get_factor_attribution accepts the following parameters.

ParameterTypeDescriptionExample
weightsdict[str, float] | NoneThe weight per asset. Defaults to None, which uses the weights of the Portfolio the Toolkit came from over time, or equal weights.None, which uses the weights of the Portfolio the Toolkit came from over time, or equal weights
selectionstrHow the loadings are estimated (see get_factor_loadings). Options are: “ols” (every factor), “forward” (forward selection), “backward” (backward selection), “pcr” (principal components regression). Defaults to “ols”."ols"
factorspd.DataFrame | NoneThe factor returns, one column per factor, at the frequency of the period. Defaults to None, the Fama and French five factors of the region.None, the Fama and French five factors of the region
regionstrThe region of the Fama and French factors. Options are: “United States”, “Developed”, “Developed ex US”, “Europe”, “Japan”, “Asia Pacific ex Japan”, “North America”. Defaults to “United States”."Europe"
periodstrThe frequency of the returns. Options are: “daily” (daily returns), “weekly” (weekly returns), “monthly” (monthly returns), “quarterly” (quarterly returns), “yearly” (yearly returns). Defaults to “daily”."weekly"
include_benchmarkboolWhether to include the benchmark as an asset. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding.2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Grinold, R. C. and Kahn, R. N. (2000). “Active Portfolio Management.” 2nd edition, McGraw-Hill, chapter 17.
  • Paper Fama, E. F. and French, K. R. (2015). “A Five-Factor Asset Pricing Model.” Journal of Financial Economics, 116(1), 1-22.
  • Library Referenced against empyrical’s perf_attrib
  • Library Shares similar logic as empyrical’s compute_exposures
  • Library Shares similar logic as pyfolio’s perf_attrib
Share