The Feynman–Kac Formula
Mathematics has two great languages for change. The analyst's is the partial
differential equation: a local law, obeyed point by point, solved by calculus. The
probabilist's is the random path: a particle jittering through time, its
future summarised by an expectation. The Feynman–Kac formula says they are
the same language: the solution of a parabolic PDE can be written as an expectation
over random paths — and any such expectation solves a PDE. Cross the bridge one way and a
probability problem becomes calculus; cross it the other and a differential equation can be
solved by rolling dice.
For us the stakes are concrete. We have priced an option two ways: by solving the
Black–Scholes PDE,
and by taking a
risk-neutral expectation.
They had better agree — and Feynman–Kac is the theorem that guarantees they do. In general
form: let X follow the diffusion
dX = a(t, X)\,dt + b(t, X)\,d\tilde W, and suppose
u(t, x) solves the terminal-value problem
u_t + a\,u_x + \tfrac12 b^2\,u_{xx} - r\,u = 0, \qquad u(T, x) = g(x).
Then u is an expectation of the terminal data
g, carried along the diffusion and discounted at
r:
u(t, x) = \mathbb{E}\big[\,e^{-r(T - t)}\,g(X_T)\,\big|\,X_t = x\,\big].
The Black–Scholes PDE is exactly this with a = rS and
b = \sigma S. But before proving it, learn to read it —
every symbol in the PDE names an ingredient of the random path.
The dictionary: read the PDE as a recipe for a path
Feynman–Kac is best memorised as a dictionary between the two languages. Lay
the Black–Scholes PDE and the risk-neutral SDE side by side,
u_t + \underbrace{rS}_{\text{drift}}\,u_S + \tfrac12 \underbrace{\sigma^2 S^2}_{\text{diffusion}^2}\,u_{SS} - \underbrace{r}_{\text{discount}}\,u = 0
\qquad\longleftrightarrow\qquad dS = \underbrace{rS}_{a}\,dt + \underbrace{\sigma S}_{b}\,d\tilde W,
and translate term by term:
-
The coefficient of u_S is the SDE's drift
a. Here it is rS — the
risk-neutral drift, because the PDE came from a no-arbitrage argument. Whatever
multiplies the first spatial derivative tells the particle which way to lean.
-
The coefficient of u_{SS} is half the squared diffusion,
\tfrac12 b^2. Here \tfrac12\sigma^2 S^2,
so b = \sigma S. Second derivatives are the fingerprint of
randomness — they enter through the (dX)^2 = b^2\,dt term of
Itô's lemma,
which is why the \tfrac12 is there.
-
The zeroth-order term -ru is the discount factor
e^{-r(T-t)} in front of the expectation. Probabilists call it
killing: imagine the particle dying at rate r, and the
expectation only counting payoffs from survivors.
-
The terminal condition u(T, x) = g(x) is the payoff
— the function you evaluate at the path's endpoint X_T.
The dictionary works in both directions. Handed a PDE you cannot solve on paper, read
off a, b, r,
g, simulate the SDE, and average. Handed an expectation you cannot
compute, write down its PDE and hit it with a century of numerical analysis. One theorem, two
solvers.
The bridge, line by line
Why is the theorem true? The strategy is the one that keeps recurring in this subject: form the
right
martingale,
then take its expectation. We apply
Itô's lemma
to the discounted process Y_t = e^{-rt}\,u(t, X_t) and watch the PDE
make all the drift vanish. Every step below is mechanical; the miracle is in step 3, where the
equation and the probability lock together.
Step 1 — Itô on the discounted process. With
Y_t = e^{-rt}u(t, X_t), the product/chain rule of Itô gives a
discount term plus the Itô expansion of u:
dY_t = e^{-rt}\Big( -r\,u + u_t + a\,u_x + \tfrac12 b^2\,u_{xx}\Big)\,dt + e^{-rt}\,b\,u_x\,d\tilde W_t.
Step 2 — group the dt terms.
The bracket multiplying dt is
u_t + a\,u_x + \tfrac12 b^2\,u_{xx} - r\,u.
Step 3 — invoke the PDE. But that bracket is exactly the left-hand
side of the PDE u was assumed to solve — and it equals zero. The
entire drift annihilates:
u_t + a\,u_x + \tfrac12 b^2\,u_{xx} - r\,u = 0 \quad\Longrightarrow\quad dY_t = e^{-rt}\,b\,u_x\,d\tilde W_t.
Step 4 — recognise a martingale. What remains is a pure
d\tilde W differential — no dt drift left
— so (under the usual integrability conditions) Y_t = e^{-rt}u(t, X_t)
is a martingale. The PDE was precisely the condition needed to kill the drift. This is the
heart of the whole subject: a parabolic PDE is nothing but the statement that a certain
process is a martingale.
Step 5 — take the conditional expectation. A martingale forecasts itself:
Y_t = \mathbb{E}[Y_T \mid \mathcal{F}_t]. Writing both ends out,
e^{-rt}u(t, X_t) = \mathbb{E}\big[\,e^{-rT}u(T, X_T)\,\big|\,\mathcal{F}_t\,\big].
Step 6 — apply the terminal condition and rearrange. At
T, u(T, X_T) = g(X_T). Multiply by
e^{rt} and use the Markov property
(X from X_t = x forgets its past):
u(t, x) = \mathbb{E}\big[\,e^{-r(T - t)}\,g(X_T)\,\big|\,X_t = x\,\big].
The solution of the PDE is a discounted expectation along the diffusion — that is the
bridge. Specialised to a = rS,
b = \sigma S, and the call payoff
g(S) = (S - K)^+, it reproduces the risk-neutral price exactly.
Suppose u(t, x) solves the terminal-value problem
u_t + a(t, x)\,u_x + \tfrac12 b(t, x)^2\,u_{xx} - r\,u = 0, \qquad u(T, x) = g(x),
where dX_s = a(s, X_s)\,ds + b(s, X_s)\,d\tilde W_s. Then, under
mild growth conditions,
u(t, x) = \mathbb{E}\big[\,e^{-r(T - t)}\,g(X_T)\,\big|\,X_t = x\,\big].
In particular the Black–Scholes PDE price and the risk-neutral expectation are the
same number: PDE solution = discounted expected payoff.
Feynman–Kac is the keystone that unifies this whole chapter. The
replication/PDE
derivation and the
measure-change/expectation
derivation are not two competing answers; they are the same answer viewed analytically versus
probabilistically. The drift of the discounted value vanishes for the same algebraic
reason in both: in the PDE it is the equation set to zero, in the expectation it is the
martingale property.
This duality is also intensely practical. It hands the quant two numerical
methods for the price of one theorem:
-
Finite differences on the PDE — discretise the
(t, S) grid and march the equation backward from the terminal
payoff. Fast and accurate in low dimensions.
-
Monte-Carlo on the expectation — simulate many risk-neutral paths, average
the discounted payoffs (exactly the figure in risk-neutral pricing). The method of choice
in high dimensions, where the PDE grid explodes.
Feynman–Kac is the guarantee that, run correctly, the two agree. Real desks exploit the
split daily: vanilla books are marked with PDE grids, while a basket option on twenty
underlyings — a PDE in twenty space dimensions, hopeless on any grid — is priced by
simulation without a second thought.
Worked example 1: the heat equation is Brownian motion
Strip the theorem to its simplest case and it becomes something you can verify with bare hands.
Set the drift a = 0, the diffusion b = 1
and the rate r = 0. The diffusion is then plain Brownian motion,
dX = d W, and the PDE collapses to the
(backward) heat equation:
u_t + \tfrac12 u_{xx} = 0, \qquad u(T, x) = g(x)
\qquad\Longrightarrow\qquad u(t, x) = \mathbb{E}\big[\,g(W_T)\,\big|\,W_t = x\,\big].
In words: the temperature at x is the average of the terminal
data over where a Brownian particle started at x ends up.
Since W_T given W_t = x is Gaussian with
mean x and variance \tau = T - t, the
expectation is a convolution with a Gaussian bell — which is exactly the classical heat kernel.
Brownian motion is the heat kernel wearing a probabilist's hat.
Check it on an explicit payoff. Take g(x) = x^2.
Writing W_T = x + Z with
Z \sim N(0, \tau):
u(t, x) = \mathbb{E}\big[(x + Z)^2\big] = x^2 + 2x\,\mathbb{E}[Z] + \mathbb{E}[Z^2] = x^2 + (T - t).
Now differentiate the answer and confirm it really solves the PDE:
u_t = -1, u_x = 2x,
u_{xx} = 2, so
u_t + \tfrac12 u_{xx} = -1 + 1 = 0 — satisfied — and at
t = T the extra term dies, leaving
u(T, x) = x^2 = g(x). The expectation solved the equation without a
single separation of variables. Notice what the formula is saying: far from expiry the
surface x^2 + \tau floats above the payoff by the accumulated
variance; as t \to T it settles down onto it.
The figure below shows the same phenomenon for the option-like payoff
g(x) = x^+ = \max(x, 0). The dashed hockey-stick is the terminal
data; the solid curve is u(t,x) = \mathbb{E}[\,g(x + W_\tau)\,],
which works out to x\,\Phi(x/\sqrt{\tau}) + \sqrt{\tau}\,\varphi(x/\sqrt{\tau}).
Slide the time-to-maturity \tau: more time means more Brownian
spread, so the expectation smooths the kink away — heat diffusing through a sharp corner. At
\tau = 0 the two curves coincide, exactly as the terminal condition
demands.
Worked example 2: two toy contracts, priced both ways
Back in the Black–Scholes world (a = rS,
b = \sigma S), it is worth confirming the bridge holds in cases you
can verify on both sides. Take first the trivial payoff
g(S) = 1 — a contract paying one unit of cash at
T no matter what. The expectation side is immediate:
u(t, S) = \mathbb{E}\big[\,e^{-r(T - t)}\cdot 1\,\big] = e^{-r(T - t)}.
Now check the PDE side. With u = e^{-r(T - t)} independent of
S, the spatial derivatives vanish, and
u_t = r\,e^{-r(T - t)} = r u. The PDE reads
u_t + rS u_S + \tfrac12\sigma^2 S^2 u_{SS} - r u = r u + 0 + 0 - r u = 0
— satisfied, with terminal value u(T, S) = 1. The discount bond
prices itself.
Second contract: the stock itself, g(S) = S
(equivalently, a forward). The expectation side uses the fact that under the risk-neutral
measure the stock grows at rate r on average,
\mathbb{E}[S_T \mid S_t = S] = S\,e^{r(T-t)}:
u(t, S) = e^{-r(T - t)}\,\mathbb{E}[S_T \mid S_t = S] = e^{-r(T - t)}\,S\,e^{r(T - t)} = S.
The discounting and the risk-neutral growth cancel exactly — today's price of
receiving the stock at T is just today's stock price. PDE side:
try u = S. Then u_t = 0,
u_S = 1, u_{SS} = 0, and
0 + rS\cdot 1 + 0 - rS = 0 — satisfied, with
u(T, S) = S = g(S). Both toy contracts agree on both sides of the
bridge, for structurally different reasons: the bond because the -ru
term eats u_t, the forward because the drift term eats it. The same
machinery, applied to (S - K)^+, yields the full
Black–Scholes formula
— the integral is just longer.
Pricing by dice: the Monte-Carlo consequence
Read the theorem right-to-left one more time and a numerical method falls out for free. The
price is an expectation; the law of large numbers says an expectation is (almost surely) the
limit of a sample average. So: simulate N
independent risk-neutral paths of the SDE, evaluate the payoff on each
terminal value, average, and discount:
u(0, S_0) \;\approx\; e^{-rT}\,\frac1N \sum_{i=1}^{N} g\!\big(S_T^{(i)}\big),
\qquad S_T^{(i)} = S_0\,\exp\!\Big(\big(r - \tfrac12\sigma^2\big)T + \sigma\sqrt{T}\,Z_i\Big),\; Z_i \sim N(0,1).
That is a PDE being solved by a random-number generator. The error shrinks like
1/\sqrt{N} — slow, but blissfully independent of dimension, which is
why simulation wins the moment the payoff depends on many underlyings. Run it yourself: the
snippet prices a call by both routes and prints them side by side. Bump N and
watch the dice converge on the calculus.
// A European call priced two ways: exact Black–Scholes vs Monte-Carlo on the expectation.
const S0 = 100, K = 100, r = 0.05, sigma = 0.2, T = 1;
// Standard normal CDF via an erf approximation (Abramowitz & Stegun 7.1.26).
function Phi(z: number): number {
const x = Math.abs(z) / Math.SQRT2;
const t = 1 / (1 + 0.3275911 * x);
const erf = 1 - (((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t
- 0.284496736) * t + 0.254829592) * t) * Math.exp(-x * x);
return z >= 0 ? 0.5 * (1 + erf) : 0.5 * (1 - erf);
}
// Route 1: the closed-form PDE solution (the Black–Scholes formula).
const d1 = (Math.log(S0 / K) + (r + 0.5 * sigma * sigma) * T) / (sigma * Math.sqrt(T));
const d2 = d1 - sigma * Math.sqrt(T);
const exact = S0 * Phi(d1) - K * Math.exp(-r * T) * Phi(d2);
// Route 2: Feynman–Kac says the same number is a discounted expectation — so simulate it.
const N = 20000;
let sum = 0;
for (let i = 0; i < N; i++) {
// Box–Muller: turn two uniform dice rolls into one standard normal Z.
const Z = Math.sqrt(-2 * Math.log(1 - Math.random())) * Math.cos(2 * Math.PI * Math.random());
const ST = S0 * Math.exp((r - 0.5 * sigma * sigma) * T + sigma * Math.sqrt(T) * Z);
sum += Math.max(ST - K, 0); // the payoff g(S_T) = (S_T − K)⁺
}
const mc = Math.exp(-r * T) * (sum / N); // average, then discount
console.log(`PDE / closed form : ${exact.toFixed(4)}`);
console.log(`Monte-Carlo (N=${N}): ${mc.toFixed(4)}`);
console.log(`difference : ${(mc - exact).toFixed(4)} (shrinks like 1/sqrt(N))`);
The dictionary is simple, but three details bite almost every newcomer:
-
The drift must be read under the same measure as the PDE.
Feynman–Kac pairs the PDE's u_x coefficient with the SDE's drift
— whatever that drift is. The Black–Scholes PDE has drift coefficient
rS, so the paths you simulate for pricing must drift at
r: the risk-neutral dynamics. Feeding in the stock's
real-world drift \mu S gives a perfectly good Feynman–Kac
representation — of the solution to a different PDE, one that is not the
no-arbitrage price. Pricing paths drift at r, full stop.
-
Terminal-value problems run backward in time. The textbook heat
equation u_t = \tfrac12 u_{xx} starts from initial data and
diffuses forward. Finance PDEs carry their data at t = T (the
payoff) and are solved backward toward today — which is why our equation reads
u_t + \tfrac12 b^2 u_{xx} + \dots = 0 with a plus sign:
it is the heat equation under the time flip \tau = T - t. Mix up
the sign or the direction of the march and your "price" diffuses the wrong way and blows up.
-
The -ru term is "killing", not drift. It does not
push the path anywhere — it weights the payoff by e^{-r(T-t)}.
Probabilists picture the particle being killed at rate r, the
expectation counting only survivors; financiers call the same factor a discount. Forgetting
it (or applying it twice — once in the simulation and once at the end) is a classic
Monte-Carlo bug.
The name records an accident of the seminar schedule. In 1947 at Cornell, Richard
Feynman lectured on his new formulation of quantum mechanics: the amplitude of
a particle is a sum over every path it might take — the path integral. In the audience
sat the probabilist Mark Kac (rhymes with "lots"), who recognised the trick
at once: Feynman's sum was, mathematically, an expectation over random trajectories — and
where the oscillating quantum weights defied rigour, replacing time by imaginary time
turns Schrödinger's equation into the heat equation, whose paths are honest Brownian motion.
"It occurred to me that I could do the same thing with Wiener's integral," he recalled. Within
a year he had the rigorous theorem you have just proved — quantum mechanics' wildest idea,
domesticated by probability, and decades later handed to finance.
The dice half of the story starts in the same few years. In 1946 Stanislaw
Ulam, convalescing and playing solitaire, realised the chance of winning was
easier to estimate by dealing a hundred games than to compute — and that the same
idea would crack the neutron-diffusion equations stalling Los Alamos. John
von Neumann wired it into the ENIAC, and Nicholas Metropolis christened the
method after the casino at Monte Carlo where Ulam's uncle gambled. Solving a
diffusion PDE by sampling random paths is Feynman–Kac run right-to-left; today's
pricing farms are running, almost unchanged, a wartime idea born of solitaire.