Skip to content

PortPy

Portfolio analysis, risk, and performance metrics that explain themselves. PortPy centers on one object, Portfolio, which holds your price/return data and weights and exposes every metric through a single, self-documenting namespace:

portfolio.metrics.sharpe_ratio(as_result=True).explain()

Start here

  • Getting Started Install PortPy, build your first Portfolio, and compute your first metrics.

  • The Portfolio object Prices vs. returns, weights, frequency, risk-free rate, and what .metrics auto-fills for you.

  • Weights & short positions Long/short books, normalize_weights, and how negative weights flow through every metric.

  • Calendars & currencies Combining 24/7 crypto with Mon-Fri equities, and converting multi-currency prices to one base.

  • Explainability How .explain() works, where the text comes from, and MetricResult.

  • Construction, optimization & management Estimating expected returns/covariance, solving for weights, and rebalancing/monitoring/comparing afterward with .models.

  • API Reference Every function, grouped by module, generated straight from the docstrings.

Why PortPy

Two things distinguish PortPy from a plain metrics library like empyrical or quantstats (both of which PortPy's own test suite validates its numbers against):

  1. It models an actual portfolio. Weights - including shorts - asset-class tags, and explicit calendar/currency alignment are first-class, not something you build by hand before calling a flat function library.
  2. It teaches while it computes. Every metric is registered with a plain-language explanation of what it is, how to read it, and whether a given value is good or bad - call .explain() on any result.

What's here now

portpy.models - estimating inputs (expected returns, covariance, factor models), solving for weights (mean-variance, max Sharpe, risk parity, hierarchical risk parity, Black-Litterman, and more), and managing a book afterward (rebalancing, drift monitoring, before/after comparisons) - see Construction, optimization & management.

What's not here yet

portpy.visualization and portpy.strategies (backtesting) are designed but not implemented in this release. See the Roadmap for what's planned, and Architecture for the full design document.