---
title: "Quantstack: research and backtesting environment in Docker"
description: "Quantstack: a quantitative research environment in Docker with conda, JupyterLab, zipline-reloaded and ArcticDB, plus a Zipline bundle fed by the datalake."
url: "https://pythonparatrading.com/en/lab/quantstack/"
lang: "en"
image: "https://pythonparatrading.com/og/en/lab/quantstack.png"
---

# Quantstack

> Research and backtesting in one container. Once the image is built, one command starts JupyterLab with Zipline and ArcticDB.

- Stars: 7
- Language: Jupyter Notebook
- Code on GitHub: https://github.com/quantarmyz/quantstack

## What it is

Quantstack is a research and backtesting platform for algorithmic trading with Zipline, ArcticDB and JupyterLab,
packaged in Docker. The image starts from Miniconda on Debian.

It solves an environment problem. Research libraries were not designed to be used together, and in a team each
member works with a different operating system and configuration. The container fixes the system, the package manager
and the tools for everyone. Once the image is built, `docker compose up -d` brings the environment up.

## What's included

- `docker-compose.yml`: `notebook` service on port 8888, with `JUPYTER_TOKEN` (default `testing`). It mounts
  `quantarmy_repo/` as the working folder (`/WorkingData`).
- `DockerSource/Dockerfile`: `continuumio/miniconda3` image. Installs JupyterLab and TA-Lib with conda, and the rest
  of `req.txt` with pip. Copies the Zipline extension, the connector and the `.env` file into the image.
- `DockerSource/req.txt`: zipline-reloaded, pyfolio-reloaded, alphalens-reloaded, empyrical-reloaded and
  exchange_calendars; arcticdb and yfinance; pandas, numpy, scipy, scikit-learn, matplotlib, plotly, seaborn and
  pyarrow; JupyterLab extensions (git, LSP, system monitor, execution time).
- `DockerSource/extension.py`: registers the `qa_datalake` bundle with the NYSE calendar.
- `DockerSource/qa_datalake.py`: ArcticDB → Zipline connector. Reads prices, dividends and splits for the ETFs in the
  table from ArcticDB, from 2010, and writes them into the bundle.
- `DockerSource/overrides.json`: JupyterLab settings (theme, fonts).
- `quantarmy_repo/`: notebooks. `backtest/` (template `template_zipline_jupyterlab.ipynb` and the volatility example
  `01-bt-zipline-variance.ipynb`), `datalake/` (connection, contents and exploration of the datalake), `models/`
  (`01_101_ALPHAS.ipynb`) and `tools/` (`zipline_db_management.ipynb`). `analisis/`, `theory/` and `howtos/` hold an
  empty notebook for now.

ETFs in the `qa_datalake` bundle:

| Ticker | Description |
|---|---|
| XLE.US | Energy Select Sector |
| XLF.US | Financial Select Sector |
| XLI.US | Industrial Select Sector |
| XLK.US | Technology Select Sector |
| XLP.US | Consumer Staples Select Sector |
| XLU.US | Utilities Select Sector |
| XLV.US | Health Care Select Sector |
| XLY.US | Consumer Discretionary Select Sector |
| XLB.US | Materials Select Sector |
| XLC.US | Communication Services Select Sector |
| ITA.US | iShares U.S. Aerospace & Defense |

## Installation and first run

Requirements: Docker and Docker Compose, and access credentials for the QA Datalake (S3/ArcticDB).

```bash
git clone https://github.com/quantarmyz/quantstack.git
cd quantstack
```

Before building, create `DockerSource/.env` with the datalake credentials. The Dockerfile copies it into the image
(`/root/.env`).

```dotenv filename="DockerSource/.env"
ENDPOINT=your-endpoint.com
DB=your-bucket
ACCESS_KEY=your-access-key
SECRET_KEY=your-secret-key
```

Build the image and start the stack, in the background with `-d`:

```bash
docker compose build --no-cache
docker compose up -d
```

JupyterLab runs at `http://localhost:8888`, with the password `testing`. To change it, edit `JUPYTER_TOKEN` in
`docker-compose.yml`.

From a JupyterLab terminal, ingest the datalake data into the Zipline bundle:

```bash
zipline ingest -b qa_datalake
```

Then, in `backtest/`, `template_zipline_jupyterlab.ipynb` is the starting point for a new backtest.

## How it fits

Quantstack is the central piece of the lab chain. Its connector reads from the Datalake on ArcticDB, with the same
four environment variables, and feeds a Zipline bundle. Part 4 of the Big Data Management series explains that
connector. For the report, the image ships pyfolio-reloaded; QAStats, the lab's reporting library, is installed
separately.

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

## Related research

Recommended reading order

1. [The Working Environment - 1](https://pythonparatrading.com/en/docker-for-trading/)
2. [Zipline in Python - Part 1: Quant Stack and Pipeline](https://pythonparatrading.com/en/zipline-backtesting-with-python-quant-stack/)
3. [Zipline, Backtesting in Python 2: My First Data Analysis](https://pythonparatrading.com/en/backtesting-python-zipline-bundle-2/)
4. [Big Data Management 4 - Using the Datalake in Zipline](https://pythonparatrading.com/en/backtesting-with-zipline-and-arcticdb/)

## Other systems

- [QAStats](https://pythonparatrading.com/en/lab/qastats/) · Library · Python · v3.0.1 — Pandas-based reporting library for portfolios and strategies: performance and risk metrics, drawdowns and factsheets. Built on empyrical and pyfolio.
- [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.
