explaingit

ranaroussi/quantstats

7,105PythonAudience · dataComplexity · 2/5Setup · easy

TLDR

Python library that analyzes trading strategy and portfolio performance, computes Sharpe ratio, drawdown, win rate, and dozens of other metrics, then generates charts or a full HTML tearsheet report.

Mindmap

mindmap
  root((quantstats))
    What it does
      Portfolio analysis
      Risk metrics
      Performance charts
      HTML tearsheets
    Key metrics
      Sharpe ratio
      Max drawdown
      Win rate
      Value at risk
    Tools
      Stats module
      Plots module
      Reports module
    Advanced features
      Monte Carlo sim
      Benchmark compare
      yfinance download
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Calculate Sharpe ratio, max drawdown, and other risk metrics for a trading strategy's return series.

USE CASE 2

Generate a full HTML tearsheet comparing a strategy's performance against the S&P 500 benchmark.

USE CASE 3

Run Monte Carlo simulations to estimate the probability of a large drawdown in your strategy.

USE CASE 4

Create monthly return heatmaps and rolling performance charts for a portfolio analysis presentation.

Tech stack

Pythonpandasnumpyscipymatplotlibseabornyfinance

Getting it running

Difficulty · easy Time to first run · 30min

Requires Python 3.10 or newer.

In plain English

QuantStats is a Python library for analyzing how well a trading strategy or investment portfolio has performed. You give it a series of returns (daily, weekly, or monthly percentage gains and losses), and it computes a wide range of performance and risk statistics, generates charts, and can produce a full HTML report summarizing everything in one place. The library is organized into three parts. The stats module calculates metrics like Sharpe ratio, Sortino ratio, maximum drawdown, win rate, value at risk, and dozens more. The plots module produces visual charts of daily returns, rolling performance, drawdown periods, monthly return heatmaps, and similar breakdowns. The reports module combines these into ready-to-share tearsheets, either displayed in a notebook or saved as an HTML file. You can also compare a strategy against a benchmark like the S&P 500 by passing a ticker symbol. An important detail the README flags: QuantStats analyzes return periods, not individual trades. Win rate means the percentage of days (or weeks, or months) where the return was positive, not the percentage of trades that closed profitably. For systematic strategies that rebalance regularly, this distinction usually does not matter much. For discretionary traders with multi-day positions, the period-based numbers may look different from what a trade-level log would show. The library also includes Monte Carlo simulation tools, which run many randomized scenarios on your return history to estimate probabilities like the chance of a large drawdown or reaching a target return. This can help stress-test a strategy without needing live market data. Installation is through pip or conda. It requires Python 3.10 or newer and depends on standard data science packages including pandas, numpy, scipy, matplotlib, and seaborn. The yfinance library is used for downloading return data directly from Yahoo Finance.

Copy-paste prompts

Prompt 1
I have a pandas Series of daily returns for my trading strategy. Show me how to generate a full QuantStats HTML tearsheet comparing it against SPY.
Prompt 2
How do I use QuantStats to calculate just the Sharpe ratio and maximum drawdown without generating a full report?
Prompt 3
Walk me through running a Monte Carlo simulation on my return data with QuantStats to estimate the chance of a 20% drawdown.
Prompt 4
My QuantStats win rate looks different from my trade-level win rate. Explain why QuantStats calculates it differently and what it actually measures.
Prompt 5
How do I download historical return data for a ticker directly inside QuantStats using yfinance?
Open on GitHub → Explain another repo

← ranaroussi on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.