### Extending, imitating and collaborating

As the name suggests, NAG is most widely-known for its library of numerical algorithms - in fact, it's been around for nearly forty years. Back when the first version was written, the coding language of choice was Fortran and, although it's still widely-used (particularly in high-performance computing), most developers today are working in a myriad of other languages and packages. Accordingly, we've put a lot of work into making the routines from our libraries accessible from these environments, in order to (hopefully) extend the areas in which our algorithms can be used by programmers when building their applications.

I was reminded of this extension into other environments recently when I saw a demo written by my colleague Marcin Krzysztofik. Marcin's background is in financial computation, and his application nicely demonstrated some of the models that have been developed for calculating the prices of financial options. New routines for evaluating the results from these models were added to the latest release of the NAG Library, but Marcin wanted to build his demo as an Excel spreadsheet, knowing that would be a familiar environment for users who'd be interested in this type of application. Calling NAG routines from within Excel - more specifically, from a Visual Basic for Applications (VBA) program - is straightforward, and Marcin's demo (see the screenshot above) allows the user to select the pricing model and set values for dependent parameters before calling the appropriate NAG routine. It then uses Excel's plotting capabilities to visualize the behaviour of both the price and the so-called *Greeks*, which provide a measure of the sensitivity of the price to the dependent parameters of interest.

I was so impressed with Marcin's demo that I did what any good software developer would do: I copied the idea, and tried to implement it in MATLAB. Here, I was able to make use of the NAG Toolbox for MATLAB, which makes routines from the NAG Library accessible from within that popular environment. The resultant demo (see screenshot below) has a similar functionality to Marcin's Excel application, with a couple of extensions - for example, parameter values can be automatically swept back and forth within a user-defined range, which produces animated plots of the price and Greeks that might be useful for teaching purposes (or perhaps merely provides an eye-catching demo on a NAG exhibition stand).

Having created the demo, I wanted to write it up as the latest installment of an occasional series of articles which highlights the functionality of the NAG Toolbox (the previous article in this series, written in collaboration with Nicolas Esteves and Nathaniel Fenton, described an application that uses several NAG routines to solve a partial differential equation over a two-dimensional region) and it was at this point I realized that, for some time, I'd - not uncharacteristically - been working beyond the limits of my knowledge in this field. Accordingly, I went back to Marcin, who patiently explained the theory of financial option pricing to me (yet again). The eventual result of these collaborative endeavours was a jointly-written white paper which contains an introduction to option pricing that's elementary enough for me to understand, technical details of how NAG routines can be called from VBA, as demonstrated by Marcin's application, and information on Excel examples that can be downloaded from the NAG website.

We aim to follow this note up with an description of the MATLAB option pricing demo, which should be made available later this year. I enjoy collaborating with Marcin, even though I discovered during the course of our work together that he's exactly half my age, and hence has probably never been near a Fortran program (or a Fortran programmer - until now, that is).

Just an addendum to say that, as promised, our article describing the MATLAB option pricing demo is now available here. The demo itself can be downloaded from this location.

ReplyDelete