riskfolio-lib
Portfolio Optimization in Python
What it is and what it does
Riskfolio-Lib is a portfolio optimization library built on CVXPY that lets you construct investment portfolios using mathematically rigorous models without deep solver expertise. It integrates directly with Pandas DataFrames and supports a large range of optimization objectives (minimum risk, maximum return, maximum Sharpe ratio, risk parity) combined with 26+ risk measures spanning dispersion, downside, and drawdown categories. You can apply constraints on leverage, turnover, cardinality, tracking error, and graph-based relationships between assets, and use advanced techniques like hierarchical risk parity, Black-Litterman views, risk factor models, and entropy pooling.
The library is designed for students, academics, and practitioners who need to move from theory to working portfolios quickly. It handles the convex optimization setup internally, letting you focus on portfolio design rather than solver configuration. It includes tools for building efficient frontiers, calculating risk contributions, estimating uncertainty sets, clustering assets by codependence, and generating reports in Jupyter or Excel. You can also plug in commercial solvers (MOSEK, GUROBI) for large-scale problems.
Use it for:
- Build mean-variance efficient frontiers and find optimal allocations for a given risk tolerance or return target.
- Construct risk parity or equal-weight portfolios with constraints on maximum position size, leverage, or sector concentration.
- Incorporate expert views or market factors into portfolio construction using Black-Litterman or risk factor models.
- Optimize hierarchical or nested clustered portfolios to reduce estimation error and improve out-of-sample stability.
- Backtest portfolio rebalancing strategies with turnover and cardinality constraints to manage transaction costs.
- Calculate and visualize risk contributions per asset or risk factor to understand portfolio exposure.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Riskfolio-Lib builds optimized investment portfolios using mathematical models—mean-variance, risk parity, hierarchical clustering, and Black-Litterman approaches—with support for 26+ risk measures and constraints on leverage, turnover, and cardinality.
Yes, if you need to solve real portfolio optimization problems beyond simple equal-weight or market-cap allocation. The library is actively maintained, has no known vulnerabilities, runs on modern Python versions, and offers a mature API covering academic and practitioner use cases. Install friction is moderate due to numerical dependencies, but prebuilt wheels are available. The permissive BSD license poses no compliance risk. Start with the tutorial if you are new to portfolio optimization.
Install
riskfolio-lib on PyPI
pip
pip install riskfolio-libuv
uv add riskfolio-libpoetry
poetry add riskfolio-libInstalling riskfolio-lib
Before you install
Medium install friction: 15 runtime dependencies including numerical (numpy, scipy, pandas), optimization (cvxpy, clarabel, SCS), and statistical libraries (scikit-learn, statsmodels, arch). Prebuilt wheels available for Python 3.10–3.14 on macOS, Linux, and Windows. Active maintenance with recent releases.
License in practice
BSD 3-clause permissive license allows commercial use, modification, and redistribution with minimal restrictions—suitable for both proprietary and open-source projects.
Quickstart
import pandas as pd
import riskfolio as rp
returns = pd.read_csv('returns.csv', index_col=0)
port = rp.Portfolio(returns=returns)
port.optimize('MinRisk')
weights = port.weights
Requires Python >=3.10; cvxpy and its solver dependencies (clarabel or SCS) must resolve successfully; large-scale problems may benefit from commercial solvers (MOSEK, GUROBI) configured separately.
Verify before relying
- Performance characteristics and scalability limits for portfolio sizes beyond typical institutional use.
- Solver selection guidance and trade-offs between clarabel, SCS, and commercial alternatives for specific problem classes.
- Numerical stability and convergence guarantees under extreme market conditions or edge-case covariance matrices.
Package facts
| License | BSD (3-clause) (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 15 — numpy, scipy, pandas, matplotlib, clarabel, SCS, cvxpy, scikit-learn, statsmodels, arch, xlsxwriter, networkx, astropy, pybind11, vectorbt |
| Maintenance | actively maintained — 75 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 104,228/month — #12,760 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: riskfolio_lib-7.3.0-cp310-cp310-macosx_10_9_universal2.whl; riskfolio_lib-7.3.0-cp310-cp310-macosx_10_9_x86_64.whl; riskfolio_lib-7.3.0-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; riskfolio_lib-7.3.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; riskfolio_lib-7.3.0-cp310-cp310-win_amd64.whl; riskfolio_lib-7.3.0-cp311-cp311-macosx_10_9_universal2.whl; riskfolio_lib-7.3.0-cp311-cp311-macosx_10_9_x86_64.whl; riskfolio_lib-7.3.0-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; riskfolio_lib-7.3.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; riskfolio_lib-7.3.0-cp311-cp311-win_amd64.whl; riskfolio_lib-7.3.0-cp312-cp312-macosx_10_13_universal2.whl; riskfolio_lib-7.3.0-cp312-cp312-macosx_10_13_x86_64.whl; riskfolio_lib-7.3.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; riskfolio_lib-7.3.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; riskfolio_lib-7.3.0-cp312-cp312-win_amd64.whl; riskfolio_lib-7.3.0-cp313-cp313-macosx_10_13_universal2.whl; riskfolio_lib-7.3.0-cp313-cp313-macosx_10_13_x86_64.whl; riskfolio_lib-7.3.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; riskfolio_lib-7.3.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; riskfolio_lib-7.3.0-cp313-cp313-win_amd64.whl
Keywords: finance, portfolio, optimization, quant, asset allocation, investing
Tags
More Mathematics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
sympySymPy is a Python library for symbolic…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnxruntimeonnxruntime loads and executes Open Neural…
permissive · top 1,000 on PyPI
pyportfoliooptPyPortfolioOpt implements portfolio…
permissive · top 15,000 on PyPI
skfolioskfolio is a Python library for portfolio…
permissive · top 15,000 on PyPI
empyrical-reloadedComputes financial return and risk…
permissive · top 15,000 on PyPI
quantstatsQuantStats computes portfolio performance…
permissive · top 15,000 on PyPI
QuantLibQuantLib provides Python bindings to a C++…
permissive · top 5,000 on PyPI
cvxpyCVXPY is a Python modeling language for…
permissive · top 5,000 on PyPI
numpy-financialProvides elementary financial functions (IRR,…
permissive · top 5,000 on PyPI
PuLPPuLP is a linear and mixed-integer programming…
permissive · top 5,000 on PyPI
optlangOptlang formulates and solves linear,…
permissive · top 15,000 on PyPI
vectorbtVectorized backtesting engine that packs…
unclear · top 15,000 on PyPI