Kwants Docs

Quick start

Minimal flow from zero → data → backtest. Run from the project root.

See also: Database setup and Backtest & DSL guide.

1) Install requirements

pip install -r requirements.txt

2) Set up environment variables

Copy .env.example to a new file named .env in the project root, then set your Polygon credentials.

Required keys Set POLYGON_API_KEY, POLYGON_S3_ACCESS_KEY_ID, and POLYGON_S3_SECRET_ACCESS_KEY.

3) Get tickers + adjustments

Build a point-in-time ticker universe and download split/dividend adjustments (Step 4 is included by default).

python build_historical_tickers.py --start-date 2018-01-01 --end-date 2026-02-08

4) Download flat files (build data)

Download Polygon/Massive S3 flat files, stream 1m → 5m + daily, and build derived layers. Requires the S3 env vars in step 2.

python download_flatfiles.py --start-date 2018-01-01 --end-date 2026-02-08
Order Run tickers/adjustments first, then flat files.

5) Run a backtest

Use any strategy file (.json, .yaml, or .py).

python run_backtest.py <strategy_file>

Example:

python run_backtest.py strategies/short_touch.py

Extra columns in trades.xlsx: optional strategy.attributes in the strategy JSON (values computed on the entry bar). See Backtest & DSL — Strategy attributes.

Daily updates (schedule)

Recommended: Monday–Friday, tickers/adjustments first then flat files. Example: 2:00 AM ET and 5:00 AM ET. On Linux/macOS, cron uses the machine’s local clock—shift hours if the host is not ET. On Windows, use Task Scheduler and match your desired wall time (ET or local).

# 2:00 AM ET: tickers + adjustments; 5:00 AM ET: flat files (adjust hours if server is not ET)
0 2 * * 1-5 cd /path/to/polygon-scanner && python build_historical_tickers.py
0 5 * * 1-5 cd /path/to/polygon-scanner && python download_flatfiles.py --end-date $(date +\%Y-\%m-\%d)
Note If your server timezone isn’t ET, convert the schedule to your local time.