jQuantStats: Portfolio Analytics for Quants



Overview
jQuantStats is a Python library for portfolio analytics that helps quants and portfolio managers
understand their strategy performance in depth. It provides two complementary entry points:
a Portfolio route that works directly from price and position data, and a Data route
for arbitrary return streams. All analytics, visualizations, and HTML reports are available
from either entry point.
The library is inspired by QuantStats, but extends
it significantly — particularly around position-level analysis that is impossible when you
start from a return series alone. Key improvements include:
- Polars-native design with zero pandas runtime dependency
- Modern interactive visualizations using Plotly, or static ones using matplotlib
- A Portfolio route — the primary entry point — that exposes tools unavailable in QuantStats
- Comprehensive test coverage with pytest
- Clean, fully type-annotated API
The Portfolio Route — Why It Matters
The original QuantStats only accepts a return series. That is convenient but lossy: once you
reduce prices and positions to returns, you lose the information needed to answer the
questions that matter most in practice.
jQuantStats introduces Portfolio as the primary entry point. You provide the raw
price series and the cash positions your strategy held over time, and the library compiles
the NAV for you. This unlocks a class of analysis tools that simply do not exist in
QuantStats:
Execution-Delay Analysis
Real strategies suffer from execution lag: the signal fires at the close, but the trade
fills the next open, or the next close, or later. A return series hides this completely.
A Portfolio exposes it.
>>> import numpy as np
>>> import polars as pl
>>> from jquantstats import Portfolio
>>> rng = np.random.default_rng(42)
>>> n = 252 # approximately one trading year
>>> prices = pl.DataFrame(
... {
... "date": pl.date_range(pl.date(2020, 1, 2), pl.date(2020, 12, 31), interval="1d", eager=True)[:n],
... "AAPL": (100.0 * np.cumprod(1 + rng.normal(0.0005, 0.015, n))).tolist(),
... "META": (150.0 * np.cumprod(1 + rng.normal(0.0003, 0.018, n))).tolist(),
... }
... )
>>> # Allocate $500k to each asset as constant cash positions
>>> positions = prices.select("date").with_columns(
... [
... pl.lit(500_000.0).alias("AAPL"),
... pl.lit(500_000.0).alias("META"),
... ]
... )
>>> pf = Portfolio.from_cash_position(prices=prices, cash_position=positions, aum=1_000_000)
>>> # Shift all positions forward by one period — simulate T+1 execution
>>> pf_lagged = pf.lag(1)
>>> sharpe_t0 = pf.stats.sharpe() # ideal (no delay)
>>> sharpe_t1 = pf_lagged.stats.sharpe() # realistic (T+1 fill)