Python toolkit for trading research that backtests thousands of strategy ideas across assets and timeframes using vectorized NumPy and pandas operations.
ranaroussi/quantstats
Python library for portfolio performance analytics, providing risk metrics, plots, and HTML tear sheets for return series.
- Stars
- 7,801
- Forks
- 1,276
- Open issues
- 32
- Last commit
- 5 days ago
Repolode describes open-source projects and does not give investment advice. Trading and investing can lose money: assess the risk yourself and follow the laws where you live before using this project.
What is it?
QuantStats is a Python library for profiling investment portfolios. It takes a series of periodic returns and computes performance and risk metrics such as Sharpe ratio, Sortino ratio, volatility, maximum drawdown and win rate, then visualizes them with charts covering drawdowns, rolling statistics and monthly returns.
The library is organized into three modules: stats for metric calculations, plots for visualization, and reports for batch plotting and full tear sheets that can be saved as HTML. It also includes a pandas extension so metrics can be called directly on a returns Series, and helpers to download price-based returns for tickers via yfinance.
The project also provides Monte Carlo simulation for probabilistic risk analysis, with functions to estimate bust and goal probabilities. Metrics are computed on return periods rather than discrete trades, so results reflect daily, weekly or monthly return behavior.
Key features
- 01Calculates over 60 performance and risk metrics such as Sharpe, Sortino, CAGR and max drawdown.
- 02Generates snapshot charts, drawdown plots, rolling statistics and monthly return heatmaps.
- 03Produces HTML tear sheets comparing a portfolio against a benchmark.
- 04Runs Monte Carlo simulations to estimate bust and goal probabilities.
- 05Extends pandas Series with metric methods and downloads ticker returns via yfinance.
Use cases
- Evaluating the historical performance of a systematic trading strategy.
- Comparing a portfolio against a benchmark such as SPY in a shareable HTML report.
- Assessing tail risk and drawdown behavior of a return series.
- Running probabilistic risk simulations on a portfolio's expected returns.
Quick start
- 1
Install the package with pip
pip install quantstats --upgrade --no-cache-dir - 2
Import quantstats and fetch daily returns for a stock
import quantstats as qs stock = qs.utils.download_returns('META') - 3
Show the Sharpe ratio
qs.stats.sharpe(stock)
Things to know
- Metrics are period-based on return series, not discrete trade statistics, so win rate and payoff ratio can differ from trade-level results.
- Full documentation is still marked as coming soon in the README.
In collections
Topics
FAQ
- What is quantstats?
- Python library for portfolio performance analytics, providing risk metrics, plots, and HTML tear sheets for return series. QuantStats is a Python library for profiling investment portfolios. It takes a series of periodic returns and computes performance and risk metrics such as Sharpe ratio, Sortino ratio, volatility, maximum drawdown and win rate, then visualizes them with charts covering drawdowns, rolling statistics and monthly returns.
- Is quantstats free to use? What license does it have?
- quantstats is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is quantstats still maintained?
- Actively maintained. The last commit to quantstats was on Nov 2, 2026.
- What can I use quantstats for?
- Evaluating the historical performance of a systematic trading strategy. Comparing a portfolio against a benchmark such as SPY in a shareable HTML report. Assessing tail risk and drawdown behavior of a return series. Running probabilistic risk simulations on a portfolio's expected returns.
- How do I install quantstats?
- Install the package with pip: pip install quantstats --upgrade --no-cache-dir Import quantstats and fetch daily returns for a stock: import quantstats as qs stock = qs.utils.download_returns('META') Show the Sharpe ratio: qs.stats.sharpe(stock)
- Where can I get quantstats?
- The source code and installation instructions are on GitHub: https://github.com/ranaroussi/quantstats
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A self-hosted Python framework for researching, backtesting, optimizing and live-trading your own crypto trading strategies.
Pythonic event-driven backtesting library for trading strategies, a community-maintained fork of Quantopian's Zipline.
A curated, categorized list of open-source libraries, packages and resources for quantitative finance, spanning pricing, backtesting, data and more.
A curated Awesome list of libraries, papers, strategies, books, blogs and courses for systematic (quantitative) trading.
Rust-native, event-driven trading engine with Python control plane for backtesting and live trading across crypto, FX, equities, futures, options and betting venues.