Brugervejledning

I dette bilag præsenteres en kortfattet brugervejledning til det medfølgende program, så det er muligt hurtigt at komme i gang med at bruge det. Vejledningen er udarbejdet på engelsk for at udenlandske brugere af programmet også kan få glæde af den. Vejledningen kan findes i Mathematica-format på CD-ROM'en som \QuantLibMma\QuantLibMma-brugvejl.nb.

Interfacet kaldes QuantLib for Mathematica, da det er tænkt som en generel udvidelse, der eksporterer beregningsfunktionaliteten fra QuantLib til Mathematica. Indtil videre stiller størstedelen af funktionerne dog beregningsrutinerne fra NesQuant (udviklet i denne afhandling) til rådighed.

Installation

In order to use QuantLib for Mathematica, you need to have a working copy of Mathematica installed on your computer. A 30-day trial version (with saving disabled) can be downloaded from http://www.wolfram.com/products/mathematica/trial.cgi

To install QuantLib for Mathematica, copy the folder \QuantLibMma\QuantLib from the CD-ROM into your Mathematica Applications directory. In version 5 on a Microsoft Windows system this is most often c:\Program Files\Wolfram Research\Mathematica\5.0\AddOns\Applications.

After having done this, you can start QuantLib for Mathematica from within Mathematica with the following command.

<< QuantLib`

To see a description you can use the following command.

?QuantLib

Valuing a European option

The basic idea of the QuantLib for Mathematica interface is that you can value a specific instrument in a specific model using a specific method. Depending on the method, it may be possible to specify additional options and parameters to control how the method calculates the value. If the method is not specified, a default method is used.

To demonstrate the concept, we start by valuing a european option using the Black-Scholes model. First we can use "?" to get a description of a EuropeanOption.

?EuropeanOption

Then we use the variable eur to define a European call option.

eur = EuropeanOption[625, 0.25, CallOption];

Then we define the model under which it should be priced:

?BlackScholesModel

bsmodel = BlackScholesModel[625, 0.0345, 0, 0.1823]

Now we use can calculate the value for this option. Automatically the default Method -> Analytic is used.

Value[eur, bsmodel]

However if we want to, we can also use the Monte Carlo method. Here we use the Keyfigures function as we also would like to have the standard error returned.

Keyfigures[eur, bsmodel, Method -> MonteCarlo]

If we want better precision, we can use more sample paths.

?Samples

Keyfigures[eur, bsmodel, Method -> MonteCarlo, 
      Samples -> 500000]

Now we can use the standard Mathematica features to e.g. show how the standard error depends on the number of samples used.

Table[
      StandardError /. 
        Keyfigures[eur, bsmodel, Method -> MonteCarlo, 
          Samples -> s], {s, 10000, 100000, 10000}]

European option in the SVJD-model

We can evaluate the same option in a different model, namely the SVJD-model.

?SVJDModel

The following parameters are estimated parameters for the S&P500 stock-index taken from Bakshi, Cao and Chen (1997, p. 2018).

svjdmodel = 
        SVJDModel[625, 0.0345, 0, 0.1403, 0.38, 0.1403, 2.03, -0.57, 
          0.59, -0.05, 0.07];

Keyfigures[eur, svjdmodel]

We also have the possibility to draw the probability density function for the return on the stock.

Plot[PDF[eur, svjdmodel, z], {z, -0.3, 0.3}]

We can also calculate the mean, variance, skewness and kurtosis for the return.

{Skewness[eur, svjdmodel], KurtosisExcess[eur, svjdmodel]}

If we want to know what the implied Black-Scholes volatility is a given price calculated in the SVJD-model, we can use the ImpliedVolatility function. Obviously the same function can be used to find the implied volatility for a market observed price.

ImpliedVolatility[Value[eur, svjdmodel], eur, bsmodel]

Monte Carlo for a European option

Earlier we saw how to value a European option in the BS-model using Monte Carlo simulation. The same approach is used for the SVJD-model. In this example we also use the antithetic paths to reduce variance.

Keyfigures[eur, svjdmodel, Method -> MonteCarlo, 
      AntitheticPaths -> True]

It is also possible to change the number of time steps. The default is 100.

Options[Keyfigures]

There is also a function to show the development of the underlier along a path.

ListPlot[MonteCarloPath[svjdmodel], PlotJoined -> True]

Finite differences for an American option

It is possible to use the method of finite differences to value an American option in the BS-model.

?FiniteDifferences

am = AmericanOption[625, 0.25, CallOption];

Value[am, bsmodel, GridPoints -> 200, 
      TimeSteps -> 4000]

Least-squares Monte Carlo for an American option

When the method MonteCarlo is specified when valuing an American option the least-squares Monte Carlo algorithm is used. The number of samples, time steps and number of basis functions (PolynomialDegree) can be specified.

Keyfigures[am, bsmodel, Method -> MonteCarlo, 
      TimeSteps -> 50, PolynomialDegree -> 4]

In this case it's possible to use the european option price as a control variate.

Keyfigures[am, bsmodel, Method -> MonteCarlo, 
      ControlVariate -> True]

American option in the SVJD-model

For an American option in the SVJD-model there is only one supported way to find the value, namely using the least-squares Monte Carlo method. This method is automatically chosen by default.

Keyfigures[am, svjdmodel, AntitheticPaths -> True, 
      ControlVariate -> True]

For this method there is one further option. As the American option is effectively evaluated as a Bermudan option with a limited number of exercise points, the number of these can be modified. As default, ExercisePoints is chosen to be the same number as the number of time steps used in the path generation (TimeSteps).

Keyfigures[am, svjdmodel, AntitheticPaths -> True, 
      ControlVariate -> True, ExercisePoints -> 50]