PyPortfolioOpt: Portfolio Optimisation in Python
Citation. Robert Andrew Martin (University of Cambridge). "PyPortfolioOpt: portfolio optimization in Python". Journal of Open Source Software 6(61), 3066, 2021. DOI 10.21105/joss.03066. The software is PyPortfolio/PyPortfolioOpt, formerly robertmartin8/PyPortfolioOpt, version 1.6.0 of 26 February 2026, under MIT. Its last push was on 7 July 2026.
Status. Not applicable. It optimises a portfolio from estimates, but it doesn't test the result out of sample. Its performance figures are in-sample point estimates with no error. Its cost model is a flat rate on turnover. The project needs its own splitters and errors in any case, and skfolio (skfolio.md, #259) covers more for the same dependencies. Don't depend on either for now. The one idea worth keeping is whole-share allocation for paper trading.
Read. Read on 2026-11-28. I read the JOSS paper in outline, from the PDF. Through the GitHub API at tag v1.6.0, I read semicovariance in pypfopt/risk_models.py, transaction_cost in pypfopt/objective_functions.py, portfolio_performance in pypfopt/base_optimizer.py, the method list of pypfopt/discrete_allocation.py, and pyproject.toml. I didn't read the cookbook or run it.
Summary
Claim. "Many portfolio optimization tasks can be framed as convex optimization problems". PyPortfolioOpt lets users solve them without writing them in cvxpy's terms. The paper says the package "has been downloaded over 160,000 times".
What the code does.
- Semicovariance.
drops = np.fmin(returns - benchmark, 0), thendrops.T @ drops / T * frequency. The default benchmark is "the daily risk-free rate",1.02^(1/252) − 1, a rate of 2% a year. - Transaction costs.
transaction_cost(w, w_prev, k=0.001)addsk * ‖w − w_prev‖₁to the objective: "a very simple transaction cost model", "a fixed percentage commission from your broker". - Performance.
portfolio_performance(weights, expected_returns, cov_matrix, risk_free_rate=0.0)returns the "expected return, volatility, Sharpe ratio" of the weights, computed from the same estimates that chose them. - Discrete allocation.
greedy_portfolioandlp_portfolio. The second uses "integer programming", and needs "the CVXPY solver to use (must support mixed-integer programs)". - Dependencies. cvxpy, NumPy, pandas, scikit-base, scikit-learn and SciPy.
Findings. It is a library, with no study.
Where the claims go beyond the evidence
Its performance is in sample. portfolio_performance scores the weights on the expected returns and covariance that chose them. A maximum-Sharpe portfolio then shows the highest Sharpe ratio by construction. That number says nothing about how it will do next. It has no error either.
Maximising the Sharpe ratio maximises estimation error. With historical means as expected returns, the optimiser puts most weight where the mean was overestimated. DeMiguel et al. found that 1/N beats most optimisers out of sample (optimal-versus-naive-diversification.md).
The cost model is flat. A fixed 10 basis points of turnover ignores the spread, which varies by asset and by month, and the price impact of size. The project's cost model charges both legs of each trade by venue and size (open_familyoffice/costs.py, #9).
No splitters. Like most optimisers, it fits once. Any backtest of its portfolios has to come from the user's own walk-forward.
Credit. The code names its simplifications plainly, as "a very simple transaction cost model". Its semicovariance divides by all T periods, which is the right lower partial moment. It offers integer allocation, which few libraries do.
Use in this repo
Against skfolio.
| PyPortfolioOpt 1.6.0 | skfolio 1.15.2 (skfolio.md) |
|
|---|---|---|
| Optimisers | mean–variance, CLA, Black–Litterman, HRP, semivariance, CVaR and CDaR | mean–risk with many risk measures, such as semi-variance, CVaR and CDaR. skfolio.md doesn't list the rest |
| Model selection | none | walk-forward, combinatorial purged CV, randomised CV |
| Performance | in-sample point estimates | out-of-sample paths |
| Costs | one flat rate on turnover | a linear cost per asset on turnover, plus fees |
| Whole shares | greedy and integer programming | not read |
| Dependencies | cvxpy, NumPy, pandas, scikit-base, scikit-learn, SciPy | cvxpy, Clarabel, scikit-learn, Plotly and others |
| Last activity | push of 7 July 2026 | release of 27 November 2026 |
The recommendation: neither, for now. The project already has its splitters (splits.py, #10), its errors (#8) and its cost model (#9). Both libraries would add cvxpy. If a portfolio optimiser is ever needed, skfolio is the better match, because it tests out of sample. That matches option 1 of skfolio.md.
The downside matches, but the target doesn't. PyPortfolioOpt's semicovariance and the project's metrics.sortino both divide the squared shortfalls by all n periods. But its default target is 2% a year, and the project's is 0. A comparison between them must set the same target, and store it with the result.
Whole shares matter for small accounts. Rounding target weights to whole shares changes both the weights and the costs. For paper trading with small capital, the harness could record the shares actually held as well as the target weights. The difference is a cost of size that a backtest in weights doesn't see (#30).
Every optimiser setting is a trial. The estimator of returns, the risk model, the shrinkage target, the objective and the constraints are each a choice (#7). HRP's linkage and Black–Litterman's views and confidences are more.