---
title: "QAStats: strategy reporting library in Python"
description: "QAStats, a reporting library built on pandas, empyrical and pyfolio: statistics, drawdowns, VaR, Monte Carlo and a full strategy report."
url: "https://pythonparatrading.com/en/lab/qastats/"
lang: "en"
image: "https://pythonparatrading.com/og/en/lab/qastats.png"
---

# QAStats

> Strategy reporting on pandas. From a daily return series to a full report.

- Version: 3.0.1
- Stars: 2
- Language: Python
- Code on GitHub: https://github.com/quantarmyz/QAStats

## What it is

QAStats is a Python library for financial reporting on portfolios and strategies, built on pandas. It starts from
empyrical and pyfolio, in their `-reloaded` versions, and adapts them to an in-house workflow.

It was built to fix a problem of method. Without a common tool, each team member computed and presented results in
their own way, and reports could not be compared. QAStats sets a single way of measuring: the same statistics and the
same charts for every strategy.

The input is simple: the daily percentage change of the strategy and of its benchmark. It does not work with
individual trades, but with the end-of-day aggregate. It can be used as is, but it is meant as a base: understand how
it works inside and adapt it to each case.

## What's included

The `qastats` package (version 3.0.1) has these modules:

- `stats`: daily (`get_daily_stats`) and monthly statistics tables, drawdowns in relevant periods
  (`get_drawdown_stats`), daily VAMI (`get_vami_diario`), worst drawdown periods, SQN and omega ratios, and dollar VaR
  (`var_usd`).
- `plots`: cumulative returns against the benchmark, heatmap and distribution of monthly returns, annual returns,
  underwater drawdown and drawdown periods, stress events, rolling volatility, alpha, beta, Sharpe and VaR, and Monte
  Carlo.
- `timeseries`: maximum drawdown and top drawdowns, rolling metrics and a bootstrap forecast cone.
- `randomizer`: parametric Monte Carlo of the equity curve, with return and maximum drawdown percentiles.
- `reports`: `create_return_dd`, the full report in a single figure. It is saved as PDF (`noname.pdf` when no name is
  given).
- `interesting_periods`: market events used by the relevant-period drawdowns.
- `extension` and `utils`: `extend_pandas` (adds `varusd` to pandas objects) and table and date utilities.

The repository ships an example, `examples/example1.ipynb`, with its return series (`examples/diario_normal.pickle`),
and the report it produces (`noname.pdf`, `noname.png`).

Version 3 adds the SQN ratio to the advanced statistics, updates the list of relevant events, fixes bugs and installs
with `pip`.

## Installation and first run

In a dedicated conda environment, clone the repository and install the dependencies and the package.
`requirements.txt` includes a patched version of quantstats that the library imports.

```bash
conda create -n qastats python
conda activate qastats
git clone https://github.com/quantarmyz/QAStats
cd QAStats
pip install -r requirements.txt
pip install .
```

The repository example uses a DataFrame with two columns of daily returns: `Close` (the strategy) and `bench` (the
benchmark). In the example the benchmark is synthetic: returns of the same strategy drawn at random.

```python
import numpy as np
import pandas as pd
import qastats

data = pd.read_pickle('examples/diario_normal.pickle')
data['bench'] = np.random.choice(data['Close'], len(data))

qastats.stats.get_daily_stats(data)
```

The full report takes a single call:

```python
qastats.reports.create_return_dd(data)
```

## How it fits

QAStats is the last piece of the lab chain. Data comes from the Datalake, the backtest runs on Zipline in Quantstack
and the report comes from QAStats.

In the quant stack of the reports, pyfolio and empyrical handle reporting. QAStats was built to bring pyfolio's ideas
into an in-house format, on top of empyrical's calculations. It is not part of the Quantstack image: install it
separately with the steps above.

*Data, backtest and report: Datalake → Quantstack (Zipline) → QAStats*

## Related research

Recommended reading order

1. [Advanced Financial Report Library in Python](https://pythonparatrading.com/en/advanced-reporting-2/)
2. [QAStats V3 Released](https://pythonparatrading.com/en/qastats-v3-released-2/)

## Other systems

- [Datalake](https://pythonparatrading.com/en/lab/datalake/) · Library · Python · v5.1 — NoSQL S3 datalake on ArcticDB: ingestion from several market data sources, Alpha Vantage included, and a management CLI.
- [Quantstack](https://pythonparatrading.com/en/lab/quantstack/) · Repository · Jupyter Notebook — Research and backtesting environment in one container: Docker, Debian, conda, JupyterLab, zipline-reloaded and ArcticDB.
