Sitemap
JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

How To Use Loop Engineering To Build A Self-Improving Quant Trading System

8 min readJul 6, 2026

--

I will break down exactly how to build the loops that run an entire quant trading system on their own.

Part 1: The Difference Between Prompting And Loop Engineering

For the last two years, working with AI looked like this.

You typed a prompt. You read what came back. You typed the next prompt based on what you saw.

You were the loop.

The agent was a tool. You held it the entire time. Every move was you sitting at your keyboard deciding what to do next.

Loop engineering ends that.

You stop being the thing inside the loop. You become the architect who designs it.

A loop is a recursive goal. You define a purpose. The agent iterates against it. The loop keeps running until a real stopping condition is met.

The agent forgets between runs. The loop does not.

That single fact is the entire architecture.

This is what Boris meant when he said his job is to write loops. He stopped typing instructions one at a time. He built systems that send the instructions for him, read the results, and decide what happens next.

For coding, this changes how software ships.

For trading, this changes everything.

Because no quant has ever made money by typing one prompt and walking away. The edge comes from running the same cycle thousands of times, getting one percent better every iteration, and never sleeping.

That is exactly what a loop does.

If you are still typing prompts into Claude one trade at a time, you are doing what Boris stopped doing two years ago. The leverage point has moved one floor up. You are not writing better prompts anymore. You are writing the system that writes the prompts.

The Difference Between Prompting And Loop Engineering

Part 2: The Six Pieces That Run Every Working Loop

A working loop is built out of six parts. Miss one and the loop breaks quietly.

1. The automation.

This is the heartbeat. A cron schedule, a webhook, a /loop command, or a hook inside Claude Code that fires without you typing.

There are two flavors worth knowing. /loop reruns on a cadence regardless of state. /goal keeps going until a verifiable condition you wrote is actually true, with a separate small model grading whether the work is done.

In trading, /loop is your data pull every minute. /goal is “keep iterating on this signal until the backtest Sharpe is above 1.5.”

2. The skill.

A skill is a procedure manual the agent reads instead of being told from scratch every session.

It lives in a SKILL.md file. It holds your conventions, your rules, your “we don’t do it like this because of that one incident.”

Without skills, every loop run starts from zero. With skills, intent compounds.

3. The state file.

A markdown file. Usually called STATE.md or PROGRESS.md.

It survives between runs. The agent forgets. The file does not.

The agent reads it at the start of every run. It writes back what happened at the end.

This sounds too dumb to matter. It is actually the spine of every working loop.

4. The verifier.

The agent that wrote the code is the worst possible judge of whether the code is correct.

Apply this to trading. The agent that generated the signal is the worst possible judge of whether the signal is real alpha or noise.

You need a separate agent, with different instructions, ideally a different model, whose only job is to verify the work.

This is the maker checker pattern. Every prop shop on Wall Street is structured this way internally. At Jane Street, the trader who proposes a trade does not approve the trade. At Citadel, the researcher who builds the model does not validate the model.

5. The worktrees.

The moment you run more than one agent against the same files, they start colliding.

Git worktrees give each agent its own isolated working directory pointed at its own branch.

In trading, this lets you run signal research, backtesting, and risk monitoring in parallel without ever stepping on each other.

6. The connectors.

A loop that can only read files is a tiny loop.

Connectors built on the Model Context Protocol let the loop hit a broker API, query a database, post to Slack, send orders to the exchange.

This is the difference between a loop that suggests trades and a loop that actually places them.

These six pieces are universal. They show up in Claude Code. They show up in Codex. They show up in every working agentic system on the planet.

Get Moonsat’s stories in your inbox

Join Medium for free to get updates from this writer.

Now let me show you how to wire them together into a complete trading system.

Part 3: How To Build A Self-Improving Quant Trading Loop

The quant trading loop has five stages. Each stage is its own sub loop, with its own skill, its own state file, and its own verifier.

Stage one. Data ingestion.

An automation fires every minute, every hour, or every day depending on the asset class.

@loop(interval="1h")
def ingest_data():
data = fetch_market_data(symbols=universe, lookback="30d")
state.write("latest_data.parquet", data)

The data goes into a shared state file the next stage reads.

Stage two. Signal generation.

This is where the alpha research happens.

@loop(trigger="data_updated")
def generate_signal():
data = state.read("latest_data.parquet")
signal = claude.run_skill("alpha_research", data)
state.write("pending_signal.json", signal)

The signal generation agent reads from a SKILL.md file that holds your alpha research rules.

# alpha_research_skill.md

## Goal
Generate signals using linear regression on the last 30 days
of price and volume data.

## Rules
- Sharpe ratio must be above 1.5 in 3 of the last 5 backtests
- Position size limited to 2 percent of capital per signal
- Skip signals on FOMC announcement days
- Skip signals 48 hours before earnings releases

## Lessons learned
- 2026-02-14: Lost 4.2 percent during earnings week.
New rule: skip any signal 48 hours before earnings.
- 2026-03-08: Sector exposure breach caused 6 percent drawdown.
New rule: cap sector exposure at 30 percent.
- 2026-04-22: Momentum signal blew up on FOMC day.
New rule: kill all momentum signals on FOMC days.

The skill grows over time. Every loss writes a new lesson back. Every lesson becomes a new rule for the next run.

This is what makes the system self improving.

Stage three. Verification.

The signal goes to a completely separate agent. Different model. Different instructions. No exposure to how the original signal was reasoned.

@checker
def verify_signal(signal):
result = claude.invoke(
skill="backtest_verification_skill.md",
signal=signal,
rules=[
"Sharpe ratio above 1.5",
"Max drawdown below 10 percent",
"Newey-West t-stat above 2.0",
"Out of sample period at least 2 years"
]
)
return result.verdict

If verification fails, the signal is killed. If it passes, it moves to execution.

The verifier never sees what the maker reasoned. That separation is the entire edge.

You can also use a stronger model for the checker than the maker. Claude Opus for verification, Claude Sonnet for generation. Different model architectures catch different kinds of errors. This is the same logic ensemble methods use in machine learning.

The maker checker split

Stage four. Execution.

Only verified signals reach this stage.

@auto_mode
def execute(signal):
if verify_signal(signal):
broker.send_orders(signal, max_position=0.02)
state.write("active_trades", signal)

The MCP connector handles the broker API. The loop never asks for permission. Auto mode lets it run hands off.

Stage five. Risk monitoring.

Running in a parallel worktree the entire time.

@loop(interval="1m")
def monitor_risk():
positions = broker.get_positions()
if drawdown(positions) > 0.05:
broker.close_all()
state.append("STATE.md", "Drawdown trigger hit. All positions closed.")

This is the kill switch. It enforces rules without negotiation.

Together these five sub loops form one self running system.

Data flows in. Signals get generated. Signals get verified. Verified signals get executed. Risk gets monitored. Lessons get written back to memory.

Then it starts over.

How the loop compounds

I designed this once. I have not prompted any of these steps since.

That is loop engineering. That is what Boris meant when he said his job is to write loops.

One warning. A loop without a real stopping condition fails quietly. The agent emits a completion signal believing the half done job is finished. The loop exits. The bad trade sits open.

Your stop conditions need to be checkable by something other than the agent’s own claim. “Sharpe above 1.5 over the last 30 trades.” “Drawdown below 5 percent.” “Test suite passes.” Never “the agent says it is done.”

In my game theory article I explained why every trade is a strategic move in a multi player game with imperfect information.

The loop is what lets you sit at that table forever without burning out.

Summary

Quant trading is already a loop. Every fund on Wall Street runs it. They just need hundreds of humans sitting inside.

Loop engineering removes the humans.

Six pieces make every working loop. Automations fire the heartbeat. Skills hold the project knowledge. State files hold the memory. Verifiers grade the output. Worktrees isolate parallel work. Connectors give the loop hands in the real world.

Wire them around the five stage trading cycle and you have a self improving system that runs alpha research, verifies signals, executes trades, and monitors risk on its own.

The system gets smarter every cycle. Every loss writes a new lesson. Every lesson becomes a new rule. After a hundred trades, the skill file is a living document. After a thousand, it is closer to institutional knowledge than anything a single human could remember.

The funds that build this first will compound for the next decade. The ones still prompting will be left behind.

So here is the question to sit with.

If loop engineering is the next abstraction above prompting, and quant trading is the highest stakes loop in the world, are you the person still typing prompts one trade at a time, or are you the architect who designed the loop that trades for you while you sleep?

There is no wrong answer but there are very revealing ones.

Before you go

  • Please take a moment to like the post and follow the writer!
  • Did you know that over 400,000 developers share what they’re building, learning, and discovering across our platforms every month? Learn how you can contribute here

--

--

Moonsat
Moonsat

Written by Moonsat

Prediction Market Engineer | Strategy Researcher | Blockchain Engineer. Telegram Info: @goldminer1_1

JavaScript in Plain English
JavaScript in Plain English

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.