Skip to main content

riskparity

Risk parity portfolio optimization via the improved CCD method of Choi & Chen (2022).

Choi, J., & Chen, R. (2022). Improved iterative methods for solving risk parity portfolio. Journal of Derivatives and Quantitative Studies, 30(2). https://doi.org/10.1108/JDQS-12-2021-0031

What is risk parity?

A risk parity (equal risk contribution) portfolio chooses weights w so that every asset contributes the same fraction of total portfolio volatility:

$$\frac{w_i (\mathbf{C}\mathbf{w})_i}{\mathbf{w}^\top \mathbf{C}\mathbf{w}} = b_i \quad \forall i$$

where C is the return covariance matrix and b is the risk-budget vector (defaults to 1/N for equal risk parity).

Algorithm

The improved CCD method (Algorithm 1 in the paper) works on the correlation matrix and adds a rescaling step after each sweep, making it ~3× faster than the original CCD method and saving ~40% of iterations.

Installation

pip install riskparity

Quick start

import numpy as np
from riskparity import risk_parity

# 3-asset covariance matrix
cov = np.array([
    [0.04,  0.01,  0.002],
    [0.01,  0.09,  0.015],
    [0.002, 0.015, 0.0025],
])

result = risk_parity(cov)
print(result.weights)            # portfolio weights, sum to 1
print(result.risk_contributions) # fractional risk contributions, sum to 1
print(result.iterations)         # number of CCD iterations
print(result.converged)          # True if tolerance was met

Custom risk budgets

b = np.array([0.5, 0.3, 0.2])   # 50 / 30 / 20 % risk allocation
result = risk_parity(cov, b=b)

Standalone risk contribution utility

from riskparity import risk_contributions
rc = risk_contributions(weights, cov)  # fractional RC for any portfolio

API reference

risk_parity(cov, b=None, tol=1e-6, max_iter=1000)

Parameter Type Description
cov (N, N) array Covariance matrix (positive semi-definite)
b (N,) array or None Risk budgets, must be positive and sum to 1. Default: 1/N
tol float Convergence tolerance (default 1e-6)
max_iter int Maximum iterations (default 1000)

Returns a RiskParityResult dataclass:

Field Type Description
weights (N,) array Portfolio weights, sum to 1
risk_contributions (N,) array Fractional risk contributions, sum to 1
iterations int Outer iterations used
converged bool Whether tolerance was met

risk_contributions(weights, cov)

Compute fractional risk contributions for any portfolio.

License

MIT

Release files for mafn-pypackagetest 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mafn-pypackagetest 0.1.0
File Size Uploaded
mafn_pypackagetest-0.1.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mafn-pypackagetest 0.1.0
File Interpreter ABI Platform
mafn_pypackagetest-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / mafn_pypackagetest-0.1.0.tar.gz

Download URL mafn_pypackagetest-0.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
311e9f46097d6f9bb60425cabdad45b7264588fcff876d1bca6abbb2a0b87288
BLAKE2b-256 checksum
How to use checksums
7b6463bef3178b99fdf52b93e2dfbe6f193f43e70cf9f556e67fd2c9405fa736
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 23, 2026.

Transparency log

Release files / mafn_pypackagetest-0.1.0-py3-none-any.whl

Download URL mafn_pypackagetest-0.1.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a05c6dad376d13cc9ab7eca3b2e90a081cfa61da948e99abc6c0144e3c7119d9
BLAKE2b-256 checksum
How to use checksums
e1a3c95197b84f881d085cc1449c7b8c7967015422d77411a8735dcccbb58989
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 23, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page