The Policy Gradient Theorem
A recipe for improving a decision-making policy by nudging up the probability of actions that turned out well, even when the environment is a black box you cannot differentiate through. It is the foundation of REINFORCE, actor-critic and PPO.
Prerequisites: Markov Decision Processes, Expected Value, Stochastic Gradient Descent
Value-based methods like Q-Learning work by scoring every action and then taking the best one. That is fine when there are five actions. It falls apart when the action is a number — how many shares to send, how wide to quote, what fraction of the book to lift — because you cannot enumerate a continuum, and it falls apart again when the right behaviour is deliberately random, as it is for any market maker who does not want to be predictable. What you want instead is to hold the decision rule itself in your hands, with dials on it, and turn the dials in whichever direction makes money.
The obstacle is that you cannot differentiate profit with respect to those dials. Profit comes out of the market, and the market is not a function you have source code for. You cannot compute "how would my P&L have changed if I had quoted one tick tighter," because you never ran that world.
Here is the way around it, and it is worth sitting with before any symbols appear. Imagine a coach who does not understand the sport. She cannot analyse why a play works. All she can do is call plays from a deck, watch the score, and then reshuffle the deck: plays that were followed by good outcomes get more copies, plays followed by bad outcomes get fewer. She never learns the physics of the game, yet the deck steadily improves. The policy gradient theorem is the precise, unbiased version of that reshuffling — and crucially, it needs only the probabilities she assigned to her own plays, never a model of the game.
Setting up the dials
Write the policy as : the probability of choosing action when the state is , where is the vector of parameters — the dials, or the weights of a neural network. Unlike a value table, this outputs probabilities directly, so randomness is built in rather than bolted on.
The thing we want to maximise is , the expected total reward earned over an episode when actions are drawn from . In words: the average P&L of the strategy, if you ran it many times. We would like , the direction in dial-space that raises that average fastest.
The theorem
In plain English: to improve the policy, take each action you actually took, ask "which way should I move the dials to make this action more likely," and scale that direction by how good the action turned out to be. Good actions get pushed up hard, mediocre actions get a gentle push, bad actions get pushed down.
Two things are remarkable about this. First, — called the score function — depends only on your own policy. You wrote it; you can differentiate it. The environment never appears inside a derivative. Second, the expectation is over trajectories you can simply sample, so an average over a batch of real episodes is an unbiased estimate of the true gradient. No model, no simulator, no dynamics.
Worked example: one honest update
Take the simplest possible policy: two actions, two dials , probabilities from a softmax. Start at , so both actions are equally likely at .
For a softmax policy the score function has a famously clean form: for the action you took, the derivative is ; for every action you did not take, it is . Read it as "raise the one you played, lower the rest, in proportion to how surprised you should have been."
Now sample. The agent plays action 1 and collects a return of .
Step 1 — the score function at the sampled action:
Step 2 — scale by the return:
Step 3 — take a gradient ascent step with learning rate :
Step 4 — read off the new probabilities. With and summing to :
The probability of the action that worked rose from to about . Nothing about the environment was ever consulted.
Worked example: why a baseline is nearly free money
Now suppose both actions pay well: action 1 returns 10, action 2 returns 12. Start again at with both probabilities , and sample two episodes — one of each action.
Without a baseline:
Averaging them gives . The direction is right — favour action 2 — but look at the scale. The signal is while the individual samples were and . You are extracting a whisper from two shouts that nearly cancel, and with real noise you would need thousands of episodes to hear it.
With a baseline , the average return, subtracted from each return:
The average is — identical. But now the two samples agree perfectly instead of disagreeing violently. Same answer, a fraction of the variance.
That is the single most important practical corollary of the theorem: you may subtract any quantity that does not depend on the action without biasing the gradient, because the probabilities sum to one and the extra term cancels in expectation. Choosing , the state's average value, turns into the advantage — "was this action better or worse than typical here" — and every modern algorithm from Actor-Critic Methods to Proximal Policy Optimization is built on it.
Policy gradient is still gradient ascent, so it inherits every pathology of a step-size choice. Drag the learning rate below and watch the same three failure modes you get anywhere else — crawling, converging, and overshooting into instability.
What this means in practice
If you are training an execution agent, the policy gradient is what lets the action be "send of remaining size" rather than a menu of five choices. If you are training a market maker, it is what lets the quote be genuinely stochastic so it is not picked off by pattern-matching counterparties.
What breaks in practice is almost always variance, not bias. Financial rewards are dominated by noise — the same policy on the same day can make or lose money for reasons it did not cause. So the gradient estimate is honest but extremely wobbly, and vanilla REINFORCE on market data typically needs far more episodes than you have. The fixes are all variance reductions: subtract a learned baseline, use advantage estimates over short windows, average over large batches, and clip how far the policy can move in a single update.
Differentiate the probability of the action, not the reward. The environment never gets differentiated — it only supplies a scalar that says how hard to push. That is why policy gradients work on black boxes, discrete jumps, and anything else with no usable derivative.
The most common misreading is thinking is telling you which action was correct, like a supervised-learning label. It is not. It points toward making the action you happened to sample more likely, full stop. The return is the only thing deciding whether that is a good idea, and it may be negative, in which case the very same vector is used to push the action down. A second, related trap: subtracting a baseline is often assumed to bias the result toward the baseline. It does not — the expected gradient is unchanged, only its variance shrinks.
The theorem is the bridge from "score the actions" to "tune the behaviour", and it underwrites The REINFORCE Algorithm, Actor-Critic Methods and Generalized Advantage Estimation alike.
Related concepts
Practice in interviews
Further reading
- Sutton, McAllester, Singh & Mansour, Policy Gradient Methods for RL with Function Approximation (2000)
- Sutton & Barto, Reinforcement Learning: An Introduction (ch. 13)
- Williams, Simple Statistical Gradient-Following Algorithms (1992)