Performance attribution

From JoelLewis/finance_skills · View interactive version

Performance attribution is an AI agent skill from the GitHub repository JoelLewis/finance_skills. Decompose portfolio returns into explainable components to identify where value was added or lost. Use when the user asks about Brinson attribution, allocation vs selection effects, factor-based attribution, fixed-income attribution, or currency attribution. Also trigger when users mention 'what dro

How to use this skill

Skill file

Performance Attribution

Core Concepts

Brinson-Fachler Attribution (Single Period)

The classic equity attribution model decomposes active return (portfolio return minus benchmark return) into three effects:

Where: w_p,i = portfolio weight in sector i, w_b,i = benchmark weight in sector i, R_p,i = portfolio return in sector i, R_b,i = benchmark return in sector i, R_b = total benchmark return.

Multi-Period Attribution

Single-period attribution does not compound across periods. Geometric linking methods are required:

Factor-Based Attribution

Decomposes returns into exposures to systematic risk factors:

Fixed-Income Attribution

Decomposes bond portfolio returns into component sources:

Currency Attribution

For international portfolios, returns decompose into:

Holdings-Based vs Returns-Based Attribution

Key Formulas

| Formula | Expression | Use Case |

|---------|-----------|----------|

| Allocation effect (sector i) | A_i = (w_p,i - w_b,i) × (R_b,i - R_b) | Sector weighting decisions |

| Selection effect (sector i) | S_i = w_b,i × (R_p,i - R_b,i) | Security selection within sector |

| Interaction effect (sector i) | I_i = (w_p,i - w_b,i) × (R_p,i - R_b,i) | Joint allocation-selection effect |

| Total active return | R_p - R_b = Σ(A_i + S_i + I_i) | Sum of all effects equals active return |

| Factor return contribution | C_k = β_k × F_k | Return from factor k exposure |

| Duration effect | ΔP/P ≈ -D × Δy | Bond price change from yield shift |

| Currency return | R_fx = (S_end - S_start) / S_start | Exchange rate impact |

Worked Examples

Example 1: Brinson-Fachler equity attribution

Given: Two-sector portfolio (Tech and Healthcare). Portfolio: 35% Tech (returned 15%), 65% Healthcare (returned 8%). Benchmark: 25% Tech (returned 12%), 75% Healthcare (returned 6%). Total benchmark return: 0.25×12% + 0.75×6% = 7.5%.

Calculate: Allocation, selection, and interaction effects for each sector, and total active return.

Solution:

  1. Total portfolio return: 0.35×15% + 0.65×8% = 5.25% + 5.20% = 10.45%.
  2. Total active return: 10.45% - 7.50% = 2.95%.
  3. Tech allocation effect: (0.35 - 0.25) × (12% - 7.5%) = 0.10 × 4.5% = +0.45% (overweight a sector that beat the benchmark).
  4. Tech selection effect: 0.25 × (15% - 12%) = 0.25 × 3% = +0.75% (stock picks in Tech beat Tech benchmark).
  5. Tech interaction effect: (0.35 - 0.25) × (15% - 12%) = 0.10 × 3% = +0.30% (overweight AND outperformed).
  6. Healthcare allocation effect: (0.65 - 0.75) × (6% - 7.5%) = -0.10 × -1.5% = +0.15% (underweight a sector that lagged the benchmark).
  7. Healthcare selection effect: 0.75 × (8% - 6%) = 0.75 × 2% = +1.50% (stock picks in Healthcare beat Healthcare benchmark).
  8. Healthcare interaction effect: (0.65 - 0.75) × (8% - 6%) = -0.10 × 2% = -0.20% (underweight but outperformed — interaction is negative).
  9. Totals: Allocation = 0.45 + 0.15 = 0.60%. Selection = 0.75 + 1.50 = 2.25%. Interaction = 0.30 + (-0.20) = 0.10%. Sum = 0.60 + 2.25 + 0.10 = 2.95% ✓.

Example 2: Factor-based attribution

Given: A fund has factor loadings: β_mkt = 1.1, β_smb = 0.3, β_hml = -0.2. During the period: MKT = 5%, SMB = 2%, HML = -1%. Risk-free rate = 1%. Fund excess return = 7%.

Calculate: Factor contributions and alpha.

Solution:

  1. Market contribution: 1.1 × 5% = 5.50%.
  2. Size (SMB) contribution: 0.3 × 2% = 0.60%.
  3. Value (HML) contribution: -0.2 × (-1%) = +0.20%.
  4. Total factor-explained return: 5.50 + 0.60 + 0.20 = 6.30%.
  5. Alpha (residual): 7.00% - 6.30% = +0.70%.
  6. Interpretation: The fund's excess return of 7% is mostly explained by above-market beta (5.5%) and a small-cap tilt (0.6%). The negative value loading helped (+0.2%) as value underperformed. After accounting for all factors, the manager generated 0.70% of true alpha.

Common Pitfalls

Cross-References

Running the script

Run with uv run scripts/performance_attribution.py (the PEP 723 header resolves numpy automatically) or with python3 scripts/performance_attribution.py after pip install numpy scipy. A bare run prints three demos: the Brinson-Fachler attribution from Worked Example 1, an OLS factor attribution on seeded synthetic data, and Carino multi-period linking. Use --verify to assert outputs match this skill's worked example numbers (exit code 0 on PASS) and --help for an overview of the classes. The file is primarily meant to be imported as a module (e.g., from performance_attribution import BrinsonFachler).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.