Stochastic Control and the HJB Equation
How to make the best decision at every instant when the future is random: the Hamilton-Jacobi-Bellman equation turns a lifetime of choices into one equation about right now.
Prerequisites: The Bellman Equations, Itô's Lemma, Brownian Motion
Suppose you manage a portfolio and can rebalance continuously between a risky asset and cash. How much should you hold in the risky asset, at every instant, for the rest of your life, to maximise how happy you'll be with your final wealth? You can't just pick one number — the right allocation depends on how much wealth you currently have, how much time is left, and the fact that tomorrow's price is random. Answering "what should I do right now" when the future keeps branching randomly is what stochastic control is for, and the Hamilton-Jacobi-Bellman (HJB) equation is the single equation that answers it.
The analogy: a canoeist crossing a river with a current that shifts by the minute
Picture paddling across a river to reach a dock, but the current's strength and direction drift randomly as you go. You can't plan your whole route in advance — a plan made now will be wrong five minutes from now, when the current has changed. The only sane strategy is a rule: at every point in the river, given how the current feels right now, choose the paddling direction that gives you the best expected outcome from here onward. That rule is a function of your position and the current, not a fixed list of moves. The HJB equation is the mathematical machine that produces exactly this kind of rule for any random system: instead of planning the whole journey, it tells you the best action at every possible state, at every moment, accounting for all the randomness still to come.
Writing it down
Let be the state of the system at time — in the canoe story, your position; in finance, your wealth. You pick a control at each instant — your paddling direction, or the fraction of wealth in stocks — and the state evolves as a stochastic differential equation:
In words: the state drifts by an amount that depends on where you are and what you do, plus a random wiggle of size driven by Brownian motion , whose size also depends on your state and your choice.
You want to choose at every instant to maximise the expected value of a reward — some running payoff collected along the way plus a payoff at the final time :
In words: , the value function, is the best expected total payoff you can achieve if you're in state at time and play optimally from there on. It is the entire point of the exercise — everything else builds toward computing .
The HJB equation is what must satisfy. It comes from a one-line argument: the best thing to do over a tiny interval is to pick the that maximises the instant's reward plus the expected change in the future's best value, and by Itô's lemma that expected change is . Setting the best achievable rate of improvement to zero (since is already optimal) gives:
In words: at every instant, the rate the value function is falling due to time passing () is exactly offset by the best you can currently extract — the running reward , plus how a small nudge in the state moves value (, the marginal value of the state), plus a correction for the randomness itself (, curvature — this is the same Itô correction that shows up everywhere randomness meets calculus). The maximisation inside the brackets is solved pointwise, for each separately — that is what turns an infinite-dimensional planning problem into something you can actually compute.
Drag the drift and volatility here and watch how the paths fan out. HJB is the tool that decides, at every point along a fan like this, what action keeps the expected best outcome highest — not just for one path, but averaged over every path that could still happen.
Worked example 1: the merton problem, one step at a time
Take the classic setup: wealth , invest fraction in a risky asset with expected return and volatility , rest in cash earning zero, no consumption, maximise . Wealth evolves as . Guess for some function (log utility has this clean separable form). Then , , and the HJB equation becomes
The bracket is a plain quadratic in — maximise it by calculus: differentiate with respect to , set to zero: , so . Plug numbers in: , , so . This says invest 200% of wealth in the risky asset — borrowing 100% of wealth to lever up — because log utility with this risk-reward ratio wants that much exposure. Note the answer didn't depend on wealth or time at all; that constant-fraction result is the celebrated Merton finding, and it dropped straight out of solving the bracket.
Worked example 2: a two-state grid, done by hand
Take a toy two-period, two-state version to see the "solve backward" logic without calculus. Wealth is either $90 or $110 at time 1 (equally likely), and at time 1 you choose to hold cash (locks in current wealth) or a coin-flip bet that pays $20 gain or $20 loss with equal probability. Utility is .
At $90: cash gives . The bet gives . Cash wins, so .
At $110: cash gives . The bet gives . Cash wins again, .
Working backward from these values to time 0 is exactly the HJB logic in discrete form: at each state, compare the payoff of each action plus the already-computed future value, and keep the best. The continuous-time HJB equation is the same backward sweep, shrunk to instants and solved with calculus instead of a lookup table.
What this means in practice
- Portfolio choice, market making, and execution algorithms all reduce to an HJB equation. Optimal execution (how fast to sell a large block) and market-maker quoting (Avellaneda-Stoikov) are both HJB problems with different state variables.
- Solving HJB by hand only works for a few tidy cases (log or power utility, linear dynamics). Real trading desks solve it numerically — on a grid, or via reinforcement learning, which is secretly approximating the same value function.
- The verification theorem matters. A function that satisfies the HJB equation and the right boundary conditions is provably the optimal value — this is what justifies trusting a numerically computed policy in production.
The HJB equation turns "find the best plan over a random future" into "at every state, right now, pick the action that maximises immediate reward plus the expected rate of change of the best-possible future value." Solving it backward from the endpoint mirrors ordinary dynamic programming; the only new ingredient is the Itô correction term for randomness in the state.
The classic confusion is treating the HJB equation as something you solve forward, the way you'd simulate a path. You cannot — the value function at time depends on optimal decisions all the way to the terminal time , so it must be computed backward from to , exactly like discrete-time dynamic programming. A second, related trap: forgetting that the maximisation over happens inside the equation, separately at every . Students often solve for a single "optimal " as if it were one number for the whole problem, when in general it is a full function of time and state — it only collapsed to a constant in the Merton example because of the special structure of log utility.
Related concepts
Practice in interviews
Further reading
- Fleming & Soner, Controlled Markov Processes and Viscosity Solutions (ch. 2)
- Merton, Optimum Consumption and Portfolio Rules in a Continuous-Time Model (1971)
- Pham, Continuous-time Stochastic Control and Optimization with Financial Applications (ch. 3)