Tools · SPBoucher
Menu

PyPortfolioOpt

by Robert Andrew Martin and contributors · Library · also known as pypfopt

Python library for portfolio optimization: efficient frontier, Black-Litterman, hierarchical risk parity and discrete allocation

MIT licenseOpen sourceFreeLocalSelf-hostable
Visit official site Compare

Link verified Nov 2, 2026

Overview

PyPortfolioOpt is an open-source Python library for portfolio optimization created by Robert Andrew Martin and now maintained under the PyPortfolio organisation. It implements the classical mean-variance efficient frontier with pluggable expected-return and risk-model estimators (sample, exponentially weighted, shrinkage), Black-Litterman views blending, CVaR and semivariance objectives, hierarchical risk parity, and a discrete allocation step that converts weights into whole-share positions for a given budget. Optimization is expressed through cvxpy, so custom constraints and objectives can be added. It suits analysts and students who want transparent allocation code on top of pandas price data. It is not a backtester or data source, assumes inputs are already clean, and large universes or complex constraints can hit solver limits.

Capabilities

  • Mean-variance optimization with custom constraints via cvxpy
  • Return and risk estimators including shrinkage covariance
  • Black-Litterman model with investor views
  • Hierarchical risk parity and CVaR/semivariance objectives
  • Discrete allocation to whole shares

Typical workflows

  1. Estimate returns and covariance from prices, optimize for maximum Sharpe, then allocate a budget
  2. Blend market-implied returns with analyst views via Black-Litterman

Strengths

  • Readable API suited to teaching
  • MIT license
  • Extensible objectives and constraints

Limitations

  • No backtesting or data retrieval
  • Solver performance degrades with large universes or many constraints

Prerequisites

  • Python with pandas, NumPy, SciPy and cvxpy

Who it is for

  • Finance students
  • Analysts prototyping allocation models

Alternatives & comparison

Riskfolio-Lib covers a wider set of risk measures and optimization models and leans on the same cvxpy stack; PyPortfolioOpt is smaller and simpler to read. QuantLib addresses instrument pricing rather than allocation.

  • Ghostfolio

    Open-source wealth-tracking web app for stocks, ETFs, crypto and other assets, self-hostable with Docker or used as a hosted service

    Open sourceOpen source
  • QuantLib

    Open-source C++ library for quantitative finance covering instruments, term structures, pricing engines and calendars, with Python and other bindings

    Open sourceOpen source
  • Riskfolio-Lib

    Python library for quantitative portfolio optimization with many risk measures, robust estimators and hierarchical clustering models

    Open sourceOpen source
  • SciPy

    Core open-source Python library for scientific computing on NumPy arrays: optimization, integration, interpolation, linear algebra, sparse matrices, statistics, signal processing

    Open sourceFree
Compare PyPortfolioOpt with its alternatives →

Sources & verification

Primary sources consulted for this record. Claims are tied to the fields each source supports; the automated link checker re-verifies every URL on a schedule.

  • License
    LICENSE (MIT)

    https://github.com/PyPortfolio/PyPortfolioOpt/blob/main/LICENSE

    Supports: license_spdx

    checked Nov 1, 2026
  • Official site
    PyPortfolioOpt documentation

    https://pyportfolioopt.readthedocs.io/en/latest

    Supports: name, summary, capabilities

    checked Nov 1, 2026
  • Repository
    PyPortfolio/PyPortfolioOpt

    https://github.com/PyPortfolio/PyPortfolioOpt

    Supports: product_status, languages

    checked Nov 1, 2026
Confidence
High
Reviewed
Nov 1, 2026
Links
Verified · Nov 2, 2026

Spotted an error?

Broken link, outdated license, wrong category, or a tool that no longer exists? Tell us; reports are reviewed by the editor.

Ghostfolio

Ghostfolio · Portfolio & wealth management

Open-source wealth-tracking web app for stocks, ETFs, crypto and other assets, self-hostable with Docker or used as a hosted service

AGPL-3.0-onlyOpen sourceFreemiumSelf-hostedNov 2, 2026