![]() QuantLib 0.3.7Getting startedReference manual |
Monte Carlo frameworkDetailed DescriptionWarning: this section of the documentation is currently outdated.This framework (corresponding to the ql/MonteCarlo directory) contains basic building blocks for the numerical calculation of the integral
where
where the
The above sum has a straightforward interpretation in the case of a derivative product, namely, the
It must also be mentioned that for all such methods, the error
Separate implementations are provided in the library for the three components of the above average, namely, the random drawing of the Path generationThe Black-Scholes equation
where
Therefore, the paths to be generated for a Monte Carlo model of the Black-Scholes equation will be vectors of successive variations of the logarithm of the underlying price over The QuantLib::Path class stores the variation vector decomposed in its drift (determined) and diffusion (random) components. As shown below, this allows the implementation of antithetic variance reduction techniques. The QuantLib::MultiPath class is a straightforward extension which acts as a vector of Path objects. Classes are provided which generate paths and multi-paths with the desired drift and diffusion components, namely, QuantLib::PathGenerator and QuantLib::MultiPathGenerator. For the time being, the path generator is initialized with a constant drift and variance. This requirement will most likely be relaxed in the next release. The multi-path generator is initialized with an array of constant drifts---one for each single asset---and a covariance matrix which encapsulates the relations between the diffusion components of the single assets. The time discretization of the (multi)paths can be specified either as a given number of equal time steps over a given time span, or as a vector of explicitly specified times at which the path will be sampled. Pricing an instrument on a pathThe QuantLib::PathPricer class is the base class from which path pricers must inherit. The only method which subclasses are required to implement iswhere P can be Path or MultiPath depending on the derivative whose value must be calculated.Similarly, the term path will be used in the following discussion as meaning either path or multi-path depending on the context. The term single path is not to be taken as opposite to multi-path, but rather as meaning ``a single instance of a (multi)path" as opposed to the set of all generated (multi)paths. The above method encapsulates the pricing of the derivative on a single path and must return its value had the evolution of the underlying(s) followed the path passed as argument. For this reason, control variate techniques (see below) must not be implemented at this level since they would cause the returned value to differ from the actual price of the derivative on the path. Instead, antithetic variance-reduction techniques can be effectively implemented at this level and indeed are used in the pricers currently included in the library. In short, such techniques consist in pricing an option on both the given path and its antithetic, the latter being a path with the same drift and the opposite diffusion component. The value of the sample is defined as the average of the prices on the two paths. A generic implementation of antithetic techniques could consist of a path pricer class which takes a concrete path pricer upon construction and whose operator() simply proxies two calls to the contained pricer, passing the given path and its antithetic, and averages the result. However, this would not take full advantage of the technique. In fact, it must be noted that using antithetic paths not only reduces the variance per se but also allows to factor out calculations commons to a path and its antithetic, thus reducing greatly the computation time. Therefore, such techniques are best implemented inside the path pricer itself, whose algorithm can fully exploit such factorization. A number of path pricers are available in the library and listed in reference manual. Accumulating and averaging samplesThe class QuantLib::MonteCarloModel encapsulates the general structure of a Monte Carlo calculations, namely, the generation of a number of paths, the pricing of the derivative on each path, and the averaging of the results to yield the actual derivative price.As outlined above, the first two steps are delegated to a path generator and a path pricer. The third step is also delegated to an object which accumulates weighted values and returns the statistic properties of the set of such values. One such class provided by the library is QuantLib::Statistics. The concern of the Monte Carlo model is therefore to act as a glue between such three components and can be expressed by the following pseudo-code:
The Monte Carlo model also provides the user with the possibility to take advantage of control-variate techniques. Such techniques consist in pricing a portfolio from which the price of the derivative can be deduced, but with a lower variance than the derivative alone. In our current implementation, static-hedge control variate is used, namely, the formed portfolio is long of the derivative we need to price and short of a similar derivative whose price can be calculated analytically. The value of the portfolio on a given path will of course be given by the difference of the values of the two derivatives on such path. However, due to the similarity between the derivatives, the portfolio price will have a lower variance than either derivative alone since any variation in the price of the latter will be partly compensated by a similar variation in the price of the other. Lastly, given the portfolio price, the price of the derivative we are interested in can be deduced by adding the analytic value of the other. In order to use such technique, the user must provide the model with a path pricer for the additional option and the value of the latter. The action of the Monte Carlo model is in this case expressed as:
Martingale (a.k.a. dynamic-hedge) control variate techniques are planned for future releases. A QuantLib::McPricer class is also available which wraps the typical usage of a Monte Carlo model. Details on the Monte Carlo Pricer interface will be available in the Pricers section. Examples of Monte Carlo modelsAs a simple example, we will use the outlined tools to price an European option by means of Monte Carlo techniques.
Given a current underlying price
while the price on the antithetic path --- i.e., same drift and opposite diffusion --- is
The corresponding path pricer can be implemented as:
The path pricer can now be used in a model. Let us assume the following parameters: The path generator can be instantiated as where QuantLib::GaussianPathGenerator is a typedef to a path generator using the default choice for a Gaussian random number generator. The path pricer is instantiated as
The model can now be created and used as following:
More examples of path pricers can be found in the ql/MonteCarlo directory, while examples of more sophisticated pricers which uses them in Monte Carlo models can be found in the ql/Pricers directory. Notes(1) A more rigorous approach would lead us to integrate the above equation by means of Green functions or Laplace transforms. Both such methods would show that the price at time![]() ![]() ![]()
where
and can be interpreted as the option payoff discounted to the present time, while the probability distribution is
which again shows that the logarithms of the underlying prices at time
|
QuantLib.org![]() |
Hosted by![]() |
Documentation generated by![]() |