In continuous time, the Vasicek (1977) model proposes the following SDF:
\frac{d\Lambda}{\Lambda} = - r dt - \frac{\lambda}{\sigma} dz,
where
dr = \kappa (\theta - r) dt + \sigma dz.
The parameter \kappa determines the speed of mean-reversion towards the long-run mean \theta.
Pricing of Bonds
Consider a zero-coupon bond P(r, T) with face value $1 and expiring at T.
The fundamental pricing equation is
\operatorname{E}\left(\frac{dP}{P}\right) - r dt = - \frac{d\Lambda}{\Lambda} \frac{dP}{P},
or
\operatorname{E}(dP) - r P dt = - \frac{d\Lambda}{\Lambda} dP.
The Bond Price Evolution
Since the zero-coupon bond price is P(r, T), Ito’s lemma implies that
\begin{aligned}
dP & = P_{r} dr + \frac{1}{2} P_{rr} (dr)^{2} - P_{T} dt \\
& = \left( \kappa (\theta - r) P_{r} + \frac{1}{2} \sigma^{2} P_{rr} - P_{T} \right) dt + P_{r} \sigma dz.
\end{aligned}
The covariance between the SDF returns and the changes in the bond price implies that
\kappa (\theta^{*} - r) P_{r} + \frac{1}{2} \sigma^{2} P_{rr} - P_{T} - r P = 0.
\tag{1} where \theta^{*} = \theta - \frac{\lambda}{\kappa}.
The equation requires that P(r, 0) = 1.
To solve it, we can guess that
P(r, T) = \exp(A(T) + r B(T)).
We find that P_{r} = B P, P_{rr} = B^{2} P, and P_{T} = (A' + r B') P, so that
\kappa (\theta^{*} - r) B + \frac{1}{2} \sigma^{2} B^{2} - (A' + r B') - r = 0.
\tag{2}
Solving for the Bond Price
Since (2) must be valid for any r, it must be the case that
\begin{aligned}
A' & = \kappa \theta^{*} B + \frac{1}{2} \sigma^{2} B^{2}, \\
B' & = - 1 - \kappa B,
\end{aligned}
subject to A(0) = 0 and B(0) = 0, implying that
\begin{aligned}
B(T) & = - \phi(T) T, \\
A(T) & = - \theta^{*} T (1 - \phi(T)) + \frac{1}{2} \frac{\sigma^{2}}{\kappa^{2}} T (1 - 2 \phi(T) + \phi(2 T)),
\end{aligned}
where
\phi(T) = \frac{1 - e^{-\kappa T}}{\kappa T}.
The Bond Price
The price of the zero-coupon bond can be written as
P(r, T) = \exp(- y(T) T),
where
y(T) = \theta^{*} (1 - \phi(T)) - \frac{1}{2} \frac{\sigma^{2}}{\kappa^{2}} (1 - 2 \phi(T) + \phi(2 T)) + \phi(T) r,
where y(T) is the zero-coupon rate.
The model proposed by Heston (1993) is one of the most cited papers in finance.
In the model, the stock price S and its variance of return v follow a joint-process of the form
\begin{aligned}
\frac{dS}{S} & = \mu dt + \sqrt{v} dz_{1}, \\
dv & = \kappa (\theta - v) dt + \sigma \sqrt{v} dz_{2},
\end{aligned}
where z_{1} and z_{2} are two correlated Brownian motions such that dz_{1} dz_{2} = \rho dt.
The process for the variance is a CIR process which guarantees that the variance will stay positive.
The Stochastic Discount Factor
One possible specification of the SDF is
\frac{d\Lambda}{\Lambda} = -r dt - \frac{\lambda_{1}}{\sqrt{v}} dz_{1} - \frac{\kappa \lambda_{2}}{\sigma \sqrt{v}} dz_{2}.
If the stock pays a dividend yield q, the fundamental pricing equation says that
\operatorname{E}\left(\frac{dS}{S}\right) + q dt - r dt = - \frac{d\Lambda}{\Lambda} \frac{dS}{S},
or (\mu + q - r) dt = \lambda_{1} dt, which we typically write as \mu - \lambda_{1} = r - q.
This is the risk-neutral adjustment to the stock price dynamics!
Pricing Derivatives on the Stock
Consider a European-style derivative with price F written on the stock and expiring at T, such a European call option written on S.
The fundamental pricing equation is
\operatorname{E}(dF) -r F dt = - \frac{d\Lambda}{\Lambda} dF.
To go further, we need to apply Ito’s lemma to F(S, v, T),
\begin{aligned}
dF & = F_{S} dS + F_{v} dv + \frac{1}{2} F_{SS} (dS)^{2} + \frac{1}{2} F_{vv} (dv)^{2} + F_{Sv} (dS) (dv) - F_{T} dt \\
& = \left( \mu S F_{S} + \kappa (\theta - v) F_{v} + \frac{1}{2} v F_{SS} + \frac{1}{2} \sigma^{2} v F_{vv} + \sigma v \rho F_{Sv} - F_{T}\right) dt \\
& \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad + F_{S} S \sqrt{v} dz_{1} + F_{v} \sigma \sqrt{v} dz_{2}.
\end{aligned}
The Partial Differential Equation
Applying the fundamental pricing equation we find that the derivative’s price must satisfy
(r - q) S F_{S} + \kappa (\theta^{*} - v) F_{v} + \frac{1}{2} v F_{SS} + \frac{1}{2} \sigma^{2} v F_{vv} + \sigma v \rho F_{Sv} - F_{T} - r F = 0.
If we could solve this equation, we could use it to price European call and put options written on the stock.
It turns out that equations of this type can only be solved in closed form for linear payoffs like futures.
This was Heston’s insight.
He solved the equation for the characteristic function of the stock price and used it to price European call and put options.
A Note on Characteristic Functions
The characteristic function of a random variable X is defined as
f_{X}(\phi) = \operatorname{E}(e^{i \phi X}).
If we know the characteristic function of X we can obtain the distribution of X as
\Pr(X < x) = \frac{1}{2} - \frac{1}{2 \pi} \int_{-\infty}^{\infty} \frac{e^{-i \phi x} f_{X}(\phi)}{i\phi} d\phi.
That is, if you know the characteristic funcion of the log-stock price you can compute quatities such as
\Pr(S < K) = \Pr(\ln(S) < \ln(K)),
which is what we need to value options.
The Option Price
The price of a European call with strike price K and maturity T is
C = S e^{-q T} P_{1} - K e^{-r T} P_{2},
where
\begin{aligned}
P_{1} & = \frac{1}{2} + \frac{1}{\pi} \frac{1}{F} \int_{0}^{\infty} \operatorname{Re} \left(\frac{e^{i \phi \ln(K)} f(\phi - i, 0)}{i \phi} \right) d\phi, \\
P_{2} & = \frac{1}{2} + \frac{1}{\pi} \int_{0}^{\infty} \operatorname{Re} \left(\frac{e^{i \phi \ln(K)} f(\phi, 0)}{i \phi} \right) d\phi.
\end{aligned}
F = S e^{(r - q) T} is the forward price of S and f(\phi, \varphi) is the joint characteristic function of \ln(S(T)) and v(T) given \ln(S) and v.
Unlike Heston (1993), I use the same characteristic function to compute P_{1} and P_{2} by changing to the forward measure.
The Characteristic Function for the Heston Model
If we define x = \ln(S), the risk-neutral Heston model can be re-written as
\begin{aligned}
dx & = (r - q) dt + \sqrt{v} dz_{1}^{*}, \\
dv & = \kappa (\theta^{*} - v) dt + \sigma \sqrt{v} dz_{2}^{*},
\end{aligned}
where z_{1}^{*} and z_{2}^{*} are two correlated Brownian motions under the risk-neutral measure such that dz_{1}^{*} dz_{2}^{*} = \rho dt.
The characteristic function of x(T) and v(T) is defined as
f(\phi, \varphi) = \operatorname{E}^{*}(e^{i \phi x(T) + i \varphi v(T)}).
The expectation is taken under the risk-neutral measure, and to compute it we need to know the current x and v.
To price the call we just need f(\phi, 0).
The Joint Characteristic Function of x(T) and v(T)
The characteristic function can be computed using the same PDE satisfied by all derivatives written on S and v.
\begin{gathered}
f(\phi, \varphi) = \exp\left(i (r - q) \phi T + (\delta - \frac{2 \gamma}{\sigma^{2}}) \kappa \theta^{*} T + i \phi x + \delta v \right) \\
\qquad \qquad \qquad \times \left(e^{-\gamma T} - \frac{\sigma^{2}}{2 \gamma} (1 - e^{-\gamma T}) (i \varphi - \delta)\right)^{- 2 \kappa \theta^{*} / \sigma^{2}} \\
\qquad \qquad \qquad \times \exp\left(\frac{v (i \varphi - \delta)}{(e^{- \gamma T} - \frac{\sigma^{2}}{2 \gamma} (1 - e^{- \gamma T}) (i \varphi - \delta))}\right)
\end{gathered}
where
\begin{aligned}
\gamma & = \sqrt{\kappa^{2} + (1 - \rho^{2}) \sigma^{2} \phi^{2} + i (\sigma - 2 \kappa \rho) \sigma \phi}, \\
\delta & = \frac{\kappa + \gamma - i \rho \sigma \phi}{\sigma^{2}}.
\end{aligned}
Numerical Issues
The trick for this to work in a computer is to make sure that everything is written with e^{- \gamma T} instead of e^{\gamma T}.
If you do not do that you will get all sorts of numerical instabilities.
How you know that you did not make a mistake computing or entering the formula?
You can simulate the model and generate many possible values for x(T) and v(T).
Make sure that the average of e^{i \phi x(T) + i \varphi v(T)} corresponds to your formula.
Do this for different parameter values to check for numerical instabilities.
You can do the same to verify that you are getting the right option prices.
References
References
Heston, Steven L. 1993. “A Closed-Form Solution for Options with Stochastic Volatility with Applications to Bond and Currency Options.”Review of Financial Studies 6 (2): 327–43.
Vasicek, Oldrich. 1977. “An Equilibrium Characterization of the Term Structure.”Journal of Financial Economics 5 (2): 177–88.