Calculate Sharpe ratio, max drawdown, and other risk metrics for a trading strategy's return series.
Generate a full HTML tearsheet comparing a strategy's performance against the S&P 500 benchmark.
Run Monte Carlo simulations to estimate the probability of a large drawdown in your strategy.
Create monthly return heatmaps and rolling performance charts for a portfolio analysis presentation.
Requires Python 3.10 or newer.
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.
← ranaroussi on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.