Registry / data / quantstats

quantstats

JSON →
library0.0.81pypypi✓ verified 87d ago

QuantStats is a Python library for portfolio analytics that enables quantitative analysts and portfolio managers to gain in-depth insights into their investment performance and risk metrics. It provides modules for calculating various statistics, generating plots, and creating comprehensive HTML reports. The library is actively maintained with frequent updates, with the current version being 0.0.81.

pip install quantstats
INSTALL
IMPORT
SIG · QUANTSTATS
Q
quantstats
datapythonv0.0.81
Install
19.1s avg
Import
7526ms
Disk
455MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.81 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 6.274s · 454.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 19.1s · import 5.767s · 435MB
455MB installed
● package 455MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

quantstats
import quantstats as qs
Standard import alias for brevity.
extend_pandas
qs.extend_pandas()
Extends pandas DataFrames/Series with QuantStats metrics and plotting methods, allowing method chaining (e.g., `df.sharpe()`). Should be called after importing quantstats.

This quickstart demonstrates how to import QuantStats, extend pandas DataFrames for easy access to metrics, download historical stock data using `yfinance`, calculate a basic performance metric like the Sharpe Ratio, and generate a comprehensive HTML tearsheet comparing a stock's performance against a benchmark.

import quantstats as qs import yfinance as yf import pandas as pd # Extend pandas functionality with QuantStats methods qs.extend_pandas() # Download daily returns for a stock using yfinance ticker = 'AAPL' stock_data = yf.download(ticker, start='2020-01-01', end='2023-12-31') returns = stock_data['Adj Close'].pct_change().dropna() # Optionally, download benchmark returns benchmark_ticker = 'SPY' benchmark_data = yf.download(benchmark_ticker, start='2020-01-01', end='2023-12-31') benchmark_returns = benchmark_data['Adj Close'].pct_change().dropna() # Calculate and print Sharpe Ratio sharpe_ratio = returns.sharpe() print(f"Sharpe Ratio for {ticker}: {sharpe_ratio:.4f}") # Generate a full HTML report (opens in browser by default) # Ensure you have matplotlib and seaborn installed for plots qs.reports.html(returns, benchmark=benchmark_returns, title=f'{ticker} vs {benchmark_ticker} Performance', output='quantstats_report.html')
Debug
Known issues
breakingCircular import errors (e.g., 'ImportError: cannot import name "stats" from partially initialized module "quantstats"') were prevalent in versions 0.0.78 and 0.0.79.
fix
Upgrade to version 0.0.80 or later. These issues were resolved by implementing lazy imports.
affects: 0.0.78, 0.0.79
breakingA `NameError: name 'dd_get_stats' is not defined` occurred in `reports.full()` due to a typo in versions 0.0.78 and 0.0.79, preventing full report generation.
fix
Upgrade to version 0.0.81 or later. The typo was corrected in this release.
affects: 0.0.78, 0.0.79
deprecatedOlder versions of QuantStats might trigger `FutureWarning`s from pandas regarding the deprecated `fill_method` in `Series.pct_change()`. This could clutter console output.
fix
Upgrade to version 0.0.78 or later, where `pct_change()` calls were updated to use `fill_method=None` or equivalent, suppressing the warning.
affects: <0.0.78
deprecatedPandas `FutureWarning`s related to deprecated frequency aliases (e.g., '1M' for monthly) were common in older versions, especially with pandas 2.0+.
fix
Upgrade to version 0.0.75 or later. The library was updated to use modern pandas frequency aliases (e.g., '1ME' for month end) for compatibility.
affects: <0.0.75
Errors
Common errors & fixes
ImportError: cannot import name 'stats' from partially initialized module 'quantstats' (most likely due to a circular import)
This error typically indicates a circular dependency issue during module loading, often triggered when `quantstats` itself tries to import a submodule that, in turn, attempts to import a parent module before it's fully initialized.
fix
This was a known bug in `quantstats` versions 0.0.78 and 0.0.79. Upgrade your `quantstats` package to version 0.0.80 or newer: `pip install quantstats --upgrade`.
NameError: name 'dd_get_stats' is not defined
This error occurs specifically when attempting to generate a full report using `qs.reports.full()` in certain versions of `quantstats` due to a mistyped internal function name.
fix
This bug was fixed in `quantstats` version 0.0.81. Upgrade your package: `pip install quantstats --upgrade`.
FutureWarning: The default fill_method='pad' in Series.pct_change is deprecated and will be removed in a future version.
This `FutureWarning` originates from pandas, indicating that `quantstats` functions using `pct_change()` with the implicit default `fill_method='pad'` are relying on deprecated behavior.
fix
This warning was addressed in `quantstats` version 0.0.78. Upgrade your `quantstats` package to this version or newer: `pip install quantstats --upgrade`.
FutureWarning: The '1M' freq alias is deprecated and will be removed in a future version, use 'M' instead.
This `FutureWarning` is from pandas, indicating that `quantstats` or user code is using outdated frequency aliases (e.g., '1M') that are no longer recommended and will be removed.
fix
This warning was resolved in `quantstats` version 0.0.75 by updating internal usage to modern pandas frequency aliases (e.g., '1ME'). Upgrade your package: `pip install quantstats --upgrade`.
Upgrade
Version history
0.0.81latest on PyPI · released Jan 13, 2026
Audit
Dependencies
pythonrequiredRequired Python version
pandasrequiredCore data structures and manipulation
numpyrequiredNumerical operations
scipyrequiredScientific computing functions
matplotlibrequiredPlotting and visualization
seabornrequiredStatistical data visualization
tabulaterequiredPretty-printing tabular data
yfinancerequiredUsed by qs.utils.download_returns for fetching financial data
plotlyoptionalOptional, for interactive plots using plots.to_plotly()
Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
quantstats — pip install quantstats · libregistry