Factor Risk Contributions
Calculate how much each factor, by default the five factors of Fama and French, contributes to the risk of a portfolio, rather than each asset.
The portfolio’s exposure to the factors is y = B’w, with B the loadings of the assets on the factors (see get_factor_loadings), and the marginal risk of the factors follows from that of the assets \(m = \partial \rho / \partial w\) (see get_risk_contributions) through the pseudo-inverse of B’: \(\partial \rho / \partial y\) = pinv(B’)’m. A factor contributes its exposure times its marginal risk, and the part of the weights the factors cannot span forms an Other factor, so the contributions add up to the risk measure (Meucci, 2009; Roncalli and Weisang, 2016). With fewer assets than factors the factors span every portfolio and Other is zero.
The risk measure is any of get_risk_contributions: the volatility (annualized), the expected shortfall, the drawdowns or the other measures of the Risk module (per period).
Also known as: factor risk decomposition, factor risk budget, risk factor contributions.
Example · AAPL, MSFT, JNJ, XOM · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_factor_risk_contributions:
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_risk_contributions(
weights={"AAPL": 0.4, "MSFT": 0.3, "JNJ": 0.2, "XOM": 0.1}
)
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
How much did each Fama and French factor contribute to the risk of a portfolio of 40% Apple, 30% Microsoft, 20% Johnson & Johnson and 10% ExxonMobil from 2021 to 2025?
Which returns:
| Factor | Exposure | Marginal Contribution | Risk Contribution | Percentage Contribution |
|---|---|---|---|---|
| Mkt-RF | 0.9376 | 0.1727 | 0.1619 | 0.8731 |
| SMB | -0.1694 | -0.0254 | 0.0043 | 0.0232 |
| HML | -0.1765 | -0.0437 | 0.0077 | 0.0416 |
| RMW | 0.2806 | 0.0336 | 0.0094 | 0.0509 |
| CMA | 0.1144 | 0.0184 | 0.0021 | 0.0113 |
| Other | 0.0000 | 0.0000 | ||
| Total | 0.1855 | 1.0000 |
7 rows
Parameters
get_factor_risk_contributions accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
weights | dict[str, float] | None | The weight per asset. Defaults to None, which uses the latest weights of the Portfolio the Toolkit came from, or equal weights. | None, which uses the latest weights of the Portfolio the Toolkit came from, or equal weights |
risk_measure | str | A risk measure of get_risk_contributions. Options are: “volatility” (of the covariance estimate), “cvar” (the expected shortfall), “semideviation” (below a return of zero), “mad” (the mean absolute deviation), “cdar” (the Conditional Drawdown at Risk), “var” (historical Value at Risk), “evar” (Entropic Value at Risk), “worst_realization” (the largest loss), “gini_mean_difference” (Gini mean difference), “tail_gini” (Tail Gini), “lower_partial_moment” (first lower partial moment below zero), “kurtosis” (square root of the fourth central moment), “maximum_drawdown” (maximum drawdown), “average_drawdown” (average drawdown), “drawdown_at_risk” (Drawdown at Risk), “entropic_drawdown_at_risk” (Entropic Drawdown at Risk), “ulcer_index” (Ulcer Index). Defaults to “volatility”. | "volatility" |
alpha | float | The tail probability of the tail measures, e.g. 0.05 for the worst 5% of periods. Defaults to 0.05. | 0.01 |
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 Meucci, A. (2009). “Managing Diversification.” Risk, 22(5), 74-79.
- Paper Roncalli, T. and Weisang, G. (2016). “Risk Parity Portfolios with Risk Factors.” Quantitative Finance, 16(3), 377-388.
- 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 Riskfolio-Lib’s Factors_Risk_Contribution