--- id: pyportfolioopt version: "1.6.0" license: MIT License Copyright (c) 2018 Robert Andrew Martin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),… (full text in the JSON record) license_treatment: permissive maintenance: active --- # pyportfolioopt — Financial portfolio optimization in python License: permissive · Maintenance: active · Downloads: 195.2K/mo ## 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 above — verify before relying. PyPortfolioOpt implements portfolio optimization methods including mean-variance optimization, Black-Litterman allocation, and Hierarchical Risk Parity to compute optimal asset allocations based on expected returns and risk models. 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 pip install pyportfolioopt uv add pyportfolioopt poetry add pyportfolioopt ## Installing pyportfolioopt 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: MIT License Copyright (c) 2018 Robert Andrew Martin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),… (full text in the JSON record) (permissive) - Python support: unspecified - Install friction: low - Maintenance: active - Downloads: 195.2K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags portfolio optimization, mean-variance optimization, efficient frontier, asset allocation, Black-Litterman, Sharpe ratio optimization, risk-adjusted returns, portfolio weights, portfolio-optimization, quantitative-finance, convex-optimization [View on SkillFed](https://skillfed.io/packages/pyportfolioopt) · [View on PyPI](https://pypi.org/project/pyportfolioopt/)