PyPortfolioOpt
by Robert Andrew Martin and contributors · Library · also known as pypfopt
Python library for portfolio optimization: efficient frontier, Black-Litterman, hierarchical risk parity and discrete allocation
Overview
PyPortfolioOpt is an open-source Python library for portfolio optimization created by Robert Andrew Martin and now maintained under the PyPortfolio organisation. It implements the classical mean-variance efficient frontier with pluggable expected-return and risk-model estimators (sample, exponentially weighted, shrinkage), Black-Litterman views blending, CVaR and semivariance objectives, hierarchical risk parity, and a discrete allocation step that converts weights into whole-share positions for a given budget. Optimization is expressed through cvxpy, so custom constraints and objectives can be added. It suits analysts and students who want transparent allocation code on top of pandas price data. It is not a backtester or data source, assumes inputs are already clean, and large universes or complex constraints can hit solver limits.
Capabilities
- Mean-variance optimization with custom constraints via cvxpy
- Return and risk estimators including shrinkage covariance
- Black-Litterman model with investor views
- Hierarchical risk parity and CVaR/semivariance objectives
- Discrete allocation to whole shares
Typical workflows
- Estimate returns and covariance from prices, optimize for maximum Sharpe, then allocate a budget
- Blend market-implied returns with analyst views via Black-Litterman
Strengths
- Readable API suited to teaching
- MIT license
- Extensible objectives and constraints
Limitations
- No backtesting or data retrieval
- Solver performance degrades with large universes or many constraints
Prerequisites
- Python with pandas, NumPy, SciPy and cvxpy
Who it is for
- Finance students
- Analysts prototyping allocation models
Alternatives & comparison
Riskfolio-Lib covers a wider set of risk measures and optimization models and leans on the same cvxpy stack; PyPortfolioOpt is smaller and simpler to read. QuantLib addresses instrument pricing rather than allocation.
- Ghostfolio
Open-source wealth-tracking web app for stocks, ETFs, crypto and other assets, self-hostable with Docker or used as a hosted service
Open sourceOpen source - QuantLib
Open-source C++ library for quantitative finance covering instruments, term structures, pricing engines and calendars, with Python and other bindings
Open sourceOpen source - Riskfolio-Lib
Python library for quantitative portfolio optimization with many risk measures, robust estimators and hierarchical clustering models
Open sourceOpen source - SciPy
Core open-source Python library for scientific computing on NumPy arrays: optimization, integration, interpolation, linear algebra, sparse matrices, statistics, signal processing
Open sourceFree
Sources & verification
Primary sources consulted for this record. Claims are tied to the fields each source supports; the automated link checker re-verifies every URL on a schedule.
- Licensechecked Nov 1, 2026
- Official sitePyPortfolioOpt documentationchecked Nov 1, 2026
https://pyportfolioopt.readthedocs.io/en/latest
Supports: name, summary, capabilities
- RepositoryPyPortfolio/PyPortfolioOptchecked Nov 1, 2026
https://github.com/PyPortfolio/PyPortfolioOpt
Supports: product_status, languages
- Confidence
- High
- Reviewed
- Nov 1, 2026
- Links
- Verified · Nov 2, 2026
Spotted an error?
More in Portfolio & wealth management
Ghostfolio
Ghostfolio · Portfolio & wealth management
Open-source wealth-tracking web app for stocks, ETFs, crypto and other assets, self-hostable with Docker or used as a hosted service