QuantStats: Powerful Python Library for Portfolio Analytics

QuantStats: Powerful Python Library for Portfolio Analytics

Summary

QuantStats is a comprehensive Python library designed for portfolio profiling, offering in-depth analytics and risk metrics for quants and portfolio managers. It helps users better understand their investment performance through robust statistical analysis and powerful visualization tools. This library simplifies the process of generating detailed performance reports and conducting advanced quantitative analysis.

Repository Info

Updated on February 4, 2026
View on GitHub

Introduction

QuantStats is a powerful Python library designed for comprehensive portfolio profiling and analytics. It empowers quants and portfolio managers to gain deeper insights into their investment performance by providing a rich set of in-depth analytics and risk metrics. Built with ease of use in mind, QuantStats streamlines the process of understanding and visualizing complex financial data.

The library is structured around three core modules:

  • quantstats.stats: For calculating various performance metrics like Sharpe ratio, Win rate, Volatility, and more.
  • quantstats.plots: For visualizing performance, drawdowns, rolling statistics, monthly returns, and other key aspects.
  • quantstats.reports: For generating detailed metrics reports, batch plotting, and creating complete tear sheets that can be saved as HTML files.

QuantStats also includes advanced features such as Monte Carlo simulations for probabilistic risk analysis, helping users forecast potential outcomes and assess risk more effectively.

Installation

Getting started with QuantStats is straightforward. You can install it using either pip or conda.

Using pip:

pip install quantstats --upgrade --no-cache-dir

Using conda:

conda install -c ranaroussi quantstats

Examples

QuantStats offers a quick and intuitive way to analyze stock performance and generate comprehensive reports. Here are a few examples to get you started:

First, import the library and extend pandas functionality:

import quantstats as qs

# extend pandas functionality with metrics, etc.
qs.extend_pandas()

Next, fetch daily returns for a stock (e.g., 'META') and calculate its Sharpe ratio:

# fetch the daily returns for a stock
stock = qs.utils.download_returns('META')

# show sharpe ratio
qs.stats.sharpe(stock)

# or using extend_pandas() :)
stock.sharpe()

Output:

0.7604779884378278

Visualize the stock's performance with a snapshot plot:

qs.plots.snapshot(stock, title='Facebook Performance', show=True)

# can also be called via:
# stock.plot_snapshot(title='Facebook Performance', show=True)

Snapshot plot

Finally, generate a complete HTML tearsheet report, comparing the stock against a benchmark like 'SPY':

# benchmark can be a pandas Series or ticker
qs.reports.html(stock, "SPY")

This will generate a detailed HTML report similar to this:

HTML tearsheet

You can also explore Monte Carlo simulations for probabilistic risk analysis:

mc = qs.stats.montecarlo(stock, sims=1000, bust=-0.20, goal=0.50)
print(f"Bust probability: {mc.bust_probability:.1%}")
print(f"Goal probability: {mc.goal_probability:.1%}")
mc.plot()

For a full list of available methods, you can inspect qs.stats and qs.plots. It's important to note that QuantStats analyzes return series (daily, weekly, monthly returns), not discrete trade data. This means metrics like "Win Rate" refer to the percentage of periods with positive returns.

Why Use QuantStats?

QuantStats stands out as an essential tool for anyone involved in quantitative finance or portfolio management due to several key advantages:

  • Comprehensive Analytics: Access a vast array of performance metrics and risk indicators, from basic returns to advanced conditional value-at-risk.
  • Powerful Visualizations: Generate insightful plots and charts that make complex data easy to understand, including drawdowns, rolling statistics, and monthly heatmaps.
  • Automated Reporting: Quickly create detailed HTML tearsheets that consolidate all relevant metrics and plots into a single, shareable report.
  • Ease of Integration: Seamlessly extends pandas DataFrames, allowing for intuitive method chaining and a more fluid analytical workflow.
  • Advanced Features: Incorporates sophisticated tools like Monte Carlo simulations for robust risk assessment and future performance forecasting.
  • Open Source: Being open-source, it benefits from community contributions and transparency, ensuring continuous improvement and reliability.

Whether you're backtesting strategies, monitoring live portfolios, or conducting academic research, QuantStats provides the robust framework needed for in-depth financial analysis.

Links