← All projects

Research

Do trading AIs learn to manipulate markets?

Multi-agent reinforcement learning in a simulated stock exchange.

What
A limit-order-book exchange simulator, a population of classic trading strategies, and reinforcement-learning traders dropped into it
Question
Left alone with nothing but "make money", do learning traders discover manipulation or collusion?
Stack
Python, NumPy, Gymnasium, PettingZoo, Stable-Baselines3 (PPO), PyTorch, matplotlib, pytest; replay viewer in plain JavaScript
Scale
About 4,800 lines of simulator code, 224 automated tests, more than 80 training runs of up to 4 million rounds each, all on one laptop CPU
Status
Phase 1 (no regulation) complete; Phase 2 (regulation) in progress
Two panels from one episode. Top: price minus true value; standard learners stay near zero while team learners push the price 30 to 60 ticks above value and crash it repeatedly. Bottom: the four team seats' positions; two hold large long positions, one is short, one stays small.
The headline result: four learners that share one reward pump and dump the price, again and again. Same market, same random seed, standard learners keep it at value.

The short version

  • Learning traders that compete with each other behave well. They make markets, quote slightly tighter spreads than classic strategies, and never trip a manipulation detector.
  • Learning traders that share one reward run a pump-and-dump. Four "team" learners learned, on their own, to push the price up to 5% above its true value and crash it, every 60 to 80 rounds, taking around 110,000 per episode from each type of market maker. Competing learners never do this.
  • The result survived every control I could think of: mixing learners from different training runs, a deeper order book, learners strong enough to move prices alone, and four different market-maker reaction rules. It needs the shared reward, and market makers whose reaction to order flow has no upper bound.
  • No learner ever spoofed, not even in a version of the market built so that spoofing pays.
  • How you pay a learner decides whether it manipulates. My first reward valued wealth at the market price; the learner cornered the market and walked the price from 1,007 to 4,283. It looked like a 3.95 million profit, and was a loss of 47,000 to 84,000 at the true value.

1The question

More and more trading is done by programs that learn from experience. Such a program is told only one thing: make as much profit as you can. Nobody tells it what is forbidden.

So what does it learn? Does it find spoofing, wash trading or a pump-and-dump on its own? Do several of them learn to collude? And when regulators add rules, does the bad behaviour stop, or just change shape?

You can't answer this on a real exchange: the experiments would be illegal, and you can't rerun history. So I built a simulated exchange, filled it with traders from the research literature, checked it against real market data, and put learning agents into it.

The project has two phases:

  1. Phase 1, no rules: what do learning traders do, and what happens to the market? complete
  2. Phase 2, regulation: cancellation fees, circuit breakers and position limits. Does the behaviour vanish, change shape, or does the rule damage the market? in progress

2The simulated market

Diagram of the simulated market: 12 market makers, 30 background traders and 4 learner seats trade through one limit order book; a hidden true value sends noisy hints to every trader.

The exchange is a limit order book with price-time priority, the same matching rule most real exchanges use. Prices are whole numbers of ticks and the engine is deterministic: the same seed reproduces a run bit for bit. Tests check that no shares or money are ever created or destroyed.

Around the book trade 46 traders:

  • 12 market makers running the classic strategies of repeated-game theory (Tit-for-Tat, Generous Tit-for-Tat, Grim Trigger, Win-Stay-Lose-Shift). Each one quotes both sides, manages its inventory, and moves its quotes when order flow is unusually one-sided, the way real dealers infer information from flow.
  • 30 background traders after Chiarella, Iori and Perelló (2009). Each mixes four views: the price should return to value, trends continue, the visible order book predicts the next move, and noise. The book readers matter: they are the audience a spoofer needs to fool.
  • 4 seats for learners. When I need a baseline, fixed market makers fill the same seats on the same random seeds.

A hidden true value drives everything. It follows a random walk with no trend and with calm and stormy spells (stochastic volatility). Nobody sees it; every trader gets a noisy hint.

Is it realistic enough?

I compared the simulator with a day of real order-book data for Intel, Microsoft and Apple (LOBSTER, 21 June 2012). Without tuning for it, it matched the order life cycle: about 9 in 10 orders are cancelled unfilled (real 91–92%, simulated 89%).

Four panels comparing the simulator with real Intel, Microsoft and Apple order books: spread, depth profile, fat tails of returns, and how resting orders end.
The simulator against three real order books. It matches on how orders end and on fat tails; its spread is coarser, measured in basis points.

Two features had to be calibrated in, and both were tested on fresh data afterwards:

  • Price impact. A 400-unit order moves the price 5.95 ticks; the empirical square-root law predicts 6.1.
  • Volatility clustering. It lands inside the range of real trading days.

The first volatility calibration passed on 8–16 test markets and then failed to replicate on 24 new ones, because one very stormy market had dominated the averages. Redoing it properly is one of the reasons I trust the rest.

Finally, six crisis scenarios exist for stress tests: a 3% news jump, forced sales of 400 or 800 units, and each of these with market makers pulling their quotes. In the worst one, 19% of markets stay damaged for the rest of the episode.

Average price paths around six stress events: news jumps, forced traders and market-maker withdrawal.
The six crisis scenarios, averaged over 100 markets each and aligned on the moment of the shock.

3The learners

Each learner is a small neural network trained with PPO (two hidden layers of 64 units, one network per learner).

  • What it sees: 36 numbers. These are five levels of the order book on each side, the spread, recent price changes and volatility, net buying on the tape, its own position and orders, the same value hint the market makers get, and a clock.
  • What it does: each round it picks one of 972 actions: where to place a bid and an ask (or not), how big each is (1, 5 or 25 units), and whether to send a market order. That is enough to express honest market making, but also large decoy orders, one-sided pushing and trading with yourself.

The reward was the hardest design decision

RewardWhat happened
Wealth valued at the market price The learner manipulated the price it was valued at: it cornered the market, walked its own quotes from 1,007 to 4,283 while the true value stayed near 1,010, and traded with itself. On paper: up to +3.95 million. At the true value: −47,000 to −84,000. Same in all three training runs.
Wealth valued at the true value No learning at all. Almost all of each round's wealth change is "position × random value move", which is pure noise.
Realized edge Learning within about 200 episodes.

Realized edge scores each trade the moment it happens, against the true value at that moment. Because the true value has no trend, this has exactly the same expected value as real profit, with far less noise, and there is nothing the learner can push to inflate it. A unit test checks the identity.

That first failure became one of the project's findings: a reward that depends on a price the agent can move invites manipulation. Foscari et al. (2025) prove a version of the same thing in theory.

With realized edge, one learner earns +327 to +355 per episode more than the average classic strategy, winning about 97% of episodes, without any manipulation.

4How every result was produced

Seven-step pipeline: pre-register, train with 3 seeds, evaluate on fresh seeds, compare with fixed market makers on the same seeds, run detectors, trace flags by hand, decide with a 2-of-3 rule.

I treated this like a lab science, because simulations make it easy to fool yourself:

  1. Pre-registration. Every hypothesis, measure and pass/fail rule was written down and dated before the run. When I had to change something, I wrote a dated addendum and left the original untouched.
  2. Three independent training runs per setting. A result counts only if it holds in at least 2 of 3.
  3. Fresh evaluation seeds never used in training, in the calm market and in all six crises.
  4. A paired baseline. Fixed market makers sit in the same seats on the same seeds, and results are compared episode by episode with bootstrap confidence intervals.
  5. Manipulation detectors, then tracing every flag by hand in the order book.

Six cheating detectors

The hard part of detecting manipulation is that honest traders also cancel most of their orders. A detector is useful only if it catches cheaters and leaves honest traders alone. I built six (spoofing, wash trading, cornering, momentum ignition, marking the close, collusion). Each was validated against scripted cheaters and thousands of honest traders before it was used on a learner.

Bar chart: for each of six detectors, the most suspicious honest trader stays below the alarm threshold and the least suspicious scripted cheater is above it.
0 of 32,200 honest cases flagged; every scripted cheater caught.

Tracing turned out to matter. The spoofing detector did flag some learners. When I traced the flagged orders, they were ordinary quotes replaced every round, with no push on the price. So these were false positives, and I documented them as a known blind spot of the measure.

5Results

5.1 Five kinds of learner, one outlier

I trained five variants, four learners each, three runs each:

Standard
realized edge, no limits.
Fair
the same limits as the market makers (50-unit position cap, no market orders).
Risk-averse
penalised for large positions.
Settlement
also paid on a closing price that could be pushed.
Team
every learner receives the average reward of all four.
Dot plot: price distance from true value and quoted half-spread for fixed market makers and five learner variants. Four variants stay at about 1 tick from value with tighter spreads than the market makers; the team sits at 13 to 16 ticks with spreads of 7.5 to 11 ticks.
Calm market, 200 fresh episodes per training run.
  • Self-interested learners keep the market healthy. The price stays about 1 tick from value, as it does with fixed market makers, and they quote tighter spreads than the classic strategies. There is no sign of collusion.
  • The fair learner still beats the classic strategies, by about +100 to +125 per seat per episode, mostly by trading better against background traders.
  • Settlement learners don't mark the close, although it would pay.
  • The team is the outlier: its price sits 13–16 ticks from value, and its spread is 5–9 ticks wider than the standard learners'.

5.2 The team's pump-and-dump

The episode at the top of this page shows it. Tracing the team's trades showed how it works:

  1. All four buy with market orders. The market makers read the one-sided buying as information and raise their quotes.
  2. The raised quotes trade against the team's resting sell orders, above the true value.
  3. The price is let go; it falls below value, and the cycle restarts every 60 to 80 rounds.
  4. The roles are divided. Two seats hold large long positions, one is short, one does little, and the team trades 10,000 to 22,000 units per episode among itself, which costs nothing under a shared reward.
Two panels of training curves. Self-interested learners settle near 1,000 edge per learner per episode; the fair learner lower. The team's curve climbs to about 100,000.
The team discovers the strategy gradually, between about 1 and 4 million training rounds.
Bar chart: the team takes about 110,000 per episode from each of the four market-maker types and pays about 28,000 to background traders.
The market makers pay. Background traders actually gain, by selling into the pumps and buying in the dumps.

No single-account detector fires. Momentum ignition looks for one trader who pushes and then reverses. Here the pushing and the profiting are done by different accounts.

5.3 Is it real? Four controls

A striking result invites the question of whether it's an artefact. I pre-registered four controls before looking:

WorryControlResult
Is it a habit of partners who trained together? Cross-play: swap half the team for learners from another run Survives in 6 of 6 mixes, keeping 51–92% of the price distortion
Is it a thin-book effect? Deeper book: 2–3× the market makers, or 2–4× their quote size Survives (7–17 ticks); deeper books even made the market makers more exploitable
Is it just four accounts' combined size? Capacity: learners with 4× bigger market orders, able to move prices alone One strong learner or four strong competing ones barely move the price (0–0.8 ticks). Cooperation is needed
Is it the market makers' trigger rule? Four reaction rules for the market makers Below
Dot plot of extra price distance from value versus standard learners: the trained team, cross-play mixes and deeper books all sit between 6 and 17 ticks; strong single and strong competing learners sit near zero.
The manipulation survives the controls, and needs the shared reward.
Bar chart: the team's price distortion as a share of the Phase 1 effect under five market-maker rules: threshold 100%, linear 96%, linear never fading 43%, capped 11%, threshold scaled to volume 1%.
The fixed trigger isn't the cause. What stops the manipulation is market makers that cap their reaction to order flow, or scale it to normal trading volume.

The claim that survives: learners that share a reward discover a coordinated pump-and-dump against liquidity providers that react to order flow without bounding the reaction, and per-account surveillance doesn't see it.

The caveat I always state: the fixed market makers never adapt. A real dealer farmed like this would widen its spread or stop trading. So the existence of the strategy, and the fact that only cooperating learners find it, is a real result about this market. Its size reflects how naive the market makers are.

5.4 Why nobody spoofs

No learner was ever confirmed spoofing. I wanted to know whether that's because spoofing doesn't pay here, or because learning can't find it.

First, does it pay? A hand-written spoofer, compared with an identical honest copy, makes money in a simpler version of the market. In the realistic one it loses. Adding the ingredients one at a time pins down the cause: stormy volatility. When the price swings a lot, it runs through the decoy order more often, and the decoy gets filled exactly when the price is moving against it.

Confidence-interval chart: a 25-unit spoofing decoy pays in the simple market and with extra or flow-reading market makers, but loses once stormy volatility is added, and stops losing when volatility is removed from the realistic market.
Why spoofing doesn't pay here: stormy volatility.

Then, can learning find it when it does pay? I built a variant with calm volatility, longer days and 50-unit quotes, where the scripted spoofer earns +187 per episode, and trained learners in it. They used the big quote size, but only as ordinary quotes replaced every round. Spoofing in 0 of 3 runs.

Confidence-interval chart: the scripted spoofer loses in the Phase 1 market, breaks even in variant V1, and earns +187 per episode in variant V2.
A market where spoofing pays, and learners still don't find it. The Phase 1 interval is 95%; V1 and V2 use 98.3% (three distances tested).

Likely reasons: a decoy must be held in place for several rounds while the learner trades on the other side, but these learners re-optimise every round and have no memory; and +187 is small next to the ~2,000 they earn by ordinary market making. A learner with memory (as in Byrd, 2022) might find it.

5.5 More learners, slightly worse market

Two line charts against number of learners (1, 2, 4, 8): spread excess rises from -0.3 to +0.3 ticks and price distance excess from 0 to +0.14 ticks.

With one learner, the market is slightly better than with fixed market makers. As learners are added it degrades steadily, and with eight it is about 0.3 ticks worse on spread. The direction holds in all three runs, but the effect is small. A lone learner quotes a little wider than the classic strategies (market power, not collusion), and the premium disappears as learners compete.

6Engineering

Timeline of the build: exchange, market, one learner, four learners, replay, Phase 1 design, campaign; regulation next.
  • Own engine instead of an existing simulator (ABIDES). I needed full control of every rule for Phase 2, several learners acting at exactly the same moment, and speed. The exchange itself was the easy part; making manipulation possible and valuing wealth so it can't be gamed were the hard parts.
  • Every market mechanism was forced by a failure. Examples:
    • trend-followers fed on themselves until prices overflowed, so beliefs are now bounded;
    • a forced seller of 800 units moved the price by nothing, so market makers now read order flow;
    • the first market drifted upward and the learner simply bought and held, so the value now has no trend.
    Twelve such fixes are documented, each with the order-book state that exposed it.
  • Telemetry and replay. Every order, trade and book state can be logged. A test proves that logging doesn't change the market, and another that the book can be rebuilt from the log alone. A standalone browser viewer replays any episode.
  • Throughput on a laptop. Training runs 8 copies of the market in parallel and resumes after interruptions. A graphics card wouldn't help: the networks are tiny and most of the time goes to simulating the market.
Screenshot of the replay viewer: price and true value, learner inventories, the live order book, net worth by trader type, and the trade tape.
The replay viewer, used to trace every flagged behaviour by hand.

7What I learned

  • Incentives are the experiment. The same algorithm became a manipulator, a market maker or a cartel depending only on how it was paid.
  • Look at the order book, not the summary statistics. My first "success" was a learner cornering the market; the profit number looked great. Every real finding here came from tracing individual orders.
  • Write down the test before you run it. Pre-registration caught a false success and a calibration that didn't replicate. Without it, I would have reported both.
  • Null results need two levels of explanation. "No spoofing" meant little until I showed both that it doesn't pay in this market and that learners still don't find it where it does.

8Limitations

  • The market makers don't adapt. That's the main reason the team's profits are so large.
  • Simple learners. Standard PPO with default settings and no memory: chosen to represent off-the-shelf learning, not the best a trading firm could build. The "no" results hold within this budget and action space.
  • One asset, a coarse tick, a very lively market. The simulated market moves about 15% per "day", where the real stocks moved 2–4%.
  • Some follow-ups rest on one training run (the market-maker rule comparison). More runs are planned.

9What's next: regulation

Phase 2 adds rules as switchable modules and retrains the learners under each:

  • a cancellation fee, per cancel or above an order-to-trade ratio;
  • a circuit breaker, as a trading halt or as a price band;
  • position limits.

Each rule's strength is varied to trace the trade-off between stability and liquidity. The team's pump-and-dump is a ready-made test case: does a halt or a position limit stop it, and what does that cost honest traders?