Markets and trading · Edition No. 51 · 15 Oct 2026

PyPortfolio/PyPortfolioOpt

Works out how to split a sum of money across a set of holdings, then converts the percentages into whole share counts.

← Markets and tradingRead the whole edition →
PyPortfolioOpt: how much of each holding. Works out how to split money across holdings.

6,098 stars · MIT, from the repository sidebar · 1.6.0 (2026-02-26), settled on pypi.org/project/pyportfolioopt/ because the repository shows no GitHub releases; ungh pushedAt 2026-07-07T21:18:14Z · Track this in Scout

Works out how to split a sum of money across a set of holdings, then converts the percentages into whole share counts.

▶Repo detailsthe review · specs · pros & cons · install

What it does

It is built in four parts you combine. First an estimate of expected returns, from plain historical averages, an exponentially weighted average that favours recent data, or the capital asset pricing model. Second a risk model, which is a covariance matrix, with several shrinkage methods that reduce the error in that estimate. Third an objective, such as the highest Sharpe ratio, the lowest volatility, or a target return at the lowest risk. Fourth the optimiser, which is handled by cvxpy. After that a discrete allocation step converts the percentages into whole numbers of shares for a given amount of money, which is the step most examples leave out. It also implements Black-Litterman, which lets you blend your own opinions into the estimate, plus mean-semivariance, mean-CVaR and hierarchical risk parity. Constraints cover long-only, long and short, market neutrality, position limits and a penalty that stops the answer piling everything into two names. The newest release is 1.6.0, from 26 February 2026, and code landed on 7 July 2026. What it does not do is fetch any data or place any orders. Prices go in as a pandas table that you supply, and weights come out.

Why it matters

Who it suits. Anyone sizing more than one position who is currently doing it by feel. It suits a person who already has price history in a spreadsheet or a database and wants the next step done correctly rather than approximately. Skip it if you hold one thing, because there is nothing to divide. Skip it as well if you cannot write a few lines of Python, because there is no interface of any kind.

Verdict. Worth an afternoon, and the README is more honest than most financial software. It states that returns are notoriously hard to forecast, that sample covariance carries high estimation error, and that portfolios with many zero weights tend to do badly afterwards. Treat those sentences as the documentation rather than as modesty: they tell you to use the shrinkage methods and the regularisation penalty rather than the plain defaults. Two practical notes. Market neutrality is only available for two of the objectives, because the others are not leverage-invariant. And the project says its tests do not cover every combination of objective and parameter, so check an unusual combination against a hand calculation before trusting it. dcajasn/Riskfolio-Lib at 4,400 stars carries a far larger library of risk measures and is the one to reach for when variance is not the risk you care about; Edition 18 covered it. skfolio/skfolio at 2,100 stars writes the same ideas as scikit-learn estimators with proper cross-validation built in, which is the better shape if you want to test whether a method works before using it; Edition 33 covered it.

Stars6,098
LicenceMIT, from the repository sidebar
Latest1.6.0 (2026-02-26), settled on pypi.org/project/pyportfolioopt/ because the repository shows no GitHub releases; ungh pushedAt 2026-07-07T21:18:14Z
Good
  • The discrete allocation step turns percentages into whole shares for a real amount of money.
  • Several covariance shrinkage methods, which is the part that stops the answer being nonsense.
  • Black-Litterman lets your own view enter the calculation instead of being applied afterwards by hand.
Watch for
  • No data fetching and no order placing, so it sits in the middle of a pipeline somebody has to build.
  • Market neutrality works with only two of the objectives, which is easy to miss in the documentation.
  • The project states its tests do not cover every combination of objective and parameter.
Similar repositories
Install
pip install pyportfolioopt
Screenshots
PyPortfolio/PyPortfolioOpt: GitHub preview cardPyPortfolio/PyPortfolioOpt: Screenshot 1PyPortfolio/PyPortfolioOpt: Screenshot 2PyPortfolio/PyPortfolioOpt: Screenshot 3

Get the next edition in your inbox

A dozen repositories, opened and checked. The licence read, the last release dated, and the ones that did not make it named with the reason. It is the half most lists leave out.

No tracking pixels. One click to leave. The archive stays free either way.

We use your address to send the edition and nothing else. Confirm by email, leave in one click. How we handle it.