TradeBot Check
Trading involves a risk of losing money. Nothing on this site is financial advice and past results do not guarantee future results. Risk disclosure
Backtesting

PyPortfolioOpt

Python library for portfolio optimization, with mean-variance, Black-Litterman and Hierarchical Risk Parity methods, several risk models and discrete allocation into whole shares.

robertmartin8/PyPortfolioOpt★ 6,203 stars last commit 2026-07-07
Our take

Turn a list of assets into a clear set of portfolio weights, with sensible risk models and whole-share quantities, in a few lines of Python.

Who it is for

Investors, analysts and bot builders who want to test how to split capital between assets and rebalance with clear risk rules.

Strengths

  • Objectives include maximum Sharpe ratio, minimum volatility, efficient return, efficient risk and maximum quadratic utility.
  • Risk models include sample, semicovariance, exponential and shrinkage covariance (Ledoit-Wolf, Oracle Approximating Shrinkage).
  • Adds Black-Litterman allocation, Hierarchical Risk Parity, mean-CVaR, mean-semivariance and the critical line algorithm.
  • Supports weight bounds, long/short portfolios and discrete allocation that converts weights into whole-share quantities.

Good to know

  • Not a backtesting engine or broker connector: you bring your own price data and execution.
  • Estimates from historical returns and covariance carry estimation risk, and the author notes mean-variance results can have many zero weights.
  • Market-neutral portfolios are not available for the maximum Sharpe or minimum volatility objectives.
  • Needs Python knowledge; the README says tests do not cover every combination of objectives and parameters.

Custom bots are coming soon
We are preparing a service to build bots on tools like this one. Follow our Telegram channel to know when it opens.

Notify me

Real-life uses

Rebalance suggestions for a small portfolio

Feed a few years of prices for your watchlist into a short Python script, compare minimum-volatility and Hierarchical Risk Parity weights, and get whole-share quantities to review by hand. Illustrative only, never a promise of returns.

⚖️ Suggested weights ready: min-volatility vs HRP, 5 assets, 2 trades to review (example figures).

Compare it with others

Guides that use it

Quick answers

How much does PyPortfolioOpt cost?

Free and open source (MIT). Install with pip; market data comes from whichever source you choose, so check the official website of that provider for costs. Prices change, so check the official website before you decide.

Is PyPortfolioOpt open source?

Yes. License: MIT.

Who is PyPortfolioOpt for?

Investors, analysts and bot builders who want to test how to split capital between assets and rebalance with clear risk rules.

What is PyPortfolioOpt written in?

PyPortfolioOpt is written in Python.

What should I know before using PyPortfolioOpt?

Not a backtesting engine or broker connector: you bring your own price data and execution. Estimates from historical returns and covariance carry estimation risk, and the author notes mean-variance results can have many zero weights. Market-neutral portfolios are not available for the maximum Sharpe or minimum volatility objectives. Needs Python knowledge; the README says tests do not cover every combination of objectives and parameters.

Want a bot like this when custom bots open? Get notified · All comparisons · Guides

Sources

Every fact on this page comes from these sources, checked on 2026-11-18. If something has changed, the source wins.

  1. https://raw.githubusercontent.com/robertmartin8/PyPortfolioOpt/master/README.md: features, objective functions, risk models, constraints, Black-Litterman, HRP, pip install, MIT licence, not investment advice, estimation-risk notes
  2. https://api.github.com/repos/robertmartin8/PyPortfolioOpt: MIT, about 6,100 stars, last push 2026-07-07, not archived

Alternatives in Backtesting