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.
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:
The most widely used risk-adjusted return measure: excess return earned per unit of total volatility taken on.
Formula:
mean(r - rf) / std(r - rf, ddof=1) * sqrt(periods_per_year)
How to read it:
A Sharpe of 1.0 means you earned, on average, one standard deviation of excess return for the volatility you took on.
Good vs. bad:
Rules of thumb: <0 poor (lost money net of the risk-free rate), 0-1 sub-par, 1-2 good, 2-3 very good, >3 excellent (and worth double-checking for overfitting or a very short sample).
Caveats:
Assumes returns are roughly symmetric - it penalizes upside volatility just as much as downside, and can be misleadingly high for strategies with rare, large negative tail events (e.g. option-selling). Pair with sortino_ratio and max_drawdown.
This result:
sub-par
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
empyricalandquantstatson real market data — seetests/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
Portfolioobject, weights & shorts, calendar/currency alignment, the explainability layer - API Reference — every function, by module
- Roadmap — what's implemented today vs. planned (
models,strategies,visualizationare 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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| portpy_quant-0.1.0.tar.gz | 154.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| portpy_quant-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 212.8 kB
Release files / portpy_quant-0.1.0.tar.gz
| Download URL | portpy_quant-0.1.0.tar.gz |
|---|---|
| Size | 154.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55ade8d216f5be828382a1e205196b2895b7d5964635ea4404521459a9f9e199
|
|
BLAKE2b-256 checksum How to use checksums |
cfac3b65812af4212052a1443ed5201e064b4cee601c9d41561acfab6a04247a
|
| 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.0-py3-none-any.whl
| Download URL | portpy_quant-0.1.0-py3-none-any.whl |
|---|---|
| Size | 58.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7507fcdae15c47d049db52132f4c7fd9448c08bba38847c8f691c27004a45983
|
|
BLAKE2b-256 checksum How to use checksums |
8bb19152e4f60ed06752b93192f357d1e050abec43f5c4a457509f402d413d1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|