## Friday, 14 June 2013

### The NAG Library for Java – An Illustrative Example Using Black And Scholes Pricing

Introduction

Hello everyone, my name is Peter Guo. I come from Taipei city and work in NAG’s Taipei Branch Office. In this, my first NAG Blog, I want to present some applications of the NAG Library. I am pleased to be part of NAG and hope to contribute to the NAG Blog on many future occasions.

When I was a graduate student, I focused on researching numerical computation, derivative pricing, and financial management. My professor, Professor Lin, is a famous specialist on financial engineering and has been working in this academic area for more than 10 years. I am now delighted that he is now using the NAG C Library. He thinks that the NAG Library is not only accurate and fast, but also enjoys a good reputation for its routines, especially in optimization.

The NAG Library

NAG is a numerical algorithms company, providing high quality numerical computing software. The NAG Library contains algorithms which are powerful, accurate, and flexible to use, from operating systems as diverse as Windows, Linux, and Mac OS.

The next section contains an illustrative example of how to use the NAG Library for Java in which we use the problem of pricing a European option as a concrete problem to be solved. The problem is particularly simple, for which an explicit solution is known, however in the real world the problems are more complicated and alternative methods have to be employed. For this reason we use a very basic Monte-Carlo method to illustrate the use of the NAG random number generators, whilst acknowledging that in practice a number of variance-reduction techniques would employed by the professional.

Monte Carlo simulation

Monte Carlo simulation uses repeated random sampling to compute numerical results. It is used heavily in financial computation. In this article, I use quasi-random numbers (the NAG routine G05YJF) and pseudo-random numbers (the NAG routine G05SKF and the explicit Black and Scholes formula (the NAG routine S30AAF) to provide benchmark. Computation time and accuracy are measured to compare the performance of the two different random number generators.

The basic theory

The background to option pricing is given in the chapter introduction for the NAG special function chapter, S.

Assume that stock prices at time t follow the geometric Brownian motion as shown in the following stochastic process:

Given a function f(St,t) = logSt that is twice continuously differentiable, then the solution is

In the risk-neutralized pricing probabilities, equation (2) follows the stochastic process

Equation (3) may be discretized using Euler’s method :

Simulated stock price paths

Example 1: Generating simulated stock paths

Example 2: Generating the 95% confidence interval for stock price paths

These results of a simulation using just two paths are arranged in table 1. We estimate the stock price at every time period by generating the random sequence from a Normal distribution. These prices can be shown in the figure 1. In the figure 1 the most simulated stock prices will be located between 95% upper and lower bound, however there are still very small number (such as those in the second path) located outside the 95% upper and lower bound. Breaching the lower bound is particular important because the portfolio is often concerned with downside risk.

Using the NAG routines

Example 3: Simulating the stock price paths (the NAG routine G05YJF). StockPriceSimulationQuasi.java
Example 4: Using pseudo-random numbers to simulate European option (the NAG routine G05SKF).   BlackScholesSimulationPseudo.java
Example 5: Using  quasi-random numbers to simulate European option (the NAG routine G05YJF).    BlackScholesSimulationQuasi.java
Example 6: Using the explicit Black and Scholes pricing routine (the NAG routine S30AAF).       BlackScholesCloseForm.java

Pricing a call option

The price of European option may be obtained by simulating equation (6).

The results for Monte Carlo method and Black-Scholes closed form are reported in table 2. Quasi and pseudo Monte Carlo methods are calculated by the NAG routines G05YJF and G05SKF respectively, and Black-Scholes closed form is calculated by the NAG routine S30AAF. Due to the fact that quasi-random number has uniform and dispersed sequence throughout the domain of space, this property makes them well-suited for Monte Carlo methods. They yield more accurate estimates than pseudo-random numbers for a given sequence length (Read the full introduction post here).

As shown in table 2, quasi Monte Carlo method may use fewer paths to converge to a true value (calculated here by Black and Scholes Closed form). The differences between quasi and pseudo Monte Carlo methods results diminish as the number paths increases, but the quasi Monte Carlo method is faster and has better relative error and standard deviation.

References

1. Black, F. and M. S. Scholes, “The Pricing of Options and Corporate Liabilities,” Journal of Political Economy, 81, 1973, pp. 637-654.
2. Boyle, P. P. “Options: A Monte Carlo Approach,” Journal of Financial Economics, 4 1977, pp. 323-338.
3. Using the NAG Toolbox for MATLAB – Part 3. (online)
4. G05SKF NAG routine document. (online)
5. G05YJF NAG routine document. (online)
6. S30AAF NAG routine document (online)
7. Klebaner, F., "Introduction to Stochastic Calculus with Application," Imperial College Press, 2005.