Contents

This book is a a discussion of the calculation of specific formulas in finance. The field of finance has seen a rapid development in recent years, with increasing mathematical sophistication. While the formalization of the field can be traced back to the work of Markowitz (1952) on investors mean-variance decisions and Modigliani and Miller (1958) on the capital structure problem, it was the solution for the price of a call option by Merton (1973); Black and Scholes (1973) which really was the starting point for the mathematicalization of finance. The fields of derivatives and fixed income have since then been the main fields where complicated formulas are used. This book is intended to be of use for people who want to both understand and use these formulas, which explains why most of the algorithms presented later are derivatives prices.

This project started when I was teaching a course in derivatives at the University of British Columbia, in the course of which I sat down and wrote code for calculating the formulas I was teaching. I have always found that implementation helps understanding these things. For teaching such complicated material it is often useful to actually look at the implementation of how the calculation is done in practice. The purpose of the book is therefore primarily pedagogical, although I believe all the routines presented are correct and reasonably efficient, and I know they are also used by people to price real options.

To implement the algorithms in a computer language I choose C ++. My students keep asking why anybody would want to use such a backwoods computer language, they think a spreadsheet can solve all the worlds problems. I have some experience with alternative systems for computing, and no matter what, in the end you end up being frustrated with higher end ``languages'', such as Matlab og Gauss (Not to mention the straitjacket which is is a spreadsheet.) and going back to implementation in a standard language. In my experience with empirical finance I have come to realize that nothing beats knowledge a real computer language. This used to be FORTRAN, then C, and now it is C ++ . All example algorithms are therefore coded in C ++.

The manuscript has been sitting on the internet for a number of years, during which it has been visited by a large number of people, to judge by the number of mails I have received about the routines. The present (2003) version mainly expands on the background discussion of the routines, this is much more extensive. I have also added a good deal of introductory material on how to program in C ++, since a number of questions make it obvious this manuscript is used by a number of people who know finance but not C ++. All the routines have been made to confirm to the new ISO/ANSI C ++ standard, using such concepts as namespaces and the standard template library.

The current manscript therefore has various intented audiences. Primarily it is for students of finance who desires to see a complete discussion and implementation of some formula. But the manuscript is also useful for students of finance who wants to learn C ++, and for computer scientists who want to understand about the finance algorithms they are asked to implent and embed into their programs.

In doing the implementation I have tried to be as generic as possible in terms of the C ++ used, but I have taken advantage of a some of the possibilities the language provides in terms of abstraction and modularization. This will also serve as a lesson in why a real computer language is useful. For example I have encapsulated the term structure of interest rate as an example of the use of classes.

This is not a textbook in the underlying theory, for that there are many good alternatives. For much of the material the best textbooks to refer to are Hull (2003) and McDonald (2002), which I have used as references, and the notation is also similar to these books.

2003-10-22