Module contents
Lesson 29 of 31Advanced 115 min

Change of measure: Girsanov, martingale representation and conditioned processes

Change probability measures on paths with Girsanov and Novikov, calculate KL divergence between diffusion laws, apply importance sampling to rare events, and study martingale representation and Doob's h-transform.

After this lesson you can

  • Prove constant-drift Girsanov and apply it to change Brownian drift.
  • Verify Novikov in examples and construct a strict-local-martingale counterexample.
  • Calculate KL divergence between diffusions and connect it to a learned-drift loss.
  • Estimate rare path-event probabilities with importance sampling and reduce variance.
  • Derive Brownian bridge drift as an h-transform and simulate endpoint-conditioned diffusions.

Before you start

Changing path probabilities

In risk simulation you may need an event so rare that almost no path reaches it. In valuation you may work under another measure; in generative models you may compare complete path laws. In all three cases, changing measure assigns new weights to the same possible outcomes.

On a finite space, if Pi>0P_i>0, a new law QiQ_i is constructed by wi=Qi/Piw_i=Q_i/P_i: for any function FF, EQF=EP[wF]E_QF=E_P[wF] and EPw=1E_Pw=1. Highly unequal weights do not change the identity, but make it difficult to estimate with a finite sample.

InteractiveThe same cloud, different weights

We generate 1200 Brownian paths under P in 48 intervals. The chart shows the first 12 paths and the eight with greatest weight, without duplicates. Thickness grows with terminal weight, with a visual minimum to keep lighter paths visible; lines between nodes are interpolations.

  • Paths under P versus time, thickness by weight

The mean uses all 1200 paths, not only those drawn. The line is the exact mean under the target measure.

  • Sample weighted mean
  • Unweighted P mean
  • Theoretical mean θt

Let Z(T)=exp(θB(T)−θ²T/2) and dQ/dP=Z(T). Under Q, B(t)−θt is Brownian and E_Q[B(t)]=θt. Terminal weight applies to the whole path: conditioned on information up to t, its expectation is Z(t)=exp(θB(t)−θ²t/2).

The mean of Z(T) is 1 and theoretical variance is exp(θ²T)−1. Weights are calculated in log space and normalized before obtaining ESS=1/Σwᵢ². The weighted mean is a ratio of random sums: in a finite sample it can be biased and differ from θt, especially when few paths concentrate weight. High ESS alone does not guarantee accuracy for every function.

0.6
2.0
Sample mean Z(T)0.9421
Theoretical mean Z(T)1
Effective sample size ESS604.6
ESS / paths50.4 %
Largest normalized weight0.7 %
Theoretical variance Z(T)1.05
Final weighted mean1.081
Target mean θT1.200
Seed2629
Reweight Brownian paths and observe the change in mean and concentration of weights.

From a normal to Brownian motion with drift

Let BB be Brownian under PP and fix T<∞T<\infty. For constant θ\theta, define

Zt=exp⁡(θBt−12θ2t),dQdP∣FT=ZT.Z_t=\exp\left(\theta B_t-\tfrac12\theta^2t\right), \qquad \frac{dQ}{dP}\bigg|_{\mathcal F_T}=Z_T.

The normal moment-generating function shows EPZT=1E_PZ_T=1; since ZT>0Z_T>0, PP and QQ are equivalent on FT\mathcal F_T. Completing the square in the density of BTB_T gives BT∼N(θT,T)B_T\sim N(\theta T,T) under QQ. For any partition, ZTZ_T factorizes over independent Brownian increments; each increment shifts by θΔt\theta\Delta t and remains independent. By continuity, Bt−θtB_t-\theta t is Brownian under QQ. This proof uses the law of every increment, not just one terminal distribution.

The figure uses terminal weights for earlier dates too: EP[ZT∣Ft]=ZtE_P[Z_T\mid\mathcal F_t]=Z_t, so EP[ZTBt]=EP[ZtBt]=θtE_P[Z_TB_t]=E_P[Z_tB_t]=\theta t. The normalized weighted mean of a finite sample is a random ratio and is not generally unbiased. Effective sample size (∑Zi)2/∑Zi2(\sum Z_i)^2/\sum Z_i^2 measures weight concentration, not guaranteed accuracy for every functional.

Girsanov and Novikov

Let θt\theta_t be predictable, with ∫0Tθt2dt<∞\int_0^T\theta_t^2dt<\infty almost surely. The stochastic exponential

Zt=exp⁡(∫0tθs dBs−12∫0tθs2ds)Z_t=\exp\left(\int_0^t\theta_s\,dB_s-\frac12\int_0^t\theta_s^2ds\right)

is a positive local martingale. A sufficient condition for it to be a true martingale on [0,T][0,T] is Novikov’s condition:

EPexp⁡(12∫0Tθs2ds)<∞.E_P\exp\left(\frac12\int_0^T\theta_s^2ds\right)<\infty.

Then EPZT=1E_PZ_T=1 and Girsanov’s theorem states that WtQ=Bt−∫0tθsdsW_t^Q=B_t-\int_0^t\theta_sds is Brownian under QQ defined by ZTZ_T. Novikov is sufficient, not necessary. The general proof uses Itô’s product rule: after localization, covariation compensation turns WQW^Q into a local martingale under QQ. Its quadratic variation is tt; Lévy’s characterization identifies it as Brownian motion. For localization and integrability details see Lawler, chapter 5.

A local exponential need not have expectation one. Let Rt=∥(1,0,0)+Wt(3)∥R_t=\|(1,0,0)+W_t^{(3)}\| be a three-dimensional Bessel process starting at 1. Its inverse Zt=1/RtZ_t=1/R_t satisfies dZt=−ZtRt−1dβtdZ_t=-Z_tR_t^{-1}d\beta_t and is a positive local stochastic exponential. However,

EPZt=2Φ(1/t)−1<1(t>0).E_P Z_t=2\Phi(1/\sqrt t)-1<1\qquad(t>0).

Therefore it is a strict local martingale: by itself it does not define a probability density with mass one. This example and its expectation appear in Föllmer and Protter; the Bessel calculation is also treated in Lawler, section 4.2. Here Novikov cannot hold on the horizon, because it would imply a true martingale. A sample average near one proves neither Novikov nor the martingale property.

Divergence between path laws

KL divergence between path laws quantifies separation between complete processes. Consider a nondegenerate scalar diffusion with coefficients measurable in time and state, the same initial law and σ(t,x)≠0\sigma(t,x)\ne0. If under PP the process satisfies dX=b0(t,X)dt+σ(t,X)dBdX=b_0(t,X)dt+\sigma(t,X)dB and under QQ has drift b1=b0+σθb_1=b_0+\sigma\theta, equivalence conditions and necessary integrability give

DKL(Q∥P)=EQlog⁡dQdP=12EQ∫0Tθt2dt.D_{\mathrm{KL}}(Q\Vert P) =E_Q\log\frac{dQ}{dP} =\frac12E_Q\int_0^T\theta_t^2dt.

Here θ=(b1−b0)/σ\theta=(b_1-b_0)/\sigma is a function of state and noise is recovered from the path through the equation. Direction matters: expectation is under QQ, the numerator law. In several dimensions, with square invertible diffusion matrix, use θ=σ−1(b1−b0)\theta=\sigma^{-1}(b_1-b_0). The stochastic integral under QQ must have zero expectation for this equality; formally writing the square is insufficient. If initial laws differ, initial KL also appears. With noise unobservable in XX, KL of observed paths can be smaller than that of the underlying noise space.

For example, if QQ is a reference law with known drift brefb_{\rm ref} and PφP_\varphi a model with drift bφb_\varphi, the same initial law and common scalar diffusion σ\sigma, minimizing DKL(Q∥Pφ)D_{\rm KL}(Q\Vert P_\varphi) is equivalent, under the same assumptions, to minimizing expectation under QQ of 12∫0T[(bref−bφ)/σ]2dt\frac12\int_0^T[(b_{\rm ref}-b_\varphi)/\sigma]^2dt. This explains a diffusion-weighted quadratic drift loss. Applying the idea to a generative model requires identifying its reference law, time direction and boundary terms; swapping measures is insufficient.

Quadratic variation is a path property. An equivalent measure does not change an almost-sure quadratic-variation identity: for example, Brownian motions with two distinct positive constant volatilities have singular laws on continuous path space because their deterministic quadratic variations differ. This does not justify claiming singularity for every pair of distinct coefficients without analyzing the laws.

Importance sampling in path space

Path importance sampling uses, for event AA, P(A)=EQ[1A dP/dQ]P(A)=E_Q[\mathbf1_A\,dP/dQ] if PP is absolutely continuous with respect to QQ. To simulate a rare rise, QQ can shift drift toward the barrier; each path is corrected with its likelihood ratio. Excessive shifting can produce highly unequal weights and increase variance. The ideal zero-variance proposal would be the conditional law of PP given AA: it weights the measure restricted to AA, since PP is not absolutely continuous with respect to that proposal outside the event. Constructing it requires information we normally seek to estimate.

InteractiveMaking a rare event visible

Estimated relative error is standard error divided by the estimate. Each point uses the indicated prefix of a simulation; if no crossings occurred it is not drawn.

  • Direct Monte Carlo
  • Importance sampling

At equal budget, compare the nine drifts. The vertical line marks the selected proposal.

Target: OU dX=−Xdt+dB, X₀=0; we seek X≥2.5 before T=2. The proposal adds θ to drift. The 100 Gaussian transitions are exact at nodes and each weight is the product of target/proposal transition ratios through the first observed crossing.

The weighted mean unbiasedly estimates crossing probability at those nodes. Paths without an observed crossing stop at T and contribute zero: they may have crossed between nodes. Continuous first-passage probability can be larger. Standard error measures sampling variation only, not this monitoring bias.

Each proposal uses a different reproducible sample. Few crossings or highly unequal weights can make standard error unreliable; without crossings it is not reported as zero. The observed minimum depends on the sample and does not guarantee an optimal proposal.

1.5
4000
1
Direct: probability0.001000
Direct: grid crossings4 / 4000
Importance: probability0.001624
Importance: standard error0.000079
Importance: relative error4.9 %
Importance: grid crossings547 / 4000
Change the proposal drift for an OU and compare estimated uncertainties.

The figure uses exact OU transitions at the nodes and stops the weight at the first observed crossing. It estimates the grid event, which may miss a continuous crossing. A standard error calculated from few hits can be unreliable; zero hits do not prove zero probability. In the lab below we use a Brownian-specific conditional correction for continuous crossing.

In rare-event simulation you will again choose proposals and measure bias, variance and cost jointly.

Representation and conditioning

The martingale representation theorem says that in the usual augmentation of the Brownian natural filtration, every square-integrable martingale MM admits

Mt=M0+∫0tHs dBs,E∫0THs2ds<∞,M_t=M_0+\int_0^t H_s\,dB_s, \qquad E\int_0^T H_s^2ds<\infty,

with HH predictable and unique except on sets of dt⊗dPdt\otimes dP measure zero. In finance, under a pricing measure and complete market with nondegenerate discounted-asset volatility, that integrand constructs a replicating portfolio. A richer filtration or incomplete market requires additional assumptions.

The Doob h-transform reweights a diffusion to describe conditioning. For Brownian motion starting at aa and ending at bb at TT, take h(t,x)=p(T−t,x,b)h(t,x)=p(T-t,x,b), the transition density to bb. Then

Lhf=L(hf)−fLhh=Lf+(σσT∇log⁡h)⋅∇f.L^hf=\frac{L(hf)-fLh}{h}=Lf+(\sigma\sigma^\mathsf T\nabla\log h)\cdot\nabla f.

The product rule introduces the Hessian cross term; for time-dependent hh, the backward equation of hh cancels additional time terms. Since here L=12∂xxL=\tfrac12\partial_{xx}, the resulting drift is

dXt=∂xlog⁡h(t,Xt) dt+dBt=b−XtT−t dt+dBt,t<T.dX_t=\partial_x\log h(t,X_t)\,dt+dB_t =\frac{b-X_t}{T-t}\,dt+dB_t,\qquad t<T.

Drift grows approaching the end and is not evaluated at TT. Since P(BT=b)=0P(B_T=b)=0, the bridge is defined through a regular conditional distribution, not division by that probability. An exact construction at nodes is Xt=a+(b−a)t/T+Wt−(t/T)WTX_t=a+(b-a)t/T+W_t-(t/T)W_T; it satisfies XT=bX_T=b and has covariance min⁡(s,t)−st/T\min(s,t)-st/T.

InteractiveThe bridge and its drift field

The cloud starts at zero and ends at the marked point. You can drag it vertically; the slider offers the same keyboard control. The crosshair marks the chosen time and state for evaluating drift.

-4-20240.000.250.500.751.00Time tState Xₜ
  • Paths
  • Conditional mean
  • 95% marginal band
  • Endpoint and selected state

For X₀=0 and T=1, conditional drift at t<1 is (b−x)/(1−t). Gray arrows indicate its direction and their length grows with magnitude, but is clipped at a visual maximum: the real field can diverge near T. The crosshair is an arbitrary query point, not necessarily a path.

Each path is obtained from Wₜ−tW₁+bt with independent Gaussian increments. The 101 nodes have the exact joint law of the bridge; segments between nodes are visual interpolation only. Paths remain fixed when b changes and are renewed with another seed.

Mean is bt and variance t(1−t). The shaded band uses mean ± 1.96 deviations: it covers approximately 95% at each fixed time, not simultaneously over the whole path. A particular sample can leave the band.

1.5
5
0.50
0.0
Endpoint b at T = 11.5
Mean at t0.750
Deviation at t0.500
Drift at (t, x)3.00
Nodes per path101
Seed2629
Move the destination and compare conditioned paths with h-transform drift.

The same principle describes a diffusion conditioned to exit through part of the boundary: with h(x)=Px(Xτ∈A)>0h(x)=P_x(X_\tau\in A)>0 and Lh=0Lh=0, drift changes to b+a∇log⁡hb+a\nabla\log h, with a=σσTa=\sigma\sigma^\mathsf T, until exit under suitable assumptions. For the bridge, hh also depends on remaining time. Time reversal of generative diffusions and Schrödinger bridges also change path laws, with their own conditions and terms; they are not automatically this Brownian bridge. Control as inference connects decisions and changes of measure when model and cost assumptions hold.

Lab: weights, Novikov and divergence

Construct complete paths under PP and evaluate ZtZ_t at three dates. For constant θ\theta, Novikov is checked analytically: its expectation is eθ2T/2e^{\theta^2T/2}. Mean weights and weighted mean in a simulation illustrate the identity but do not replace proof. The theoretical variance of ZTZ_T is eθ2T−1e^{\theta^2T}-1.

[ ]Girsanov weights along pathsBrowser
import numpy as np
from scipy.stats import norm

rng=np.random.default_rng(2929)
m,steps,T,theta=6000,64,2.,.6
dt=T/steps
increments=rng.normal(size=(m,steps))*np.sqrt(dt)
paths=np.column_stack((np.zeros(m),np.cumsum(increments,axis=1)))
for i in (16,32,64):
    t=i*dt
    z=np.exp(theta*paths[:,i]-.5*theta**2*t)
    weighted=np.sum(z*paths[:,i])/np.sum(z)
    print("t, media de pesos, media ponderada, objetivo, ESS:",
          t,z.mean(),weighted,theta*t,z.sum()**2/np.sum(z*z))
print("Novikov exacto y varianza exacta de Z_T:",
      np.exp(.5*theta**2*T),np.expm1(theta**2*T))

The next cell directly simulates law QQ to estimate EQ[log⁡(dQ/dP)]E_Q[\log(dQ/dP)]. The same calculation with expectation under PP would have another direction and sign.

[ ]KL on path spaceBrowser
m=50000
terminal_q=theta*T+np.sqrt(T)*rng.normal(size=m)
log_density=theta*terminal_q-.5*theta**2*T
kl_sample=log_density.mean()
kl_se=log_density.std(ddof=1)/np.sqrt(m)
kl_exact=.5*theta**2*T
print("KL(Q||P), error estándar y valor exacto:",kl_sample,kl_se,kl_exact)
assert abs(kl_sample-kl_exact)<5*kl_se

The norm of a three-dimensional Brownian motion starts at (1,0,0)(1,0,0). Its reciprocal at t=1t=1 has expectation strictly less than one, although it is a positive local martingale. The exact formula lets us check the example without interpreting a sample estimate as proof.

[ ]A strict local martingaleBrowser
vectors=rng.normal(size=(80000,3))
vectors[:,0]+=1.
inverse=1/np.linalg.norm(vectors,axis=1)
exact=2*norm.cdf(1)-1
se=inverse.std(ddof=1)/np.sqrt(len(inverse))
print("inverso Bessel, media, error estándar y esperanza exacta:",
      inverse.mean(),se,exact)
assert abs(inverse.mean()-exact)<5*se

Lab: ruin and a continuous barrier

Consider reserves Rt=x0+ct+σBtR_t=x_0+ct+\sigma B_t and ruin before TT if Rt≤0R_t\le0. After changing sign and scale, this is equivalent to Yt=μt+BtY_t=\mu t+B_t reaching a=x0/σa=x_0/\sigma, with μ=−c/σ\mu=-c/\sigma. We simulate only YTY_T and use the conditional crossing probability of a bridge to integrate crossings between dates exactly.

Under the proposal, YT=(μ+θ)T+TZY_T=(\mu+\theta)T+\sqrt T Z and ratio dP/dQdP/dQ is exp⁡[−θ(YT−μT)+θ2T/2]\exp[-\theta(Y_T-\mu T)+\theta^2T/2]. Given the endpoint, the bridge does not depend on constant drift. If YT<aY_T<a, conditional crossing probability is e−2a(a−YT)/Te^{-2a(a-Y_T)/T}; if YT≥aY_T\ge a it equals one. Multiplying by that probability is a conditional Monte Carlo version: it reduces variance for each proposal, but does not guarantee every θ\theta improves on the original proposal.

[ ]Continuous ruin with importance samplingBrowser
x0,c,sigma,T=3.,.3,1.,1.
a=x0/sigma
mu=-c/sigma
sample_size=60000
def crossing_contribution(theta,size,rng):
    y=(mu+theta)*T+np.sqrt(T)*rng.normal(size=size)
    bridge=np.ones(size)
    below=y<a
    bridge[below]=np.exp(-2*a*(a-y[below])/T)
    weights=np.exp(-theta*(y-mu*T)+.5*theta**2*T)
    return weights*bridge

direct=crossing_contribution(0.,sample_size,rng)
shifted=crossing_contribution(2.5,sample_size,rng)
truth=norm.cdf((mu*T-a)/np.sqrt(T))+np.exp(2*mu*a)*norm.cdf((-mu*T-a)/np.sqrt(T))
for name,values in (("directo",direct),("propuesta",shifted)):
    se=values.std(ddof=1)/np.sqrt(len(values))
    print(name,"media, error estándar y error relativo estimado:",
          values.mean(),se,se/values.mean())
    assert abs(values.mean()-truth)<5*se
print("probabilidad continua exacta:",truth)
print("cociente de varianzas muestrales directo/propuesta:",
      direct.var(ddof=1)/shifted.var(ddof=1))

The printed ratio applies to this configuration and sample: it compares contribution variances with equal simulation counts and can change when the proposal changes. This bridge formula is exact for a constant barrier of Brownian motion with constant drift. Do not transfer it to OU or a moving barrier without proof. If computing weights over many steps, use logarithms to control overflow and retain independence between paths.

Exercises

ProofChange the law of every increment
Prove: Let B be Brownian under P, θ constant and dQ/dP=exp(θB_T−θ²T/2). Show Bₜ−θt is Brownian under Q.
0
For a partition, write the density as a product of factors for each increment and calculate their generating functions.

Step 1 of 3. How is the density factor of an increment ΔB of duration h expressed?

ProofDerive bridge drift
Prove: For standard Brownian motion required to end at b at time T, derive the h-transform drift term for t<T.
0
The remaining transition density is h(t,x)=(2π(T−t))⁻¹ᐟ² exp[−(b−x)²/(2(T−t))].

Step 1 of 3. What is the spatial derivative of log h?

NumericKL of path laws
On [0,1], what is KL(Q||P) if under Q Brownian motion has drift 0.5 and under P zero drift, with unit diffusion?
QuizWhat an equivalent measure changes
What statement is justified for Brownian motions with different positive constant volatilities on a nontrivial interval?
CodeImportance sampling with bridge correction
Implement is_hitting_probability(level,T,theta,n,seed=29) for P(max₀≤t≤T Bₜ≥level), with level>0, T>0. Simulate the endpoint under a Brownian proposal with drift θ, use the dP/dQ ratio and conditional bridge crossing probability. Return mean and standard error of contributions. Reject n<2 or nonfinite parameters.
import numpy as np

def is_hitting_probability(level,T,theta,n,seed=29):
  pass
Shift+Enter to run
Key idea

Girsanov changes drift by reweighting equivalent laws, while quadratic variation remains tied to the path. Controlling normalization and weight variance is as important as applying the formula; conditioning a diffusion requires specifying the imposed event or endpoint.

[ ]Check the exercise KLBrowser
print("KL con deriva 0,5 en [0,1]:",.5*.5**2)