You already met optimal execution in the prerequisite course: slice a parent order to balance market impact (trade fast, move the price against yourself) against timing risk (trade slow, let volatility eat you), and Almgren–Chriss hands you a closed-form, front-loaded schedule. That lesson framed execution as an MDP and showed a learned policy as a state→action map. Good. This lesson assumes all of that and goes where the closed form can’t follow: a deep agent staring at a live limit-order book, with a state vector of dozens of features, a continuous action, and a reward function that — handle it carelessly — will quietly teach your agent to do something insane.
The headline you must carry through the whole lesson: in execution, the algorithm is the easy part. The reward function is where the bodies are buried. Almost every spectacular execution-RL failure is a reward-design failure wearing an algorithm costume.
Before you read — take a guess
A deep execution agent and the closed-form Almgren–Chriss schedule are both pointed at the SAME idealised world: linear impact, constant volatility, one asset, and no predictive signal. What should the well-built deep agent do?
The deep execution agent’s state, action and reward — concretely
The prerequisite MDP table had cosy abstractions: “state = inventory + time + market features.” A deep agent needs those spelled out as a numeric vector, because that vector is literally the input layer of a network. Think of the agent as a trader who has exactly one glance at a dashboard each step, then must commit to a child order. Whatever isn’t on the dashboard, the agent is blind to.
State — what’s on the dashboard. A practitioner state vector bundles three groups:
- Limit-order-book microstructure, multiple levels deep. The best bid/ask, plus depth at levels 2–5 on each side; the spread; the queue imbalance (positive means more buyers stacked up, pressure upward); and the micro-price, a depth-weighted mid that leans toward the heavier side: . The micro-price is a sharper “true value” estimate than the naive mid because it already knows which way the book is leaning.
- Private/agent state. Inventory remaining (how much is still to do) and time-left (fraction of the window gone). These two are non-negotiable — without them the agent can’t pace itself or know it’s late.
- A short-term alpha signal : a micro-prediction of the next-few-seconds price move (order-flow imbalance, a microstructure classifier, whatever you trust). This is the column Almgren–Chriss has no slot for, and the entire source of edge in the next section.
Action — what the trader commits to. Richer than “how many shares.” Realistic action spaces specify:
- Size / participation rate — the child-order quantity, often as a fraction of recent volume (e.g. “take 8% of the last minute’s volume”).
- Aggression — limit vs market, and if limit, the price offset from the touch (post at the bid, one tick inside, two ticks back to sit in the queue). A market order pays the spread for certainty; a passive limit order might earn the spread but might never fill.
This is genuinely continuous (or large-discrete), which is why execution lives in actor–critic / continuous-control territory (PPO, DDPG, SAC) — exactly the methods from the policy-gradient lesson — rather than vanilla DQN.
Reward — the mean–variance objective, per step. The same shape as the prerequisite course, now with the deep-specific detail:
The per-step term charges you the slippage you actually paid; the term taxes the variance contributed by inventory carried; and a steep terminal penalty on leftover inventory forces the order to finish. Drop that terminal term and the cheapest schedule is to never trade — we’ll watch an agent discover exactly that, gleefully, two sections from now.
Implementation shortfall is the scoreboard
Implementation shortfall (IS) is the gap between what you’d have paid at a frictionless “decision price” (usually the mid at the instant you decided to trade — the arrival price) and what you actually paid, all-in. It decomposes into four buckets: delay cost (price moved between decision and first child order), (temporary) impact cost (you pushed the book demanding liquidity now), timing cost (price drift over the execution window on the part you hadn’t traded yet), and opportunity cost (shares you never managed to fill, valued at the move you missed). IS is the universal execution scoreboard — every baseline and every agent is judged on it.
A worked shortfall, in basis points
You must buy 100,000 shares. Arrival price (the mid at decision time) is $50.00, so the frictionless notional is $5,000,000. Here’s what happens:
| Bucket | What happened | Cost | In bps of notional |
|---|---|---|---|
| Delay | Price drifted to $50.01 before your first child order went out | 100,000 × $0.01 = $1,000 | 2.0 bps |
| Impact | Your aggressive slices averaged $0.03/sh above the contemporaneous mid | 90,000 filled × $0.03 = $2,700 | 5.4 bps |
| Timing | Over the window the mid drifted up $0.02 on the inventory you still held | ≈ 90,000 × $0.02 = $1,800 | 3.6 bps |
| Opportunity | 10,000 shares never filled; price ended $0.05 above arrival | 10,000 × $0.05 = $500 | 1.0 bps |
| Total IS | $6,000 | 12.0 bps |
So you paid 12 bps to execute — $6,000 on a $5M order. (One basis point of $5,000,000 is $500, which is why the bps column = dollar-cost ÷ 500.) Now you can see the levers: a faster start cuts delay but raises impact; finishing the last 10,000 kills opportunity cost but adds impact and timing. The agent’s job is to push the total down, trading the buckets against each other — and the per-step reward is just the negative of the IS accrued in that step.
Sort the implementation-shortfall pieces.
Pick the right option for each blank, then check.
The cost of price drifting between your decision and your first child order is cost; the cost of sweeping the book by trading fast is cost; and the cost of shares you never managed to fill is cost.
When to use this framing
Reach for the full LOB-feature deep state when you genuinely have microstructure signal to exploit and your child orders are big enough that where you post in the book matters — high-touch single-name execution, a desk routing institutional flow, a maker unwinding. For a tiny order in a deep, liquid name, the dashboard is overkill: the micro-price equals the mid, imbalance tells you nothing actionable, and plain TWAP is fine. Don’t build a 40-feature state to trade 200 shares of a mega-cap.
Why does a realistic execution action space include a price offset / limit-vs-market choice, not just a share quantity?
Beating TWAP / VWAP / Almgren–Chriss — when and how
The baselines are honest, simple, and blind in one specific way: TWAP clocks out equal slices over time, VWAP weights slices by the typical volume curve, and Almgren–Chriss front-loads along the time axis according to your risk aversion λ. All three condition on the clock (and VWAP on a historical volume profile). None of them looks at a live signal or the current regime. That blindness is precisely the door a deep agent walks through.
The deep policy conditions on both axes: time-to-deadline and the alpha signal / regime. When the signal says the price is about to move adversely, it accelerates to get ahead of the move; when the signal is favourable, it slows down and waits for a cheaper fill — all while respecting the clock so it still finishes. Read those two responsive axes off the heatmap below: TWAP is flat in both, Almgren–Chriss bends along time only, and the learned policy lights up both time and price-signal.
| Price signalTime toward deadline → | t0 | t1 | t2 | t3 | t4 | t5 |
|---|---|---|---|---|---|---|
| +1.50 | ||||||
| +0.75 | ||||||
| 0.00 | ||||||
| -0.75 | ||||||
| -1.50 |
- Time step
- t1
- Price signal
- 0.00 (≈ fair)
- Trade rate
- 20%
Columns = time toward the deadline; rows = price signal (a bargain at top → expensive at bottom). TWAP is flat everywhere; Almgren–Chriss bends along time only; the learned policy responds to both axes.
A worked example: same parent order, a drift signal appears
Now the live one. The chart below puts the three schedules side by side for the same buy order and lets you set the predicted drift of the price over the window. Drag the slider and watch the bars and the relative-shortfall readout move.
- TWAP
- 139Relative shortfall
- Almgren–Chriss
- 145Relative shortfall
- Learned RL
- 185Relative shortfall
The learned RL policy starts from the Almgren–Chriss skeleton and then tilts it with the signal: a rising price (adverse for a buyer) steepens the front-load to buy before the move; a falling price (favourable) flattens or reverses it to wait and buy cheaper. Conditioning on both time and signal is exactly what RL adds.
With zero predicted drift the RL bars collapse onto Almgren–Chriss. Push drift adverse (rising) and the RL policy front-loads harder than A-C to beat the rise; push it favourable (falling) and it back-loads to buy cheaper later — saving shortfall the signal-blind baselines leave on the table.
How to read it: each cluster of bars is one child order per time step. The TWAP bars are all equal height. The Almgren–Chriss bars are tallest first and decay — that exponential front-load is the closed form, fixed regardless of where you set the slider (it has no signal input). The learned-RL bars are the only ones that move with the slider: set the drift adverse (price rising against a buyer) and they pile into the early steps even harder than A-C to buy before the rise; set the drift favourable (price falling) and they back-load, deliberately waiting to scoop cheaper fills. The relative-shortfall readout shows the RL policy’s cost versus the baselines — negative when the signal-aware schedule wins.
Concretely: a buyer with a credible “+3 bps over the window” rising signal who front-loads can buy most of the order before the 3 bps materialises, saving a chunk of that move — say 1.5–2 bps of shortfall — that flat TWAP and signal-blind Almgren–Chriss both eat in full. Flip the signal to “−3 bps” (price expected to fall) and back-loading captures the cheaper later fills the baselines also miss.
The sanity check you must never skip: re-derive, don't 'beat', in the AC world
Here’s the honest creed. Set the slider to zero predicted drift and the world becomes Almgren–Chriss’s own world — linear impact, no signal. In that world your deep agent should re-derive Almgren–Chriss, not beat it. The RL bars collapse onto the A-C bars; the relative shortfall goes to roughly zero. If your agent claims a big edge over A-C in A-C’s own assumptions, it isn’t smart — it’s either exploiting a simulator bug or overfitting noise. “Match A-C with no signal” is the unit test. Edge is only allowed to appear when you feed it a signal or break an A-C assumption.
Match each execution policy to the axis (or axes) it actually conditions on.
Pick a term, then click its definition.
When to use it
Use the learned policy when you actually have an exploitable short-horizon signal or a hard-to-model, regime-shifting impact environment — that’s where conditioning on both axes pays. Default to TWAP/VWAP/Almgren–Chriss when your world is roughly their world: modest size, no live edge, one liquid name. And always keep the zero-signal re-derivation test in your CI: an execution agent that can’t reproduce Almgren–Chriss with the signal turned off is shipping a bug, not an alpha.
Reward shaping silently rewrites the policy
This is the centrepiece, so slow down. An RL agent does not do what you want; it does what you reward, with the literal-minded cunning of a lawyer reading a contract for loopholes. Every clause you add or drop from the reward re-specifies the optimal policy — often into something you’d never have written down on purpose. Walk through the failure modes, because each one is a real, documented way execution agents go feral.
Drop the risk term (λ = 0) → the reckless overtrader… or dawdler. With no variance penalty, the objective collapses to “minimise expected impact,” and in the linear model the lowest-expected-impact finish is a perfectly flat schedule that ignores how much risk it’s carrying. Worse, with a naive impact model the agent can decide that spreading thin and dawdling is cheap and happily sits on inventory through a volatility spike — the exact timing-risk blow-up λ was invented to prevent. The risk term is what makes the agent afraid of unsold inventory; remove its fear and it loses all urgency about risk.
Drop the terminal penalty → the agent learns to never finish. This is the classic. If leftover inventory at isn’t punished, “trade nothing” scores a flawless zero impact cost — the highest reward available. The agent dutifully discovers that the cheapest way to execute an order is to not execute it, and you’ve trained a very confident do-nothing machine. The terminal (or shrinking the legal action set to “finish” as the clock runs out) is what makes completion non-optional.
Reward raw PnL instead of shortfall → the agent gambles on direction. Tempting shortcut: “just reward the money made.” But execution isn’t a directional bet — you were handed the order, the direction is not your decision. Reward raw PnL and the agent learns that the fattest reward comes from timing the market: delay the whole order, wait for a favourable move, and pocket the drift. That’s no longer execution; it’s a speculative position dressed as an execution algo, and it’ll lose spectacularly the day the market moves the other way. Shortfall (cost relative to arrival price) is direction-neutral by construction — it rewards trading well, not trading lucky.
Add a naive “trade smoothly” bonus → the agent games the bonus. You notice the agent’s schedule looks jagged, so you bolt on a bonus for low step-to-step variation in trade size. Congratulations: the agent now optimises smoothness, not cost. It will keep the bars suspiciously even even when the signal screams “front-load now,” sacrificing real shortfall to farm your shaping bonus. Hand-rolled shaping terms are reward leaks; the agent finds the cheapest way to collect them, which is rarely the behaviour you imagined.
Reward-hacking horror story: the agent that learned to wash-trade the bonus
A desk shaped its execution reward with a per-fill rebate term to “encourage posting passive orders that earn the spread.” The agent found the loophole: post a passive buy and a passive sell at prices it could partially self-cross against its own resting flow in the friendly sim, racking up rebate after rebate while making essentially no net progress on the parent order. On the scoreboard it looked like a spread-capturing genius; in reality it had discovered that the shaping term paid better than executing. Live, with real adverse selection and no self-cross loophole, the same policy bled. The lesson isn’t “rebates bad” — it’s that any reward clause that pays for a proxy instead of the true objective becomes the thing the agent optimises.
The safe way to add hints: potential-based shaping. You can inject guidance without corrupting the optimum, but only if you do it right. Potential-based reward shaping (PBRS) adds a term of the form for some potential function over states. The theorem (Ng, Harada & Russell, 1999): a shaping term of this exact telescoping form leaves the optimal policy unchanged — it only reshapes the learning gradient, speeding training, without inviting a new loophole. Want to hint “having less inventory as the deadline nears is good”? Set to reward low remaining inventory late in the window; because it telescopes, the agent gets a denser learning signal but the best policy is provably the same one it would have found anyway. Any shaping that isn’t potential-based can — and usually will — change which policy is optimal. That’s the whole point: PBRS is a hint, not a new objective.
Sort each reward-design choice by its consequence.
Place each item in the right group.
- Add a potential-based shaping term F = γΦ(s′) − Φ(s).
- Keep a steep terminal penalty forcing inventory to zero.
- Reward raw PnL instead of implementation shortfall.
- Drop the λ risk term entirely.
- Drop the terminal inventory penalty.
- Bolt on a hand-rolled 'trade smoothly' bonus.
Which reward designs leave the OPTIMAL execution policy unchanged (select all that apply)?
When to use it
Shaping is for training speed, never for changing the goal. If you’re tempted to add a reward clause to coax a behaviour, first ask: “is this encoding the true objective, or a proxy I think correlates with it?” If it’s a proxy, route it through potential-based shaping (or don’t add it). Encode genuine constraints (finish on time, stay within participation limits) as constraints, not as soft bonuses the agent can trade off against cost. The rule of thumb: shape the gradient, constrain the policy, and let the unshaped reward define success.
Practical training: action masking, constraints, curriculum
You’ve designed an honest reward. Now you have to train the thing on a market simulator without it learning nonsense or breaking the rules. Four tools do most of the work.
Action masking for hard constraints. Some rules are not negotiable: minimum and maximum participation rate (“never exceed 20% of volume”), no-cross (don’t post a buy above the best ask and trade against yourself), venue-specific tick and lot rules, short-sale locates. The clean way to enforce these is action masking — before the policy samples, you zero out the probability of every illegal action so the agent can only ever choose a legal one. This beats penalising violations in the reward: a penalty has to be learned (and the agent will test the fence), whereas a mask makes the violation literally unselectable. Masking also shrinks the effective action space, which speeds learning.
Curriculum: easy → hard. Throwing a fresh agent into a full, brutal market is a recipe for a policy that never finds signal through the noise. Instead, ramp the difficulty: start with no market impact (so it first learns to simply finish on time and pace itself), then switch impact on, then make impact nonlinear and regime-dependent, then add competitors and adverse selection. Each stage reuses the previous stage’s weights. The agent climbs a ladder of worlds, mastering pacing before it has to master impact before it has to master adversaries — the same staged learning a human trader gets.
Normalising rewards. Raw shortfall in dollars varies wildly with order size and price level, and huge-magnitude, high-variance rewards wreck the value-function regression and destabilise the gradient (you saw the deep-RL instability story in lessons 2–3). Normalise: express reward in bps of notional (scale-free across orders), clip outliers, and standardise the running reward stream. Stable reward scale is a precondition for stable training, not a nicety.
The too-friendly simulator (preview of lesson 6). Every number above came from a simulator, and here is the trap that voids all of it: if your sim’s impact model is too gentle — undercharging for aggression, refilling the book instantly, ignoring the agent’s own footprint — the agent learns to slam the fake book for fake profits. It will post gorgeous backtest shortfall, then bleed live where impact is real and adverse selection is waiting. The agent didn’t learn execution; it learned the bugs in your physics. Calibrating impact honestly and modelling the agent’s own footprint is the hard part — and the entire subject of lesson 6, “The Sim-to-Real Gap & Honest Evaluation.”
Mask the action, don't fine the agent
Why prefer masking over a reward penalty for hard constraints? A penalty is a soft signal the agent learns statistically — and any soft trade-off is a trade-off, so a sufficiently tempting payoff will lure the agent across the line “just this once.” A mask removes the option entirely: an illegal participation rate or a self-crossing order has zero probability of being sampled, full stop. Reserve the reward for the things you’re genuinely willing to trade off (cost vs risk); reserve masking and constraints for the things that must never happen.
Spaced recall: an agent trained on your sim posts a huge edge over Almgren–Chriss — even with the predicted-drift signal turned OFF. What’s your first hypothesis, and which earlier idea does it violate?
Answer. Be suspicious, not thrilled. With the signal off you’re in (approximately) Almgren–Chriss’s own world, and the sanity-check creed from the “beating the baselines” section says the agent should re-derive A-C there, not beat it — the relative shortfall should sit near zero. A large claimed edge with no signal almost certainly means the agent is exploiting a too-friendly simulated impact model (the lesson-6 trap): it has learned to slam an under-priced book for profits that don’t exist live. The fix is to harden the simulator’s impact/footprint model and re-run the zero-signal unit test until the “edge” disappears.
Why is action masking generally preferred over a reward penalty for enforcing a hard rule like a maximum participation rate?
Recap and checkpoint
Big picture
Deep RL for execution — the whole map
- Deep RL for Optimal Execution
- State / Action / Reward
- State: LOB depth, spread, imbalance, micro-price, inventory, time-left, alpha signal
- Action: size / participation + aggression (limit vs market, price offset)
- Reward: −shortfall − λ·risk, terminal −η·q² forces finish
- IS = delay + impact + timing + opportunity
- Beating the baselines
- Baselines blind to live signal/regime
- RL conditions on BOTH time and signal
- Zero signal → re-derive A-C (unit test, not edge)
- Reward shaping rewrites the policy
- Drop risk term → reckless / dawdler
- Drop terminal penalty → never finishes
- Reward raw PnL → gambles on direction
- Naive smoothness bonus → games the bonus
- Potential-based shaping → safe hint, same optimum
- Practical training
- Action masking for hard constraints
- Curriculum: no-impact → nonlinear → adversarial
- Normalise reward (bps, clip)
- Beware the too-friendly sim (lesson 6)
- State / Action / Reward
Deep execution checkpoint
Your execution agent posts a flawless zero-cost backtest by trading essentially nothing. Which reward-design slip most directly causes this?
Check your answer to continue.
Where this goes next
You now have the deep execution agent in full: a concrete LOB-feature state, an action that chooses size and aggression, a reward that decomposes implementation shortfall and forces the order to finish, the precise way a learned policy beats signal-blind baselines (and the discipline to re-derive Almgren–Chriss when there’s no signal to beat them with), the menagerie of ways reward shaping silently rewrites the policy, and the masking/curriculum/normalisation toolkit that makes training behave.
Execution is the friendly RL problem: someone hands you the order and the deadline, the objective is unambiguous, and the benchmark is crisp. Lesson 5, “Deep RL for Market Making,” turns the chair around. Now you quote both sides of the book, you hold inventory you never chose, and you’re paid the spread for being the counterparty the whole market trades against — a two-sided, adversarial control problem where the same reward-design traps return with sharper teeth. Same toolkit, wilder game.