Portfolio return attribution in Python: Brinson-Hood-Beebower, Brinson-Fachler, and multi-period linking.
Project description
pybrinson
Portfolio return attribution in Python — with sources you can audit.
pybrinson decomposes a portfolio's excess return versus a benchmark into
allocation, selection, and interaction effects, across any
user-defined classification (sector, country, asset class). Every formula
ships with its mathematical statement, an academic citation, and a
clickable URL — readers can verify the math without leaving the file.
It targets the gap left by the existing Python finance stack: R has the
pa package on CRAN and MATLAB ships brinsonAttribution, but no
maintained PyPI package implements the Brinson family of models.
Status
v1.2 — adds Menchero (2000, 2004) optimised multi-period linking (patent US 7,249,082 B2 expired 2024-02-18), second-source literature fixtures from Frongello (2002), and a ppar cross-validation script for the Cariño coefficient. Also fixes the v1.1 Frongello implementation to match the published convention (prefix portfolio × suffix benchmark, per the recursion on pp. 4-5 of Frongello 2002).
Methods supported
| Method | Reference | |
|---|---|---|
| Single-period | Brinson-Hood-Beebower (3-effect) | Brinson, Hood & Beebower (1986) |
| Single-period | Brinson-Fachler (3-effect) | Brinson & Fachler (1985) |
| Single-period | Multi-level hierarchical roll-up (any depth) | Bacon (2008), chap. 5 |
| Multi-period linking | Cariño log-smoothing | Cariño (1999) |
| Multi-period linking | GRAP factors | GRAP (1997) |
| Multi-period linking | Frongello recursive | Frongello (2002) |
| Multi-period linking | Menchero optimised | Menchero (2000, 2004) |
| Multi-period linking | Geometric (Bacon) | Bacon (2008), chap. 6 |
Deferred to v1.3+: currency attribution (Karnosky-Singer),
pandas / polars adapters, fixed-income (Campisi) attribution.
See docs/implementation-v1.3.md.
Install
pip install pybrinson
pybrinson has zero runtime dependencies — just the Python standard
library. Requires Python 3.14+.
Quickstart
from pybrinson import Segment, bhb
segments = [
Segment("UK Equity", portfolio_weight=0.40, benchmark_weight=0.40,
portfolio_return=0.20, benchmark_return=0.10),
Segment("Japan Equity", portfolio_weight=0.30, benchmark_weight=0.20,
portfolio_return=-0.05, benchmark_return=-0.04),
Segment("US Equity", portfolio_weight=0.30, benchmark_weight=0.40,
portfolio_return=0.06, benchmark_return=0.08),
]
result = bhb(segments, period="2024-Q1")
print(result)
BHB attribution — period 2024-Q1
R_p = 8.3000% R_b = 6.4000% excess = 1.9000%
Segment Allocation Selection Interaction Total
------------ ---------- --------- ----------- --------
UK Equity 0.0000% 4.0000% 0.0000% 4.0000%
Japan Equity -0.4000% -0.2000% -0.1000% -0.7000%
US Equity -0.8000% -0.8000% 0.2000% -1.4000%
Total -1.2000% 3.0000% 0.1000% 1.9000%
The identity allocation + selection + interaction == excess_return
holds within 1e-9 by construction; pybrinson raises
AttributionError rather than storing a silent residual when it fails.
Multi-period linking
from pybrinson import bhb, link_carino, Segment
period_attrs = [
bhb([Segment("Equities", 0.6, 0.5, 0.10, 0.05),
Segment("Bonds", 0.4, 0.5, 0.05, 0.10)], period="P1"),
bhb([Segment("Equities", 0.5, 0.5, 0.20, 0.10),
Segment("Bonds", 0.5, 0.5, 0.05, 0.10)], period="P2"),
]
print(link_carino(period_attrs))
See examples/ for runnable scripts covering BHB, Brinson-Fachler, and
Cariño / GRAP / Frongello / geometric linking.
Multi-level hierarchies (v1.1+)
Each Segment may declare an immediate parent label. For chains
deeper than one level, pass a parents={parent: grandparent} mapping
to bhb() / fachler():
from pybrinson import Segment, bhb
leaves = [
Segment("UK", 0.20, 0.25, 0.10, 0.08, parent="Europe"),
Segment("Germany", 0.25, 0.20, 0.05, 0.06, parent="Europe"),
Segment("US", 0.30, 0.35, 0.12, 0.10, parent="Americas"),
Segment("Brazil", 0.25, 0.20, -0.04, -0.02, parent="Americas"),
]
result = bhb(leaves, parents={"Europe": "Equity", "Americas": "Equity", "Equity": None})
Allocation, selection and interaction roll up additively at every level: each parent equals the sum of its descendants, and the root parent equals the period total.
Reusable cited fixtures (v1.1+)
from pybrinson import bhb
from pybrinson.fixtures import bacon_2008_ch5_bhb
segments, expected = bacon_2008_ch5_bhb()
result = bhb(segments)
assert abs(result.excess_return - expected["excess_return"]) < 1e-12
The same fixtures back the test suite — there is one source of truth.
Design principles
- Pure Python first. Zero runtime dependencies. Realistic attribution inputs are small (≤1k segments × ≤1k periods); a NumPy dependency would not pay for itself.
- Specification-driven, externally verified. Every function carries its formula, an academic citation, and a clickable URL. The math is cross-checked against published worked examples.
- No silent residuals. Identity failures raise. Bad inputs raise. pybrinson never imputes, rescales or swallows residuals.
- Typed and tested. Public API is fully type-annotated; ships
py.typed; tests cover both pinned worked examples and randomised identity checks.
Positioning vs ppar / fincore
ppar |
fincore |
pybrinson |
|
|---|---|---|---|
| BHB | no | yes | yes |
| Brinson-Fachler 3-effect | 2-effect only | no | yes |
| Cariño linking | yes | no | yes |
| GRAP linking | no | no | yes |
| Frongello linking | no | no | yes |
| Menchero linking | no | no | yes |
| Geometric linking | no | no | yes |
| Multi-level hierarchical roll-up | no | no | yes |
| Public fixture pack of cited examples | no | no | yes |
| Cross-method consistency suite | no | no | yes |
| Inline source citations | no | no | mandatory |
| Identity failure handling | n/a | silent residual | raises |
| Runtime dependencies | 9 | 2 | 0 |
See docs/implementation-v1.md for the audited findings against pinned
upstream commits.
Development
This project uses uv and targets Python 3.14.
uv sync # install deps, fetch Python 3.14 if needed
uv run pytest # full test suite
uv run pytest -k bhb # subset
uv build # sdist + wheel into dist/
References
Primary papers cited in the source:
- Brinson, G. P., Hood, L. R., & Beebower, G. L. (1986). "Determinants of Portfolio Performance." Financial Analysts Journal, 42(4). DOI
- Brinson, G. P., & Fachler, N. (1985). "Measuring Non-U.S. Equity Portfolio Performance." Journal of Portfolio Management, 11(3). DOI
- Cariño, D. R. (1999). "Combining Attribution Effects Over Time." Journal of Performance Measurement, 3(4).
- Groupe de Recherche en Attribution de Performance (1997). Synthèse des modèles d'attribution de performance.
- Frongello, A. (2002). "Linking Single Period Attribution Results." Journal of Performance Measurement, 6(3).
- Frongello, A. (2002). "Attribution Linking: Proofed and Clarified." Journal of Performance Measurement, 7(1). Author PDF
- Menchero, J. (2000). "An Optimized Approach to Linking Attribution Effects Over Time." Journal of Performance Measurement, 5(1).
- Menchero, J. (2004). "Multiperiod Arithmetic Attribution." Financial Analysts Journal, 60(4). DOI
- Bacon, C. R. (2008). Practical Portfolio Performance Measurement and Attribution, 2nd ed., Wiley. Wiley page
- Bacon, C. R. (2019). Performance Attribution: History and Progress. CFA Institute Research Foundation. Free PDF
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybrinson-1.2.0.tar.gz.
File metadata
- Download URL: pybrinson-1.2.0.tar.gz
- Upload date:
- Size: 44.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
635b8e99f27586d7855f30c27fe7fdfef7523de8a8f46d21581e3f0048101a20
|
|
| MD5 |
8c9194da045283b175b45ddc0be608cf
|
|
| BLAKE2b-256 |
6c0eedd99510a6ecb5b8d16265f5239c66cc66f34dcbfe0aad6c7edaad65ba48
|
Provenance
The following attestation bundles were made for pybrinson-1.2.0.tar.gz:
Publisher:
release.yml on gghez/pybrinson
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybrinson-1.2.0.tar.gz -
Subject digest:
635b8e99f27586d7855f30c27fe7fdfef7523de8a8f46d21581e3f0048101a20 - Sigstore transparency entry: 1280917447
- Sigstore integration time:
-
Permalink:
gghez/pybrinson@69aae4c91096b22b2d12b7302ec57f3e93faab32 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/gghez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@69aae4c91096b22b2d12b7302ec57f3e93faab32 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pybrinson-1.2.0-py3-none-any.whl.
File metadata
- Download URL: pybrinson-1.2.0-py3-none-any.whl
- Upload date:
- Size: 41.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3c7c716207742df35d2da5666f0d1c45d96b16597d754afc2e0ac8055af16e3
|
|
| MD5 |
4fde3f3375aeb0cd6c3a22f1fce6e47c
|
|
| BLAKE2b-256 |
cbb04f2728022cdd7a29541c58915415376b1cd31b326fb3c1cccb759fa2cb9a
|
Provenance
The following attestation bundles were made for pybrinson-1.2.0-py3-none-any.whl:
Publisher:
release.yml on gghez/pybrinson
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybrinson-1.2.0-py3-none-any.whl -
Subject digest:
a3c7c716207742df35d2da5666f0d1c45d96b16597d754afc2e0ac8055af16e3 - Sigstore transparency entry: 1280917455
- Sigstore integration time:
-
Permalink:
gghez/pybrinson@69aae4c91096b22b2d12b7302ec57f3e93faab32 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/gghez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@69aae4c91096b22b2d12b7302ec57f3e93faab32 -
Trigger Event:
push
-
Statement type: