Registry / data / pyportfolioopt

pyportfolioopt

JSON →
library1.6.0pypypiunverified

PyPortfolioOpt is a financial portfolio optimization library for Python, providing methods for mean-variance optimization, Black-Litterman allocation, and risk parity. Version 1.6.0 supports CVXPY-based solvers and offers both classical and objective-based optimization approaches. Release cadence is irregular, with contributions from the community.

pip install pyportfolioopt
INSTALL
IMPORT
SIG · PYPORTFOLIOOPT
P
pyportfolioopt
datapythonv1.6.0
Install
16.7s avg
Import
Disk
453MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 16.7s · import 0.000s · 397MB
453MB installed
● package 453MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EfficientFrontier
from pypfopt import EfficientFrontier
from pypfopt import EfficientFrontier

Basic mean-variance optimization using historical returns and sample covariance.

import pandas as pd from pypfopt import EfficientFrontier, risk_models, expected_returns # Sample data: prices of 3 assets data = pd.DataFrame({ 'AAPL': [1.0, 0.9, 0.8, 0.85], 'GOOG': [1.0, 1.1, 1.0, 1.05], 'MSFT': [1.0, 0.95, 1.1, 1.0] }) # Calculate expected returns and covariance matrix mu = expected_returns.mean_historical_return(data) Sigma = risk_models.sample_cov(data) # Optimize for maximum Sharpe ratio ef = EfficientFrontier(mu, Sigma) weights = ef.max_sharpe() print(ef.clean_weights())
Debug
Known issues
gotchaImport package as pypfopt, not pyportfolioopt. The pip install name and the import name differ.
fix
Use 'from pypfopt import ...' instead of 'from pyportfolioopt import ...'
affects: all
gotchaCVXPY may require a separate solver installation (e.g., 'pip install cvxpy') on some systems, especially for advanced solvers like ECOS or SCS.
fix
Install CVXPY with pip install cvxpy or use the bundled solver (may not work for large problems).
affects: all
breakingIn version 1.5+, the EfficientFrontier object no longer accepts a target return as a parameter to some methods; use objective functions instead.
fix
Use methods like `ef.efficient_return(target_return)` directly, not via a constructor parameter.
affects: >=1.5.0
deprecatedThe `pypfopt.plotting` module is deprecated as of version 1.6.0 and will be removed in a future release.
fix
Use matplotlib directly to plot efficient frontier or weights.
affects: >=1.6.0
Upgrade
Version history
1.6.0latest on PyPI · released Feb 26, 2026
Audit
Dependencies
cvxpyrequiredConvex optimization solver, required for optimization
numpyrequiredNumerical computations
pandasrequiredData handling and returns calculation
scipyoptionalScientific computing, used for some optimizers
Agent activity
4 hits · last 30 days
node
4
Resources
pyportfolioopt — pip install pyportfolioopt · libregistry