GK.Gergely Kovács
← Lab
Lab project

Gemma4 — Multi-Agent Trading Research

ActiveQuantitative trading2025 — 2026
Gemma4 — Multi-Agent Trading Research — hero image

FastAPI + Docker multi-agent backtesting and alpha-discovery platform.

Concurrent Gemini agents orchestrate a backtesting engine over statistical alpha hypotheses (BERZERK mode). Python / FastAPI service, Pandas-driven analysis, Nginx reverse proxy, full docker-compose stack.

Architecture

How it's built

A FastAPI service behind Nginx, fronting a Celery worker fleet that fans out concurrent Gemini agents over a backtesting engine. Pandas handles the indicator math, Postgres stores strategy + result history, and Redis carries the broker, results, cache and custom state on four separate databases so they cannot contend. The whole thing is one docker-compose stack so a hypothesis run on the laptop is bit-for-bit the production path.

Data flow
  1. 01Client posts a backtest config to /backtest — Nginx terminates TLS, FastAPI validates JWT and writes the job row to Postgres.
  2. 02FastAPI enqueues the job into the Redis broker DB and returns a 202 with the task id.
  3. 03A Celery worker picks the job up and pulls OHLCV from CCXT (Binance, Kraken) with exponential backoff.
  4. 04Pandas computes indicators in-process; concurrent Gemini agents propose and score alpha hypotheses in parallel.
  5. 05Each agent's result is upserted into Postgres; intermediate progress is pushed to the Redis results DB.
  6. 06Client polls /backtest/{id} — FastAPI reads progress from Redis and the final Sharpe / drawdown / ROI from Postgres.
  7. 07Celery Beat fires the nightly sweep job from its PersistentScheduler — the same pipeline runs without a human.
Design decisions
  • Four Redis logical databases (broker / results / cache / state) — keeps queue traffic and cache eviction from competing.
  • Celery prefetch_multiplier=1 so a slow Gemini call cannot starve other workers of fair scheduling.
  • Gunicorn + Uvicorn workers behind Nginx for TLS termination and horizontal scale without touching the app.
  • Celery Beat with a PersistentScheduler so recurring alpha sweeps survive restarts without re-armed cron drift.
  • Stateless FastAPI: a request only ever reads/writes Postgres or Redis — every worker is interchangeable.
External integrations
Gemini API (multi-agent)CCXT (Binance, Kraken, …)StripePostgres 16Redis (4 logical DBs)Nginx