Risk Decomposition

Calculate the systematic, specific and total risk of an investment portfolio or asset: its volatility split into the part that comes from the market, which diversification cannot remove, and the part that is its own.

The formulas are as follows:

\[\text{Systematic Risk} = \text{Beta} \cdot \text{Volatility of the Benchmark Excess Returns}\] \[\text{Specific Risk} = \text{Volatility of the Residuals}\] \[\text{Total Risk} = \sqrt{\text{Systematic Risk}^{2} + \text{Specific Risk}^{2}}\]

Where Beta and the Residuals come from the CAPM regression of the daily excess returns on the benchmark’s within each period, Excess Return = Alpha + Beta x Benchmark Excess Return + Residual. The volatilities are sample standard deviations of the daily values scaled to the period (times the square root of 252 trading days for a year, 365 calendar days for a ticker that trades on weekends), so the yearly figures are annualized. With the same degrees of freedom the regression splits the variance exactly, so the Total Risk equals the volatility of the excess returns. A specific risk that dominates the total means the asset’s moves are mostly its own, as a low R-squared (see get_r_squared) shows.

Also known as: market and idiosyncratic risk, diversifiable and non-diversifiable risk, residual risk.

Example · AAPL, XOM · 2021 to 2025

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

from financetoolkit import Toolkit

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

toolkit.performance.get_risk_decomposition().xs("XOM", level=0, axis=1)

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

How much of ExxonMobil's risk was systematic and how much specific to the company in each year from 2021 to 2025?

Which returns:

Parameters

get_risk_decomposition accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe period to use for the calculation. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “quarterly” if the Toolkit is initialised with quarterly=True, otherwise “yearly”."weekly"
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the ratios. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
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 Bacon, C.R. (2008). “Practical Portfolio Performance Measurement and Attribution.” 2nd edition, John Wiley & Sons, pp. 71-72.
  • Library Referenced against PerformanceAnalytics (R)’s SystematicRisk
  • Library Referenced against PerformanceAnalytics (R)’s SpecificRisk
  • Library Shares similar logic as PerformanceAnalytics (R)’s TotalRisk
Share