riskfolio-lib
Portfolio Optimization in Python
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- 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.
- 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.
License · maintenance · safety
BSD (3-clause) (permissive) — BSD 3-clause permissive license allows commercial use, modification, and redistribution with minimal restrictions—suitable for both proprietary and open-source projects.
last release 2026-05-31 (75 days) · last repo commit 2026-06-22 · 4,441 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 104,228 downloads/mo, #12,760 on PyPI
Alternatives
Verify before relying
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- 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.
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 on it.
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
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.
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.
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
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 packagesnumpyscipypandasmatplotlibclarabelSCScvxpyscikit-learnstatsmodelsarchxlsxwriternetworkxastropypybind11vectorbt |
| 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 |
| Classifiers | Intended Audience :: Financial and Insurance IndustryIntended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: MacOSOperating System :: MicrosoftOperating System :: UnixProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Office/Business :: FinancialTopic :: Office/Business :: Financial :: InvestmentTopic :: Scientific/Engineering :: Mathematics |
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
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “mean variance optimization”
- riskfolio-libRiskfolio-Lib builds optimized investment portfolios using…
- statisticsProvides basic mathematical statistics functions (mean, median, mode,…
- runstatsComputes summary statistics (mean, variance, standard deviation,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Mathematics packages
NetworkX provides data structures and algorithms for creating, analyzing, and manipulating graphs and networks, supporting everything from simple undirected graphs to complex directed and weighted networks.
kiwisolver is a Python binding to a fast C++ implementation of the Cassowary constraint solver, enabling you to solve systems of linear constraints and inequalities.
Install it if you need to solve constraint systems; skip it if you only need simple linear algebra.
SymPy is a Python library for symbolic mathematics, performing algebraic manipulation, calculus, equation solving, and mathematical expression simplification without numerical approximation.
ContourPy calculates contours of 2D quadrilateral grids using C++11 algorithms wrapped in Python, offering serial and multithreaded implementations without requiring Matplotlib as a dependency.
PyTorch provides GPU-accelerated tensor computation and automatic differentiation for building and training deep neural networks in Python.
onnxruntime loads and executes Open Neural Network Exchange (ONNX) models with a focus on inference performance across CPUs and accelerators.
Install it if you have ONNX models to run in production or development.
See also pyportfolioopt · skfolio · empyrical-reloaded · quantstats · QuantLib · cvxpy · numpy-financial · PuLP · optlang · vectorbt