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:
| Item | 2025-09 | 2025-10 | 2025-11 | 2025-12 |
|---|---|---|---|---|
| Mkt-RF | 0.0297 | 0.0170 | -0.0012 | -0.0030 |
| SMB | 0.0043 | 0.0028 | -0.0033 | 0.0004 |
| HML | 0.0019 | 0.0058 | -0.0068 | -0.0042 |
| RMW | -0.0050 | -0.0130 | 0.0032 | 0.0006 |
| CMA | -0.0030 | -0.0055 | 0.0008 | 0.0005 |
| Common Return | 0.0278 | 0.0071 | -0.0072 | -0.0058 |
| Specific Return | 0.0256 | 0.0227 | 0.0284 | -0.0055 |
| Total Return | 0.0534 | 0.0298 | 0.0213 | -0.0113 |
| Tilt Return | 0.0278 | 0.0071 | -0.0072 | -0.0058 |
| Timing Return | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
10 rows
Parameters
get_factor_attribution accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
weights | dict[str, float] | None | The 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 |
selection | str | How 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" |
factors | pd.DataFrame | None | The 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 |
region | str | The 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" |
period | str | The 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_benchmark | bool | Whether to include the benchmark as an asset. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding. | 2 |
show_columns | str | list[str] | None | The 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