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.2

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.2
File Size Uploaded
portpy_quant-0.1.2.tar.gz 180.1 kB Details

Built distribution (wheel)

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

Total release size: 248.3 kB

Release files / portpy_quant-0.1.2.tar.gz

Download URL portpy_quant-0.1.2.tar.gz
Size 180.1 kB
Tags Source
SHA-256 checksum
How to use checksums
11d92e911a2862c78db6b7d6c5ddbb55afe871499ce0e2067255446b1604c24a
BLAKE2b-256 checksum
How to use checksums
872be8db99d83392d0dac0d0eedb775e8ba3042cc3f693ffe47d36615bc8304d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

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

Download URL portpy_quant-0.1.2-py3-none-any.whl
Size 68.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96fd1305de7ae4b42c64f9516c19e90663768cc7f2ae141f5aa0d36988920cbe
BLAKE2b-256 checksum
How to use checksums
0cb156596fa5088024c4972d039666d68be8cbe69188c89e1ef1a7e5de4bfb97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.2 This release

2 release files

0.1.1

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