performance-attribution
Performance-attribution decomposes portfolio excess returns into specific sources including sector allocation decisions, stock-selection skill, factor exposures, and market timing through Brinson-Fachler attribution models and factor decomposition frameworks. Use this skill to analyze why a trading strategy or portfolio outperformed or underperformed its benchmark, identifying whether gains came from overweighting outperforming sectors, picking better stocks within sectors, or capturing systematic factor premiums versus manager alpha.
git clone --depth 1 https://github.com/HKUDS/Vibe-Trading /tmp/performance-attribution && cp -r /tmp/performance-attribution/agent/src/skills/performance-attribution ~/.claude/skills/performance-attributionSKILL.md
# Performance Attribution Analysis
## Overview
Decompose portfolio excess returns into explainable sources: sector allocation, stock selection, factor exposure, timing contribution, and more. This helps explain **why** a strategy made or lost money, rather than only **how much** it made or lost.
## Brinson Attribution Model
### Single-Period Brinson-Fachler Model
```
Total excess return = portfolio return - benchmark return
Decomposed into three parts:
1. Allocation effect: sector-weight deviation × sector benchmark return deviation
2. Selection effect: stock selection within a sector × sector benchmark weight
3. Interaction effect: weight deviation × stock-selection deviation
```
**Mathematical formulas**:
```
Let w_p,i = portfolio weight of sector i
w_b,i = benchmark weight of sector i
r_p,i = portfolio return of sector i
r_b,i = benchmark return of sector i
R_b = total benchmark return
Allocation_i = (w_p,i - w_b,i) × (r_b,i - R_b)
Selection_i = w_b,i × (r_p,i - r_b,i)
Interaction_i = (w_p,i - w_b,i) × (r_p,i - r_b,i)
Total excess = Σ(Allocation_i) + Σ(Selection_i) + Σ(Interaction_i)
```
### Example Brinson Attribution
```markdown
### Brinson Sector Attribution
| Sector | Portfolio Weight | Benchmark Weight | Portfolio Return | Benchmark Return | Allocation | Selection | Interaction |
|------|---------|---------|---------|---------|---------|---------|---------|
| Food & Beverage | 20% | 10% | 15% | 8% | +0.3% | +0.7% | +0.7% |
| Electronics | 15% | 12% | 5% | 10% | -0.1% | -0.6% | +0.2% |
| Banks | 5% | 20% | 3% | 2% | +0.3% | +0.2% | -0.2% |
| Others | 60% | 58% | 8% | 7% | +0.0% | +0.6% | +0.0% |
| **Total** | 100% | 100% | 9.5% | 6.2% | **+0.5%** | **+0.9%** | **+0.7%** |
Excess return 3.3% = allocation effect 0.5% + selection effect 0.9% + interaction effect 0.7% + residual 0.2%
```
### Multi-Period Attribution (Linked Brinson)
```
Directly summing single-period attribution creates residuals (compounding effect). Common approaches:
Method 1: arithmetic linking (simple sum of each period's attribution)
- Advantage: simple
- Disadvantage: residual remains
Method 2: Carino logarithmic linking
- Advantage: no residual
- Disadvantage: more complex
Practical recommendation: arithmetic linking is enough for monthly attribution; residuals are usually <0.1%
```
## Factor Attribution
### Alpha-Beta Decomposition
```
R_p = α + β × R_m + ε
α (alpha): excess return, manager skill
β (beta): market exposure, systematic risk
ε (epsilon): residual, idiosyncratic risk
Regression method: OLS regression, with at least 60 data points
```
#### Multi-Factor Attribution (Fama-French Extension)
```
R_p - R_f = α + β_mkt × (R_m - R_f) + β_smb × SMB + β_hml × HML + β_mom × MOM + ε
| Factor | Meaning | China A-share Proxy |
|------|------|--------|
| MKT | Market | CSI 300 return |
| SMB | Small-cap premium | CSI 500 - CSI 300 |
| HML | Value premium | high-PB group - low-PB group |
| MOM | Momentum | top past-12M winners - bottom group |
```
#### Factor Exposure Analysis Template
```markdown
### Factor Exposure Analysis
| Factor | Beta | t-stat | Significance | Interpretation |
|------|------|---------|--------|------|
| Market (MKT) | 0.85 | 12.3 | *** | Below 1, defensive profile |
| Small-cap (SMB) | 0.25 | 3.2 | ** | Small-cap tilt |
| Value (HML) | -0.15 | -1.8 | * | Growth tilt |
| Momentum (MOM) | 0.30 | 4.1 | *** | Significant momentum exposure |
| **Alpha** | **0.8% / month** | **2.5** | ** | **Significant alpha** |
R² = 0.72 → factors explain 72% of return variation
Alpha = 0.8% / month = 10% / year, significant
```
## Market-Timing Evaluation
### Treynor-Mazuy Model
```
R_p - R_f = α + β × (R_m - R_f) + γ × (R_m - R_f)² + ε
γ > 0 and significant → timing ability exists (adds risk in bull markets, cuts risk in bear markets)
γ ≤ 0 → no timing ability
```
### Henriksson-Merton Model
```
R_p - R_f = α + β × (R_m - R_f) + γ × max(R_m - R_f, 0) + ε
γ > 0 → portfolio beta is higher in bull markets (successful timing)
```
### Practical Timing Metrics
| Metric | Calculation | Meaning |
|------|------|------|
| Bull capture ratio | portfolio return in bull markets / benchmark return | >100% = outperforming |
| Bear capture ratio | portfolio return in bear markets / benchmark return | <100% = better downside defense |
| Timing hit rate | proportion of months where market direction was called correctly | >55% = shows skill |
| Correlation between position changes and market | `corr(position_change, future_return)` | >0 = timing is correct |
## Benchmark Comparison Framework
### Benchmark Selection
| Strategy Type | Recommended Benchmark | China A-share Code |
|---------|---------|---------|
| China A-share large cap | CSI 300 | 000300.SH |
| China A-share small cap | CSI 500 / CSI 1000 | 000905.SH |
| China A-share broad market | CSI All Share | 000985.SH |
| Hong Kong equities | Hang Seng Index | HSI |
| US equities | S&P 500 | SPX |
| Crypto | BTC | BTC-USDT |
| Multi-asset | 60/40 portfolio | self-constructed |
### Risk-Adjusted Performance Metrics
| Metric | Formula | Excellent | Good | Average |
|------|------|------|------|------|
| Sharpe | `(R_p - R_f) / σ_p` | >1.5 | 1.0-1.5 | 0.5-1.0 |
| Sortino | `(R_p - R_f) / σ_down` | >2.0 | 1.5-2.0 | 1.0-1.5 |
| Calmar | `R_p / MaxDD` | >1.0 | 0.5-1.0 | 0.2-0.5 |
| Information Ratio | `(R_p - R_b) / TE` | >1.0 | 0.5-1.0 | 0.2-0.5 |
| Treynor | `(R_p - R_f) / β` | used comparatively | | |
### Rolling Analysis
```
Use rolling windows (such as 12 months) to analyze:
- Rolling Sharpe: strategy stability
- Rolling alpha: whether alpha persists
- Rolling beta: whether market exposure is stable
- Rolling information ratio: persistence of benchmark outperformance
Suggested windows: 252 days for daily data, 12-36 months for monthly data
```
## Analysis Framework
### Step 1: Aggregate Analysis
```
1. Cumulative return vs benchmark
2. Excess-return decomposition (annual / monthly)
3. SummaryProfessional finance research toolkit — backtesting (7 engines + benchmark comparison panel), factor analysis, Alpha Zoo (452 pre-built alphas across qlib158/alpha101/gtja191/academic), options pricing, 77 finance skills, 29 multi-agent swarm teams, Trade Journal analyzer, and Shadow Account (extract → backtest → render) across 7 data sources (tushare, yfinance, okx, akshare, mootdx, ccxt, futu).
ADR/H-share/A-share cross-listing premium analysis — track pricing gaps between US-listed ADRs, HK-listed H-shares, and A-shares for arbitrage signals, dual-listing valuation, and delisting risk assessment.
AKShare financial data aggregator (18k+ stars). Free, no API key. Covers A-shares, US, HK, futures, macro, forex. Primary fallback for tushare and yfinance.
Browse and bench the bundled alpha zoos — prebuilt cross-sectional factor libraries (Kakushadze 101, GTJA 191, Qlib 158, Fama-French / Carhart). Use when the user asks "which alphas exist", wants metadata on a named alpha, or wants to run IC/IR on a whole zoo over a universe.
A 股 ST/*ST 风险预测框架 — 基于最新中报/三季报或业绩预告/快报,预测下一财年是否会因营收、利润、净资产、分红不达标而被风险警示,并将新浪监管处罚记录作为独立证据面纳入风险等级。仅适用于 A 股,不预测财务造假。
Asset allocation theory and optimizer usage — MPT / Black-Litterman / risk budgeting / all-weather strategy, including guides for 4 optimizers and rebalancing rules.
Diagnose failed or underperforming backtests, locate the root cause, and fix the issue
Behavioral finance applications: theories of overreaction and underreaction, behavioral explanations for momentum and reversal, investor sentiment cycles, cognitive-bias checklists, and debiasing quantitative strategies.