# What tools are used to numerically solve differential equations in Quantitative Finance?

There are a lot of Quantitative Finance models (e.g. Black-Scholes) which are formulated in terms of partial differential equations. What is a standard approach in Quantitative Finance to solve these equations? Do people use some general packages for solving differential equations (like Maple, MATLAB or Mathematica)? Or, do people use some standard packages tuned for financial equations? Is it common to program numerical methods from scratch (say in C++, Java or Python)?

Except in highly unusual cases, financial PDEs lack analytic solutions. The mathematical tools used are Monte Carlo, plus the usual ones for solving PDEs on grids, almost always one of the following:

• Trees, for very simple cases
• Explicit finite differencing, for throwaway projects or very specific cases
• Implicit or Crank-Nicolson finite differencing for robust projects

The software tools used are typically Matlab or C, especially for finite differencing. It is common to prototype something in Matlab or Python/Numpy, then translate to C for the final solution.

PDE solving "packages" are relatively unused, mainly because they are set up to handle the kinds of boundary conditions you would encounter in, say, materials stress analysis and not what want you to work with in finance .

Note that the problems you are referring to, essentially ones of option valuation, can be thought of as solving expectation problems. In particular, if an option has european exercise then its time $t$ value $V(t)$ can be written

$E\left[ B(t,T) V(T) \right]$

where $B$ represents discounting and the expectation is taken over paths specified by a stochastic differential equation (SDE). In this case, the problem is amenable to Monte Carlo integration, which can be slow but is very easy to program.

Using either the Feynman-Kac theorem or arbitrage arguments one can arrive at the "companion PDE" to this expectation on a SDE. American exercise changes the expectation to something nastier

$\sup_\tau \left\{ E\left[ B(t,T) V(T) \right] \right\}$

where $\tau$ is the set of all possible early exercise strategies. From this perspective, trees and differencing schemes are essentially "dynamic programming" techniques for finding option values and optimal exercise strategies at the same time. Monte Carlo cannot achieve that (though dynamic modifications of it such as LSMC exist).

Grid schemes are hard to code, but are usually the only way to handle early exercise. Exchange-traded equity options, bermudan interest rate swaps, convertible bonds, and untold numbers of exotic payoffs have to be treated using them.

A large investment bank will have at least three proprietary monster PDE grid solvers around, almost always more. Each one will handle several kinds of options, but the basic categories go like this:

• A Black-Scholes solver for equity options and other payoffs on the Black-Scholes SDE
• A solver for their favorite interest rate model to handle callable bonds, bermudan swaptions and so on
• A jump-to-default Black-Scholes solver for convertible bonds

These will have some overlap in capabilities, for example the Black-Scholes solver and the jump-to-default Black-Scholes will both be able to handle american exercise equity options.

Volatility exotics or the use of models such as stochastic volatility with jumps would require their own solvers in addition to the ones above.

You may want to look into these two open source projects:

QuantLib which is aimed at providing a comprehensive software framework for quantitative finance. This is written in C++.

JQuantLib the 100% Java implementation based on the first project.

• +1 JQuantLib is interesting and a hand-rolled port from QuantLib. – rajah9 Sep 28 '11 at 13:55

As far as I know, differential equations such as the Black-Scholes PDE are solved once analytically and then the result is used directly. If a given derivatives-pricing differential equation could not be solved analytically, it would probably be better to model it numerically using Monte Carlo methods than to derive a complicated PDE which must then be solved numerically.