![]() QuantLib 0.3.7Getting startedReference manual |
Finite-differences frameworkDetailed DescriptionThis framework (corresponding to the ql/FiniteDifferences directory) contains basic building blocks for the numerical solution of a generic differential equation
where
Writing the equation in the above form allows us to implement separately the discretization of the differential operator Differential operatorsThe discretization of the differential operator![]() ![]()
Such choice is obvious in the 1-D case where the domain
the first derivative
and implemented in class QuantLib::DPlus; the operator
and implemented in class QuantLib::DMinus; and the operator
and implemented in class QuantLib::DZero. The discretization error of the above operators is
the second derivative
and implemented in class QuantLib::DPlusDMinus. Its discretization error is The boundary condition for the above operators is by default linear extrapolation. Methods are currently provided for setting other kinds of boundary conditions to a tridiagonal operator which these operators inherit, namely, Dirichlet---i.e., constant value---and Neumann---i.e., constant derivative---boundary conditions. This might change in the future as boundary conditions could be astracted and passed as an additional argument to the model. A programmer can also implement its own operator. However, in order to fit into this framework it will have to implement a required interface depending on the chosen evolver (see below). Also, it is currently required to manage itself any boundary conditions. Again, this could change in the future.
On the other hand, there is no obvious choice in the 2-D case. While it is immediate to discretize the domain into a series of points Time schemesOnce the differential operator![]()
In this framework, such choice is encapsulated in so-called evolvers which, given A number of evolvers are currently provided in the library which implement well-known schemes, namely, the forward Euler explicit scheme in which the equation is discretized as
hence
from which the backward Euler implicit scheme in which the equation is discretized as
hence
from which the Crank-Nicolson scheme in which the equation is discretized as
hence
from which Each of the above evolvers forces a set of interface requirements upon the differential operator which are detailed in the documentation of the corresponding class, namely, QuantLib::ExplicitEuler, QuantLib::ImplicitEuler, and QuantLib::CrankNicolson, respectively. A programmer could implement its own evolver, which does not need to inherit from any base class. However, it must implement the following interface:
Finally, we note again that the pricing of an option requires the finite difference model to solve the corresponding equation backwards in time. Therefore, given a discretization must calculate the discrete solution at the previous time, ![]() Step conditionsA finite difference model can be passed a step condition to be applied at each step during the rollback of the solution (e.g. the early exercise American condition). Such condition must be embodied in a class derived from QuantLib::StepCondition and must implement the interface of the latter, namely,
An example of finite difference modelThe Black-Scholes equation can be written in the above form as
It can be seen that the operator
and can be built from the basic operators provided in the library as
Its implementation closely reflects the above decomposition and can be written as taking as inputs the relevant parameters of the equation ( ![]() ![]() ![]() ![]() ![]()
As simple example cases, we will use the above operator to price both an European and an American option. The parameters of the two options will be the same, namely, they will be both call options with underlying price
The grid upon which the model will act will be a logarithmic grid of underlying prices, i.e.,
The initial condition is determined by the values of the option at maturity, i.e., either the difference between underlying price and strike if such difference is positive, or 0 if that is not the case (the above will have to be suitably modified for a put option or a straddle.) Such ``initial'' condition will be rolled back in time by our model.
Now the differential operator can be initialized. Also, Neumann initial conditions are set which correspond to the initial value of the derivatives at the boundaries (see the BoundaryCondition class documentation for details).
We are now already set for the pricing of the European option. Also, the exercise condition is the only thing still to be defined for the American option to be priced. Such condition is equivalent to the statement that at each time step, the value of the option is the maximum between the profit realized in exercising the option (which we already calculated and stored in
Everything is now ready. The model can be created gluing the piece together by means of the QuantLib::FiniteDifferenceModel class. The current value of the option is calculated by rolling back the solution to the current time, i.e.,
|
QuantLib.org![]() |
Hosted by![]() |
Documentation generated by![]() |