Consider the stochastic differential equation of the Heston model for the dynamics of the log-spot

The Fokker-Planck partial differential forward equation describes the time evolution of the probability density function

with the initial condition

where denotes the Dirac delta distribution. A semi-closed form solution for this problem is presented in [1]. When solving the Fokker-Planck forward equation special care must be taken with respect to the boundary conditions, especially if the Feller constraint

is violated. In this case the boundary at the origin is instantaneously attainable. A generalisation of Feller’s zero-flux boundary condition should be applied at the origin [2].

A three point forward differentiation formula can be used to calculate a second order accurate approximation of the partial derivative for [3].

The diagram below shows the solution of the forward equation for the model

The Feller constraint is violated for and this changes the shape of the solution completely.

The code for this example is available here and it is based on the latest QuantLib version from the SVN trunk. It also depends on RInside and Rcpp to generate the plots. In addition the zip contains a short movie clip of the time evolution of the solution for .

[1] A. Dragulescu, V. Yakovenko, Probability distribution of returns in the Heston model with stochastic volatility

[2] V. Lucic, Boundary Conditions for Computing Densities in Hybrid Models via PDE Methods

[3] K. A. Kopecky, Numerical Differentiation