Multi-period attribution linking for portfolio returns
Project description
attriblink
Multi-period attribution linking for portfolio returns.
Overview
Attribution linking is a technique used in investment performance analysis to decompose portfolio returns across multiple periods while preserving additivity. This package provides implementations of linking methods, starting with the Carino method.
Installation
pip install attriblink
Usage
import pandas as pd
from attriblink import link
# Quarterly portfolio and benchmark returns
portfolio_returns = pd.Series(
[0.025, 0.035, -0.012, 0.048],
index=pd.date_range("2025-01-01", periods=4, freq="ME")
)
benchmark_returns = pd.Series(
[0.018, 0.028, -0.015, 0.038],
index=portfolio_returns.index
)
# Attribution effects from Brinson-Fachler
effects = pd.DataFrame({
"allocation": [0.005, 0.006, 0.002, 0.008],
"selection": [0.003, 0.002, -0.001, 0.004],
"interaction": [0.001, 0.001, 0.000, 0.002]
}, index=portfolio_returns.index)
# Link effects using Carino method
result = link(effects, portfolio_returns, benchmark_returns)
# View results
print(result.summary())
# Access individual effects
print(f"Allocation: {result['allocation']:.4%}")
print(f"Selection: {result['selection']:.4%}")
# k-factor interpretation
print(f"k-factor: {result.k_factor:.4f}")
# k > 1: volatile excess returns, k < 1: consistent excess
Understanding the k-Factor
The k-factor is a smoothing coefficient that scales attribution effects to achieve geometric additivity:
- k = 1.0: No adjustment needed (arithmetic = geometric)
- k > 1: Volatile excess returns — effects scaled up
- k < 1: Consistent excess returns — effects scaled down
The sum of linked effects always equals the cumulative excess return.
API
link(effects, portfolio_returns, benchmark_returns, method='carino', check_effects_sum=True, strict=False)
Links attribution effects across multiple periods.
Parameters:
effects(pd.DataFrame): DataFrame where each column is an attribution effect (e.g., allocation, selection). Index must align with return series.portfolio_returns(pd.Series): Portfolio returns for each period.benchmark_returns(pd.Series): Benchmark returns for each period.method(str): Linking method to use. Currently only "carino" is supported.check_effects_sum(bool): If True, validates that period-by-period effects sum to period-by-period excess returns. Default is True.strict(bool): If True andcheck_effects_sumis True, raisesEffectsSumMismatchErrorwhen effects don't sum to excess. If False, issues a UserWarning but continues. Default is False.
Returns:
AttributionResult: An object containing linked effects and attribution data.
Raises:
AttributionError: If inputs are invalid or misaligned.EffectsSumMismatchError: If effects don't sum to excess return andstrict=True.
Validation Behavior:
By default, the function validates that each period's effects sum to that period's excess return (portfolio - benchmark). This helps catch attribution errors early. Use check_effects_sum=False to disable this check for legacy data or when using custom scaling.
Development
# Install dependencies (requires uv)
uv sync
# Activate the virtual environment
source .venv/bin/activate
# Run tests
uv run pytest
License
MIT License - see LICENSE file for details.
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 attriblink-0.1.1.tar.gz.
File metadata
- Download URL: attriblink-0.1.1.tar.gz
- Upload date:
- Size: 65.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6435cf8b7400da0ae42ed329e3d16eecfb3d16e0038e9a2b6897e39526082866
|
|
| MD5 |
ddb665122c597751dd163c5d261b5735
|
|
| BLAKE2b-256 |
b52d87e8e73261d9fff23e1b2d959b6e3b6edf01cd8508f8ad3a6faac05aeda6
|
File details
Details for the file attriblink-0.1.1-py3-none-any.whl.
File metadata
- Download URL: attriblink-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
817347d16f8953dd5baec8c0e46b3c4d5ebba5e0a0dcdc7465f6a8f5935c8ce7
|
|
| MD5 |
b33828c8fbbfd42337e9e2f417de7a2b
|
|
| BLAKE2b-256 |
98e2323b35dfbff093a43d983eb6feb68e25e66ac3f082806dac03f277bdaf04
|