DEV Community

Ritiksuman07
Ritiksuman07

Posted on

I built an open-source AI agent that turns a trade idea into a full backtest — here's why

I've spent a fair amount of time in the world of quantitative finance tooling, and the same frustration kept coming up — getting from an investment idea to an actual tested strategy requires stitching together five different libraries, three data sources, and a lot of glue code that nobody talks about.

Expensive platforms like Bloomberg or FactSet solve this, but they're locked behind paywalls that make no sense for indie researchers, students, or early-stage quant teams. The open-source alternatives are powerful but fragmented — you get a backtesting library here, a data fetcher there, and you're on your own for everything in between.
So I built QuantFlow.

What it does
The core idea is simple: you describe a trade thesis in plain English, and QuantFlow runs it through a full research pipeline automatically.
bashpython -m quantflow run "short small-cap biotech on FDA rejection patterns" --ticker XBI --offline --verbose
That one command kicks off a chain of agents that:

Pull and score SEC filings (10-K, 10-Q, 8-K) for signals relevant to your thesis
Measure Reddit sentiment and mention velocity around the ticker
Convert those signals into an executable strategy with entry/exit rules
Run a deterministic backtest and compute Sharpe ratio, max drawdown, Calmar, and CAGR
Export an equity curve, a report, and store everything in DuckDB for reproducible analysis

The output isn't just a number — it's a full run artifact you can query, compare, and build on.

Why this stack
If you look at the repo, you'll notice it's not just Python. There's Go, Rust, and DuckDB in there too. That wasn't accidental.
Python handles the agent logic, strategy orchestration, and backtest runtime. It's where most quant research lives and it made sense to keep the core there.
Go powers the terminal UI — a live Bubble Tea interface that shows you each pipeline stage running in real time. Demos beautifully, and Go's concurrency model makes it clean to build.
Rust is the backtest engine scaffold. The goal is deterministic, low-latency execution — the kind of thing Python struggles with at scale. Rust handles it cleanly via a JSON-driven binary.
DuckDB is the memory layer. Every run — filings, sentiment scores, strategy rules, backtest metrics — lands in a local DuckDB database. This means you can query across runs, compare strategies, and eventually let an LLM reason over historical results without re-fetching raw data every time.

The AI part
QuantFlow is designed around agentic workflows, but in a way that keeps things reproducible. The LLM slot is intentionally isolated in quantflow/agents/strategy.py — you can plug in Claude, GPT, or any model for strategy orchestration without touching the rest of the pipeline.
Everything downstream of the LLM stays deterministic. The backtest engine doesn't care where the strategy came from — it just runs the rules.
This separation was a deliberate design choice. LLM outputs can be unpredictable.

Backtest results need to be reproducible. Keeping them in separate layers means you get the creativity of AI-driven thesis generation with the rigor of deterministic execution.

What I learned building this
The hardest part wasn't the code — it was resisting the urge to over-engineer the AI layer early. It's tempting to make the LLM do everything. In practice, the more you constrain what the LLM touches, the more trustworthy the outputs are.

DuckDB was a revelation. I initially planned to use Postgres, but DuckDB's ability to run analytical queries on local files with zero setup changed how I thought about the memory layer entirely.

The multi-language architecture also forced some useful discipline — each layer has to have a clean interface. Go talks to Python via subprocess. Rust talks to the orchestrator via JSON. That constraint made the codebase easier to reason about, not harder.

Try it
bashpython -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
python -m quantflow run "short small-cap biotech on FDA rejection patterns" --ticker XBI --offline --verbose

The repo is live at github.com/Ritiksuman07/quantflow — stars, issues, and PRs are very welcome. If you're working on anything in the quant/AI agents space, I'd genuinely love to connect.

Top comments (0)