Skip to main content

PortPy

Portfolio analysis that explains itself.

PortPy is a Python library for portfolio performance measurement and risk analysis, built around one object — Portfolio — and one idea: every number it gives you can explain, in plain language, what it is, how to read it, and whether it's good or bad.

CI License: MIT Python 3.10+

import pandas as pd
from portpy import Portfolio

prices = pd.read_csv("prices.csv", index_col=0, parse_dates=True)  # columns = tickers

portfolio = Portfolio(
    prices,
    weights={"AAPL": 0.4, "MSFT": 0.35, "GOOGL": 0.25},
    name="Tech Portfolio",
    risk_free_rate=0.04,
)

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

What it is:
  Measures excess return earned per unit of total volatility taken, using the risk-free rate as the return hurdle.

Formula:
  mean(r - rf) / std(r - rf, ddof=1) * sqrt(periods_per_year)

How to read it:
  A Sharpe of 1.0 means the strategy generated approximately one unit of excess return for each unit of volatility. Higher values indicate better risk-adjusted performance.

Good vs. bad:
  Higher is generally better. Values above 1 are commonly considered strong, but interpretation depends on the asset class, time period, and strategy complexity.

Caveats:
  Sharpe treats all volatility as bad, including upside volatility. It can also overstate strategies with asymmetric downside risk, illiquidity, or short backtests. The sqrt(periods_per_year) annualization assumes i.i.d., serially uncorrelated returns - positive autocorrelation (illiquid/infrequently-priced assets) means the annualized figure is overstated (Lo, 2002).

This result:
  very good

Why PortPy

  • One object, one namespace. portfolio.metrics.<name>() auto-fills returns, weights, risk-free rate, and annualization frequency from the portfolio itself — no re-threading the same five arguments through every call.
  • A real portfolio, not just a return stream. Weights (negative/short included), asset-class tags, and explicit calendar-alignment / currency-conversion helpers for combining assets that don't trade on the same schedule (crypto, equities, bonds) or in the same currency.
  • Explains itself. .explain() on any result — a plain-language card covering what it is, how to read it, good vs. bad, and known caveats.
  • Numerically validated. Cross-checked against empyrical and quantstats on real market data — see tests/validation/.

Install

pip install portpy-quant               # core: numpy, pandas, scipy, statsmodels
pip install "portpy-quant[viz]"        # + plotly, matplotlib, seaborn
pip install "portpy-quant[data]"       # + yfinance, alpaca-py (for the examples)
pip install "portpy-quant[all]"        # everything

Documentation

  • Getting Started
  • User Guide — the Portfolio object, weights & shorts, calendar/currency alignment, the explainability layer
  • API Reference — every function, by module
  • Roadmap — what's implemented today vs. planned (models, strategies, visualization are not yet built)
  • examples/ — runnable scripts and a full tutorial notebook exercising every metric against live Alpaca + Fed (FRED) data

Status

PortPy is pre-1.0 (Development Status :: 4 - Beta). Metrics and core (calendar/currency alignment, weights, the explainability layer) are implemented and tested. Visualization, models/optimization, and strategies/backtesting are designed but not yet built — see the Roadmap.

License

MIT © Arthur Faugeron

Metadata

Release files for portpy-quant 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for portpy-quant 0.1.1
File Size Uploaded
portpy_quant-0.1.1.tar.gz 180.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for portpy-quant 0.1.1
File Interpreter ABI Platform
portpy_quant-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 248.3 kB

Release files / portpy_quant-0.1.1.tar.gz

Download URL portpy_quant-0.1.1.tar.gz
Size 180.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7172de397f4423f594a33ff9b068be876662cb1f51c4e835540f940130e815b9
BLAKE2b-256 checksum
How to use checksums
1e2d38341e257a58a7c720a37c983d6858ac97d174217892607bb8f6ac76e6a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / portpy_quant-0.1.1-py3-none-any.whl

Download URL portpy_quant-0.1.1-py3-none-any.whl
Size 68.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10051ca941d1c6131a880c36552f38b7c02bf62d3e81eb169182ff96a7699e7e
BLAKE2b-256 checksum
How to use checksums
e2a33b29abbc5f7a410e3d139d1c3900d9a9265280fbdee881fe129a082cc73b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page