pyportfolioopt
Financial portfolio optimization in python
Decision gist · record as of 2026-08-14
Yes. PyPortfolioOpt is actively maintained, has no known vulnerabilities, installs with low friction, and is licensed permissively under MIT. It provides a well-documented, scikit-learn-inspired interface to classical portfolio optimization methods suitable for both prototyping and production use. Install it if you need to compute optimal asset allocations from expected returns and risk estimates.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low install friction with a pure-Python wheel distribution.
- Active maintenance with a recent release in February 2026 and continuous commits; the repository has 5964 stars and is not archived.
License · maintenance · safety
permissive license (permissive) — MIT License permits free use, modification, and distribution with minimal restrictions, making it suitable for both commercial and open-source projects.
last release 2026-02-26 (169 days) · last repo commit 2026-07-07 · 5,964 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 195,241 downloads/mo, #9,819 on PyPI
Alternatives
Verify before relying
pip install pyportfolioopt
import pandas as pd
from pyportfolioopt import EfficientFrontier
from pyportfolioopt import risk_models, expected_returns
df = pd.read_csv("stock_prices.csv", parse_dates=True, index_col="date")
mu = expected_returns.mean_historical_return(df)
S = risk_models.sample_cov(df)
ef = EfficientFrontier(mu, S)
raw_weights = ef.max_sharpe()
print(ef.portfolio_performance(verbose=True))- Whether the package requires specific versions of cvxpy, numpy, pandas, scikit-learn, or scipy beyond what pip resolves automatically
- Performance characteristics when optimizing portfolios with hundreds or thousands of assets
- Whether all optimization methods (mean-variance, Black-Litterman, Hierarchical Risk Parity) are equally mature or if some are experimental
What it is and what it does
PyPortfolioOpt is a Python library for computing mathematically optimal portfolio allocations given historical asset prices or expected returns and risk estimates. It implements classical portfolio optimization methods rooted in Markowitz's efficient frontier theory, allowing investors to find allocations that maximize risk-adjusted returns such as Sharpe ratio or minimize portfolio volatility for a target return. The library depends on cvxpy for convex optimization, numpy and scipy for numerical computation, pandas for data handling, and scikit-learn and scikit-base for its extensible architecture.
The package is designed for both casual investors prototyping allocation strategies and professionals building quantitative trading systems. It handles the full workflow from computing expected returns and covariance matrices from historical data, through optimization with optional constraints, to converting continuous weights into discrete share counts for actual trading. The library is inspired by scikit-learn's design philosophy, emphasizing ease of use alongside extensibility for custom objective functions and risk models.
Use it for
- Compute optimal long-only portfolio weights that maximize Sharpe ratio given historical stock price data
- Convert theoretical portfolio weights into discrete share counts and dollar allocations for a fixed investment amount
- Implement Black-Litterman allocation to incorporate subjective market views alongside historical return estimates
- Optimize asset allocation subject to custom constraints such as sector limits or position size bounds
- Backtest multi-asset strategies by computing efficient frontiers and comparing risk-return tradeoffs
- Prototype quantitative trading strategies that combine multiple alpha sources into a single risk-efficient portfolio
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
PyPortfolioOpt is actively maintained, has no known vulnerabilities, installs with low friction, and is licensed permissively under MIT. It provides a well-documented, scikit-learn-inspired interface to classical portfolio optimization methods suitable for both prototyping and production use. Install it if you need to compute optimal asset allocations from expected returns and risk estimates.
Install
pyportfolioopt on PyPI
Before you install
Low install friction with a pure-Python wheel distribution. Active maintenance with a recent release in February 2026 and continuous commits; the repository has 5964 stars and is not archived.
License in practice
MIT License permits free use, modification, and distribution with minimal restrictions, making it suitable for both commercial and open-source projects.
Quickstart
pip install pyportfolioopt
import pandas as pd
from pyportfolioopt import EfficientFrontier
from pyportfolioopt import risk_models, expected_returns
df = pd.read_csv("stock_prices.csv", parse_dates=True, index_col="date")
mu = expected_returns.mean_historical_return(df)
S = risk_models.sample_cov(df)
ef = EfficientFrontier(mu, S)
raw_weights = ef.max_sharpe()
print(ef.portfolio_performance(verbose=True))
Verify before relying
- Whether the package requires specific versions of cvxpy, numpy, pandas, scikit-learn, or scipy beyond what pip resolves automatically
- Performance characteristics when optimizing portfolios with hundreds or thousands of assets
- Whether all optimization methods (mean-variance, Black-Litterman, Hierarchical Risk Parity) are equally mature or if some are experimental
Package facts
| License | permissive license permissive |
| Python support | Not specified |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 6 packagescvxpynumpypandasscikit-basescikit-learnscipy |
| Maintenance | Actively maintained 169 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 195,241 / month, #9,819 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: Financial and Insurance IndustryIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyProgramming 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 :: Investment |
Evidence: pyportfolioopt-1.6.0-py3-none-any.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”
- pyportfoliooptPyPortfolioOpt implements portfolio optimization methods including…
- skfolioskfolio is a Python library for portfolio optimization and risk…
- riskfolio-libRiskfolio-Lib builds optimized investment portfolios using…
Give your agent the search over MCP, or paste the wish link into any chat.
More Financial packages
statsmodels provides statistical models, inference methods, and descriptive statistics for Python, complementing scipy with regression, time series, discrete choice, survival analysis, and multivariate methods.
Install it if you need publication-quality statistical models, hypothesis tests, or time series analysis beyond what scipy or pandas provide.
Generates country- and subdivision-specific government holiday calendars on demand, supporting 250 country codes with optional language localization and holiday categories.
Fetches financial and market data from Yahoo Finance's public APIs, including ticker information, historical prices, and live streaming data.
However, do not use it for commercial applications or high-volume data collection without confirming compliance with Yahoo's terms of service.
Bokeh is an interactive visualization library that creates browser-based plots, dashboards, and data applications from Python code, with support for large and streaming datasets.
Install it if you need browser-based interactivity.
Parses, validates, and reformats standard numbers and codes across many countries and industries—tax IDs, bank accounts, identity numbers, VAT codes, and financial identifiers.
Install it if you validate or reformat standardized numbers.
Provides elementary financial functions (IRR, NPV, PMT, and others) that were deprecated and removed from NumPy, offering a dedicated replacement for financial calculations.
However, given the aging status (no releases since 2019) and unclear compatibility with modern Python and recent numpy versions, verify that it works with your target…
See also riskfolio-lib · skfolio · quantstats · py-vollib · py-lets-be-rational · vollib · empyrical-reloaded · backtesting · pyomo