Financial Numerical Recipes in C++.

Bernt Arne Ødegaard April 2007

5.1 5.2

5.3

Contents
6 1 On C++ and programming. 5

5.4

The interchangeability of discount factors, spot interest rates and forward interest rates . . . . . The term structure as an object . . . . . . . . . . 5.2.1 Base class . . . . . . . . . . . . . . . . . . 5.2.2 Flat term structure. . . . . . . . . . . . . Using the currently observed term structure. . . . 5.3.1 Linear Interpolation. . . . . . . . . . . . . 5.3.2 Interpolated term structure class. . . . . . Bond calculations with a general term structure and continous compounding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

52 55 55 57 58 59 61 64
67

The Mean Variance Frontier

1.1 1.2

1.3 1.4 1.5
2

Compiling and linking . . . . . . . . . . . . The structure of a C++ program . . . . . . 1.2.1 Types . . . . . . . . . . . . . . . . . 1.2.2 Operations . . . . . . . . . . . . . . 1.2.3 Functions and libraries . . . . . . . . 1.2.4 Templates and libraries . . . . . . . 1.2.5 Flow control . . . . . . . . . . . . . . 1.2.6 Input Output . . . . . . . . . . . . . 1.2.7 Splitting up a program . . . . . . . . 1.2.8 Namespaces . . . . . . . . . . . . . . Extending the language, the class concept. 1.3.1 date, an example class . . . . . . . . Const references . . . . . . . . . . . . . . . . Other C++ concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5 6 6 6 7 7 8 8 8 9 9 10 16 16
17

6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 6.10 6.11

Setup . . . . . . . . . . . . . . . . . . . . . . The minimum variance frontier . . . . . . . . Calculation of frontier portfolios . . . . . . . The global minimum variance portfolio . . . . Ecient portfolios . . . . . . . . . . . . . . . The zero beta portfolio . . . . . . . . . . . . . Allowing for a riskless asset. . . . . . . . . . . Ecient sets with risk free assets. . . . . . . . Short-sale constraints . . . . . . . . . . . . . . The Sharpe Ratio . . . . . . . . . . . . . . . . Equilibrium: CAPM . . . . . . . . . . . . . . 6.11.1 Treynor . . . . . . . . . . . . . . . . . 6.11.2 Jensen . . . . . . . . . . . . . . . . . 6.12 Working with Mean Variance and CAPM . . . 6.13 Mean variance analysis using matrix libraries
7 Futures algoritms.

67 69 69 72 72 73 73 74 75 75 76 76 76 76 77
81

7.1
8

Pricing of futures contract. . . . . . . . . . . . . Options . . . . . . . . . . . . . . . . . . . . . . . Pricing . . . . . . . . . . . . . . . . . . . . . . . . Multiperiod binomial pricing . . . . . . . . . . . The formula . . . . . . . . . . . . . . . . . . Understanding the why's of the formula . . 9.2.1 The original Black Scholes analysis . 9.2.2 The limit of a binomial case . . . . . 9.2.3 The representative agent framework Partial derivatives. . . . . . . . . . . . . . . 9.3.1 Delta . . . . . . . . . . . . . . . . . . 9.3.2 Other Derivatives . . . . . . . . . . . 9.3.3 Implied Volatility. . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81
82

Matrix Tools

2.1 2.2

The rst screen . . . . . . . . . . . . . Linear algebra . . . . . . . . . . . . . . 2.2.1 Basic matrix operations . . . . 2.2.2 Arithmetic Matrix Operations. 2.3 Solving linear equations . . . . . . . . 2.4 Element by element operations . . . . 2.5 Function denitions . . . . . . . . . . 2.6 m les . . . . . . . . . . . . . . . . . . 2.7 Flow control . . . . . . . . . . . . . . . 2.8 Plotting . . . . . . . . . . . . . . . . . 2.9 Libraries . . . . . . . . . . . . . . . . . 2.10 References . . . . . . . . . . . . . . . .
3 The value of time

18 18 18 19 22 24 24 24 24 24 25 25
26

Binomial option pricing

8.1 8.2 8.3
9

82 82 85
89

Basic Option Pricing, the Black Scholes formula

9.1 9.2

9.3

3.1 3.2 3.3 3.4
4

Present value . . . . . . . . . . . . . . . . . One interest rate with annual compounding 3.2.1 Internal rate of return. . . . . . . . . Continously compounded interest . . . . . . 3.3.1 Present value . . . . . . . . . . . . . Further readings . . . . . . . . . . . . . . .

26 27 30 34 35 35
36

9.4

90 92 93 93 93 93 93 94 96 98
99

10 Warrants

10.1 Warrant value in terms of assets . . . . . . . . . . 99 10.2 Valuing warrants when observing the stock value 100 10.3 Readings . . . . . . . . . . . . . . . . . . . . . . . 101
11 Extending the Black Scholes formula 102

Bond Pricing with a at term structure

4.1

4.2 4.3
5

Flat term structure with discrete, annual compounding . . . . . . . . . . . . . . . . . . . . . . 4.1.1 Bond Price . . . . . . . . . . . . . . . . . 4.1.2 Yield to maturity . . . . . . . . . . . . . . 4.1.3 Duration . . . . . . . . . . . . . . . . . . . 4.1.4 Measuring bond sensitivity to interest rate changes . . . . . . . . . . . . . . . . . Continously compounded interest . . . . . . . . . Further readings . . . . . . . . . . . . . . . . . .

37 37 38 41 43 47 50
51

The term structure of interest rates and an object lesson

11.1 Adjusting for payouts of the underlying. . . . . . 11.1.1 Continous Payouts from underlying. . . . 11.1.2 Dividends. . . . . . . . . . . . . . . . . . . 11.2 American options . . . . . . . . . . . . . . . . . . 11.2.1 Exact american call formula when stock is paying one dividend. . . . . . . . . . . . . 11.3 Options on futures . . . . . . . . . . . . . . . . . 11.3.1 Black's model . . . . . . . . . . . . . . . . 11.4 Foreign Currency Options . . . . . . . . . . . . . 11.5 Perpetual puts and calls . . . . . . . . . . . . . .

102 102 103 104 105 108 108 109 110

1

11.6 Readings . . . . . . . . . . . . . . . . . . . . . . . 111
12 Option pricing with binomial approximations 112

17 Generic binomial pricing

177

12.1 Introduction . . . . . . . . . . . . . . . . . . . . . 12.2 Pricing of options in the Black Scholes setting . . 12.2.1 European Options . . . . . . . . . . . . . 12.2.2 American Options . . . . . . . . . . . . . 12.2.3 Matlab implementation . . . . . . . . . . . 12.3 How good is the binomial approximation? . . . . 12.3.1 Estimating partials. . . . . . . . . . . . . 12.4 Adjusting for payouts for the underlying . . . . 12.5 Pricing options on stocks paying dividends using a binomial approximation . . . . . . . . . . . . . 12.5.1 Checking for early exercise in the binomial model. . . . . . . . . . . . . . . . . . 12.5.2 Proportional dividends. . . . . . . . . . . 12.5.3 Discrete dividends . . . . . . . . . . . . . 12.6 Option on futures . . . . . . . . . . . . . . . . . . 12.7 Foreign Currency options . . . . . . . . . . . . . 12.8 References . . . . . . . . . . . . . . . . . . . . . .
13 Finite Dierences

112 113 114 114 116 119 120 123 124 124 124 126 128 130 131
132

17.1 Introduction . . . . . . . . . . . . . . . . . . . . . 177 17.2 Delta calculation . . . . . . . . . . . . . . . . . . 182
18 Trinomial trees 183

18.1 Intro . . . . . . . . . . . . . . . . . . . . . . . . . 183 18.2 Implementation . . . . . . . . . . . . . . . . . . . 183 18.3 Further reading . . . . . . . . . . . . . . . . . . . 186
19 Alternatives to the Black Scholes type option formula 187

19.1 Merton's Jump diusion model. . . . . . . . . . . 187 19.2 Hestons pricing formula for a stochastic volatility model . . . . . . . . . . . . . . . . . . . . . . . . 189
20 Pricing of bond options, basic models 192

20.1 Black Scholes bond option pricing . . . . . . . . . 192 20.2 Binomial bond option pricing . . . . . . . . . . . 194
21 Credit risk 196

21.1 The Merton Model . . . . . . . . . . . . . . . . . 196 21.2 Issues in implementation . . . . . . . . . . . . . . 197
22 Term Structure Models 198

13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9

Explicit Finite dierences European Options. . . . . American Options. . . . . Implicit nite dierences . An example matrix class . Finite Dierences . . . . . American Options . . . . European Options . . . . References . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

132 132 134 137 137 137 137 140 141
142

22.1 22.2 22.3 22.4 22.5 22.6

The Nelson Siegel term structure approximation Extended Nelson Siegel models . . . . . . . . . . Cubic spline. . . . . . . . . . . . . . . . . . . . . Cox Ingersoll Ross. . . . . . . . . . . . . . . . . . Vasicek . . . . . . . . . . . . . . . . . . . . . . . Readings . . . . . . . . . . . . . . . . . . . . . . .

199 201 203 206 209 211
212

23 Binomial Term Structure models

14 Option pricing by simulation

14.1 Simulating lognormally distributed random variables . . . . . . . . . . . . . . . . . . . . . . . . . 14.2 Pricing of European Call options . . . . . . . . . 14.3 Hedge parameters . . . . . . . . . . . . . . . . . . 14.4 More general payos. Function prototypes . . . . 14.5 Improving the eciency in simulation . . . . . . 14.5.1 Control variates. . . . . . . . . . . . . . . 14.5.2 Antithetic variates. . . . . . . . . . . . . . 14.6 More exotic options . . . . . . . . . . . . . . . . . 14.7 References . . . . . . . . . . . . . . . . . . . . . .
15 Pricing American Options  Approximations

23.1 The Rendleman and Bartter model . . . . . . . . 212 23.2 Readings . . . . . . . . . . . . . . . . . . . . . . . 214
24 Interest rate trees 215

143 143 144 146 147 147 148 151 152
153

24.1 24.2 24.3 24.4 24.5

The movement of interest rates Discount factors . . . . . . . . . Pricing bonds . . . . . . . . . . Callable bond . . . . . . . . . . Readings . . . . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

215 217 217 219 221
222

25 Building term structure trees using the Ho and Lee (1986) approach

15.1 The Johnson (1983) approximation . . . . . . . . 15.2 An approximation to the American Put due to Geske and Johnson (1984) . . . . . . . . . . . . . 15.3 A quadratic approximation to American prices due to BaroneAdesi and Whaley. . . . . . . . . . 15.4 An alternative approximation to american options due to Bjerksund and Stensland (1993) . . 15.5 Readings . . . . . . . . . . . . . . . . . . . . . . .
16 Average, lookback and other exotic options

153 156 159 162 165
166

25.1 25.2 25.3 25.4 25.5

Intro . . . . . . . . . . . . . . . . Building trees of term structures Ho Lee term structure class . . . Pricing things . . . . . . . . . . . References . . . . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

222 222 222 225 227
228

26 Term Structure Derivatives

26.1 Vasicek bond option pricing . . . . . . . . . . . . 228
A Normal Distribution approximations. 230

16.1 16.2 16.3 16.4

Bermudan options . . . . . . . . . . . . . . . . . Asian options . . . . . . . . . . . . . . . . . . . . Lookback options . . . . . . . . . . . . . . . . . . Monte Carlo Pricing of options whose payo depend on the whole price path . . . . . . . . . . . 16.4.1 Generating a series of lognormally distributed variables . . . . . . . . . . . . . . 16.5 Control variate . . . . . . . . . . . . . . . . . . . 16.6 References . . . . . . . . . . . . . . . . . . . . . .

166 169 170 172 172 175 176

A.1 A.2 A.3 A.4

The normal distribution function . . . . . . . . . The cumulative normal distribution . . . . . . . . Multivariate normal . . . . . . . . . . . . . . . . Calculating cumulative bivariate normal probabilities . . . . . . . . . . . . . . . . . . . . . . . . A.5 Simulating random normal numbers . . . . . . . A.6 Cumulative probabilities for general multivariate distributions . . . . . . . . . . . . . . . . . . . . . A.7 References . . . . . . . . . . . . . . . . . . . . . .
B C++ concepts

230 231 231 232 234 235 235
236

2

C

Interfacing to external libraries

238

D E

Summarizing routine names Installation

240 250

C.1 Newmat . . . . . . . . . C.2 IT++ . . . . . . . . . . C.3 GSL . . . . . . . . . . . C.3.1 The evaluation of C.4 Internet links . . . . . .

. . . . . . . . . . . . N3 . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

238 238 238 238 239

E.1 Source availability . . . . . . . . . . . . . . . . . 250
F Acknowledgements. 255

3

This book is a a discussion of the calculation of specic formulas in nance. The eld of nance has seen a rapid development in recent years, with increasing mathematical sophistication. While the formalization of the eld 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 Black and Scholes (1973); Merton (1973) which really was the starting point for the mathematicalization of nance. The elds of derivatives and xed income have since then been the main elds 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 ecient, 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 (Not to mention the straitjacket which is is a spreadsheet.)

Matlab
C++

og

Gauss

and going back to implementation in a

standard language. In my experience with empirical nance I have come to realize that nothing beats knowledge a

real

computer language. This used to be

py‚„‚ex,

then

g,

and now it is

. All example

algorithms are therefore coded in C++. I do acknowledge that matrix tools like

w—tl—˜

are very good for

rapid prototyping and compact calculations, and will in addition to C++ in places also illustrate the use of

w—tl—˜.
The

The manuscript has been sitting on the internet a few 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.

present (2007) 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 nance but not C++. All the routines have been made to conrm 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 nance who desires to see a complete discussion and implementation of some formula. But the manuscript is also useful for students of nance who wants to learn C++, and for computer scientists who want to understand about the nance 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

™l—sses.

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 (2006) and McDonald (2006), which I have used as references. The notation of the present manuscipt is also similar to these books.

4

. . . 1. . . . . . . . . . . . . on the language is Stroustrup (1997). . . . . . . . . . . . . . . Contents 1. . . . . . . . . . . . which is then into low-level instructions (machine language) and linked compiled with libraries to make a complete executable program. . . . . . . . . . . 10 16 16 Other C++ concepts . . . . .2. . . . . . . . . . This chapter also only discusses a subset of C++. . . . . . . . . . . . . Splitting up a program . . . . Templates and libraries . .5 1. .Chapter 1 On C++ and programming. . . . . . . and we leave these details as an exercise to the reader. . . . . . . . . . Namespaces . the class concept. . .1 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 The authorative source 1. . . . . . .4 1. . . . . . . . . . . . . 1. . . . . . . . . . . In this chapter I introduce C++ and discuss how to run programs written in C++. . . . . . . . . . . . . . . This is by no means a complete reference to programming in C++. . . . . 1 s le—rned g++ from the previous edition of the ˜ookD vippm—n @IWWPAF prom wh—t s ™—n tell the present editions still seems like — good w—y of le—rning the l—ngu—geD ˜ut g++ h—s ™h—nged — lot in re™ent ye—rsF 5 . . . . . . . . . . 6 6 7 7 8 8 8 9 9 . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Compiling and linking . . . . . . an example class . . . . . . . . . . .2.1 1. . . . . . . . . 1. . . . . . 1. . . . Input Output . . . . . . . . . . . .3 Extending the language. . . . . . .2. . it is designed to give enough information to understand the rest of the book. . . . . . . . . . . . . . . . . . . . . . . . . Flow control . . . . . . . . .5 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 1. . . . . . .8 . 5 6 Types .2. . . . . . . .3. . . . . . . . . . . For really learning C++ a textbook is necessary. . . . .2. . . . .4 Const references . . . .1 Compiling and linking To program in C++ one has to rst write a separate le with the program. . . . . . . . . . . . . . . . .2. . . . . . . . . . . .6 1. . . . . . . . . . Operations . . . I have found Lippman and Lajoie (1998) an excellent introduction to the language. Functions and libraries . . . . . . . . . . . . . . . . The structure of a C++ program . . . . . . . . .2. . . . . . . . .7 1.2. . . . The mechanics of doing the compiling and linking varies from system to system. . . . . . . . . . . . . . . . . . . . . . . . . . .1 date. . . . . . . . . . . . .2 1. . . . . . . . . . . . . . . . . . . it concentrates on the parts of the language used in the remainder of this book. . . . . . .

operations and functions. subtraction. which can be grouped into types. C++ has a few basic building blocks. of which more later. Such These operations are dened for all the common datatypes. Everything must be declared before it is used. ˜ool this•is•trueatrueY int i a HY long j a IPQRSTUVWY dou˜le pi a QFIRISWPTSQSVWUWQPQVRTPTRQY string s@4this is — string4AY The most important part of C++ comes from the fact that these basic types can be expanded by use of classes. as we will see later.2 Operations To these basic types the common mathematical operations can be applied. it does come in handy for more abstract data constructs.2.2 The structure of a C++ program The rst thing to realize about C++ is that it is a strongly typed language. An example we will be using often is incrementing and decrementing a variable. When we want to increase the value of one item by one. 6 . dou˜le and string. multiplication and division: int int int int i j n m a a a a IHH IHH IHH IHH C E B G SHY SHY PY PY string type. long. 1. and it is excusable to think that this operation is not really necessary.2.1 Types The types we will work with in this book are Here are some example denitions ˜ool.1. to get the next date will simply be a matter of d—te d@IDIDIWWSAY dCCY These two statements will result in the date in d being 2jan95. with exception of the operations can be dened by the programmer for other datatypes as well. in most languages this is written: int iaHY i a iCIY i a iEIY In gCC this operation has its own shorthand int iaHY iCCY iEEY While this does not seem intuitive. Increment and decrement In addition to these basic operations there are some additional operations with their own shorthand. if one denes a d—te class with the necessary operations. such as addition. both variables and functions. For example. 1. int.

The example we will be considering the most is the ve™tor`b. Also included in the standard library is generic data structures. which calculates xn .. These functions are included that comes with any C++ installation.2.718281828. they are implemented as standalone functions (most of which are actually written in in the large library g or C++).4 Templates and libraries The use of libraries is not only limited to functions. the mathematical operations of taking powers and performing exponentiation are dened in the mathematical library ™m—th. 1.2. respectively. When rst dening the vector with the statement ve™tor`dou˜leb w@PAY we dened an array of 2 elements of type dou˜le. which denes an array. which can be used on any data type. However. The last statement.. w‘H“ really means the rst g or C++ from another language. Indexing of 7 . and exp@rA which calculates er . among which one nds I and b a e . 5in™lude `ve™torb ve™tor`dou˜leb w@PAY w‘H“aIFHY w‘I“aPFHY wFpush•˜—™k@QAY This example denes an array with three elements of type double P M aR I P Q Q S Note some pecularities here. When lling the array we addressed each element directly. Since they are not part of the core language they must be dened to the compiler before they can be used. not at one. which we then proceeded to ll with the values 1 and 2. For example. element of the array. Such denitions are performed by means of the include statement. In the C++ program one will write 5in™lude `™m—thb ™m—th is actually a le with a large number of function dentions. Note that in the statement w‘H“aIFHY lies one of the prime traps for programmers coming to arrays starts at zero.1. pow@xDnA The following programming stub calculates a a PP 5in™lude `™m—thb dou˜le — a pow@PDPAY dou˜le ˜ a exp@IAY which will give the variables — and ˜ values of 4 and 2. these are not parts of the core language.3 Functions and libraries In addition to the basic mathematical operations there is a large number of additional operations that can be performed on any type.. or vector of variables.

wFpush•˜—™k@QAY shows the ability of the programmer of changing the size of the array after it has been dened. In this case the value of of <n). This is the typical reputation for terseness is the possibility of elaborate for for statement. One of the causes constructs. which end up being almost impossible to read. To illustrate we provide a complete example program. one will do as follows: 5in™lude `fstre—mb ofstre—m outfY outfFopen@4testFout4AY outf `` 4„his is — test4 `` endlY outfF™le—r@AY outfF™lose@AY 1.7 Splitting up a program Any nontrivial program in C++ is split into several pieces. 1. Most programming languages do not allow the programmer to specify variable-sized arrays on the y. The rst part gives the initial condition (iaH). operations is dened in a couple of libraries. to repeat an operation n times one can use the following for for loop: for @int iaHY i`nY iCCA { some•oper—tion@iAY }Y The for statement has tree parts. for 1. For example. and stick to the basic cases. Input and output iostre—m and fstre—m.5 Flow control To repeat statements several times one will use on of the possibilities for ow control. The next part the terminal condition (i The last part is the increment statement (iCC). and hope that we would not need to exceed that length. g's i is increased by one in each iteration. which is at the n'th iteration. push•˜—™k is a standard operation on arrays which pushes the element onto the back of the array. one will do as follows: 5in™lude `iostre—mb ™out `` 4„his is — test4 `` endlY To write to a le "testFout". To write to standard output ™out (the terminal).6 Input Output For any program to do anything useful it needs to be able to output its results. 8 . such as the or while constucts.2. In the algorithms presented in this book we will try to avoid any obfuscated statements.2. extending the size of the array by one element. saying what to do in each iteration. Usually each piece is written as a function which returns a value of a given type. In for each array. The py‚„‚ex or €—s™—l we would usually have to set a maximum length ve™tor<> template of C++ gets rid of the programmers need for bookkeeping in such array manipulations.2. which says to stop when i <n is not fullled.1. shown in C++ Code 1. The rst covers in/output to standard terminals and the second in/output to les.

n++){ }. 9 . return p. the program will provide the following output P”I P”P P”Q P”R P”S 1. the class concept.1: A complete program The program denes a function performing the mathematical power operation. C++ Code 1. for the current purposes we will allow all routines access to the whole standard namespace.n) << endl. called the standard namespace. culates xn through the identity xn a en ln@xA . }. To actually access these library functons it is necessary to explicitly specify that one wants to access the standard namespace.n<6. by the statement using n—mesp—™e stdY Instead of such a general approach. One of the major advances of C++ relative to other programming languages is the programmers ability to extend the language by creating new data types and dening standard operations on these data types. GG the —˜ove is p—rt of the st—nd—rd n—mesp—™e double power(double x. int m—in(){ for (int n=1.8 a a a a a P R V IT QP Namespaces To help in building large programs. the concept of a n—mesp—™e was introduced. since much of the work in programming is done by creating objects. }. An object is best though of as a data structure with operations on it dened. linked and run. This ability is why C++ is called an object oriented programming language. 1. double n){ GG de(ne — simple power fun™tion double p = exp(n*log(x)). For now it is necessary to know that any function in the standard C++ library lies in its own namespace. power@xDnA which cal- This function is then used to calculate and print the rst 5 powers of 2. ™out << " 2^" << n << " = " << power(2.2.#include <iostre—m> GG input output oper—tions #include <™m—th> GG m—them—ti™s li˜r—ry using namespace std. How one uses an object is best shown by an example. Namespaces are a means of keeping the variables and functions dened local to the context in which they are used. one can also specify the namespace on an element by element basis. When compiled. but this is more a topic for specialized C++ texts.3 Extending the language.

1 date. it can also be represented by the strings:  PHHQGVGIP. Let us limit ourselves to the Gregorian calendar. or by the number of years since 1 january 1900. < (const d—te&. int month() const.  IPGVGPHHQ and so on. bool v—lid() const. Header le 1. GG pre(x   (int). const d—te&). As internal representation of the date is d—y•. However.3. d—te(const int& d. <= (const d—te&.1. bool bool bool bool bool bool operator operator operator operator operator operator == (const != (const d—te&. ). void set d—y (const int& d—y ). int month int d—y . const d—te&). public: . operator operator operator operator GG pre(x GG post(x   (). 12 august 2003 is a common way of specifying a date. they want to be able to enter dates in some abstract way. for most people writing programs the representation of a date is not relevant. but we will show a trivial such date class as an example of how one can create a class. This is the data structure which is then manipulated by the various functions dened below. an example class Consider the abstract concept of a date. Typically one will look around for an extant class which has already implemented this. and then are conserned with such questions as:    Are two dates equal? Is one date earlier than another? How many days is it between two dates? A C++ programmer will proceed to use a class that embodies these uses of the concept of a date. const d—te&). void set month (const int& month void set ye—r (const int& ye—r ). GG ™omp—rison oper—tors d—te&. d—te(). as shown in chosen the three integers Dening a d—te class Header le 1. GG post(x ++(). d—te d—te d—te d—te }. the number of months since January. int d—y() const. A date can be specied in any number of ways. const d—te&). month• and ye—r•. >= (const d—te&. const int& m. The functions are used to 10 . However. int ye—r() const. const d—te&).1: A class is dened in a header le. class d—te { protected: int ye—r . const int& y).1. const d—te&). and the day of the month (which is how a UNIX programmer will think of it). > (const d—te&. ++(int).

by providing an integer as arguments to the function. the user of the class can safely ignore the class' privates. ba. For exmple. d—te object will only need to look at the header le to know what are the possible functions one can use with a d—te object. month@A and and Functions outputting the date by the three integer functions Functions setting the date ye—r@A. initialization. and be happy about not needing to know Any C++ programmer who want to use this anything about how these functions are implemented. Let us look at the implementation of this. Increment and decrement functions Comparison functions ! 3E. all details about implementation of the class objects and its functions is not used in code using this object. which are used set•d—y@intA. This is the encapsulation part of object oriented programming. anyway. all relevant information about the d—te object is specied by the header le. b. programmers using such a class will then treat an object of type just like any other.2 valid. set•month@intA CC and and set•ye—r@intA. In fact. d—te `. which is only good manners. C++ Code 1. `a. aa After including this header le. d—te d@IDIDPHHIAY CCdY would result in the d—te object d containing the date 2 january 2001. This is the only point of interaction. denes the basic operations. and checking whether a date is 11 .     Create a date variable: d—te@™onst int8 dD ™onst int8 mD ™onst int8 yAY d—y@A. setting the date.

int d—teXXd—y() const { return d—y . void d—teXXset d—y (const int& d—y) { d—teXXd—y = d—y.#include "date.2: Basic operations for the date class 12 .}. void d—teXXset month(const int& month) { d—teXXmonth = month. }.h" d—teXXd—te(){ ye—r = 0. month = month. d—teXXd—te(const int& d—y. }. bool d—teXXv—lid() const { GG „his fun™tion will ™he™k the given d—te is v—lid or notF GG sf the d—te is not v—lid then it will return the v—lue f—lseF GG xeed some more ™he™ks on the ye—rD though return false. const int& ye—r){ d—y = d—y. int d—teXXmonth() const { return month . }. int d—teXXye—r() const { return ye—r . if ((d—y ==31 && ( month ==2 j j month ==4 j j month if return false. void d—teXXset ye—r (const int& ye—r) { d—teXXye—r = ye—r. }. d—y = 0. }. month = 0. GG should —lso ™he™k for le—p ye—rsD ˜ut for now —llow for fe˜ PW in —ny ye—r return true. ye—r = ye—r. C++ Code 1. if (d—y >31 j j d—y <1) return false. const int& month. }. }. }. ==6 j j month ==9 j j month ==11) ) ) ( d—y ==30 && month ==2) return false. if (ye—r <0) if (month >12 j j month <1) return false.

} return (dI<dP).d—y()). } return (dI. For dates there is the natural ordering. GG see —˜ove rem—rk if (dI.For many abstract types it can be possible to dene an ordering.3: Comparison operators for the date class 13 .v—lid() && (dP. }. const d—te& dP) if (dI==dP) { return true. #include "date.ye—r()). const d—te& dP){ if (! (dI. { return (dI. return (dI>dP).v—lid())) ) { return false.ye—r()) { GG s—me ye—r if (dI. } bool operator >=(const d—te& dI.ye—r())).}. { bool operator bool operator > (const d—te& dI. } else }.} C++ Code 1.3 shows how such comparison operations is dened.d—y()==dP. }.month()==dP. const d—te& dP){ if (dI==dP) { return true.v—lid())) ) { return false. }.ye—r()==dP.ye—r()==dP.h" bool operator == (const d—te& dI. const d—te& dP) !=(const { return !(dI <=dP).}.month()==dP.month()) && (dI.d—y()) && (dI.month()). { else }. ((dI.month()<dP.month()) { GG s—me month return (dI.ye—r()<dP. const d—te& dP){ return !(dI==dP). —ltern—tiveX throw ex™eption BG bool operator < (const d—te& dI. d—te& dI.d—y()<dP. C++ Code 1. }.const d—te& dP){ GG ™he™k for equ—lity if (! (dI.v—lid() && (dP. GB if d—tes not v—lidD not ™le—r wh—t to doF return }. GG di'erent ye—r GG rem—ining oper—tors de(ned in terms of the —˜ove bool operator <=(const d—te& dI.

v—lid()) return pd—t.month() 1).month() 1).v—lid()) return pd—t. }.ye—r()).v—lid()) return nd—t. pd—t = d—te(31.(d.ye—r() 1)). } d—te previous d—te(const d—te& d){ if (!d. pd—t = d—te(29.(d.(d.d—y() 1). nd—t = d—te(1. GG try previous month pd—t = d—te(30. }.d. return *this.C++ Code 1.v—lid()) return pd—t. GG (rst try —dding — d—y if (nd—t.d. return d.d.month() 1). GG try s—me month pd—t = d—te(31. } d—te d—teXXoper—tor   (int){ GG post(x oper—torD return ™urrent v—lue d—te d = *this. d—te d—teXXoper—tor ++(int){ GG post(x oper—tor d—te d = *this. return *this. GG then try —dding — month if (nd—t. if (pd—t. nd—t=d—te(1.v—lid()) return nd—t. called an iteration operator.v—lid()) { return d—te().ye—r()).(d.1.v—lid()) return pd—t.d.ye—r()). if (pd—t.month()+1).(d. *this = previous d—te(*this). if (pd—t.4: Iterative operators for the date class 14 .(d.12.ye—r()+1)). } d—te d—teXXoper—tor   (){ GG pre(x oper—torD return new v—lue *this = previous d—te(*this). *this = next d—te(d). if (pd—t. GG must ˜e next ye—r return nd—t.month() 1).month(). return d.d.h" d—te next d—te(const d—te& d){ if (!d.ye—r()).d. GG d—te nd—t=d—te((d. GG return the def—ult d—te d—te pd—t = d—te((d.4 shows operations for nding previous and next date. }. C++ Code 1. }.d.d. } d—te d—teXXoper—tor ++(){ GG pre(x oper—tor *this = next d—te(*this).d—y()+1).v—lid()) return pd—t.ye—r()). if (pd—t.(d.v—lid()) { return d—te().d.month().ye—r()). pd—t = d—te(28. #include "date.ye—r()). GG try previous ye—r return pd—t.

and return this date. etc. The function v—lid@A in the date class accepts february 29'th in every year.4. Implement a function querying the operating system for the weekday of a given date. ‡indows). why would you say that w—tl—˜ has an o-by-one problem relative to ‡indows? w—tl—˜ and 15 . Once the date class is available. Take a look at how dates are dealt with in various computing environments. Go to the end or beginning of a month? 3. Exercise 1. 2. Find the relevant functions in your implementation. Extract a date from a string? (Here one need to make some assumptions about the format) Exercise 1. and return a representation of the weekday as a member of the set: {4mon4D4tue4D4wed4D4thu4D4fri4D4s—t4D4sun4} 3. Reimplement the v—lid@A function using a system call. Add a given number of days to a date? 2.1. Exercise 1.3. a number of obvious functions begs to be implemented.2. Implement a function querying the operating system for the current date. At what level of abstraction is the interface? Do you need to know how dates are implemented? For those with access to both ‡indows. but this should ideally only happen for leap years. and 1. Modify the function to return a f—lse if the year is not a leap year. such as the operating system (…nix. which your typical C++ implementation can call. How would you 1. Find the distance betwen two dates (in days or in years)? 4. applications (Spreadsheets). programming languages. A typical operating system has functions for dealing with dates.Exercise 1.

However.5 Other C++ concepts A number of other C++ concepts. They only appear in a few places and is better introduced where they are used. which in most cases one do not want. but in the second case one uses the same variable. dened by function calls: Consider two alternative calls to a function. 16 .1. The latter is more ecient. it says that the function can not modify its argument. one worries that the variable referred to is changed in the function. will be introduced later in particular contexts. such as function prototypes and templates. In the rst case a copy of the variable referenced to in the argument is created for use in the function. 1. Therefore the ™onst qualier. in particular when the argument is a large class. but they work dierently.4 Const references Let us now discuss a concept of more technical nature. some•fun™tion@dou˜le rAY some•fun™tion@™onst dou˜le8 rAY They both are called by an argument which is a double. in most of the following routines arguments are therefore given as as constant references. and that argument is guaranteed to not be changed in the calling function. For eciency. the argument is a reference to the location of the variable. The compiler will warn the programmer if an attempt is made to modify such a variable.

in many applications in nance a very handy tool is a language for manipulating vectors and matrices using linear algebra. While the bulk of the present book concerns itself with C++. An early tool of this sort was matlab. There are a lot of dierent possible programs that behaves very similarly. the notation tends to be so close how a mathematician would write them that programs can be relatively easy to follow. General tools include the commercial package sold by Mathworks. the tool for business school Of course. While compact notation is always prone to tense. w—tl—˜ Tools that are similar. making programs using it unreadable. As for what program to install. All of these tools are programs that lets the user manipulate vectors and matrices using very compact notation. and good for learning the basics of such a matrix tool. this is not such a large problem in w—tl—˜. All of them perform the basic operations done by the commercial w—tl—˜ package. F¢ ¢ means that the matrix e is taken to the power 2 (multiplied with itself). For the basic learning of how these tools work. As a result of this there is a proliferation of programs with similar syntax to w—tl—˜ doing similar analysis. any of the mentioned packages will do the job.Chapter 2 Matrix Tools Being computer literate entails being aware of a number of computer tools and being able to choose the most suitable tool for the problem at hand. o™t—ve. where the operator operator For example. a spreadsheet is very useful for very many business applications. there is no right answer. bb e a ‘I I Y I I“ e a I I I I bb e”P —ns a P P P P bb eF”P —ns a 17 . Ox and S and with its public domain clone ‚. For students on a limited budget the public domain tools s™il—˜ and R are obvious candidates. with a syntax taken from the mathematical formulation of linear algebra. and want to t any problem to the computer tool they know. The tool that very often is students is a spreadsheet like Excel. in particular it is easy to miss the dierence between a command operating on a whole matrix and the corresponding element by element operation. and the means that each element of the matrix e is taken to the power 2. However. with a large number of programs s™il—˜. include Gauss. but more copying much of the syntax of this program. it is not the best tool for more computationally intensive tasks. The two commands give very dierent answers. Way to many people turns this around. There are some pitfalls for the unwary user. the public domain programs o™t—ve geared towards econometrics. consider the following short example.

2. 2. the matrix tool will respond to this command by printing This particular command denes a matrix the matrix that was just dened: e a I P Q R S T 2. We will bb as the prompt. In w—tl—˜ the type of each variable is determined when you rst dene it.1 The rst screen How you start the particular tool you are using depend both on which program and which operating system you are working on. The tools are interactive. vectors. We assume the reader have this basic knowledge.2 Linear algebra To use such a tool you need some knowledge of linear algebra.2. if not a quick perusal of a standard mathematical text on linear algebra is called for. and matrices. The details of how to start it is left as an exercise to the reader. which means that the program is ready to receive commands. they present you with a prompt.1 Basic matrix operations In matrix algebra a set of mathematical rules are given for operating on the basic elements real numbers.I I I I The rest of this chapter gives an introduction to a tool like this. and expect you to start writing commands. In the text output of the matrix tool will be shown typewritten as: bb e a ‘ID PD QY RD SD T“ e. bb —aI — a I bb ˜aP ˜ a P bb ™aQ ™ a Q bb ya‘IYPYQ“ y a I P Q bb xa‘IDPDQ“ x a I P Q 18 .

both Note that e and — are dened. given the above denitions: bbfa‘™ f a Q I bb g a g a I P R S I P bb h a errorX errorX x“ P Q ‘eYx“ Q T Q ‘e y“ num˜er of rows must m—t™h ev—lu—ting —ssignment expression ne—r line PPD ™olumn Q w—tl—˜ If the dimensioning is wrong. a semicolon a new row. end the line with a semicolon: bb ea‘IDPDQDR“Y bb ea‘IDPDQDR“ e a I P Q R bb You can also use dened variables to dene new variables. as long as the dimensions make sense. and the variable is not dened. its builtin matrix arithmetic.bb ea‘I P QYR S T“ e a I P Q R S T Observe that when lling in a vector or a matrix a space or a comma means a new number. To see what is in a variable. We rst show how to manipulate numbers and vectors: bb —aI — a I bb ˜aP ˜ a P bb —C˜ —ns a Q 19 . namely. let us add and subract a few elements according to the rules of matrix algebra.2 Arithmetic Matrix Operations. To suppress the printing of what you just dened. We now get to the important parts of w—tl—˜. 2.2. Given the de- nitions above. you get an error message. tell to print the value by giving the name: bb — — a I bb e e a I P R S Q T w—tl—˜ is case-sensitive. For example.

but in terms of notation it is just like vector multiplication. it is a much more complex operation. When multiplying matrices.bb xa‘I P Q R“ x a I P Q R bb ya‘R Q P I“ y a R Q P I bb xCy —ns a S S S S bb yEx —ns a Q I EI EQ bb —BxC˜By —ns a W V U T similarly. for matrices: ea‘I P QY R S T“ e a I P Q R S T bb fa‘T S RY Q P I“ f a T S R Q P I bb eCf —ns a U U U U U U bbeEf —ns a ES EQ EI I Q S bb —BeC˜Bf —ns a IQ IP II IH W V b eBf9 —ns a PV IH UQ PV In linear algebra. you need to be aware that matrix multiplication is not element by element multiplication. you need to be more careful about dimensions. bb ea‘I P QYR S T“ e a I P Q R S T bb f a ‘I PYQ RY S T“ 20 . where all possible vector combinations are multiplied with each other.

f a I P Q R S T bb eBf —ns a PP PV RW TR bb fBe —ns a W IP IW PT PW RH IS QQ SI AB and For these matrices. in fact. If we let B be a P ¢ P matrix. bb fa‘I PYQ R“ f a I P Q R bb eBf errorX non™onform—nt m—tri™es @opI is PxQD opP is PxPA bb fBe —ns a W IP IS IW PT QQ Let us now discuss some standard matrix concepts. both BA are dened operations. The transpose of a matrix e is found in w—tl—˜ as e9: bb e e a I P R S bb e9 —ns a I R P S Q T Q T Two special matrices are the null and identity matrices: bb null a zeros@QDQA null a H H H H H H H H H bb ident a eye@QDQA ident a I H H H I H 21 . even the dimension of the product is dierent. then multiplying AB is an error. but note that the results are dierent.

we solve the linear equation by nding the unique solution x a A 1 b 22 .3 Solving linear equations Consider the basic linear equation Ax a b This equation has a dened solution if the rank of A equals the rank of ‘Ajb“. bb ha‘I PYI R“ h a I P I R bb inv@hA —ns a PFHHHHH EIFHHHHH EHFSHHHH HFSHHHH bb h”EI —ns a PFHHHHH EIFHHHHH EHFSHHHH HFSHHHH To make sure that this is the inverse.H The H I of a matrix is is the number of independent rows or columns in the matrix. and calculated as rank bb ehi e a I P Q R S T bb r—nk@eA —ns a P The inverse of a square matrix or in mathematical notation e is the matrix inv@eA AA I a I. such that A*inv(A) equals the identity matrix. If A is nonsingular. multiply h and inv@hA: bb h B inv@hA —ns a I H H I Determinant bb f f a I P Q R bb det@fA —ns a EP 2.

But you should be aware that solving the system of equations by calculation of the inverse is not the numerically most stable way of doing the calculation. operator w—tl—˜ has built in a direct linear matrix solver. Since A is bb inverse@eA —ns a QFHHHH EPFHHHH EPFHHHH IFSHHH bb x a inverse@eA B ˜ x a EI P The solution to the system of equations is xa  I P ! In this case we calculated the solution by nding the inverse. which is invoked by the left division bb x a e’˜ x a EI P 23 . we can calculate the solution as ‘Ajb“ by ‘e ˜“.Consider the linear equation QxI C RxP a S RxI C TxP a V Write this in matrix form by dening Aa Q R R T S V ! ! ba Let us rst check that this system is solvable bb e a ‘Q RYR T“ e a Q R R T bb ˜a‘SYV“ ˜ a S V bb r—nk@eA —ns a P bb r—nk @‘e ˜“A —ns a P Note how to create the augmented matrix square. The rank of the two is the same.

when taking the exponent of a matrix b ea‘I IYI I“ e a I I I I bb e”IH —ns a SIP SIP SIP SIP bb eF”IH —ns a I I I I 2. not the vector or matrix.5 Function denitions 2.6 m les 2. it means the command applies to each element of a vector or matrix. and it is usually the preferred way to do this operation. with the two vectors below. can be better 24 . consider the dierence in multiplying the two and doing an element by element multiplication: b xa‘I P Q “ x a I P Q b ta‘I P Q“ t a I P Q bb xBt9 —ns a IR b xFBt —ns a I R W Similarly. unless the inverse is needed for other purposes.4 Element by element operations When a command is prexed with a period.7 Flow control 2.This solves the system of equations directly. For example.8 Plotting A very important use for a tool like w—tl—˜ is its ability to produce plots graphing mathematical relationships. For illustrating mathematical relations a two or three dimensional picture than the thousands words of the old adage. 2.

9 Libraries 2.10 References You need the manual for your chosen package. 25 .2.

. . . . . . . . . . Such a price is also called a discount factor. . . . . . . . .1 3. . 35 35 Finance as a eld of study is sometimes somewhat ippantly said to deal with the value of two things: time and risk. . . . . . . . . . . . . . We will return to how one would adjust the prices for risky cash ows. or the value of time. . . These are the two issues which is always present. . . . . .1 Present value t. . .Chapter 3 The value of time Contents 3. . . . . . there is a deal of truth in it. . . . . . . . . . .2 3. dI . . . . . . . PV a N ˆ iaI dti Cti 26 . . . While this is not the whole story. . . . . . . . . . .4 Present value . . . tN Ct be the cash ow at time C1 0 To nd the C2 t2 CN t1 E time present value of these future cash ows one need a set of prices of future cash ows. . . . Let Suppose we have N future cash ows that occur at times tI . . One interest rate with annual compounding . . . . . . . . . . . . . . : : : . .1 Internal rate of return. . . 3. . . . . . . . .. . . . . . . Suppose dt is the price one would pay today for the right to receive one dollar at a future date t. . .1 3. .2. . . . . the prices of riskless future cash ows. . 26 27 3. . Further readings . . . . . . . . . . ¡ ¡ ¡ . . . . . . . . . . . . . . . . . . . . . dP . If one knows the set of prices for future claims of one dollar. . . . . . . . tP . . . . . . one would calculate the present value as the sum of the present values of the dierent elements. . To complicate matters further such prices will dier depending on the riskiness of the future cash ows. . . . . tN . . We start our discussion by ignoring risk and only considering the implications of the fact that anybody prefers to get something earlier rather than later. . . . . . . . . . . . . . . . . . . . . .3 3. . . . . . . . .3. . For now we concentrate on one particular set of prices. . . . . . . 30 34 Continously compounded interest . The present value is the current value of a stream of future payments. Present value . . . . . . . . .

}. This is termed a at term structure.size(). The implementation of this calculation is shown in #include <™m—th> #include <ve™tor> using namespace std. @I C rAt as In this case one would calculate the present value of a stream of cash ows paid at discrete dates t a I. or yields. P. To further r is constant for all periods.Ct 1 0 Ct 2 t2 Ct N tN t1 E time dt1 Ct1 dt2 Ct2 dtN CtN ' ' ' However.2 One interest rate with annual compounding The best known way to simplify the present value calculation is to rewrite the discount factors in terms of interest rates.t++) { €† += ™)ow —mounts[t]/pow(1.™)ow times[t]). The prices for valuing the future payments dt is calculated from this interest rate: simplify this calculation one can impose that this interest rate dt a I . through the relationship: dt a where I @I C rt At rt is the interest rate (usually termed the spot rate) relevant for a t-period investment.0+r. for (int t=0. We will in the next chapter relax this simplifying assumption. and some way has to be found to simplify the data need inherent in such general present value calculations. }. t<™)ow times.0.1: Example Present value with discrete compounding 27 . #include <iostre—m> double ™—sh )ow pv dis™rete(const ve™tor<double>& ™)ow times. const double& r){ double €†=0. knowing this set of current prices for cash ows at all future dates is not always feasible.1. const ve™tor<double>& ™)ow —mounts. 3. : : : N PV a N ˆ @I C rAt taI Ct : C++ Code 3. C++ Code 3. return €†.

push ˜—™k(75). What is the Net Present Value of the project? w—tl—˜ program: g=[ 100 75 75] t=[0 1 2] r = 0. Show that the present value of this perpetuity simplies to PV a X X @I C gAt I a I @I C rAt r g taI 28 . A I ˆ ICr taI X a X r X growing perpetuity is again an innite sequence of cashows. X each period for the indenite future. i. there are a number of useful special cases of cash ows where one can calculate the present value in a simplied manner. and so on.1 d=(1/(1+r)). the time 2 payment is X @IC gA. ve™tor<double> times. where the payment the rst year is each consequent payment grows by a constant rate is X @I C gAP .1.0). times.push ˜—™k(1).1. Some of these are shown in the following exercises. ™)ows. times.e. double r=0. I ˆ g.push ˜—™k(75). times.push ˜—™k(2).^t x€†=g*d' Output from w—tl—˜ program: g a EIHH US US t a H I P r a HFIHHHH d a IFHHHHH HFWHWHW HFVPTRS x€† a QHFITS C++ program: ve™tor<double> ™)ows. Output from C++ program: €resent v—lueD IH per™ent dis™retely ™ompounded interest a QHFITSQ Given the assumption of a discrete.2.An investment project has an investment cost of 100 today. Show that the present value of this sequence of cash ows is calculated simply as PV a Exercise 3. r) << endl. Exercise 3.push ˜—™k( 100. annual interest rate.0). ™)ows. Suppose 1. and produces cash ows of 75 each of the next two years. A perpetuity is a promise of a payment of a xed amount there is a xed interest rate r. 10 percent discretely compounded interest = " << ™—sh )ow pv dis™rete(times. the time 3 payment and 1.push ˜—™k(0. ™)ows. ™out << " Present value. ™)ows.

the payments grows at a rate of P the third X @I C g A . Consider a period. 2. An T ˆ taI @I C rAt X aX I I   I @I C rAT r r ! growing annuity is a sequence of cashows for a given number of years. say where each payment grows by a given factor each year. i.5.3. A perpetuity with an annual payment of $100.e. say an annuity paying a xed amount X each period. After that. A 10 year growing annuity. 4. A growing perpetuity. 29 . 1. 1. Rank the following cash ows in terms of present value. 3. The interest rate is r. T periods into the future.4. where the rst payment is $75. An annuity is a sequence of cashows for a given number of years. T ˆ g per year. Consider 1. T periods into the future. and so on. Use an interest rate of 5%. Show that the present value of this growing annuity can be simplied as   X @I C gA@t IA I ICg T I PV a aX   ICr r g @I C rAt r g taI 4 5 Exercise 3. and each subsequent payment grows by 2%. T -period annuity that pays X the rst the second year the cash ow is X @I C g A. A 10-year annuity with an annual payment of $90. Show that the present value of this sequence of cash ows can be simplied as PV a Exercise 3.Exercise 3. and each subsequent payment grows by 5%. where the rst payment is $85.

3.2 is suitable. To estimate a return for a set of cash ows we calculate the internal rate of return. The IRR method also assumes intermediate cash ows are reinvested at the internal rate of return. When there is a uniquely dened internal rate of return we get a relative measure of the protability of a set of cash ows. where we know that there is one IRR. there in no way to nd an explicit Note that this is a polynomial equation. measured as a return. Teukolsky. 30 . The internal rate of return for a set of cash ows is the interest rate that makes the present value of the cash ows equal to zero. Saying that an investment earns 10% per year is a good way of summarizing the cash ows in a way that does not depend on the amount of the initial investment. the method implemented in process called bisection.e. C++ Code 3. the interest rate has some further use. Vetterling. Suppose the cash ows are of the equation CH . a at term structure). Note some of the implicit assumptions made here. typically expressed as a percentage. The percentage return on an investment is a summary measure of the investment's protability. Chapter9). We assume that the same interest rate applies at all future dates (i. CP . In addition to its role in simplifying present value calculations.2. : : : CT . and as solution to the equation. The return is thus a relative measure of protability. 1992. it is an iterative It is an adaption of the bracketing approach discussed in (Press.1 Internal rate of return. Finding an internal rate of return is nding a solution y T ˆ @I C y At taI Ct   CH a H T becomes large. and Flannery. For well behaved cash ows. CI . It therefore needs to be solved numerically.

double rt˜.6*(xP xI)). double fP = ™—sh )ow pv dis™rete(™)ow times.0) { return i‚‚y‚.6*(xI xP)). GG errorF C++ Code 3. { fP = ™—sh )ow pv dis™rete(™)ow times. double f mid = ™—sh )ow pv dis™rete(™)ow times.0.5. double f = ™—sh )ow pv dis™rete(™)ow times. double xI = 0.0) { rt˜ = x mid. double dx=0. rt˜ = xI. xP+=1.0) { break. const double egg…‚eg‰ = 1. }. double x mid = rt˜+dx. } else }. dx *= 0.2.™)ow —mounts. if (f <0.size()!=™)ow —mounts. }. xP). ™)ow —mounts. dx = xI xP. } else { rt˜ = xP. }. int i. if (f mid<=0.h" const double i‚‚y‚=  1e30. { double ™—sh )ow irr dis™rete(const ve™tor<double>& ™)ow times. return i‚‚y‚.2: Estimation of the internal rate of return 31 . } if ( (f—˜s(f mid)<egg…‚eg‰) j j (f—˜s(dx)<egg…‚eg‰) ) return x mid.i<weˆ s„i‚e„syxƒ. ™)ow —mounts.#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. #include "fin_recipes.™)ow —mounts. const int weˆ s„i‚e„syxƒ = 50. for (i=0. for (i=0.0e 5. if (fP*fI>0. x mid). const ve™tor<double>& ™)ow —mounts) GG simple minded irr fun™tionF ‡ill (nd one root @if it existsFA GG —d—pted from routine in xumeri™—l ‚e™ipes in gF if (™)ow times.0) { }. GG if (f—˜s(fI)<f—˜s(fP)) { fI = ™—sh )ow pv dis™rete(™)ow times. xI+=1. xI).i++){ }.size()) return i‚‚y‚. }. xI).™)ow —mounts.i<weˆ s„i‚e„syxƒ.i++) { if ( (fI*fP) < 0. double xP = 0.™)ow —mounts. dx=xP xI. GG ™re—te —n initi—l ˜r—™ketD with — root somewhere ˜etween ˜otDtop double fI = ™—sh )ow pv dis™rete(™)ow times.

0). ™)ows. 5 percent discretely compounded interest = " . ™)ows. ™out << ™—sh )ow irr dis™rete(times. times. CP a IIH 1. ™)ows) << endl. ™)ows.0).Example We are considering an investment with the following cash ows at dates H. times. ™out << " internal rate of return. ve™tor<double> times. I and P: CH a  IHH.push ˜—™k(2). Determine the present value of the cash ows.push ˜—™k( 100. ™out << " present value. CI a IH.push ˜—™k(1). The current interest rate (with discrete. w—tl—˜ program: g=[ 100 10 110] t=[0 1 2] r = 0. Find the internal rate of return of this sequence of cash ows.push ˜—™k(0.0).push ˜—™k(110. times. ™out << ™—sh )ow pv dis™rete(times.push ˜—™k(10.05. annual compounding) is 5%.05 d=(1/(1+r)). ™)ows. Output from C++ program: present v—lueD S per™ent dis™retely ™ompounded interest a WFPWUHS intern—l r—te of returnD dis™rete ™ompounding a HFI 32 .^t x€†=g*d' s‚‚ = irr(g) Output from w—tl—˜ program: g a EIHH IH IIH t a H I P r a HFHSHHHH d a IFHHHHH HFWSPQV HFWHUHQ x€† a WFPWUI s‚‚ a HFIHHHHH C++ program: ve™tor<double> ™)ows. double r=0. 2.0). discrete compounding = ". r) << endl.

04 0.} else {return  1. bool ™—sh )ow unique irr(const ve™tor<double>& ™)ow times. we also have to deal with technical problem stemming from the fact that any polynomial equation has potentially several solutions.t<™)ow times. In economics we prefer the real solutions. GG ™he™k the —ggreg—te ™—sh )owsD due to xorstrom sign ™h—nges=0. }.2 CH a  IHH. so you may still have a well-dened IRR even if this returns false. aggregated cash ows #include <™m—th> #include <ve™tor> using namespace std. return false.}. inline int sgn(const double& r){ if (r>=0) {return 1.1 0. we can go further and check the for sign changes (See Norstrom (1972)). If there is more than one change in the sign of cash ows. CP a IHH CH a  IHH.. the code shown in code 3. for (int t=1.05 0.2 -0.size(). = ™)ow —mounts[0].15 -0. From Descartes rule we know that the number of real roots is one if there is only one sign change. } C++ Code 3. To see whether we are likely to have problems in identifying a single meaningful IRR. some of which may be imaginary.t<™)ow times.++t){ if (sgn(™)ow —mounts[t 1]) !=sgn(™)ow —mounts[t])) sign ™h—nges++. CI a IH.05 0 0.3: Test for uniqueness of IRR A better way to gain an understanding for the relationship between the interest rate and the present value is simply to plot the present value as a function of the interest rate.02 0. It is only a necessary condition for a unique IRR.3 implements a simple check.. Note that the set of cash ows on the right has two possble interest rates that sets the present value equal to zero.1 0.1 -0. The following picture illustrates the method for two dierent cash ows.   if (sign ™h—nges==0) return false.15 0. The rst test is just to count the number of sign changes in the cash ow. GG (rst ™he™k hes™—rtes rule for (int t=1.++t){ if (sgn(e) != sgn(e+=™)ow —mounts[t])) sign ™h—nges++. complex interest rates are not something we have much intuition about. const ve™tor<double>& ™)ow —mounts) { int sign ™h—nges=0. if (sign ™h—nges<=1) return true. }. 10 pv(r) 0 2 pv(r) 0 1 5 0 0 -1 -2 -5 -3 -10 -4 -15 0 0. CI a PHI. double e }.In addition to the above economic qualications to interpretations of the internal rate of return.12 -5 -0.06 0.size(). By imaginary here we mean that we move away from the real line to the set of complex numbers. CP a  IHH 33 .08 0. GG ™—n not (nd —ny irr if (sign ™h—nges==1) return true. not sucient.

nd the equivalent interest rate with quarterly compounding.Exercise 3. n: compounding periods per year.1 summarizes some rules for translating between continously compounded and discretly compounded interest rates.6. rR a n e n   I a R e 0:412   I a IP:IV7   ¡   w—tl—˜ to do the calculations: w—tl—˜ r rR program: = 12 * = 4 * ( log( 1+0. An alternative way of estimating the IRR is to use an external subroutine that nds the root of a polynomial equation. 2. one would calculate the current price dt of reciving dt a e rt . r a n ln I C   r  rn  n ¡ rn a n e n   I Future value Present value a ert a e rt Notation: rn : interest rate with discrete compounding. Carrying out the calculations: 1.15/12) exp(0. Search for a suitable general subroutine for root nding and replace the IRR estimation with a call to this subroutine. Formula 3. Formula 3.12/4) 1 )   Output from w—tl—˜ program: r a HFIRWHU rR a HFIPIVP 34 . and one dollar at a future date t as r is the interest rate. The discretely compounded case assumes that interest is added at discrete points in time (hence the name). r: interest rate with continuous compounding.3 Continously compounded interest Such discrete compounding as we have just discussed is not the only alternative way to approximate the discount factor. r a IP ln I C HIP a IR:WI7   ¡ r r a IP7 . If compounding is continous. t: time to maturity. an alternative assumption is to assume that interest is added continously. However. Given a 15% interest rate with monthly compounding. 3. calculate the equivalent interest rate with continuous compounding. Given a 12% interest rate with continuous compounding. Using :IS rIP a IS7.1: Example Translating between discrete and continous compounding 1. 2.

4. because it is easier to deal with uneven time periods.g. and Marcus (2005). t<™)ow times. 35 . and Jae (2005)) and investments (e. 3. Discretely compounded interest is easy to use with evenly spaced cash ows (such as annual cash ows). Kane. const double& r){ double €†=0. double ™—sh )ow pv( const ve™tor<double>& ™)ow times. tP . }. const ve™tor<double>& ™)ow —mounts.3. Westereld.4: Present value calculation with continously compounded interest There is a In much of what follows we will work with the case of continously compounded interest.size(). return €†. but harder otherwise. but a prime reason is actually that it is easier to use continously compounded interest than discretely compounded. Bodie. C++ Code 3. for (int t=0. : : : . Haugen (2001) or Sharpe. number of reasons why.4 Further readings The material in this chapter is covered in most standard textbooks of corporate nance (e. tn . Brealey and Myers (2002) or Ross.t++) { €† += ™)ow —mounts[t] * exp( r*™)ow times[t]). Alexander. This calculation is implemented in #include <™m—th> #include <ve™tor> using namespace std. we get the following present value PV a n ˆ iaI e rti Cti C++ Code 3.0.3. }.1 Present value Applying this to a set of cash ows at future dates calculation: tI .g. and Bailey (1999)).

. . . . . interest rate changes .1. . . . 37 4. paying a xed amount each period. . .3 4. . . .1 4. it could be a oating rate. . . . . Such bonds are typically bonds issued by governments. . . . . . For such a bond the principal amount outstanding is paid gradually during the life of the bond. . . . . . . . . . . . . Further readings . .1.Chapter 4 Bond Pricing with a at term structure Contents 4. . . . . . . . . . . . . . . . . . . . annual compounding . . . . . .4 4. . . . . . . . . The bond could for example ba an annuity bond. To fully specify the dt is the discount factor. . . . . . . . . . We start by considering a xed interest bond with no default risk. . . . . Then the bond current price BH is found as the present value of these payments. . . . . . . . . . . . Another thing that makes bond pricing dicult in practice. .3 Bond Price . . . . . . . . . . . . . . or the time 0 price of a payment of 1 at time 36 . Q Each period the bond pays a xed The cash ows from the bond thus look as follows. There is however a large number of alternative contractual features of bonds. . . .1 Flat term structure with discrete. the interest rate paid could be a function of some market rate. . .2 4. . . . . . . . . 37 38 41 43 47 50 Continously compounded interest . . . Measuring bond sensitivity to . . . . . Many bonds are issued by corporations. . ta Coupon Face value Total cash ows H C I C P C ¡¡¡ CI a C CP a C T ˆ taI T C F ¡ ¡ ¡ CT a C C F ¡¡¡ In general a bond price is found as the present value BH a dI CI C dP CP C ¡ ¡ ¡ C dT CT a where dt C t t. . . . constant maturity bond with no default risk. . . . . . We start by assuming that all the promised payments are certain. T periods from now. . . and in such cases there is a risk that the company issued the bond defaults. . . . . . . . . . . . . The simplest. The bond is a promise to pay a face value F at the maturity date percentage amount of the face value as coupon C. . . . . . is that interest rates tend to change over time. . . . . . is a xed interest. . . Duration . . . . The interest rate the bond pays need not be xed. . . . . .1. . . In this section we use the present value framework of the previous chapter to price bonds and other xed income securities. . .2 4. . . . . . . . . . . What distinguishes bonds is that the future payments are set when the security is issued. . . . . .1. . . . . Yield to maturity . . . . . . . . . The rst step of pricing is to use the terms of the bond to nd the promised payments. . and the bond does not pay the complete promised amount. . . . . . . and most typical bond. . . . . . . . . . . . .

™)ows.push ˜—™k(110). Example If we continue with the example of a standard xed interest bond./(1+r). and specied by the interest rate r. In this chapter we will work with a specially simple speciction of the term structure. 4. dt a 4.1.push ˜—™k(1). Determine the current bond price.1  I ICr t a I @I C rAt Bond Price The current bond price ( BH a T  ˆ BH ) is the present value of the cash ows from the bond  (4. ve™tor<double> times.09 d=(1. ™)ows. ™)ows. times. Here are the calculations: w—tl—˜ program: g =[10.push ˜—™k(10).^t) f = d * g' Output from w—tl—˜ program: g a IH IH IIH t a I P Q r a HFHWHHHH d a HFWIURQ HFVRITV HFUUPIV f a IHPFSQ C++ program: ve™tor<double> ™)ows. ™)ows. times.10.09.push ˜—™k(10). double r=0. 1.push ˜—™k(2). ™out << " bonds price = " << ˜onds pri™e dis™rete(times. The current interest rate (with annual compounding) is 9%. Output from C++ program: ˜onds pri™e a IHPFSQI 37 . and show how the bond price will be calculated using w—tl—˜.push ˜—™k(3).1) T ˆ I Ct Ct a @I C rAt @I C rAt taI taI CT a C C F . times. namely that it is at. where Ct a C when t<T and A 3 year bond with a face value of $100 makes annual coupon payments of 10%.1 Flat term structure with discrete. annual compounding This is the simplest possible specication of a term structure. r) << endl. The current bond price: IH IH IIH BH a @ICH:HWA1 C @ICH:HWA2 C @ICH:HWA3 a IHP:SQI.110] t = 1:3 r = 0.problem it is necessary to nd all discount factors dt .

38 .2) This calculation therefore has the same qualications as discussed earlier calculating IRR. it supposes reinvestment of coupon at the bond yield (the IRR).size(). C++ Code 4. return p. We then nd an upper bound on the yield by increasing the interest rate until the bond price with this interest rate is negative. for (int i=0. The obvious way of doing that is asking the question: What is the internal rate of return on the investment of buying the bond now and keeping the bond to maturity? The answer to that question is the yield to maturity of a bond.2 is thus simple bisection. const ve™tor<double>& ™—sh)ows.i<times. The algorithm for nding a bonds yield to maturity shown in C++ Code 4.1: Bond price calculation with discrete. the yield is the solution y to the equation BH a T ˆ Ct @I C y At taI (4. for a known price BH .1.1. We then bisect the interval between the upper and lower until we are close enough. The yield to maturity is the interest rate that makes the present value of the future coupon payments equal to the current bond price. }.times[i])). We know that the bond yield is above zero and set zero as a lower bound on the bond yield. #include <™m—th> #include <ve™tor> using namespace std. since the structure of cash ows is such that there exist only one solution to the equation. it is also useful to nd an interest rate number that summarizes the terms of the bond.The general code in C++ for calculating the bond price with discrete annual compounding is shown in C++ Code 4. that is. 4. }. double ˜onds pri™e dis™rete(const ve™tor<double>& times. annual compounding.2 Yield to maturity Since bonds are issued in terms of interest rate.i++) { p += ™—sh)ows[i]/(pow((1+r). const double& r) { double p=0. There is much less likelihood we'll have technical problems with multiple solutions when doing this yield estimation for bonds. C++ Code 4.2 implements this idea.

return r. C++ Code 4.2: Bond yield calculation with discrete.0.#include <™m—th> using namespace std.   r = 0. for (int i=0. annual compounding 39 . const ve™tor<double>& ™—sh)ows. const double& ˜ondpri™e) { const double egg…‚eg‰ = 1e 5.i++){ double di' = ˜onds pri™e dis™rete(times. double r = 0.   }. top) > ˜ondpri™e) { top = top*2. ™—sh)ows. const int weˆ s„i‚e„syxƒ = 200. #include "fin_recipes.5 * (top+˜ot). while (˜onds pri™e dis™rete(times.r) ˜ondpri™e.h" double ˜onds yield to m—turity dis™rete( const ve™tor<double>& times. if (di' >0. }.5 * (top+˜ot). if (f—˜s(di' )<egg…‚eg‰) return r. ™—sh)ows.i<weˆ s„i‚e„syxƒ. double ˜ot=0.} else { top=r.0) { ˜ot=r. top=1. }. }.

Find the bond's yield to maturity. 1. double f = ˜onds pri™e dis™rete(times. w—tl—˜ program: g = [ 10 10 110 ]. r=0. ™)ows.push ˜—™k(110). t = 1:3. ™out << " Bond price. times. ™)ows.push ˜—™k(1). ™)ows.push ˜—™k(3). times.^t))' y = irr([ f g ]) Output from w—tl—˜ program: f a IHPFSQ y a HFHWHHHH C++ program: ve™tor<double> ™)ows. 9 percent discretely compounded interest = " << f << endl.push ˜—™k(10). 2. ™out << " bond yield to maturity = " << ˜onds yield to m—turity dis™rete(times.push ˜—™k(2). Find the bond's current price. times. Output from C++ program: fond pri™eD W per™ent dis™retely ™ompounded interest a IHPFSQI ˜ond yield to m—turity a HFHW 40 .09. The current interest rate (with annual compounding) is 9%. ™)ows./((1+r). ve™tor<double> times. double r=0. ™)ows. f = g * (1. r). f) << endl.push ˜—™k(10).Example A 3 year bond with a face value of $100 makes annual coupon payments of 10%.09.

t.5) obviously produces the same number.4. ™—sh)ows[i] / pow(1+r.1 we calculate duration as € Da € @ICrtAt Ct t @ICrAt t tC (4. If the bond is priced correctly. these should produce the same number. const double& r) { double f=0. the yield to maturity must equal the current interest rate. C++ Code 4. An important component of such calculation is the duration of a bond. y for the bond.i<times.times[i]). return h/f.5) Macaulay duration C++ Code 4. This is called yield to maturity.i++){ h f += += times[i] * ™—sh)ows[i] / pow(1+r.4) and (4. }. and (4.3. annual compounding and a at term structure An alternative approach to calculating duration is calculate the yield to maturity use that in estimating the bond price.times[i]).size(). The duration of a bond should be interpreted as the weighted average maturity of the bond. Note though. double ˜onds dur—tion dis™rete(const ve™tor<double>& times.3: Bond duration using discrete. If two calculations in equations (4. from Macaulay Duration. and is calculated as € Duration a Ct t t @ICrAt Bond Price . that in the present case.3 Duration When holding a bond one would like to know how sensitive the value of the bond is to changes in economic environment. const ve™tor<double>& ™—sh)ows. ray the Example A 3 year bond with a face value of $100 makes annual coupon payments of 10%.3) where Ct is the cash ow in period r the interest rate. The most relevent piece of the economic environment is the current interest rate. }. 41 .1. #include <™m—th> #include <ve™tor> using namespace std. the Bond price a T ˆ @I C y At taI € t @ICyAt Ct t @ICyAt Ct and then use this y in the duration calculation: a € t tC (4. The current interest rate (with annual compounding) is 9%.4 implements this calculation. Using the bond price calculated in equation 4.4) which is shown in C++ Code 4. and First one calculates y. with a at term structure. double h=0. for (int i=0.

double f = ˜onds pri™e dis™rete(times./(1+y). ™)ows. ™out << " bond duration = " << ˜onds dur—tion dis™rete(times.   I¡IH ¡ IH D a IHPISQI I:HW C IP:¡HW2 C Q¡:IIH a P:UR : I HW3 w—tl—˜ program: g =[10. times.^t)' h= (1/f)*t. f) << endl. ™out << " bonds price = " << f << endl. times.^t)' y = irr([ f g ]) hw= (1/f)*t.h" double ˜onds dur—tion m—™—ul—y dis™rete(const ve™tor<double>& times. ™)ows.09./(1+r). Output from C++ program: ˜onds pri™e ˜ond dur—tion ˜ond m—™—ul—y a IHPFSQI a PFUQVWS a PFUQVWS 42 .4: Calculating the Macaulay duration of a bond 1. ™—sh)ows.110]. Need to calculate the following: The current bond price: The bond's duration: IH IH IIH BH a @ICH:HWA1 C @ICH:HWA2 C @ICH:HWA3 a IHP:SQI. ™)ows. ˜ond pri™e).push ˜—™k(110). ™)ows. ™—sh)ows. double r=0. ™)ows. Calculate the duration using the current interest rate. ve™tor<double> times. GG use ‰„w in dur—tion ™—l™ul—tion }. f= g * (1. times. y).push ˜—™k(3). r). const ve™tor<double>& ™—sh)ows.^t)' Output from w—tl—˜ program: f a IHPFSQ h a PFUQWH y a HFHWHHHH hw a PFUQWH C++ program: ve™tor<double> ™)ows.* g * (1. Determine the current bond price. 3. const double& ˜ond pri™e) { double y = ˜onds yield to m—turity dis™rete(times. ™)ows. C++ Code 4. return ˜onds dur—tion dis™rete(times.10.push ˜—™k(10).push ˜—™k(10). t = 1:3.push ˜—™k(1). r = 0.09. Calculate the duration using the MaCaulay denition./(1+r). ™out << " bond macaulay = " << ˜onds dur—tion m—™—ul—y dis™rete(times.push ˜—™k(2). r) << endl.* g * (1.#include "fin_recipes. 2.

double h = ˜onds dur—tion dis™rete(times. C++ Code 4. For simplicity one often calculates the term in front of the ¡y D ICy directly and terms it the bond's modied duration. and is then D The modied duration is also written in term's of the bond's yield to maturity D£ a C++ Code 4. a D£ a ICr Modied Duration D The sensitivity calculation is then ¡BH BH %  D£ ¡r y. ™—sh)ows. return h/(1+y).1. can ¡BH BH %   I D r ¡r C in the where above. T bond price d d d d d d d d d d d d E yield Duration measures of tangent. the reason for why we say that we can measure the sensitivity of a bond price using duration. const double& ˜ond pri™e){ double y = ˜onds yield to m—turity dis™rete(times. }. 'angle 43 .4 Measuring bond sensitivity to interest rate changes Now.h" double ˜onds dur—tion modi(ed dis™rete (const ve™tor<double>& times. ™—sh)ows. D is the bond's duration. ˜ond pri™e). To a rst approximation. const ve™tor<double>& ™—sh)ows.5 ICy shows this calculation. be calculated ¡BH . y).4. the change in the bond price for a small change in the interest rate ¡r.5: Modied duration Approximating bond price changes using duration is illustrated in the following gure. #include <ve™tor> using namespace std. #include "fin_recipes.

To improve on the estimate of how the bond price #include <™m—th> #include "fin_recipes.times[i])).size(). r: interest rate.6: Bond convexity with a at term structure and annual compounding change when the interest rates changes you will then calculate ¡BH BH %  D£ ¡y C I Cx @¡yAP P @BH ) T ˆ Modied duration Formula 4. C++ Code 4.6. To quantify this curvature we calculate the convexity of a bond. for (int i=0. Approximating the change in bond price with duration is thus only a rst order approximation.6) This calculation is implemented in C++ Code 4.1: aI P Q Bond pricing formulas with a at term structure and discrete. gx+= ™—sh)ows[i]*times[i]*(times[i]+1)/(pow((1+r).T. Bond pays coupon at evenly spaced dates t . To improve on this approximation we also need to account for the curvature in the relationship between bond price and interest rate. const double& r) { double gx=0. annual compounding 44 . B0 : current bond price. .2)))/f. ™—sh)ows. y: bond yield to maturity.1 summarizes the above calculations. double f=˜onds pri™e dis™rete(times. Bond Price BH a @I C rAt taI T ˆ Ct D£ a Convexity ICy D Yield to maturity y solves @CxA T Ct I ˆ @t C tP A BH @I C rAP taI @I C rAt BH a Duration @D A I Ct @I C y At taI T ˆ Cx a I Da tCt BH taI @I C rAt tCt BH taI @I C yAt I T ˆ Approximating bond price changes ¡BH Macaulay duration BH BH %  D£ ¡y I %  D£ ¡y C P ¢ Cx ¢ @¡yAP Da ¡BH Ct : Cash ow at time t. r). :::. Convexity a Cx a T I ˆ Ct @t C tP A BH @I C rAP taI @I C rAt I (4. }. const ve™tor<double>& ™—sh)ows. return (gx/(pow(1+r. Formula 4.h" double ˜onds ™onvexity dis™rete(const ve™tor<double>& times.i++){ }.i<times.The modied duration measures the angle of the tangent at the current bond yield.

The current interest rate (with annual compounding) is 9%. Determine the current bond price.^2.push ˜—™k(10)./(1+r). I:HW The modied duration: D a ICr IHW P : @ICIA¡IH C @P2 CPA2¡IH C @QCQ2 A¡3IIH  a V:WQ. Output from C++ program: ˜onds pri™e a IHPFSQI ˜ond dur—tion a PFUQVWS ˜ond dur—tion modified a PFSIPV ˜ond ™onvexity aVFWQPRV new ˜ond pri™e a IHH 45 .09. f= g * (1. ™)ows. 1. 2. Need to calculate the following: The current bond price: IH IIH IH BH a @ICH:HWA1 C @ICH:HWA2 C @ICH:HWA3 a IHP:SQI. ™out << " bond duration modified = " << ˜onds dur—tion modi(ed dis™rete(times. t = 1:3. double f = ˜onds pri™e dis™rete(times. ™out << " bond duration = " << ˜onds dur—tion dis™rete(times. Suppose the interest rate changes to 10%. r = 0./(1+0.push ˜—™k(10)./(1+r). r) << endl. ™)ows.push ˜—™k(2). times. ™)ows. times. Use convexity to improve on the estimate using duration only.*g newf=g* (1. f) << endl.110]. ™out << " bonds price = " << f << endl.Example A 3 year bond with a face value of $100 makes annual coupon payments of 10%. ™out << " bond convexity =" << ˜onds ™onvexity dis™rete(times. determine the new price of the bond by direct calculation.push ˜—™k(110).push ˜—™k(1)./(1+r). times. ™)ows.09. ™)ows.^t)' h= (1/f)*t. r). I 2 I The convexity: Cx a @ICH:HWA IHP:SQI I:HW I:HW I:HW Here are the calculations: w—tl—˜ program: g =[10.push ˜—™k(3). ™)ows. I   I¡IH C P¡IH2 C Q¡IIH ¡ a P:UR The bond's duration: D a 3 IP I D £ IHP:SQI a:HW:UR a:HW:SI.^t)' gx= (1/(1+r)^2) * (1/f)*t. ™out << " new bond price = " << ˜onds pri™e dis™rete(times. 0.^t)' w—tl—˜ program: f a IHPFSQ h a PFUQWH gx a TFTPUP newf a IHHFHH C++ program: ve™tor<double> ™)ows. r) << endl.* g * (1. ve™tor<double> times.1). 3. 4. ™)ows. ™)ows.1). double r=0.10. Use duration to estimate the new price and compare it to the correct price.^t)' Output from * (1.

A and B. 46 . 2. Bond B is a zero coupon bond with 3 years to maturity.1. The current interest rate is 5%. Determine the bond prices. Determine the convexity of your position. 4. Bond A is a zero coupon bond with 1 year to maturity. Find the number of each bond invested. Consider the pricing of a perpetual bond. 1. Exercise 4. [5] Consider an equally weighted portfolio of two bonds. let us see what happens when the interest rate increases to 10%. 3. Your portfolio is currently worth 2000. Determine the duration of the portfolio. Determine the rst derivative of the price with respect to the interest rate. which can be conrmed with direct computation: C C a IHH BH a @I C H:IAI @I C H:IAP @I C H:IAQ Using duration to estimate the change in the bond price for a unit change in the interest rate: IH IH IIH ¡BH BH a  D£ ¡y a  P:SI ¡ H:HI a  H:HPSI   Using this duration based number to estimate the new bond price. ¡BH ” B a BH C BH a IHP:SQI   H:HPSI ¡ IHP:SQI a WW:WSU BH Additionally using convexity in estimating the change in the bond price: ¡BH BH I I a  D£ ¡y C Cx y P a  P:SI ¡ H:HI C V:WQ@H:HIAP a  H:HPSI C H:HHHRR a  H:HPRTS P P     ¡BH ” B a IHP:SQI I C BH a IHP:SQI@I   H:HPRTSA a IHH:HHQT BH Exercise 4. Perpetual duration [4] The term structure is at with annual compounding.2. 2. Let per period cash ow C be the BH a I ˆ @I C rAt taI C a C r 1. equal to 100. Find the duration of the bond. Both bonds have face values of 100.Using these numbers to answer the questions. This means the bond will be selling at par.

const ve™tor<double>& ™—sh)ows. e: natural exponent. : : : at times t1 .2 Continously compounded interest We will go over the same concepts as covered in the previous section on bond pricing. t2 .9 C++ Code 4.7. #include <™m—th> #include <ve™tor> using namespace std. }. C++ Code 4. Ct2 . double ˜onds pri™e(const ve™tor<double>& ™—sh)ow times. Notation: B0 : current bond price. : : :. as was done in the discrete case.i++) { p += exp( r*™—sh)ow times[i])*™—sh)ows[i]. one does not in the continously compounded formula.size().7: Bond price calculation with continously compounded interest and a at term structure 47 . Note also the dierence in the divide by @I C y AP convexity calculation. Bond Price BH : BH a e rti A Cti ˆ i Convexity Cx: BH I ˆ i Yield to maturity y solves: ˆ BH a Cti e yti D: i Cx a Cti tP e rti i Approximating bond price changes Duration Da Da BH BH I I ˆ i ti Cti e rti ti Cti e yti ¡BH BH BH %  D¡y I %  D¡y C P ¢ Cx ¢ @¡yAP Macaulay duration ˆ i ¡BH Bond paying cash ows Ct1 .8.1. When using continously compounded interest.4. and C++ Code 4.2 corresponds to the earlier summary in formula 4. for (int i=0.i<™—sh)ow times. Formula 4. In the continously compounded case one uses the calculated duration directly to approximate bond changes. Formula 4.10 show continously compounded analogs of the earlier codes for the discretely compounded case. C++ Code 4. const double& r) { double p=0. There are certain subtle dierences in the calculations.2: Bond pricing formulas with continously compounded interest and a at term structure Some important dierences is worth pointing out. }. return p. one does not need the concept of modied duration. C++ Code 4. as seen in the formulas describing the approximation of bond price changes.

double hI=0. return ˜onds dur—tion(™—sh)ow times. double ˜onds dur—tion(const ve™tor<double>& ™—sh)ow times.h" double ˜onds dur—tion m—™—ul—y(const ve™tor<double>& ™—sh)ow times.i<™—sh)ow times. for (int i=0.2) * exp( r*times[i]). GG use ‰„w in dur—tion }.r). const double& r ) { double g=0. const ve™tor<double>& ™—sh)ows.size(). const double& ˜ond pri™e) { double y = ˜onds yield to m—turity(™—sh)ow times.8: Bond duration calculation with continously compounded interest and a at term structure #include "fin_recipes. return hI }. ™—sh)ows. }. / }.size(). C++ Code 4. ƒ. ™—sh)ows. ™—sh)ows. return g/f.i<times. double f=˜onds pri™e(times. ˜ond pri™e). hI += ™—sh)ow times[i] * ™—sh)ows[i] * exp( r*™—sh)ow times[i]).i++){ g += ™—sh)ows[i] * pow(times[i]. for (int i=0.#include <™m—th> #include <ve™tor> using namespace std. const ve™tor<double>& ™—sh)ows. C++ Code 4. C++ Code 4. const double& r) { double ƒ=0. const ve™tor<double>& ™—sh)ows. }.9: Calculating the Macaulay duration of a bond with continously compounded interest and a at term structure #include <™m—th> #include "fin_recipes.i++){ ƒ += ™—sh)ows[i] * exp( r*™—sh)ow times[i]). y).h" double ˜onds ™onvexity(const ve™tor<double>& times.10: Bond convexity calculation with continously compounded interest and a at term structure 48 .

Calculations: w—tl—˜ program: g =[10. 1.3.Example A 3 year bond with a face value of $100 makes annual coupon payments of 10%. ™out << " bond convexity =" << ˜onds ™onvexity(times. double r=0. ™)ows.push ˜—™k(110). times. and compare with the actual bond price using the correct interest rate.1 —™tu—lf = g*(1.*t*d' h—dj=h/(1+r) r=0. a IHIFRTR a PFUQUSQ aUFVTUUW a IHRFPVP 49 .push ˜—™k(1).^t)' Output from w—tl—˜ program: g a IH IH IIH t a I P Q r a HFHWHHHH d a HFWIURQ HFVRITV HFUUPIV f a IHPFSQ h a PFUQWH h—dj a PFSIPV r a HFIHHHH —™tu—lf a IHHFHH C++ program: ve™tor<double> ™)ows. ™)ows.push ˜—™k(2). Output from C++ program: ˜onds pri™e ˜ond dur—tion ˜ond ™onvexity new ˜ond pri™e Exercise 4.08). ™out << " new bond price = " << ˜onds pri™e(times. r) << endl. ™)ows. ™)ows. times. ™out << " bond duration = " << ˜onds dur—tion(times.10. ™)ows.09 d=(1.push ˜—™k(10). Estimate the new bond price using duration. duration and convexity. double f = ˜onds pri™e(times. times.09.push ˜—™k(3). ™out << " bonds price = " << f << endl. Calculate the bond's price. Suppose the interest rate falls to 8%. r). 0.push ˜—™k(10). yield to maturity. The current interest rate (with continous compounding) is 9%. r) << endl.^t) f = g * d' h=1/f*g. ™)ows. 2./(1+r). ve™tor<double> times./(1+r). ™)ows.110] t = 1:3 r = 0.

4.The term structure is at. where BH is the current bond price. More details can be found in textbooks on xed income.3 Further readings The material in this chapter is covered in most standard textbooks on investments (e. 50 . Show that these two denitions will produce the same number if the bond is correctly priced. such as Sundaresan (2001). (1999)). Consider two denitions of duration. 1. Bodie et al. r is the current interest rate and y is the bond's yield to maturity. the usual denition I € I € D a B0 i ti Cti e rti and the Macaulay dention: D a B0 i ti Cti e yti .g. and compounding is continous. Cti is the coupon payment at date ti . Haugen (2001) or Sharpe et al. (2005).

Chapter 5

The term structure of interest rates and an object lesson
Contents

5.1 5.2

The interchangeability of discount factors, spot interest rates and forward interest rates . . . . . The term structure as an object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

52 55

5.2.1 5.2.2
5.3

Base class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Flat term structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linear Interpolation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interpolated term structure class. . . . . . . . . . . . . . . . . . . . . . . . . . .

55 57
58

Using the currently observed term structure. . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.3.1 5.3.2
5.4

59 61
64

Bond calculations with a general term structure and continous compounding . . . . . . . . . . .

In this chapter we expand on the analysis of the previous chapter by relaxing the one interest rate assumption used there and allow the spot rates to change as you change the time you are discounting over. Recall that we said that the present value of a set of cash ows is calculated as

PV a

N ˆ iaI

dti Cti
Ct 1
0

Ct 2
t2

Ct N
tN

t1

E
time

dt1 Ct1 dt2 Ct2 dtN CtN

' '

'

To make this applicable to cash ows received at any future date number of discount factors approximate interest rate

dt , but with more exibility than the extremely strong assumption that there is one xed r, and that the discount factor for any time t is calculated as either dt a I=@I C rAt (discrete  rt (continuous compounding), which we used in the previous chapter. compounding), or dt a e
51

dt .

t

we potentially need an innite

This is not feasible, so some lower dimensional way needs to be found to

In this chapter we rst show that this approximation of the discount factors can be done in either terms of discount factors directly, interest rates, or forward rates. Either of these are useful ways of formulating a term structure, and either of them can be used, since there are one to one transformations between either of these three. We then go on to demonstrate how a feature of C++, the ability to create an abstract datatype as an object, or class, is very useful for the particular application of dening and using a term structure. It is in fact this particular application, to create a term structure class, which really illustrates the power of C++, and why you want to use an object oriented language instead of classical langues like

py‚„‚ex

and

C, or matrix languages like q—uss or w—tl—˜ for many nancial calculations.

5.1 The interchangeability of discount factors, spot interest rates and forward interest rates
t) payment of one dollar. To Ct , we calculate P V a dt Ct . This discount factor can also be specied in terms of interest rates, where we let rt be the relevant interest rate (spot rate) for discounting  r t a t-period cashow. Then we know that the present value P V a e t Ct . Since these two methods of
interest rates. A discount factor is the current price for a future (time nd the current value The term structure can be specied in terms of either discount factors, spot interest rates or forward

PV

of a cash ow

calculating the present value must be consistent,

P V a dt Ct a e rt t Ct
and hence

dt a e rt t
Note that this equation calculates terms of discount factors

dt

given

rt .

Rearranging this equation we nd the spot rate

rt

in

rt a

  ln@dt A
t tI
and repaying it at a later date

An alternative concept that is very useful is a forward interest rate, the yield on borrowing at some future date

tP .

Let

today, at the current spot rate spot rate till period

tI

ft1 ;t2

be this interest rate. If we invest one dollar

and the forward rate for the period from

tI

to

tP

(which is what you would have to do to make an actual investment), you would get the following future value

F V a ert1 t1 eft1 ;t2 @t2  t1 A
The present value of this forward value using the time

tP discount factor has to equal one:

dt2 F V a I
These considerations are enough to calculate the relevant transforms. The forward rate for borrowing at time

tI for delivery at time tP is calculated as ft1 ;t2 a

  ln 

tP   tI

dt2 d t1 

a

ln 

tP   tI

d t1 d t2 

The forward rate can also be calculated directly from yields as

ft1 ;t2 a rt2

tP   r tI tP   tI t1 tP   tI
52

dt a e rt t rt a

  ln@dt A
t
ln 

d t1 d t2 

ft1 ;t2 a

tP   tI t t ft1 ;t2 a rt2 P   rt1 I tP   tI tP   tI

Notation: dt discount factor for payment at time t, rt : spot rate applying to cash ows at time t. ft1 ;t2 forward rate between time t1 and t2 , i.e. the interest rate you would agree on today on the future transactions.

#include <™m—th> using namespace std;
double term stru™ture yield from dis™ount f—™tor(const double& d t, const double& t) return ( log(d t)/t);

 

{

}

double term stru™ture dis™ount f—™tor from yield(const double& r, const double& t) return exp( r*t);

 

{

};

double term stru™ture forw—rd r—te from dis™ount f—™tors(const double& d tI, const double& d tP, const double& time) { return (log (d tI/d tP))/time;
};

double term stru™ture forw—rd r—te from yields(const double& r tI, const double& r tP, const double& tI, const double& tP) { return r tP*tP/(tP tI) r tI*tI/(tP tI);

   

 

};

C++ Code 5.1: C++ Code 5.1 Example
You are given the one period spot rate

Term structure transformations

shows the implementation of these transformations.

rI a S7 and the two period discount factor dP a H:W.

Calculate the

two period spot rate and the forward rate from 1 to 2.

53

C++ program:

double tI=1; double r tI=0.05; double d tI=term stru™ture dis™ount f—™tor from yield(r tI,tI); ™out << " a " << tI << " period spot rate of " << r tI << " corresponds to a discount factor of " << d tI << endl; double tP=2; double d tP = 0.9; double r tP = term stru™ture yield from dis™ount f—™tor(d tP,tP); ™out << " a " << tP << " period discount factor of " << d tP << " corresponds to a spot rate of " << r tP << endl; ™out << " the forward rate between " << tI << " and " << tP << " is " << term stru™ture forw—rd r—te from dis™ount f—™tors(d tI,d tP,tP tI) << " using discount factors " << endl; ™out << " and is " << term stru™ture forw—rd r—te from yields(r tI,r tP,tI,tP) << " using yields " << endl;
Output from C++ program:

— I period spot r—te of HFHS ™orresponds to — dis™ount f—™tor of HFWSIPPW — P period dis™ount f—™tor of HFW ™orresponds to — spot r—te of HFHSPTVHQ the forw—rd r—te ˜etween I —nd P is HFHSSQTHS using dis™ount f—™tors —nd is HFHSSQTHS using yields

54

5.2 The term structure as an object
From the previous we see that the term structure can be described in terms of discount factors, spot rates or forward rates, but that does not help us in getting round the dimensionality problem. If we think in terms of discount factors, for a complete specication of the current term structure one needs an innite number of discount factors factors as a

function d@tA, that, given a nonnegative time t, returns the discount factor.

fdt gtPR

+.

It is perhaps easier to think about this set of discount Since we have

established that there are three equivalent ways of dening a term structure, discount factors, spot rates and forward rates, we can therefore describe a term structure as a collection of three dierent functions that oer dierent views of the same underlying object. A term structure is an abstract object that to the user should provide 

 

discount factors spot rates

d (prices of zero coupon bonds).

r (yields of zero coupon bonds). f t.
The user of a term structure will not need to know how the term structure is

forward rates

for any future maturity

implemented, all that is needed is an interface that species the above three functions. This is tailor made for being implemented as a C++

class.

A class in C++ terms is a collection of data In the present context it is a way of

structures and functions that operate on these data structures. specifying the three functions. r

@tA @tA

d f

@tA
Base class

5.2.1

Header File 5.1

shows how we describe the generic term structure as a C++ class.

#ifndef „i‚w ƒ„‚…g„…‚i gveƒƒ r #dene „i‚w ƒ„‚…g„…‚i gveƒƒ r
class term stru™ture ™l—ss { public: virtual double r(const double& t) const; GG yield on zero ™oupon ˜ond virtual double d(const double& t) const; GG dis™ount f—™torGpri™e of zero ™oupon ˜ond virtual double f (const double& tI, const double& tP) const; GG forw—rd r—te virtual £term stru™ture ™l—ss();
};

#endif

Header le 5.1:

Header le describing the

term•stru™ture

base class

The code for these functions uses algorithms that are described earlier in this chapter for transforming between various views of the term structure. The term structure class merely provide a convenient

interface to these algorithms. The code is shown in

C++ Code 5.2

Note that the denitions of calculations are circular. Any given over-ride at least one of the functions We next consider two examples of

specic term structures.
55

r

(yield),

d

specic
f

type of term structure has to

(discount factor) or

(forward rate).

return term stru™ture forw—rd r—te from dis™ount f—™tors(dI. }.t). double term stru™ture ™l—ssXXf (const double& tI.h" term stru™ture ™l—ssXX£term stru™ture ™l—ss(){}.2: Default code for transformations between discount factors. double term stru™ture ™l—ssXXd(const double& t) const { return term stru™ture dis™ount f—™tor from yield(r(t). }. const double& tP) const{ double dI = d(tI).t). C++ Code 5.dP.tP tI). double dP = d(tP).#include "fin_recipes.   }. double term stru™ture ™l—ssXXr(const double& t) const{ return term stru™ture yield from dis™ount f—™tor(d(t). spot rates and forward rates in a term structure class 56 .

2.f (tI. ™out << "discount factor t2 = " << tP << ":" << ts.r(tP) << endl.3: Example Implementing term structure class using a at term structure The term structure is at with rate between 1 and 2. The at term structure overrides the yield member function of the base class. virtual £term stru™ture ™l—ss )—t(). ™out << "spot rate t = " << tI << ":" << ts. double tP=2. }. }. }. GG interest r—te public: term stru™ture ™l—ss )—t(const double& r).5.d(tP) << endl. double tI=1. C++ Code 5.2 Flat term structure.tP) << endl. void term stru™ture ™l—ss )—tXXset int r—te(const double& r) ‚ = r. C++ program: r a S7. virtual double r(const double& t) const.2: Header le for term structure class using a at term structure #include "fin_recipes. #ifndef „i‚w ƒ„‚…g„…‚i gveƒƒ pve„ #dene „i‚w ƒ„‚…g„…‚i gveƒƒ pve„ #include "term_structure_class. }. ™out << "discount factor t1 = " << tI << ":" << ts.d(tI) << endl. The only piece of data this type of term structure needs is an interest rate.h" term stru™ture ™l—ss )—tXXterm stru™ture ™l—ss )—t(const double& r){ ‚ term stru™ture ™l—ss )—tXX£term stru™ture ™l—ss )—t(){}. ™out << "spot rate t = " << tP << ":" << ts.r(tI) << endl. return 0. Output from C++ program: dis™ount f—™tor tI a IXHFWSIPPW dis™ount f—™tor tP a PXHFWHRVQU spot r—te t a IXHFHS spot r—te t a PXHFHS forw—rd r—te from tIa I to tPa PXHFHS 57 . void set int r—te(const double& r). Determine the discount factors for years 1 and 2 and the forward term stru™ture ™l—ss )—t ts(0.05). { #endif Header le 5. double term stru™ture ™l—ss )—tXXr(const double& „) const { = r. if („>=0) return ‚ { .h" class term stru™ture ™l—ss )—t X public term stru™ture ™l—ss private: double ‚ . ™out << "forward rate from t1= " << tI << " to t2= " << tP << ":" << ts.

1.5 1 1.3 Using the currently observed term structure.5. A rst step to a general term structure is to use market data on bond prices and interest rates to infer discount factors. Suppose we have three bonds with cash ows at times 1. 1.5 2 3 4 The bonds are treasury secrurities.5. What is the interest rates implied in this set of discount rates? Here we can nd the discount factors for maturities of 0. BI a dI CII C dP CIP C dP CIQ BP a dI CPI C dP CPP C dP CPQ BI a dI CQI C dP CQP C dP CQQ Writing this in terms of matrices P R BI BP BQ dI dP dQ Q S P aR dI dP dQ QP SR CII CIP CIQ CPI CPP CPQ CQI CQP CQQ Q I P S R Q S Solving for the discount factors P R Q S P aR CII CIP CIQ CPI CPP CPQ CQI CQP CQQ BI BP BQ Q S or d a C I B using the obvious matrix denitions P BaR BI BP BQ Q S P daR dI dP dQ Q S P CaR CII CIP CIQ CPI CPP CPQ CQI CQP CQQ Q S Example The following set of bond and bond prices is observed: Time (in years) Bond Bond 1 2 2 3 4 5 Price 98 96 92 118 109 112 10 8 9 10 8 9 100 100 100 10 8 9 110 8 9 108 9 109 0 0. Determine the implicit discount factors in the market. 2 and 3.3 and 4.5. The simplest way of presenting this problem is in terms of linear algebra. 58 .1. which can be viewed as nominally riskless.2. 3. For what maturities is it possible to infer discount factors? 2.

0 0 100 0 0 0. in increasing order of time to maturity.0 100 0 0 f=[96 94 92 118 109 112] d=f*inv(g)' t=[0.5 1 1. This interpolation can be on either zero coupon yields.5 2 3 4] r=d. 0. 3.9 9 9 9 9 109] g=[100 0 0 0 0 0. 5 and 10.w—tl—˜ program: 0 0.3.1 0. If we are given a set of discount factors ( dt ) for various maturities. 5.1. we illustrate the case of linear interpolation of spot (zero coupon) rates.1 Linear Interpolation.8 8 8 8 108 0. discount factors or forward rates. Computer algorithm.5 Interpolate spot rates (zero rates) at times 0.5 1 5 10 r 0.3 0. 1. we need to take the observations of discount factors dt observed in the market and use these to generate a term structure.10 10 10 110 0 0.1 0. The simplest possible way of doing this is to linearly interpolate the currently observable discount factors.4 0.5. For many purposes this is good enough.^( 1. Note that the algorithm assumes the yields are ordered Example You observe the following term structure of spot rates Time 0. 59 .2 0. linear interpolation of yields. the simplest way to construct a term structure is by straightforward linear interpolation between the observations we have to nd an intermediate time./t) 1 Output from w—tl—˜ program: g a IHH H H H H H H IHH H H H H H H IHH H H H IH IH IH IIH H H V V V V IHV H W W W W W IHW f a WT WR WP IIV IHW IIP d a HFWTHHH HFWRHHH HFWPHHH HFVITQT HFUQWWH HFTTTIV t a HFSHHHH IFHHHHH IFSHHHH PFHHHHH QFHHHHH RFHHHHH r a HFHVSHTW HFHTQVQH HFHSUITP HFIHTUUP HFIHSTPV HFIHTVVR To just use todays term structure.

times.1.yields) << endl. double l—m˜d— = (o˜s times[t] time)/(o˜s times[t] o˜s times[t   * (1. yields.push ˜—™k(10). ve™tor<double> yields. GG e—rlier th—n lowest o˜sF double t m—x = o˜s times[no o˜s 1]. ™out << " yields at times: " << endl. yields.1 " << term stru™ture yield line—rly interpol—ted(0. GG l—ter th—n l—test o˜s    1]).5.times. times. times.yields) << endl. ™out << " t=0. if (no o˜s<1) return 0.1). times. GG ˜y ordering —ssumptionD time is ˜etween tEIDt double r = o˜s yields[t 1] * l—m˜d— + o˜s yields[t] return r. ™out << " t=0. ™out << " t=10 " << term stru™ture yield line—rly interpol—ted(10.h" double term stru™ture yield line—rly interpol—ted(const double& time. ™out << " t=5 " << term stru™ture yield line—rly interpol—ted(5. yields.push ˜—™k(0.push ˜—™k(0.yields) << endl.push ˜—™k(0. if (time >= t m—x) return o˜s yields[no o˜s {    1]. int t=1.yields) << endl. const ve™tor<double>& o˜s times.push ˜—™k(5).2).push ˜—™k(1).5). #include "fin_recipes. yields. }.times. }. yields.push ˜—™k(0. const ve™tor<double>& o˜s yields) GG —ssume the yields —re in in™re—sing time to m—turity orderF int no o˜s = o˜s times.push ˜—™k(0. C++ Code 5.size().4). times.yields) << endl.push ˜—™k(0. GG (nd whi™h two o˜serv—tions we —re ˜etween while ( (t<no o˜s) && (time>o˜s times[t])) { ++t.5 " << term stru™ture yield line—rly interpol—ted(0. ™out << " t=3 " << term stru™ture yield line—rly interpol—ted(3.yields) << endl. times.3). double t min = o˜s times[0]. times.0  l—m˜d—). times.4: C++ program: Interpolated term structure from spot rates ve™tor<double> times. if (time <= t min) return o˜s yields[0].1).5).push ˜—™k(0.#include <ve™tor> using namespace std. times. ™out << " t=1 " << term stru™ture yield line—rly interpol—ted(1. Output from C++ program: yields —t timesX taHFI HFI taHFS HFP taI HFQ taQ HFQS taS HFR taIH HFS 60 .

2 Interpolated term structure class. const ve™tor<double>& yields). and for observations in between observations will interpolate between the two closest. As shown in Header File 5. for the other two rely on the base class code. class term stru™ture ™l—ss interpol—ted X public term stru™ture ™l—ss private: ve™tor<double> times . void ™le—r(). void set interpol—ted o˜serv—tions(ve™tor<double>& times. }. }. int no o˜serv—tions() const { return times . term stru™ture ™l—ss interpol—ted(const term stru™ture ™l—ss interpol—ted&).3: Header le describing a term structure class using linear interpolation between spot rates 61 . term stru™ture ™l—ss interpol—ted operator= (const term stru™ture ™l—ss interpol—ted&). #endif Header le 5. term stru™ture ™l—ss interpol—ted(const ve™tor<double>& times.3. virtual double r(const double& „) const.5.size(). virtual £term stru™ture ™l—ss interpol—ted(). ve™tor<double>& yields). there is some more book-keeping involved here. GG use to keep — list of yields ve™tor<double> yields . need to have code that stores observations of times and yields. public: { term stru™ture ™l—ss interpol—ted().5. The following only provides implementations of calculation of the yield.3 and C++ Code 5.h" #include <ve™tor> using namespace std. #ifndef „i‚w ƒ„‚…g„…‚i gveƒƒ sx„i‚€yve„ih #dene „i‚w ƒ„‚…g„…‚i gveƒƒ sx„i‚€yve„ih #include "term_structure_class. The interpolated term structure implemented here uses a set of observations of yields as a basis.

yields . }.no o˜serv—tions()). for (int i=0.size()!=in yields.i<in times. times = ve™tor<double>(in times. yields }.5: Term structure class using linear interpolation between spot rates 62 .i++){ times [i] = term.}. }. }.yields [i].yields [i]. }.size()) return. if (in times.size()).no o˜serv—tions()). (*this). yields = ve™tor<double> (term. if (in times. yields = ve™tor<double>(in yields.size()).˜egin(). { term stru™ture ™l—ss interpol—ted term stru™ture ™l—ss interpol—tedXXoper—tor= (const term stru™ture ™l—ss interpol—ted& term) times = ve™tor<double> (term.end()). double term stru™ture ™l—ss interpol—tedXXr(const double& „) const { return term stru™ture yield line—rly interpol—ted(„.h" void term stru™ture ™l—ss interpol—tedXX™le—r(){ times . void term stru™ture ™l—ss interpol—tedXXset interpol—ted o˜serv—tions(ve™tor<double>& in times. yields [i]=in yields[i]. term stru™ture ™l—ss interpol—tedXXterm stru™ture ™l—ss interpol—ted(const term stru™ture ™l—ss interpol—ted& term) times = ve™tor<double> (term.er—se(times . ve™tor<double>& in yields) ™le—r().˜egin(). }.size()) return. times . }.no o˜serv—tions().no o˜serv—tions()).i<term.size()).i++) { times [i]=in times[i].no o˜serv—tions()). { term stru™ture ™l—ss interpol—tedXX£term stru™ture ™l—ss interpol—ted(){ ™le—r(). times .i<term.er—se(yields . times = ve™tor<double>(in times.times [i].end()). yields [i] = term.i++){ times [i] = term. term stru™ture ™l—ss interpol—tedXXterm stru™ture ™l—ss interpol—ted()Xterm stru™ture ™l—ss(){™le—r().size()).times [i]. }. for (int i=0. for (int i=0. yields [i] = term. yields = ve™tor<double> (term. for (int i=0. term stru™ture ™l—ss interpol—tedXXterm stru™ture ™l—ss interpol—ted(const ve™tor<double>& in times. { C++ Code 5. yields = ve™tor<double>(in yields. { return }.#include "fin_recipes. yields . const ve™tor<double>& in yields) ™le—r().no o˜serv—tions().i++) { times [i]=in times[i]. yields [i]=in yields[i].}. ).size(). }.size()!=in yields.size().i<in times.

™out << "spot rate t = " << tP << ":" << ts.08 Determine discount factors and spot rates at times 1 and 2.push ˜—™k(0.push ˜—™k(0.spotr—tes.push ˜—™k(0.08).spotr—tes).push ˜—™k(0.07 0. term stru™ture ™l—ss interpol—ted ts(times. ™out << "spot rate t = " << tI << ":" << ts. spotr—tes. ™out << "discount factor t2 = " << tP << ":" << ts.05).tP) << endl. times. Output from C++ program: dis™ount f—™tor tI a IXHFWQPQWR dis™ount f—™tor tP a PXHFVTSHPP spot r—te t a IXHFHU spot r—te t a PXHFHUPS forw—rd r—te from tIa I to tPa PXHFHUS 63 .1 1 5 r 0. double tP=2.push ˜—™k(5). ™out << "discount factor t1 = " << tI << ":" << ts. ™out << "forward rate from t1= " << tI << " to t2= " << tP << ":" << ts. times.push ˜—™k(1).05 0. double tI=1.d(tP) << endl. times. ve™tor<double> spotr—tes. C++ program: ve™tor<double> times.d(tI) << endl.07).f (tI.Example Time 0. spotr—tes. and forward rate between 1 and 2.1).r(tP) << endl.r(tI) << endl.

7 term structure class. #include "fin_recipes.i++) { p += d.size().h" double ˜onds pri™e(const ve™tor<double>& ™—sh)ow times. const ve™tor<double>& ™—sh)ows. }. const term stru™ture ™l—ss& d) { double p = 0. for (unsigned i=0. t2 .i<™—sh)ow times. C++ Code 5.d(™—sh)ow times[i])*™—sh)ows[i].6 and Bond pricing with a continously compounded term structure illustrates how one would calculate bond prices and duration if one has a C++ Code 5. return p.5.4 Bond calculations with a general term structure and continous compounding Coupon bond paying coupons at dates t1 .1: C++ Code 5. : : :: Bond Price BH a Duration ˆ i BH : Yield to maturity y solves: dti Cti a ˆ i e rti ti Cti BH a Convexity ˆ i Cti e yti D: Cx: BH BH BH I I I ˆ i Da Da Da BH BH BH I I I ˆ i ti dti Cti ti e rti ti Ct ti e yti Cti i Cx a Cx a Cx a tP dti Cti i tP e rti ti Cti i tP e yti Cti i ˆ i ˆ i ˆ i ˆ i Formula 5. }.6: Pricing a bond with a term structure class 64 .

i<™—sh)ow times. }.2) * ™—sh)ow —mounts[i] * d.d(™—sh)ow times[i]). }.8: Calculating a bonds convexity with a term structure class 65 .d(™—sh)ow times[i]). const ve™tor<double>& ™—sh)ow —mounts.d(™—sh)ow times[i]). C++ Code 5.h" #include <™m—th> double ˜onds ™onvexity(const ve™tor<double>& ™—sh)ow times. const ve™tor<double>& ™—sh)ow —mounts. C++ Code 5. const term stru™ture ™l—ss& d ) { double ƒ=0. }.#include "fin_recipes.size(). for (unsigned i=0.d(™—sh)ow times[i]). for (unsigned i=0. gx += pow(™—sh)ow times[i]. return gx/f.size(). double hI=0. return hI/ƒ. hI += ™—sh)ow times[i] * ™—sh)ow —mounts[i] * d.i++){ ƒ += ™—sh)ow —mounts[i] * d.i++){ f += ™—sh)ow —mounts[i] * d.7: Calculating a bonds duration with a term structure class #include "fin_recipes. }. const term stru™ture ™l—ss& d ) { double f=0.h" double ˜onds dur—tion(const ve™tor<double>& ™—sh)ow times. double gx=0.i<™—sh)ow times.

™out << " duration = " << ˜onds dur—tion(times. ™—sh)ows. ™—sh)ows. ™—sh)ows. times. term stru™ture ™l—ss )—t ts)—t(0. Output from C++ program: pri™e a WWFIHVV dur—tion a IFWHVU ™onvexity a QFUPTII References Shiller (1990) is a good reference on the use of the term structure. ts)—t) << endl. 66 . Calculate price.push ˜—™k(2). ™—sh)ows.1). times. ™out << " price = " << ˜onds pri™e (times. 2 year bond. ve™tor <double> ™—sh)ows. C++ program: ve™tor <double> times. ™—sh)ows.push ˜—™k(110).push ˜—™k(1). duration.Example The term structure is at with r a IH7 continously compunded interest. ts)—t) << endl. ™out << " convexity = " << ˜onds ™onvexity(times. ts)—t) << endl. and convexity of a 10%.push ˜—™k(10).

. . . . . . . 6. . . . . . . . . . . . . . . . . . . . . . . . . . . It is these properties we focus on here.5 6. . . . . 6. . . . . . . . . . . . . . . . . . . . . . .1 Setup We assume there exists n ! P risky securities. . . . . . . . . . .11. The zero beta portfolio . . . .3 6. . . . . . . . . . . . . . . . . . 76 76 76 77 We now discuss a classical topic in nance. . . . . . . . . . . 6.11.8 6. . . .12 Working with Mean Variance and CAPM . . . . . . . . . . . . . . . . . and how an investor chooses portfolio weights.Chapter 6 The Mean Variance Frontier Contents 6. . Mean variance analysis concerns investors choices between portfolios of risky assets. . . . . . . . . . . . . Q U U U S 67 . . . . . . . . . . u@pA a u@E ‘rp “. @rp AA. . . . . . . . . . . . . . . . . . . . . . . . . . In this part we consider the representation of the portfolio opportunity set of such decision makers. . . . . . . . . . . . . . . . . . . . .10 The Sharpe Ratio . . . . . . . . . There are a number of useful properties of this opportunity set which follows purely from the mathematical formulation of the optimization problem. . . . . . . . . . . . . . . . . . . . .11 Equilibrium: CAPM . . . . . . . . . . . . . . . . . The global minimum variance portfolio . . . . . . Ecient sets with risk free assets. . 6.6 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6. Ecient portfolios . . . . . . . . . .7 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 Mean variance analysis using matrix libraries . . . . . . . .9 Setup . . with utility increasing in expected return @@u=@E ‘rp “ > HA and decreasing in variance @@u=@ var@rp A < HA. . . . . . . .2 Jensen . . . . . . . . Calculation of frontier portfolios . . . . . . . . . . mean variance analysis. . . . . . . We assume that investors preferences over p satisfy a mean variance utility representation. . . . . . . . portfolios Let rp be a portfolio return. . . . . . . . . . . . . . . . . . . . . . .4 6. with expected returns e P eaT T T R E ‘rI “ E ‘rP “ E ‘rn “ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6. . . . .1 6. . . . . Short-sale constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . This leads to ways of accounting for the riskiness of cashows. . . . Allowing for a riskless asset. 67 69 69 72 72 73 73 74 75 75 76 6. . .1 Treynor . . . The minimum variance frontier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. .15] w—tl—˜ program: e a HFIHHHHH HFIIHHHH HFHVHHHH † a HFPHHHH HFHHHHH HFHHHHH HFHHHHH HFIHHHH HFHHHHH HFHHHHH HFHHHHH HFISHHH w a HFQQQQQ HFQQQQQ HFQQQQQ er a HFHWTTTU sigm— a HFPPQTI 68 . P waT T T R !I !P !n . 0 0. Determine the expected return and standard deviation of an equally weighted portfolio of the three assets w—tl—˜ program: e=[0.11 0. The expected return on a portfolio is calculated as E ‘rp “ a wH e and the variance of the portfolio is P @rp A a wH Vw Example An investor can invest in three assets with expected returns and variances as specied in the following table.20 0.10 0. rI A @rI . portfolio p is dened by a set of weights w invested in the risky assets. t Asset 1 2 3 E ‘r“ 10% 11. . Note that the weights sum to one. rP A : : : @rn .and covariance matrix V: Q U U U S P VaT T T R @rI . 1.08] †=[ 0.5% 8% P @rA 0. rn A The covariance matrix A is assumed to be invertible. rI A @rP . rP A : : : @rP . w=1/3*[1 1 1] er= e*w' sigm—=sqrt(w*†*w') Output from 0 0 0. ::: V @rn .1 0 .2 0 0. Q U U U.15 The three assets are independent (uncorrelated). S where wi is the fraction of the investors wealth invested in asset i. rI A . .1 0.

3 Calculation of frontier portfolios Proposition 1 If the matrix V wp for a frontier portfolio p wp is full rank. 6.6. je. and there are no restrictions on shortsales. . V) = wH Vw    E [~p ]   wH e   (1   wH 1) r 2 69 . the weights with mean E ‘~p “ can be found as r a g C hE ‘rp “ I @B 1H   AeH A V I @C eH   A1H A V I where ga ha D D I A a 1H V I e B a eH V I e C a 1H V I 1 B A Aa A C ! D a BC   AP a jAj Proof Any minimum variance portfolio solves the program wp = arg min w 1 2 wH Vw subject to wH e = E [~p ] r wH 1 = 1 Set up the Lagrangian corresponding to this problem   ¡ 1 L(w. a wp I a —rg min wH Vw P w subject to: wH e a E ‘~p “ r wH 1 a I The set of all frontier portfolios is called the minimum variance frontier. that is.2 The minimum variance frontier A portfolio is a frontier portfolio frontier portfolio p solves if it minimizes the variance for a given expected return.

1) with e and recognise the expression for E [rp ] in the second equation wH e = E [rp ] = eH V 1 e + 1H V 1 e Similarly post-multiply equation (6. Example g is a portfolio with expected return 0.2) (6. B .1) (6. and get wH = 1 D   H ¡ B 1   AeH V 1 + 1 D   H ¡ C e   A1H V 1 E [rp ] = g + hE [rp ] The portfolio dened by weights The portfolio dened by weights @g C hA is a portfolio with expected return 1. 1. get = B   AE [rp ] D CE [rp ]   A D = Plug in expressions for  and into equation (6.1) with 1 and recognise the expression for wH 1 = 1 = eH V 1 1 + 1H V 1 1 1 in the third equation With the denitions of A.10 0. C and D above. What are the weights of the minimum variance portfolio with mean 9%? 70 . An investor can invest in three assets with expected returns and variances as specied in the following table.15 The three assets are independent (uncorrelated). This implies the useful property that g1H a I.1) above. this becomes the following system of equations & E [rp ] 1 = = B + A A + C ' Solving for  and . and h1H a H.Dierentiate @L @w @L @ @L @ = wH V   eH   1H =0 = E [rp ]   wH e = 0 =1   wH 1 = 0 Rewrite conditions above as (note that this requires the invertibility of V.3) wH e = E [~p ] r wH 1 = 1 Post-multiply equation (6.20 0.5% 8% P @rA 0. t Asset 1 2 3 E ‘r“ 10% 11. wH = eH V  1   1H V 1 (6.

d = det(e).n))*inv(V).11 0. 0 0 0.n)   —*e')*inv(V). — = ones(1.— ™]. g = 1/d*(˜*ones(1. function w = min v—ri—n™e portfolio(e.n))*inv(V) w=g+h*r Output from w—tl—˜ program: e a HFIHHHHH HFIIHHHH HFHVHHHH † a HFPHHHH HFHHHHH HFHHHHH HFHHHHH HFIHHHH HFHHHHH HFHHHHH HFHHHHH HFISHHH r a HFHWHHHH n a Q — a PFIQQQ ˜ a HFPIQTU ™ a PIFTTU e a HFPIQTU PFIQQQQ PFIQQQQ PIFTTTTU d a HFHUVQQQ g a HFHPIPUU EPFTVHVSI QFTSWSUR h a PFIPUU QIFWIRW EQRFHRPT w a HFPIPUU HFIWIRW HFSWSUR This calculation is put into a w—tl—˜ function in w—tl—˜ Code 6.n)*inv(†)*e ˜ = e'*inv(V)*e ™ = ones(1.a*ones(1.2 0 0. end w—tl—˜ Code 6.†. 0 0.1 0.w—tl—˜ program: e=[0.n)*inv(†)*ones(n.09 n = length(e) — = ones(1. ™ = ones(1.1) e = [˜ —.n)*inv(†)*e.1 0 .n)*inv(†)*ones(n.— ™] d = det(e) g = 1/d*(˜*ones(1.a*ones(1.r) n = length(e). ˜ = e'*inv(V)*e. w=g+h*r.08]' †=[ 0.n)   —*e')*inv(V) h = h = 1/d*(™*e' .1.1: Calculation of minimum variance portfolio for given return 71 . e = [˜ —.15] r=0.1). h = h = 1/d*(™*e' .

H wmvp Let mvp be the global minimum variance portfolio.V: covariance matrix of asset returns.4 The global minimum variance portfolio The portfolio that minimizes variance regardless of expected return is called the ance portfolio. E ‘r“ T E [rmvp ] E  (rmvp ) 72  @r A . E ‘r“ T A C p E C 1  @r A 6. A C The global minimum variance portfolio has weights expected return E ‘rmvp “ a C I and variance var@rmvp A a C .Calculating the weights of the minimum variance portfolio given an interest rate wp where a g C hE ‘rp “ I @B 1H   AeH A V I @C eH   A1H A V I ga ha D D I A a 1H V I e B a eH V I e C a 1H V I 1 D a BC   AP a Notation: rp desired portfolio returns. e: vector of expected asset returns. global minimum vari- Proposition 2 (Global Minimum Variance Portfolio)   ¡ I a 1H V I 1  I 1H V I a 1H V I . 6.5 Ecient portfolios Portfolios on the minimum variance frontier with expected returns higher than or equal to called ecient E ‘rmvp “ are portfolios.

E [r] T Conversely. The zero beta portfolio zb@pA has return E ‘rzc@pA “ a D A   E ‘r C“2  A C p C T s mvp E [rzc(p) ] s p zc@pA E s Note that if if p is an ecient portfolio on the mean variance frontier then zc@pA is inecient.6.7 Allowing for a riskless asset. rp A a H: This portfolio is called the zero beta portfolio relative to p. Intuitively. p is inecient zc@pA is ecient. Suppose have N risky assets with weights w and one riskless assets with return rf .6 The zero beta portfolio Proposition 3 For any portfolio p on the frontier. the return on a portfolio with a mix of risky and risky assets can be written as E ‘rp “ a weight in risky ¢ which in vector form is: return risky C weight riskless ¢ rf E ‘rp “ a wH e C @I   wH 1Arf An ecient portfolio in the presence of a riskless asset has the weights E ‘rp “   rf wp a V I @e   1rf A H where H a @e   1rf AH V I @e   1rf A Proposition 4 73 . there is a frontier portfolio zc@pA satisfying cov@rzc@pA .     sp       s mvp     s zc@pA E  (r) 6.

74 . Then the ecient set is the line from @H. The ecient set is a line in mean-standard 6. E [r] T           rf   Ad C d d s mvp d d s de p C 1 E  (r) If rf a A C.8 Ecient sets with risk free assets. Then the ecient set is the two half-lines starting from @H. the weight in the risk free asset is one. rf A. E [r] T A C   rf   d d se         s mvp d d pd 1 Suppose Cd E  (r) rf > A C. E ‘rp “. rf A through tangency on the ecient set of assets. The risky portfolio is an zero investment portfolio. The ecient set consists of two asymptotes toward the ecient set of risky assets.The variance of the ecient portfolio is @E ‘rp “   rf AP P @rp A a H Note that standard deviation is a linear function of deviation space. Suppose risky rf < A C.

Note that in the case with a risk free asset. since this involves selling securities short. 6.9 Short-sale constraints So far the analysis has put no restrictions on the set of weights frontier. To deal with this problem in practice one will use a subroutine for solving constrained optimization problems. restricted mean variance frontiers. 75 . one rather has to investigate the Kuhn-Tucker conditions for corner solutions etc.E [r] T           A C  d d d s mvp d d p d C 1 E  (r) 6. since they do not admit a general solution.10 The Sharpe Ratio The Sharpe ratio of a given portfolio p is dened as Sp a E ‘rp “   rf @rp A Sp of a portfolio p is the slope of the line in mean-standard deviations space from the p. This has led to the investigation of to be non-negative. existence of negative weights is problematic. wp that denes the minimum variance For practical applications. the tangency portfolio has the The Sharpe ratio risk free rate through maximal Sharpe Ratio on the ecient frontier. where the weights are constrained Denition 1 wp A short sale resctricted minimum variance portfolio p solves I a —rg min wH Vw P w subject to wH e a E ‘~p “ r wH 1 a I wH !0 Such short sale resctricted minimum variance portfolio portfolios are much harder to deal with analytically.

E ‘ri “ a rf C . an economy of mean variance optimizers will aggregate to an economy where the Capital Asset Pricing Model (CAPM) holds.6. any asset returns will satisfy.11 Equilibrium: CAPM Under certain additional assumptions. Under the CAPM.

6.11.2 rp   rf .1 Tp a 6. rf Treynor the return on the risk free asset.11.i @E ‘rm “   rf A where ri is the return on asset i.

p Jensen p a rp   @rf C .

—lph— = mean(r) (rf +beta*(mean(rm) rf )). 1988. rm. rf ) beta = cov(r.rf ) s=(mean(r) mean(rf ))/std(r rf ). The issues of more concern is estimation of parameters such as covariances and betas.rm)/v—r(rm). endfun™tion     w—tl—˜ Code 6. 76 .4: Jensens alpha Readings and Sources The classical sources for this material are Merton (1972) and Roll (1977a).rm)/v—r(rm). endfun™tion   w—tl—˜ Code 6.p @rm   rf A 6. (Huang and Litzenberger.3: Treynor Ratio function —lph— = jensen(r. t = (mean(r rf ))/beta.12 Working with Mean Variance and CAPM The computational problems in mean variance optimization and the CAPM are not major. endfun™tion     w—tl—˜ Code 6. rm. except for the case of short sales constrained portfolios (quadratic programming). rf ) beta = cov(r. Ch 3) has a good textbook discussion of it.2: Sharpe Ratio function t = treynor(r. function s= sh—rpe(r.

return sqrt(v—r). the calculations are relatively simple matrix expressions. double mv ™—l™ul—te me—n(const ve™& e.tr—nspose()*w. C++ Code 6. }. Therefore. const ve™& w){ m—t tmp = w. Hence. Mean variance calculations using s„CC ea Va H:HS H:I ! I:H H:H H:H I:H H:S H:S ! ! Calculate mean. double mv ™—l™ul—te v—ri—n™e(const m—t& †. }.0).2 we show how to do the basic mean variance calculations. the o by one error is a very common occurrence when mixing libraries like this.6. Note the similarity to using w—tl—˜ in the way the matrix and vector multiplications are carried out. in adressing tmp@IDIA in the xewm—t example we are also pulling the rst element.1 and C++ Code 6.1: Example Mean variance calculations.w). variance and stdev for portfolio wa 77 . double mv ™—l™ul—te st dev(const m—t& †. #include <itpp/it˜—se. when adressing tmp@HDHA in the s„CC example we are pulling the rst element. const ve™& w){ ve™ tmp = e. the w—tl—˜ way. In C++ Code 6.13 Mean variance analysis using matrix libraries Let us now consider how to implement mean variance analysis in C++. Note also an important dierence between the two classes. }. These classes are described in more detail in an appendix.tr—nspose()*†*w.h> using namespace itpp. return tmp(0. with some references to how to obtain and install them. the usual C++ way. To implement the calculations in C++ the best way of doing it is to use a linear algebra class to deal with the calculations. calculating means and standard deviations. using the two classes. In Newmat the default indexing at one. #include <™m—th> using namespace std. const ve™& w){ double v—r = mv ™—l™ul—te v—ri—n™e(†. This serves as a warning to read the documentation carefully. In element starts s„CC the indexing of elements start at zero. return tmp(0). As shown using w—tl—˜. xewm—t and s„CC. For illustrative purposes we will show usage of two dierent matrix classes.

1).w) << endl. e(1.1)=0. †(2. }. ™out << " stdev " << mv ™—l™ul—te st dev(†.1).0. return sqrt(v—r). }.1)=0.05. double mv ™—l™ul—te me—n(const w—trix& e.1.2)=0. w—trix w(2. C++ Code 6. w(2.t()*w.w) << endl.2)=1. w(1. ™out << " mean " << mv ™—l™ul—te me—n(e. e(2.1)=1.1).1)=0.h" using namespace xi‡we„. w—trix e(2. #include "newmat. †(2. return tmp(1. double mv ™—l™ul—te st dev(const w—trix& †.1)=0. †(1. Output from C++ program: ƒimple ex—mple of me—n v—ri—n™e ™—l™ul—tions me—n HFHUS v—ri—n™e HFS stdev HFUHUIHU 78 . }. ™out << " variance " << mv ™—l™ul—te v—ri—n™e(†.0.1)=0.1).t()*†*w.0.5. const w—trix& w){ return tmp(1.w) << endl.0. const w—trix& w){ double v—r = mv ™—l™ul—te v—ri—n™e(†.w). const w—trix& w){ w—trix tmp = e. double mv ™—l™ul—te v—ri—n™e(const w—trix& †. w—trix †(2.2).2: C++ program: Mean variance calculations using xewm—t ™out << "Simple example of mean variance calculations " << endl. †(1.5.#include <™m—th> using namespace std. w—trix tmp = w.

element(i. w—trix g = ones. GG inverse of † w—trix e = (ones.1)=1. †(2. ea Va H:HS H:I ! I:H H:H H:H I:H ! Find the optmal minimum variance portfolio with return C++ program: r a H:HUS.0). w. }. #include "newmat.t()*†inv*ones. w—trix †invI=†inv*ones.3: Example Calculating the unconstrained frontier portfolio given an expected return using xewm—t Mean variance calculations.1)=0.‚ele—se(). }. w—trix g = (†invI*˜   †inve*—)*(1. †(1. w—trix †inve=†inv*e.t()*†inv*e).i<no —ssets.1)=0. ‚eturnw—trix mv ™—l™ul—te portfolio given me—n un™onstr—ined(const w—trix& e. const w—trix& †.05.++i){ ones. e(2. †(2.1).1). double — = e.r). const double& r){ int no —ssets=e. double ™ = g.2).†. Output from C++ program: „esting portfolio ™—l™ul—tion suggested portfolioX wI a HFS wP a HFS 79 .4 and C++ Code 6. return w.0.1)=0.0).0.xrows().1.h" using namespace xi‡we„. w—trix ones = w—trix(no —ssets. w—trix w = g + h*r. w—trix e(2. = 1. w—trix h = (†inve*™   †invI*—)*(1.element(0.i(). ™out << "Testing portfolio calculation " << endl.3 we show how to calculate the mean variance optimal portfolio for a given required return. double r=0. double ˜ = f. C++ Code 6.In C++ Code 6. w—trix †(2. ™out << " suggested portfolio: ". and we use the analytical solution directly.0/d). This is the case where there are no constraints on the weight. e(1.0).2)=0. ™out << " w1 = " << w(1.075.0/d). w—trix f = e.1) << " w2 = " << w(2.element(0.0) w—trix †inv = †. †(1.0.0.element(0.1) << endl.t()*†inv*e. w—trix w = mv ™—l™ul—te portfolio given me—n un™onstr—ined(e. double d = ˜*™   —*—.2)=1. for (int i=0.

0). const m—t& †.size(). m—t mv ™—l™ul—te portfolio given me—n un™onstr—ined(const ve™& e.tr—nspose()*†inv*one. double d = ˜*™ —*—. }. m—t g = one.#include <itpp/it˜—se.0/d). m—t h = (†inve*™   †invI*—)*(1. m—t †inv = inv(†). GG inverse of † m—t e = one.h> using namespace itpp.tr—nspose()*†inv*e. double ™ = g(0. m—t f = e. ve™ one = ones(no —ssets).0). m—t w = g + h*r. C++ Code 6.tr—nspose()*†inv*e. m—t †invI=†inv*one. const double& r){ int no —ssets=e. double — = e(0. m—t †inve=†inv*e. double ˜ = f(0.4: Calculating the unconstrained frontier portfolio given an expected return using s„CC 80 . return w.0). m—t g = (†invI*˜   †inve*—)*(1.0/d).

Chapter 7

Futures algoritms.
Contents

7.1

Pricing of futures contract. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

In this we discuss algoritms used in valuing futures contracts.

7.1 Pricing of futures contract.
The futures price of an asset without payouts is the future value of the current price of the assset.

ft a er@T  tA St
#include <™m—th> using namespace std;

GG ™urrent pri™e of underlying —sset double futures pri™e(const double& ƒ, const double& r, GG risk free interest r—te const double& time to m—turity) { return exp(r*time to m—turity)*ƒ;
};

C++ Code 7.1: Example
Let

Futures price

S a IHH and r a IH7.

What is the futures price for a contract with time to maturity of half a year?

C++ program:

double ƒ=100; double r=0.10;
Output from C++ program:

double time=0.5; ™out << " futures price = " << futures pri™e(ƒ,r, time) << endl;

futures pri™e a IHSFIPU

81

Chapter 8

Binomial option pricing
Contents

8.1 8.2 8.3

Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Multiperiod binomial pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82 82 85

8.1 Options
Option and other derivative pricing is one of the prime success stories of modern nance. An option is a derivative security, the cash ows from the security is a function of the price of some typically called the underlying security.

other

security,

A call option is a right, but not obligation, to buy a given

quantity of the underlying security at a given price, called the exercise price interval. A put option is the right, but not obligation, to

K , within a certain time sell a given quantity of the underlying security

to an agreed excercise price within a given time interval. If an option can only be exercised (used) at a given date (the time interval is one day), the option is called an European Option. If the option can be used in a whole time period up to a given date, the option is called American. An option will only be used if it is valuable to the option holder. In the case of a call option, this is when the exercise price

K

is lower than the price one alternatively could buy the underlying security

for, which is the current price of the underlying security. Hence, options have never negative cash ows at maturity. Thus, for anybody to be willing to oer an option, they must have a cost when entered into. This cost, or price, is typically called an option a call option,

P

the price of a put option and

are indexed by time. We typically let

H be now

S

premium.

As notation, let

C

signify the price of

the price of the underlying security. All of these prices and

T

the nal maturity date of the option. From the

denition of the options, it is clear that at their last possible exercise date, the maturity date, they have cash ows.

CT a max@H; ST   K A PT a max@H; K   ST A
The challenge of option pricing is to determine the option premia

CH (call price) and PH (put price).

8.2 Pricing
All pricing uses that the cashows from the derivative is a direct function of the price of the underlying security. Pricing can therefore be done

relative

to the price of the underlying security. To price options

82

it is necessary to make assumptions about the probability distribution of movements of the underlying security. We start by considering this in a particularly simple framework, the binomial assumption. The price of the underlying is currently

SH .

The price can next period only take on two values,

Su and Sd .

¨¨ S rrH rr

¨ ¨¨

B ¨ ¨¨

Su

r

rr j r

Sd

If one can nd all possible future states, an enumeration of all possibilities, one can value a security by constructing articial probabilities, called state price probabilities, which one use to nd an articial expected value of the underlying security, which is then discounted at the risk free interest rate. The binomial framework is particularly simple, since there are only two possible states. 

nd the probability

q

of one state, we also nd the probability of the other as

@I   q A.

If we

Equation 8.1

demonstrates this calculation for the underlying security.

SH a e r @qSu C @I   qASd A q.
The contribution of binomial option pricing is in actually calculating the number

(8.1)

Now, any derivative security based on this underlying security can be priced using the same probability

start by introducing constants

u

and

d

implicitly dened by

Su a uSH

and

q. To do valuation, Sd a dSH , and you get a

price process as illustrated in gure 8.1.

SH

¨¨ r rr

B ¨ ¨¨ r j r

uSH dSH

Figure 8.1: Binomial Tree and calculate the artical probability

q as

qa
in

er   d u d
Formula 8.1
and implemented

The price of a one-period call option in a binomial framework is shown in

C++ Code 8.1.

The state price probability

q is found by an assumption of no arbitrage opportunities.

If one has the

possibility of trading in the underlying security and a risk free bond, it is possible to create a portfolio of these two assets that exactly duplicates the future payos of the derivative security. Since this portfolio has the same future payo as the derivative, the price of the derivative has to equal the cost of the duplicating portfolio. Working out the algebra of this, one can nd the expression for of the up and down movements

u and d.

q as the function

Exercise 8.1.
The price of the underlying security follows the binomial process

83

Cu a m—x@H; Su   K A Cd a m—x@H; Sd   K A CH a e r @qCu C @I   qACd A er   d qa u d Su a uS0 and Sd a dS0 are the possible values for the underlying security next period, u and d are constants, r is the (continously
compounded) risk free interest rate and K is the call option exercise price.

Formula 8.1:
#include <™m—th> #include <—lgorithm> using namespace std;

The single period binomal call option price

GG st—nd—rd m—them—ti™—l li˜r—ry GG de(ning the m—x@A oper—tor
double& double& double& double& double&

double option pri™e ™—ll europe—n ˜inomi—l single period( const const const const const double p up = (exp(r) d)/(u d); double p down = 1.0 p up; double ™ u = m—x(0.0,(u*ƒ ˆ)); double ™ d = m—x(0.0,(d*ƒ ˆ)); double ™—ll pri™e = exp( r)*(p up*™ u+p down*™ d); return ™—ll pri™e;

   

 

ƒ, GG spot pri™e ˆ, GG exer™i™e pri™e r, GG interest r—te @per periodA u, GG up movement d){ GG down movement

 

   

};

C++ Code 8.1:

Binomial European, one period

SH

B ¨ ¨¨ ¨ ¨ rr rr j r

Su

Sd

A one period call option has payos

CH

¨¨ r rr

B ¨ ¨¨ r j r

Cu a m—x@H; Su   K A Cd a m—x@H; Sd   K A

1. Show how one can combine a position in the underlying security with a position in risk free bonds to create a portfolio which exactly duplicates the payos from the call. 2. Use this result to show the one period pricing formula for a call option shown in formula 8.1.

84

8.3 Multiperiod binomial pricing
Of course, an assumption of only two possible future states next period is somewhat unrealistic, but if we iterate this assumption, and assume that every date, there are only two possible outcomes

next date,

but then, for each of these two outcomes, there is two new outcomes, as illustrated in the next gure:

¨ ¨¨ ¨St rr rr

¨ ¨¨ ¨ B r ¨ ruSt ¨¨ rr ¨

B ¨ u(uSt ) = uuSt ¨¨ ¨

r

¨¨ rr j ¨ r ¨dSt rr r rr r

r rr j r d(uS ) = u(dS ) = udS t t t B ¨ ¨¨ ¨

r d(dS ) = ddS j r t t

Iterating this idea a few times more, the number of dierent

terminal

states increases markedly, and we

get closer to a realistic distribution of future prices of the underlying at the terminal date. Note that a crucial assumption to get a picture like this is that the factors

u and d are the same on each date.

¨ ¨¨ ¨rr r ¨¨ rr ¨¨ ¨¨ r ¨r ¨¨rr ¨¨ rr r ¨ rr ¨ ¨ rr ¨¨ r¨¨ ¨ ¨ rr ¨rr ¨rr r ¨ rr r ¨¨ rr¨¨ r ¨¨ ¨¨ ¨ rr r rr ¨ ¨ r ¨ ¨ r ¨ rr r r

Pricing in a setting like this is done by working backwards, starting at the terminal date. Here we know all the possible values of the underlying security. For each of these, we calculate the payos from the derivative, and nd what the set of possible derivative prices is

one period before.

Given these, we can 

nd the option one period before this again, and so on. Working ones way down to the root of the tree, the option price is found as the derivative price in the rst node. For example, suppose we have two periods, and price a two period call option with exercise price

K.

85

CH a e r @qCu C @I   qACd A Thus. Suu   K ) ¨¨ ¨ ¨ ¨¨ Cu a e r @qCuu C @I   qACud A Cd a e r @qCud C @I   qACdd A B ¨ ¨ ¨¨ Cu CH ¨ rr rr j r Cd Cu and Cd . Exercise 8. nd option value at time 0: Final step: Using the two possible payos at time 1. and programming therefore concerns an ecient way of traversing such a tree. The obvious data structure for describing such a tree is shown in C++ Code 8. 86 .¨ ¨¨ ¨S0 rr rr ¨ ¨¨ ¨uS0 B ¨ ¨ rr rr ¨¨ B ¨ uuS0 ¨¨ ¨ r ¨ rr ¨¨ j r ¨dS0 rr rr r rr j r ddS0 r rr j r B ¨ ¨ udS0 ¨¨ First step: Find terminal payos of derivative security: ¨ B ¨ rr ¨¨ rr ¨ r ¨¨ rr ¨ j r C = max(0. ddS   K ) Next step: Find the two possible call prices at time 1: B ¨ Cuu = max(0.2. binomial pricing really concerns rolling backward in a binomial tree.2. duS   K ) ¨ rr B ¨ du ¨¨ rr ¨ ¨ r rr ¨¨ j r¨ rr rr r rr j r Cdd   max(0. where the value in each node is calculated from nding out the number of up and down steps are used to get to the particular node.

05. ™out << " two period european call = " << option pri™e ™—ll europe—n ˜inomi—l multi period given ud(ƒ.push ˜—™k(ƒ).d) << endl. More ecient would be to carry out the tree building by doing the multiplication from the previous node. C++ Code 8. for (int i=1. for (int j=0. for example the one need to add one more node by multiplying the lowest element by 1. 1. }. r a H:HPS. double u = 100. Price one and two period European Call options.0. Basing the recursive calculation of a derivative price on a triangular array structure as shown in C++ Code 8. we can get away with the more ecienent algorithm that is shown in C++ Code 8.r. j 'th vector is the j   I'th vector times u. K a IHH:H. Further reading The derivation of the single period binomial is shown in for example Bossaerts and Ødegaard (2001).3. const int& no steps){ ve™tor< ve™tor<double> > tree. double r double d = 1/u. 87 .u.0.j)*pow(d. ve™tor< ve™tor<double> > ˜inomi—l tree(const double& ƒH. }. one period europe—n ™—ll a QFTRQRP two period europe—n ™—ll a SFRRPSS Exercise 8.++i){ ve™tor<double> ƒ(i). Implement pricing of single and multi period binomial put options.2: Building a binomial tree In terms of computational eciency the approcach of lot of calls to the pow@A C++ Code 8. = 1. u a I:HS and d a I=u.2 is the most natural approach.r.025.u. Output from C++ program: double ƒ double u = 100.3.j<i.u.++j){ ƒ[j] = ƒH*pow(u.#include <ve™tor> #include <™m—th> using namespace std. Hull (2006) or McDonald (2006).2 will not be optimal. C++ program: ™out << " one period european call = " << option pri™e ™—ll europe—n ˜inomi—l single period(ƒ. Implement such an alternative tree building procedure. }.d. const double& u. but with some cleverness based on understanding the structure of the binomial tree. int no periods = 2. Note that here we only use one ve™tor<dou˜le>. and then d.i<=no steps. tree. return tree. not a triangular array as built above. Example Let S a IHH:H. since it requires a functional call. = 0.no periods) << endl.u. const double& d.i j 1).

#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std;

GG st—nd—rd m—them—ti™—l li˜r—ry GG de(ning the m—x@A oper—tor GG ƒ„v ve™tor templ—tes

double option pri™e ™—ll europe—n ˜inomi—l multi period given ud(const double& ƒ, GG spot pri™e const double& u, GG exer™i™e pri™e const double& r, GG interest r—te @per periodA const double& u, GG up movement const double& d, GG down movement const int& no periods){ GG no steps in ˜inomi—l tree double ‚inv = exp( r); GG inverse of interest r—te double uu = u*u; double p up = (exp(r) d)/(u d); double p down = 1.0 p up; ve™tor<double> pri™es(no periods+1); GG pri™e of underlying

 

   

 

for (int i=1; i<=no periods; ++i) pri™es[i] = uu*pri™es[i 1]; ve™tor<double> ™—ll v—lues(no periods+1); GG v—lue of ™orresponding ™—ll for (int i=0; i<=no periods; ++i) ™—ll v—lues[i] = m—x(0.0, (pri™es[i] u)); GG ™—ll p—yo's —t m—turity step) { for (int step=no periods 1; step>=0; for (int i=0; i<=step; ++i) {

pri™es[0]

=

ƒ*pow(d, no periods); GG (ll in the endnodesF

 

 

  

 

™—ll v—lues[i]

= (p

up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv;

}; };

return ™—ll v—lues[0];
};

C++ Code 8.3:

Binomial multiperiod pricing of European call option

88

Chapter 9

Basic Option Pricing, the Black Scholes formula
Contents

9.1 9.2

The formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Understanding the why's of the formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

90 92

9.2.1 9.2.2 9.2.3
9.3

The original Black Scholes analysis . . . . . . . . . . . . . . . . . . . . . . . . . The limit of a binomial case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The representative agent framework . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

93 93 93
93

Partial derivatives.

9.3.1 9.3.2 9.3.3
9.4

Delta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Other Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implied Volatility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

93 94 96
98

References

The pricing of options and related instruments has been a major breakthrough for the use of nancial theory in practical application. Since the original papers of Black and Scholes (1973) and Merton (1973), there has been a wealth of practical and theoretical applications. We will now consider the orginal Black Scholes formula for pricing options, how it is calculated and used. For the basic intuition about option pricing the reader should rst read the discussion of the binomial model in the previous chapter, as that is a much better environment for understanding what is actually calculated.

derivative security, its value depends on the value, or price, of some other underlying underlying security.. Let S denote the value, or price, of this underlying security. We need to keep track of what time this price is observed at, so let St denote that the price is observed at time t. A call (put) option gives the holder the right, but not the obligation, to buy (sell) some underlying asset at a given price K , called the exercise price, on or before some given date T . If the option is a so called European option, it can only be used (exercised) at the maturity date. If the option is of the so called American type, it can be used (exercised) at any date up to and including the maturity date T . If exercised at time T , a call option provides payo
An option is a security, called the

CT a m—x@H; ST   K A
and a put option provides payo

PT a m—x@H; K   ST A
The Black Scholes formulas provides analytical solutions for

European

put and call options, options

which can only be exercised at the options maturity date. Black and Scholes showed that the additional

89

information needed to price the option is the (continously compounded) risk free interest rate variability of the underlying asset, measured by the standard deviation the time to maturity

@T   tA of the option, measured in years. 

r,

the

of (log) price changes, and

The original formula was derived under

the assumption that there are no payouts, such as stock dividends, coming from the underlying security during the life of the option. Such payouts will aection option values, as will become apparent later.

9.1 The formula
Formula 9.1 gives the exact formula for a call option, and the calculation of the same call option is shown in

C++ Code 9.1

and

w—tl—˜ Code 9.1.

c a SN @dI A   Ke r@T  tA N @dP A
where

dI a
and

ln

 S¡ K C @r C

I P p P  A@T   tA  T  t

dP a dI    T   t
Alternatively one can calculate

p

dI a dP a

 S¡ ln K C r@T

ln

 S¡ K C r @T 

T  t  T  t

p p

  t A C I  pT   t
P P

dI and dP as

  t A   I  pT   t

S is the price of the underlying security, K the exercise price, r the (continously compounded) risk free interest rate,  the standard deviation of the underlying asset, t the current date, T the maturity date, T   t the time to maturity for the option and N ¡ the cumulative normal distribution.

@A

Formula 9.1:

The Black Scholes formula

#include <™m—th> #include "normdist.h"

GG m—them—ti™—l g li˜r—ry GG the ™—l™ul—tion of the ™umul—rive norm—l distri˜ution

double option pri™e ™—ll ˜l—™k s™holes(const double& ƒ, GG spot @underlyingA pri™e const double& u, GG strike @exer™iseA pri™eD const double& r, GG interest r—te const double& sigm—, GG vol—tility const double& time) { GG time to m—turity double time sqrt = sqrt(time); double dI = (log(ƒ/u)+r*time)/(sigm—*time sqrt)+0.5*sigm—*time sqrt; double dP = dI (sigm—*time sqrt); return ƒ*x(dI) u*exp( r*time)*x(dP);

   

 

};

C++ Code 9.1:

Price of European call option using the Black Scholes formula

90

= ˜l—™k s™holes ™—ll(ƒ,u,r,sigm—,time) time sqrt = sqrt(time); dI = (log(ƒ/u)+r*time)/(sigm—*time sqrt)+0.5*sigm—*time sqrt; dP = dI (sigm—*time sqrt); ™ = ƒ * norm—l ™df (dI)   u * exp( r*time) * norm—l ™df (dP); endfun™tion

function ™

w—tl—˜ Code 9.1:

Price of European call option using the Black Scholes formula

91

Example
Stock in company XYZ is currently trading at 50. Consider a call option on XYZ stock with an exercise price of

K a SH and time to maturity of 6 months.
1. Determine the option price.

The volatility of XYZ stock has been estimated to be 

a QH7.

The current risk free interest rate (with continous compounding) for six month borrowing is 10%. 

a H:Q and @T   tA a H:S.
w—tl—˜
program:

To calculate the price of this option we use the Black Scholes formula with inputs

S a SH, K a SH, r a H:IH,

ƒ = 100; u = 100; r = 0.1; sigm— = 0.1; time = 1; ™ = ˜l—™k s™holes ™—ll(ƒ,u,r,sigm—,time)
Output from

w—tl—˜

program:

™ a IHFQHV
C++ program:

™out << " Black Scholes call price = "; ™out << option pri™e ™—ll ˜l—™k s™holes(ƒ, u
Output from C++ program:

double ƒ = 50; double u = 50; double r = double sigm— = 0.30; double time=0.50;

0.10;

,

r, sigm—, time) << endl;

fl—™k ƒ™holes ™—ll pri™e a SFRSQPS
Exercise 9.1.
The Black Scholes price for a put option is:

p a Ke r@T  tA N @ dP A   SN @ dI A
where

dP a dI    T   t; S
interest rate,

dI and dP are as for the call option:  S¡ ln X C @r C I  P A@T   tA p P dI a  T  t

p

is the price of the underlying secrutity,

N @¡A the cumulative normal distribution.
1. Implement this formula.

K the exercise price, r the (continously compounded) risk free  the standard deviation of the underlying asset, T   t the time to maturity for the option and

9.2 Understanding the why's of the formula
To get some understanding of the Black Scholes formula and why it works will need to delve in some detail into the mathematics underlying its derivation. It does not help that there are a number of ways to prove the Black Scholes formula, depending on the setup. As it turns out, two of these ways are

important to understand for computational purposes, the original Black Scholes continous time way, and the limit of a binomial process way of Cox, Ross, and Rubinstein (1979).

92

3 The representative agent framework A nal way to show the BS formula to assume a representative agent and lognormality as was done in Rubinstein (1976).1). Black and dierential equation Scholes showed that the price of (9. a number of partial derivatives of the option price formula is important. with the boundary condition cT a m—x@H. allowing the binomial framework to be used as an approximation.2.2.1). 9. as it allows us to link the Black Scholes formula to the binomial.1) rS C C @S @t P @S P For any particular contingent claim. since it is important in hedging of options.2 shows the calculation of the delta for a call option.2 The limit of a binomial case Another is to use the limit of a binomial process (Cox et al. Using Ito's lemma. the terms of the claim will give a number of boundary conditions that determines the form of the pricing formula. 93 .2. The latter is particularly interesting.. and the ability to trade continuously. and Z is Brownian motion. The price of the underlying asset. S . 9. 9. The pde given in equation (9. is assumed to follow a geometric Brownian Motion process. @c a N @dI A @S C++ Code 9. 1979).1 The original Black Scholes analysis The primary assumption underlying the Black Scholes analyis concerns the stochastic process governing the price of the underlying asset. the assumption of no arbitrage.9. 9. any contingent claim written on the underlying must solve the partial @f @f I @ P f P P  S a rf (9.3 Partial derivatives. It is the derivative most people will run into. ST   K A was shown by Black and Scholes to have an analytical solution of functional form shown in the Black Scoles formula 9. conveniently written in either of the shorthand forms dS a Sdt C SdZ or dS a dt C dZ S where  and  are constants. In trading of options.1.1 Delta The rst derivative of the option price with respect to the price of the underlying security is called the delta of the option price.3.

double dI = (log(ƒ/u)+r*time)/(sigm—*time sqrt) + 0. Formula 9. 94 K a SH.2.3. C++ Code 9. GG interest r—te const double& sigm—. GG vol—tility const double& time){ GG time to m—turity double time sqrt = sqrt(time). at which time the holder of the option can recive one unit of the underlying security by paying the exercise price of The current price of the underlying security is  a QH7. }. r the (continously compounded) risk free interest rate. All of them are listed in formula 9.5*sigm—*time sqrt. The option matures 6 months from now.3. GG ƒtrike @exer™iseA pri™eD const double& r. double delt— = x(dI).h" double option pri™e delt— ™—ll ˜l—™k s™holes(const double& ƒ. K the exercise price. . S a SH. GG spot pri™e const double& u.  the standard deviation of the underlying asset. The volatility of the underlying security is given as The current risk free interest rate (with continous compounding) for six month borrowing is 10%. T the maturity date and T   t the time to maturity for the option.2 Other Derivatives Calculating the delta of the Black Scholes call option price The remaining derivatives are more seldom used.2: Partial derivatives of the Black Scholes call option formula The calculation of all of these partial derivatives for a call option is shown in Example Consider again six month call options on XYZ stock.2: 9.3. t the current date. ‚z  I n@tAdt . return delt—.     n@¡A is the normal distribution function n@z A a p1  e  2 z 2 and N @¡A the cumulative normal distribution N @zA a C++ Code 9. Delta ( ¡) ¡a   @c a N @dI A @S Gamma ( ) @Pc n@dI A P a SpT   t @S Theta ( ¢) (careful about which of these you want) I I @c a Sn@dI A  p C rKe r@T  tA N @dP A @ @T   tA P T  t @c I I a  Sn@dI A  p   rKe r@T  tA N @dP A @t P T  t Vega p @c a S T   tn@dI A @ Rho () @c a K @T   tAe r@T  tA N @dP A @r 1 2 S is the price of the underlying security. but all of them are relevant.#include <™m—th> #include "normdist.

q—mm—.     r*u*exp(  r*time)*x(dP). Gamma. double helt—. helt— = x(dI). ‚ho = u*time*exp( r*time)*x(dP). q—mm— = n(dI)/(ƒ*sigm—*time sqrt). Theta. C++ Code 9. K a SH.30.u. ™out << " Vega = " << †eg— << endl. ™out << " Theta = " << „het— << endl. void option pri™e p—rti—ls ™—ll ˜l—™k s™holes( const double& ƒ.r. Output from C++ program: fl—™k ƒ™holes ™—ll p—rti—l deriv—tives helt— a HFTQQUQU q—mm— a HFHQSRUVW „het— a ETFTIRUQ †eg— a IQFQHRT ‚ho a IQFIITV 95 . double r = 0. double dI = (log(ƒ/u)+r*time)/(sigm—*time sqrt) + 0. GG interest r—te const double& sigm—. GG spot pri™e const double& u. ™out << " Delta = " << helt— << endl. ™out << " Gamma = " << q—mm— << endl.  a H:Q and @T   tA a H:S. †eg—. To calculate the partial derivatives we use inputs C++ program: S a SH. double u = 50. time.3: Calculating the partial derivatives of a Black Scholes call option 1. }. Vega and Rho) for this option. ‚ho. „het—.10.50. GG ƒtrike @exer™iseA pri™eD const double& r. GG time to m—turity double& helt—. GG p—rti—l wrt sigm— double& ‚ho){ GG p—rti—l wrt r double time sqrt = sqrt(time). GG p—rti—l wrt ƒ double& q—mm—. double sigm— = 0. ™out << " Rho = " << ‚ho << endl. GG se™ond prt wrt ƒ double& „het—.#include <™m—th> #include "normdist. double time=0. r a H:IH. „het—. †eg—.h" using namespace std. q—mm—. „het— =  (ƒ*sigm—*n(dI))/(2*time sqrt) †eg— = ƒ * time sqrt*n(dI). GG vol—tility const double& time.sigm—. option pri™e p—rti—ls ™—ll ˜l—™k s™holes(ƒ. GG p—rti—l wrt time double& †eg—. helt—. double dP = dI (sigm—*time sqrt). ™out << " Black Scholes call partial derivatives " << endl. Calculate the partial derivatives (Delta. double ƒ = 50.5*sigm—*time sqrt. ‚ho).

which means the equation must be numerically solved to nd . double sigm— high=0. const double& option pri™e){ if (option pri™e<0.r. double test = (pri™e option pri™e). double pri™e = option pri™e ™—ll ˜l—™k s™holes(ƒ. r. return i‚‚y‚. shows such a calculation.u. GG simple ˜inomi—l se—r™h for the implied vol—tilityF GG relies on the v—lue of the option in™re—sing in vol—tility const double egg…‚eg‰ = 1. GG keep dou˜lingF pri™e = option pri™e ™—ll ˜l—™k s™holes(ƒ.sigm— high. . which is implemented in C++ Code 9. C++ Code 9.3 Implied Volatility. GG w—nt to ˜r—™ket sigm—F (rst (nd — m—ximum sigm— ˜y (nding — sigm— GG with — estim—ted pri™e higher th—n the —™tu—l pri™eF double sigm— low=1e 5. if (test < 0.4: Calculation of implied volatility of Black Scholes using bisections Instead of this simple bracketing. }.u. the only unknown is the standard deviation of the underlying stock. The general description of this method starts with a function f @A for which we want to nd a root. we can use the NewtonRaphson formula for nding the root of an equation in a single variable. the price of a cH a c@S. pri™e = option pri™e ™—ll ˜l—™k s™holes(ƒ.   }. the following equation should be solved for the value of : cH . const double rsqr †ev…i = 1e10. GG p—ni™D something wrongF }.0e 5.i<weˆ s„i‚e„syxƒ. given call option. #include <™m—th> #include "fin_recipes. if (f—˜s(test)<egg…‚eg‰) { return sigm—. const double i‚‚y‚ =  1e40. What is probably the algorithmic simplest way to solve this is to use a binomial search algorithm.h" double option pri™e implied vol—tility ™—ll ˜l—™k s™holes ˜ise™tions(const double& ƒ.0) { sigm— low = sigm—. GG m—ke this sm—ller for higher —™™ur—™y const int weˆ s„i‚e„syxƒ = 100. const double& time.9.0. K. } }.time). T   tA Unfortunately. which is actually pretty fast. GG yption pri™e is too low if this h—ppens     }.3. const double& r.0 * sigm— high.r. For example. } else { sigm— high = sigm—.sigm— high.time).r.4. A common problem in option pricing is to nd the implied volatility.5.time). We start by bracketing the sigma by nding a high sigma that makes the BS price higher than the observed price. if (sigm— high>rsqr †ev…i) return i‚‚y‚. given the observed price quoted in the market.u. in particular the Black Scholes formula. while (pri™e < option pri™e) { sigm— high = 2. const double& u. given the bracketing interval. and will (almost) always nd the solution. we search for the volatility in a systematic way. In calculation of the option pricing formulas.sigm—. f @xA a H: 96 . for (int i=0.99*(ƒ u*exp( time*r))) { GG ™he™k for —r˜itr—ge viol—tionsF return 0. and then.i++){ double sigm— = (sigm— low+sigm— high)*0.3. this equation has no closed form solution.

i<weˆ s„i‚e„syxƒ. iterate by f @x A xiCI a xi   H i f @xi A until jf @xi Aj <  where  is the desired accuracy. double t sqrt = sqrt(time). 1 por further dis™ussion of the xewtonE‚—phson formul— —nd ˜r—™ketingD — good sour™e is ™h—pter W of €ress et —lF @IWWPA 97 . }. Given a rst guess xH . where the partial derivatives are not that easy to calculate.r.u. GG (nd initi—l v—lue for (int i=0. double veg— = ƒ * t sqrt * n(dI). const double egg…‚eg‰ = 1.99*(ƒ u*exp( time*r))) { GG ™he™k for —r˜itr—ge viol—tionsF yption pri™e is too low if this h—ppens return 0. The option matures 6 months from now.  99e10. const int weˆ s„i‚e„syxƒ = 100. double di' = option pri™e pri™e. double dI = (log(ƒ/u)+r*time)/(sigm—*t sqrt) + 0.   sigm— = sigm— + di' /veg—. formula this is known. const double& u.i++){ double pri™e = option pri™e ™—ll ˜l—™k s™holes(ƒ.0e 5. const double& time.5 cobs   cBS @i A   @cBS @A @ shows the calculation of implied volatility using Newton-Raphson.5*sigm—*t sqrt. const double& option pri™e) { if (option pri™e<0. But for pricing formulas like the binomial.h" #include "normdist. }. #include "fin_recipes.398*t sqrt). const double& r. at which time the holder of the option can recive one unit of the underlying security by paying the exercise price of K a SH. each new iteration will calculate iCI a i C C++ Code 9.The function f @A needs to be dierentiable.time). simple bisection is the preferred algorithm.0. and we can use this.sigm—. GG something s™rewy h—ppenedD should throw ex™eption C++ Code 9.h" #include <™m—th> #include <iostre—m> double option pri™e implied vol—tility ™—ll ˜l—™k s™holes newton(const double& ƒ.1 In our case f @xA a cobs   cBS @A and. if (f—˜s(di' )<egg…‚eg‰) return sigm—. Example Consider again six month call options on XYZ stock.   double sigm— = (option pri™e/ƒ)/(0.5: Calculation of implied volatility of Black Scholes using Newton-Raphson For the Black-Scholes Note that to use Newton-Raphson we need the derivative of the option price. return }.

option pri™e implied vol—tility ™—ll ˜l—™k s™holes ˜ise™tions(ƒ. 1.time. C++ program: ™out ™out ™out ™out double ƒ = 50. K a SH. option pri™e implied vol—tility ™—ll ˜l—™k s™holes newton(ƒ. will produce C a P:S.time.50.r. << << << << " Black Scholes implied volatility using Newton search = ". = 50.g) << endl. double time=0. To calculate we use inputs S a SH. 98 . r a H:IH and @T   tA a H:S. Determine the volatility implicit in this price.5.10. double r = 0.u.The current price of the underlying security is compounding) for six month borrowing is 10%.g) << endl. double u double g=2.  which. input in the Black Scholes formula with these other inputs.4 References Black and Scholes (1973) Merton (1973) Gray and Gray (2001) has a simple proof of the formula.u. The current option price is The implied volatility is the an option price of S a SH.r. " Black Scholes implied volatility using bisections = ". Output from C++ program: fl—™k ƒ™holes implied vol—tility using xewton se—r™h a HFHSHHRPU fl—™k ƒ™holes implied vol—tility using ˜ise™tions a HFHSHHRIW 9. The current risk free interest rate (with continous C a P:S.

. . . . . . K. . the above arguments are summarized as:   n A Wt a CBS . . . Assume each warrant is for 1 new share. . .2 Valuing warrants when observing the stock value . . we could value the warrant in two steps: 1. .Chapter 10 Warrants Contents 10. . . . . but this new asset value is spread over more shares. . Wt be the warrant value. . . . . . . . . . . . . . . which is lower than the current stock price (If it wasn't the warrant would not be exercised. . 99 100 101 A warrant is an option-like security on equity. . . a new stock is issued. . this stock issue dilutes. . . . waters out. and when a warrant is exercised. . Suppose all warrants are exercised simultaneously. . . . . . . . . . . Then the assets of the rm increase by the number of warrants times the strike price of the warrant. but it is issued by the same company which has issued the equity. or The degree of dilution is a function of how many warrants are issued. the equity in a company. . . . . . .1 Warrant value in terms of assets . . .1 Warrant value in terms of assets Let K be the strike price. . . . . . . . 10. hence each new share is worth: At C mK mCn making each exercised warrant worth: At C mK   K a m n n At   K mCn C n   If we knew the current value of assets in the company. n mCn . . . . . . The assets of the rm is spread over all shares. . . . . . . . Value the option using the Black Scholes formula and 2. . . . . since each exercised warrant is now an equity. @T   tA . . 10. . .) Since the new stock is a a fractional right to all cashows. . This new stock is issued at a the warrant strike price. . . At be the current asset value of rm. nCm n 99 .3 Readings . r. . . . . . . At C mK. . and let n the number of shares outstanding and m the number of warrants issued. 10. . . . . . . Multiply the resulting call price with If we let At n as the current stock price. .

The current (continously compounded) risk free interest rate is 8%. K a RH and The company has n a IHHHH shares outstanding. r.2 Valuing warrants when observing the stock value However. One need to solve this equation numerically to The numerical solution for Wt is done using the Newton-Rhapson method. one would value the warrant as Wt a or nCm n n CBS  nSt C mWt . m N @d A mCn I  In this gH @Wt A a I   where dI a ln  St C m Wt n K  T  t p C @r C I  P A@T   tA P An obvious starting value is to set calculate the Black Scholes value using the current stock price. Typically one only observes the equity value of the rm.1 Example m mCn . and has issued m a IHHH Consider warrants on the same company with exercise price warrants. K. 10. @T   tA g@Wt A a Wt   nCm n g@W i I A Wti a Wti I   H ti I . time to maturity of six months. and multiply it with C++ Code 10. If we let St be the current stock price. K. g @Wt A Let Starting with an initial guess for the warrant value as follows Wto . Wt as a function of Wt . . . Determine the current warrant price. @T   tA n  m Wt . the Newton-Rhapson method is that one iterates where case i signies iteration i. @T   tA n  Wt a nd nCm CBS St C  Note that this gives the value of Wt .where CBS @¡A is the Black Scholes formula. A stock is currently priced at S a RV. r. r. implements this calculation. . K.   m n CBS St C Wt . 100 . one does not necessarily observe the asset value of the rm. until the criterion function g@Wti I A is below some given accuracy . the asset value is really: At a nSt C mWt Using the stock price.

double time = 0. return w. double sigm— = 0.r.r. Press et al. const double& u.5*sigm—*time sqrt. while (f—˜s(g)>i€ƒsvyx) { double dI = (log((ƒ+(m/n))/u)+r*time)/(sigm—*time sqrt)+0. double gprime = 1 (m/n)*x(dI).00001. w—rr—nt pri™e a IHFIRP Exercise 10. double w = (n/(n+m))*option pri™e ™—ll ˜l—™k s™holes(ƒ. 101 .u. double w = w—rr—nt pri™e —djusted ˜l—™k s™holes(ƒ. const double& time.   w=w g/gprime.sigm—. const double& sigm—. C++ Code 10. }. m.sigm—. const double& r.3 Readings McDonald (2006) and Hull (2006) are general references.sigm—. double w—rr—nt pri™e —djusted ˜l—™k s™holes(const double& ƒ.r. time. const double& m.h" #include <™m—th> const double i€ƒsvyx=0. double m = 1000. double g = w (n/(n+m))*option pri™e ™—ll ˜l—™k s™holes(ƒ+(m/n)*w.1.u. A problem with warrants is that exercise of all warrants simultaneously is not necessarily optimal. Can you see where this assumption is used? 10.u.1: C++ program: Adjusted Black Scholes value for a Warrant ™out << " warrant price = " << w << endl. GG num˜er of w—rr—nts outst—nding const double& n){ GG num˜er of sh—res outst—nding double time sqrt = sqrt(time).time). double n = 10000.r.   }.sigm—. n).h" #include "normdist. (1992) discusses the Newton-Rhapson method for root nding.time).08.time).5. double r = 0. Output from C++ program: double ƒ = 48.30.#include "fin_recipes. The solution method assumes that all warrants are exercised simultanously. double u = 40. g = w (n/(n+m))*option pri™e ™—ll ˜l—™k s™holes(ƒ+(m/n)*w.u.

. . . . . . . . . . . . . . . . in working with commodity options.4 Foreign Currency Options . . . . . . . . . 102 .1 Exact american call formula when stock is paying one dividend. . . . Exercise 11.1. . . . . . . . . . 102 11. . . . . . . For example. . . . .1 Continous Payouts from underlying. . . . . . . . . . . . . . . . . . .6 Readings . 108 11. . . . .5 Perpetual puts and calls . . . . . . . . . .3. . . . . 104 108 109 110 111 11. . . 11. . . .2 American options . . . . . For options on other nancial instruments than stocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 11. . . . . . . . . . . . . . . . . . . 11. . . To value an European option. . . . . . . . . . . . . . .2 Dividends. . . . . . . 11. which are implemented in q be the continuous payout of the C++ Code 11. . . . . The price of a put on an underlying security with a continous payout of q is: p a Ke r@T  tA N @ dP A   Se q@T  tA N @ dI A 1. . . . . . . . . .1. . .3 Options on futures . . . . . . . . . . . . . . . . . . . . .2.1 Continous Payouts from underlying. . .1 Black's model . . . . . . . . . . . . . . .1. . . . . . . . Let underlying commodity. . . . . Call and put prices for European options are then given by formula 11. . . . . . . . .1. . . . there is often some storage costs if one wanted to hedge the option by buying the underlying. . . . 11. . . . . . . . . . . . .1. . Implement this formula. . . .1 Adjusting for payouts of the underlying. . . . The simplest case is when the payouts are done continuously. . . . . a simple adjustment to the Black Scholes formula is all that is needed. . . . . . . . . . . . . . . . . .1 Adjusting for payouts of the underlying. . . . . . . . . .Chapter 11 Extending the Black Scholes formula Contents 11. . . . . . . . . 103 11. . . 11. . . . . . . . we have to allow for the fact that the underlying may have payouts during the life of the option.1. . . . . . 102 11. . . . . . . . . . .

Dividend payments at times S a IHH. The problem is the fact that most dividends are paid at discrete dates. r a H:I. Example Consider a stock option with the following data given: is one year. T the maturity date. return ™—ll pri™e. European Options on dividend-paying stock. dividend yield = 5%. • Determine the option price 103 . K a IHH. t the current date. double dP = dI (sigm—*time sqrt). double dI = (log(ƒ/ˆ) + (r q + 0. GG yield on underlying const double& sigm—. r the risk free interest rate.2). double time sqrt = sqrt(time).  a H:PS. To adjust the price of an European option for known dividends. GG ƒtrike @exer™iseA pri™eD const double& r. we merely subtract the present value of the dividends from the current price of the underlying asset in calculating the Black Scholes value. The case of continuous dividends is easiest to deal with.c a Se q@T  tA N @dI A   Ke r@T  tA N @dP A where   q C I P A@T   tA p P  T  t p dP a dI    T   t dI a ln Analytical prices for European call option on underlying security having a payout of  S¡ K C @r S is the price of the underlying secrutity. Option price. When the stock pays dividends. continous payout from underlying A special case of payouts from the underlying security is stock options when the stock pays dividends.1: 11. GG interest r—te const double& q. C++ Code 11.h" using namespace std. time to maturity H:PS and H:US. the pricing formula is adjusted. GG m—them—ti™—l li˜r—ry GG this de(nes the norm—l distri˜ution double option pri™e europe—n ™—ll p—yout( const double& ƒ. K the exercise price. Formula 11. because the dividend changes the value of the underlying. T   t the time to maturity for the option and N @¡A the cumulative normal distribution.           }.5*sigm— sqr)*time)/(sigm—*time sqrt). GG vol—tility const double& time) { GG time to m—turity double sigm— sqr = pow(sigm—. double ™—ll pri™e = ƒ * exp( q*time)* x(dI) ˆ * exp( r*time) * x(dP). GG spot pri™e const double& ˆ.1. q the (continous) payout and  the standard deviation of the underlying asset.1: q #include <™m—th> #include "normdist. It corresponds to the continuous payouts we have looked at previously.2 Dividends.

time. dividend times.0. for (int i=0.sigm—. const double& sigm—.2: C++ program: European option price. or another numerical approximation.1.time) << endl. This optimal exercise policy will aect the value of the option. 104 . ™out << " european stock call option with discrete dividend = " << option pri™e europe—n ™—ll dividends(ƒ. double double double double Output from C++ program: europe—n sto™k ™—ll option with ™ontininous dividend a IIFUQRR europe—n sto™k ™—ll option with dis™rete dividend a IIFVHWR 11.#include <™m—th> #include <ve™tor> #include "fin_recipes. dividend times. ™out << " european stock call option with contininous dividend = " << option pri™e europe—n ™—ll p—yout(ƒ.size(). double u = 100. it may pay to exercise them early. }.push ˜—™k(0. which is the case of a call on a stock that pays a known dividend once during the life of the option. There is one known known analytical price for American call options.r. For American call options on assets that do not have any payouts. dividend yield=0. double sigm— = 0. const double& u.u. const ve™tor<double>& dividend times.dividend —mounts) << endl.sigm—. const double& time to m—turity.0. which is discussed next. There are some special cases. The problem is that it may be optimal to use (exercise) the option before the nal expiry date. However. ve™tor<double> dividend —mounts. ve™tor<double> dividend times.5).5). dividend —mounts. r = 0. const ve™tor<double>& dividend —mounts double —djusted ƒ = ƒ.push ˜—™k(0. the American call price is the same as the European one.u. C++ Code 11. }.05.75).h" GG m—them—ti™—l li˜r—ry GG de(ne the ˜l—™k s™holes pri™e double option pri™e europe—n ™—ll dividends( const double& ƒ.dividend times. return option pri™e ™—ll ˜l—™k s™holes(—djusted ƒ. In all other cases the American price has to be approximated using one of the techniques discussed in later chapters: Binomial approximation.dividend yield. since the optimal exercise policy is to not exercise.push ˜—™k(2.25.r.i<dividend times.u. time=1.25).sigm—. const double& r. For American puts this this not the case.2 American options American options are much harder to deal with than European ones.r. There is therefore no general analytical solutions for American call and put options. }.time to m—turity).0. the exercise policy is not known. dividend —mounts. and the exercise policy needs to be known when solving the pde. it may also pay to exercise an American call option early. numerical solution of the partial dierential equation.push ˜—™k(2. When the underlying asset has payouts.i++) { if (dividend times[i]<=time to m—turity){ ) { —djusted ƒ  = dividend —mounts[i] * exp( r*dividend times[i]). dividend paying stock ƒ = 100.

1 Exact american call formula when stock is paying one dividend. tI A a S C DI   K S is the price of the underlying secrutity.2: Example RollGeskeWhaley price of american call option paying one xed dividend  a I:H. Consider an option on a stock paying one dividend. for the special case of one dividend payment during the life of an option an analytical solution is available. While the general dividend problem is usually approximated somehow.3. K a IHH.1. r the risk free interest rate. AA C Ke r@T  tAA N @aP . T the maturity date.  a H:PS.11. one performs the calculation shown in C++ Code 11. K the exercise price. N with one argument is the univariate normal cumulative distribution. A   @K   DI Ae r@t1  tA N @bP A where a  aI a r @tI   t ln  T  t S  D1 e q(1 K  aP a aI    T   t bI a ln  p   p C @r C I  P A P  S  D1 e r(t1  t) C @r C " S p bP a bI    T   t and p  @tI   tA I P P  A@tI   tA " S solves " " c@S.  bI . t the current date. and the value of the option is c@S   e r@t1  tA DI . . D1 is the dividend amount and  the standard deviation of the underlying asset.2 and implemented in If the inequality is not fullled. due to RollGeskeWhaley. tI the time of the maturity date of option. early exercise is not optimal. @T   tAA where c@¡A is the regular Black Scholes formula. r. When a stock pays dividend. I a H:S and DI a IH. N with three arguments is the bivariate normal distribution with the correlation between the two normals given as the third arguement. T   t the time to maturity for the option and N ¡ the cumulative normal distribution. Price the option. T K the exercise price. If we let S be the stock price. a call option on the stock may be optimally exercised just before the stock goes ex-dividend.  I a T   tI A rst check of early exercise is: DI K I   e r@T  t1 A  If this inequality is fullled. K. 105 . Formula 11. C a @S   DI e r@t1  tA A @N @bI A C N @aI . @A @A @A Formula 11. The relevant data is S a IHH. DI the amount of dividend paid.2.r=0.  bP . dividend payment. we denote the time to dividend payment and the time to maturity  a T   t.

One with expiry date equal to the ex dividend date of the options. r = 0.1.r.hI. Blacks approximation calculates the value of two European options using the Black Scholes formula. ™out << " american call price with one dividend = " << option pri™e —meri™—n ™—ll one dividend(ƒ.2. Implement Black's approximation.0.sigm—.u. The Black approximation to the price of an call option paying a xed dividend is an approximation to the value of the call.0.0. t—uI)<< endl. hI = 10.5.0. 106 .C++ program: double double double double ƒ = 100. Suppose the dividend is paid as some date tI before the maturity date of the option T. 1.25. double u = 100. but the current price of the underlying security is adjusted down by the amount of the dividend. Another with expiry date equal to the option expiry. double t—uI = 0. Output from C++ program: —meri™—n ™—ll pri™e with one dividend a IHFHITT Exercise 11.t—u. t—u = 1. double sigm— = 0.

while ( (test>0. ˜I.u. }.h" GG the regul—r ˜l—™k sholes formul— double option pri™e —meri™—n ™—ll one dividend(const double& ƒ.r. double rho = sqrt(t—uI/t—u).5*sigm— sqr)*t—uI)/(sigm—*t—uI sqrt). } else { ƒ low = ƒ ˜—r.sigm—. const double& t—uI){ if (hI <= u* (1.sigm—.#include <™m—th> #include "normdist. const double& u.h" GG de(ne the norm—l distri˜ution fun™tions #include "fin_recipes. —P = —I   sigm—*t—u sqrt.r. GG now (nd ƒ ˜—r th—t solves ™aƒ ˜—rEhCu ™ = option pri™e ™—ll ˜l—™k s™holes(ƒ ˜—r. }.0) { ƒ high = ƒ ˜—r. ˜I = (log((ƒ hI*exp( r*t—uI))/ƒ ˜—r)+(r+0. const double egg…‚eg‰ = 1e 6.t—u t—uI). double test = ™ ƒ high hI+u.sigm—.r.r.     ƒ ˜—r = 0.5 * ƒ high. ˜P.sigm—. test = ™ ƒ high hI+u.3: Option price. return g. while ( (f—˜s(test)>egg…‚eg‰) && ((ƒ high ƒ low)>egg…‚eg‰) if (test<0.rho)   (u hI)*exp( r*t—uI)*x(˜P). GG st—rt ˜y (nding — very high ƒ —˜ove ƒ ˜—r double ™ = option pri™e ™—ll ˜l—™k s™holes(ƒ high.               double ƒ ˜—r = 0. }.u.u. const double& hI. if (ƒ high>1e10) { GG e—rly exer™ise never optim—lD (nd fƒ v—lue return option pri™e ™—ll ˜l—™k s™holes(ƒ hI*exp( r*t—uI).r. ™ = option pri™e ™—ll ˜l—™k s™holes(ƒ ˜—r.u.sigm—.0. ˜P = ˜I   sigm— * t—uI sqrt.r. g = (ƒ hI*exp( r*t—uI)) * x(˜I) + (ƒ hI*exp( r*t—uI)) * x(—I.u.5 * (ƒ high + ƒ low). RollGeskeWhaley call formula for dividend paying stock 107 . C++ Code 11.0) && (ƒ high<=1e10) ) {       ƒ high *= 2.5*sigm— sqr)*t—u) / (sigm—*t—u sqrt). }. GG (rst (nd the ƒ ˜—r th—t solves ™aƒ ˜—rChIEu double ƒ low=0. double t—uI sqrt = sqrt(t—uI).0 exp( r*(t—u t—uI)))) GG ™he™k for no exer™ise return option pri™e ™—ll ˜l—™k s™holes(ƒ exp( r*t—uI)*hI. const double& sigm—.t—u t—uI). const double& t—u.t—u t—uI). test = ™ ƒ ˜—r hI+u.t—u). double t—u sqrt = sqrt(t—u). ) { double double double double double —I = (log((ƒ hI*exp( r*t—uI))/u) +( r+0.t—u).u. ™ = option pri™e ™—ll ˜l—™k s™holes(ƒ high. }. const double& r. GG de™re—se this for more —™™ur—™y double sigm— sqr = sigm—*sigm—. GG the simplestX ˜inomi—l se—r™h double ƒ high=ƒ. ƒ ˜—r = 0.rho)   (u*exp( r*t—u))*x(—P.t—u t—uI). test = ™ ƒ ˜—r hI+u.sigm—.

GG vol—tility const double& time){ GG time to m—turity double sigm— sqr = sigm—*sigm—. Information: maturity is a half year. r a V7. GG exer™ise pri™e const double& r. GG m—them—ti™s li˜r—ry GG norm—l distri˜ution double futures option pri™e ™—ll europe—n ˜l—™k( const double& p. return exp( r*time)*(p * x(dI) u * x(dP)). double time=0.3. double r = 0. C++ Code 11.3: K is the exercise price. which was developed in Black (1976).time) << endl.3 and implemented in C++ Code 11. Black's formula for the price of an European Call option with a futures contract as the underlying security #include <™m—th> #include "normdist.0. e r@T  tAr F in the Black Scholes c a e r@T  tA @F N @dI A   KN @dP AA where p P  @T   tA  T  t p dP a dI    T   t dI a ln  F ¡ K C I P F is the futures price.u.1 Black's model For an European option written on a futures contract.4. double u = 45. we use an adjustment of the Black Scholes solution.r. and get the formula shown in 11.       }. GG interest r—te const double& sigm—.  the volatility of the futures T   t is the time to maturity of the option (in years). Output from C++ program: europe—n futures ™—ll option a HFVSIRUT Exercise 11. Essentially we replace SH with formula.0.3.h" using namespace std. 108 .5 * sigm— sqr * time) / (sigm— * time sqrt). K a RS. r the risk free interest rate. double dI = (log (p/u) + 0. and time to double p = 50. double time sqrt = sqrt(time).  a H:P. double dP = dI sigm— * time sqrt.11. ™out << " european futures call option = " << futures option pri™e put europe—n ˜l—™k(p. price. C++ program: F a SH.4: Example Price of European Call option on Futures contract Price a futures option in the Black setting.08.2.sigm—. and Formula 11. GG futures pri™e const double& u.5. double sigm— = 0.3 Options on futures 11.

GG r domesti™D const double& r f. double dI = (log(ƒ/ˆ) + (r r f + (0.  a PH7 109 . #include <™m—th> #include "normdist. double time sqrt = sqrt(time).4 Foreign Currency Options Another relatively simple adjustment of the Black Scholes formula occurs when the underlying security is a currency exchange rate (spot rate).5: Example European Futures Call option on currency Price a European currency call given the following information and time to maturity = 0.4: European currency call  S¡   K C r ¡ S is the spot exchange rate and K the exercise price. r is the domestic interest rate and rf the foreign interest rate.4 and implented in c a Se rf @T  tA N @dI A   Ke r@T  tA N @dP A where   rf C I P @T   tA p P dI a  T  t p dP a dI    T   t ln Formula 11. r a V7. GG vol—tilityD const double& time){ GG time to m—turity double sigm— sqr = sigm—*sigm—.  is the volatility of changes in the exchange rate. K a SP. Implement the put option price. S be the spot exchange rate. rf a S7.5 years. and now let r be the domestic interest rate and rf the foreign interest  is then the volatility of changes in the exchange rate. call option is then shown in formula 11. interest-rate dierential.5*sigm— sqr)) * time)/(sigm—*time sqrt). T   t is the time to maturity for the option. The calculation of the price of an European C++ Code 11. Let In this case one adjusts the Black-Scholes equation for the rate. double dP = dI sigm— * time sqrt. GG r foreignD const double& sigm—. C++ Code 11. GG exer™iseD const double& r. return ƒ * exp( r f *time) * x(dI) ˆ * exp( r*time) * x(dP).5. S a SH. 11.h" GG de(ne the norm—l distri˜ution fun™tion double ™urren™y option pri™e ™—ll europe—n( const double& ƒ. GG ex™h—nge r—teD const double& ˆ. 1.           }.The Black formula for a put option on a futures contract is p a e r@T  tA @KN @ dP A   F N @ dI AA where the varibles are as dened for the call option.

double hI = 0.hI). The price for an european put for a currency option is p a Ke r@T  tA N @ dP A   Se rf @T  tA N @ dI A 1.6: Price for an american perpetual call option 1 ƒu™h options would ˜e like the ™l—ssi™—l epril fools presentD — perpetu—l zero ™oupon ˜ondF F F 110 . return pri™. C++ Code 11.5. double pri™=(u/(hI 1.time) << endl.u.08.C++ program: ™out << " european currency call option = " << ™urren™y option pri™e ™—ll europe—n(ƒ. and discuss the put in an exercise.2. Formula 11. double& double& double& double& double& ƒ. European perpetual options would probably be hard to sell. Implement this formula. Formula 11. Cp a where K hI   I S hI   I hI K s   h1 I r q hI a   P C P   r   q I P Pr   P C P P S is the current price of the underlying security.5). double r = 0. double sigm— = 0. r is the risk free interest rate. sigm—){ hI += sqrt(pow(((r q)/sigm— sqr 0. double rf =0.5 ((r q)/sigm— sqr).0)/hI)*(ƒ/u). it is ininitely lived.2)+2. double option pri™e —meri™—n perpetu—l ™—ll(const const const const const double sigm— sqr=pow(sigm—.5 gives the analytical solution. q. r. 11.sigm—. u. Of course.4. only American perpetual options make any sense.0*r/sigm— sqr).5: Price for a perpetual call option #include <™m—th> using namespace std. 1 For both puts and calls analytical formulas has been developed.0.2).05.r. q is the dividend yield and  is the volatility of the underlying asset.0. double time=0.     }.rf. double u = 52.0))*pow(((hI 1. We consider the price of an American call. europe—n ™urren™y ™—ll option a PFPPSST Exercise 11. K is the exercise price.5 Perpetual puts and calls A perpetal option is one with no maturity date. Output from C++ program: double ƒ = 50.

The original formulations of European foreign currency option prices are in Garman and Kohlhagen (1983) and Grabbe (1983). 393). ™out << " perpetual call price = " << pri™e << endl. This had some errors. The price of a perpetual put was rst shown in Merton (1973).5.r. For a perpetual call see McDonald and Siegel (1986).sigm—). r a H:HS.05. The notation for perpetual puts and calls follows the summary in (McDonald.05. double u=40. The price for a perpetual american put is Pp a where K hP   I S I   hP hP K  h2 I r q hP a   P P    s   r   q I P Pr   P C P P 1. pri™e = option pri™e —meri™—n perpetu—l ™—ll(ƒ.02. double q=0. that were partially corrected in Geske (1979).q. double double double double Output from C++ program: perpetu—l ™—ll pri™e a IWFRUTU Exercise 11. Implement the calculation of this formula. correct formula. r=0.6 Readings Hull (2006) and McDonald (2006) are general references. q a H:HP.Example Price a perpetual call. K a RH:H. See Hull (2006) for a textbook summary. sigm—=0. before Whaley (1981) gave a nal. given the following informtation C++ program: S a SH:H. A rst formulation of an analytical call price with dividends was in Roll (1977b). 2006.0. Black (1976) is the original development of the futures option.  a H:HS ƒ=50. 111 .0.u. pg. 11.

. . . . . . . .3. . . . . . . . . . . . . . . . . . . approximation to a continuous time distribution by judicious To do so one has to ask: Is it possible to nd a parametrization (choice 112 . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . 126 12. . . . . . . . . . . . . . . . . . . .2. . .3 Discrete dividends . . . . . . . . . . . . . .2. . . . . . . 114 12. . . . .Chapter 12 Option pricing with binomial approximations Contents 12. . . . . 112 113 12. . . . . . . . . . .2 Pricing of options in the Black Scholes setting . . . . . . .5 Pricing options on stocks paying dividends using a binomial approximation . . 119 123 124 12. . . . . . . . . . . . . . . . . . .5. . . 12. 12. . . . . . . . . . . . .4 Adjusting for payouts for the underlying . . . . . . .3 How good is the binomial approximation? . . . . . . . . . .1 Introduction We have shown binomial calculations given an up and down movement in chapter 8. .8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Checking for early exercise in the binomial model. . . 124 12. . . . . . . . . . . . . . . 116 12.2. . .6 Option on futures . . . . . . . . . binomial option pricing can also be viewed as an choice of the constants of u and d) of a binomial process u and d. . . .1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . .2 American Options . . . . . . . . . . . . . . . . . However. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Proportional dividends. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . .5. . . . . . . .3 Matlab implementation . . . . . . . . 120 12. . . . . . . . . . . . . . . . . . . . . .1 Estimating partials. . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 Foreign Currency options . . . . . . . . . . . .5. . . . . . . . 128 130 131 12. . . .1 European Options . . 114 12. . . . 124 12. . . . . . . . . . . . . . . .

Su   X A r rr j r Cd a m—x@H. t. 113 . To value an option using this approach. calculate the call price as a function of the For example. Sd   X A nd the call price at time 0 as CH a e r @qCu C @I   qACd A With more periods one will roll backwards as discussed in chapter 8 12. if there is one step. by imposing u a d . T T  t ¡t a n p¡t u a e p d a e  ¡t and the number of periods n. hence one uses one degree of freedom on imposing that the nodes I reconnect. and then calculate the option using a binomial tree with that number of steps. . calculate We also redene the risk neutral probabilities R a er¡t R d qa u d To nd the option price. r. ¨C rrH rr ¨ ¨¨ B ¨ ¨ ¨¨ Cu a m—x@H. X. Given n of periods to split the time to maturity S.2 Pricing of options in the Black Scholes setting Consider options on underlying securities not paying dividend. we specify the number @T   tA into.¨ ¨¨ ¨S rr rr ¨ ¨¨ ¨uS B ¨ ¨ rr rr ¨¨ B ¨ uuS ¨¨ ¨ r ¨ rr ¨¨ j r ¨dS rr rr r r rr j r B ¨ ¨ udS ¨¨ r r ddS j r which has the same time series properties as a (continous time) process with the same mean and volatility? There is actually any number of ways of constructing this. will roll backwards: At node two possible outcomes at time t C I.

allowing for the possibility of early exercise. GG ™—ll p—yo's —t m—turity for (int step=steps 1. step) { for (int i=0. unlike the European option. GG interest r—te const double& sigm—. which is the American case.0. It is also a useful way to make sure one understands binomial option pricing. ve™tor<double> ™—ll v—lues(steps+1). GG exer™i™e pri™e const double& r. the American price is the same as the European call. In general. (Try to write down the way you would solve it before looking at the algorithm below. but it is useful to see the construction of the binomial tree without the checks for early exercise. steps).2 American Options An American option diers from an European option by the exercise possibility. ++i) ™—ll v—lues[i] = m—x(0.0/‚. GG up movement double uu = u*u.2. C++ Code 12. An American option can be exercised at any time up to the maturity date. i<=steps. binomial trees are not that much used.) But by using the fact that the branches reconnect. for an American call option on non-dividend paying stock. and one may think one needs two.0/u. there is unfortunately no analytical solution to the American option problem. 114 . #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. (pri™es[i] u)). GG v—lue of ™orresponding ™—ll for (int i=0.1 European Options For European options. GG time to m—turity const int& steps){ GG no steps in ˜inomi—l tree double ‚ = exp(r*(t/steps)).2.2 illustrates the calculation of the price of an American call. ve™tor<double> pri™es(steps+1). GG vol—tility const double& t. i<=steps. }. that binomial approximations are useful. ++i) pri™es[i] = uu*pri™es[i 1]. GG (ll in the endnodesF          ™—ll v—lues[i] = (p up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv. GG inverse of interest r—te double u = exp(sigm—*sqrt(t/steps)). i<=step. You may want to check how this works.0 p up. GG interest r—te for e—™h step double ‚inv = 1. At each node we calculate the value of the option as a function of the next periods prices.1: Option price for binomial european 12. double d = 1. which can only be exercised at maturity. GG pri™e of underlying       for (int i=1. double p down = 1. but in some cases it can be found. }. and then check for the value exercising of exercising the option now C++ Code 12. since the Black Scholes model will give the correct answer. it is possible to get away with the algorithm below. The computer algorithm for a binomial in the following merits some comments. step>=0. using one less array. GG spot pri™e const double& u. return ™—ll v—lues[0]. GG st—nd—rd m—them—ti™—l li˜r—ry GG de(ning the m—x@A oper—tor GG ƒ„v ve™tor templ—tes double option pri™e ™—ll europe—n ˜inomi—l( const double& ƒ. double p up = (‚ d)/(u d). one at time t and another at time t C I. ++i) { pri™es[0] = ƒ*pow(d.12. For example. There is only one vector of call prices. It is in the case of American options. }.

pri™es[i] u).0. double d = 1. double& r. GG pri™e of underlying pri™es[0] = ƒ*pow(d. GG ™—ll p—yo's —t m—turity for (int step=steps 1. steps). }. double option pri™e ™—ll —meri™—n ˜inomi—l( const const const const const const double ‚ = exp(r*(t/steps)). }. i<=step.0/‚. the american price will equal the european. ++i) {     step) { ™—ll v—lues[i] = (p up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv. ++i) pri™es[i] = uu*pri™es[i 1]. ve™tor<double> ™—ll v—lues(steps+1).0 p up. double p up = (‚ d)/(u d). step>=0. double& t. i<=steps. pri™es[i] = d*pri™es[i+1]. C++ Code 12.0/u. double ‚inv = 1. for (int i=0. for this particular case. GG ™he™k for exer™ise ™—ll v—lues[i] = m—x(™—ll v—lues[i]. double p down = 1. int& steps) {       ve™tor<double> pri™es(steps+1).#include <™m—th> #include <ve™tor> using namespace std. ++i) ™—ll v—lues[i] = m—x(0. }. double& sigm—. (pri™es[i] u)). return ™—ll v—lues[0]. i<=steps. GG v—lue of ™orresponding ™—ll for (int i=0.2: Price of American call option using a binomial approximation Actually. for (int i=1. 115 . GG (ll in the endnodesF double uu = u*u. double u = exp(sigm—*sqrt(t/steps)). double& ƒ. double& u.

12.2. end ™—ll v—lues = max(0. p down = 1. w—tl—˜ and C++. function ™ = ˜in —m ™—ll( ƒ.steps) ‚ = exp(r*(t/steps)). u = exp(sigm—*sqrt(t/steps)).3 Matlab implementation To illustrate dierences between and w—tl—˜ Code 12.1 The calculation of a put is more compact.t. pri™es(1) = ƒ*(d^steps). r.0 p up.0.0/‚. consider the two implementations in w—tl—˜ Code 12. u. with less loops. for step=steps: 1:1 for i=1:step+1 ™—ll v—lues(i) = (p up*™—ll v—lues(i+1)+p down*™—ll v—lues(i))*‚inv. for i=2:steps pri™es(i) = uu*pri™es(i 1). ‚inv = 1. d = 1.2. pri™es(i) = d*pri™es(i+1). sigm—. w—tl—˜ Code 12. p up = (‚ d)/(u d). uu = u*u. end end       end ™= ™—ll v—lues(1). ™—ll v—lues(i) = max(™—ll v—lues(i). by some judicious use of array indexing.1: Price of American call using a binomial approximation 116 .pri™es(i) u).0/u. pri™es = zeros(steps+1). (pri™es u)).

end v—lues = max(0.0/u. p down = 1. ‚inv = 1.1). t.u pri™es). for step=steps: 1:1 v—lues = ‚inv * ( p up*v—lues(2:step+1) pri™es = u*pri™es(1:step). r. end p=v—lues(1). pri™es(1) = ƒ*(d^steps).function p = ˜in —m put( ƒ.0. pri™es = zeros(steps+1.0/‚. u = exp(sigm—*sqrt(t/steps)). end + p down*v—lues(1:step) ). sigm—. u. d = 1. uu = u*u. steps) ‚ = exp(r*(t/steps)). w—tl—˜ Code 12.0 p up. v—lues = max(v—lues. for i=2:steps+1 pri™es(i) = uu*pri™es(i 1).2: Price of American put using a binomial approximation 117 . p up = (‚ d)/(u d). (u pri™es)).

r.1. g = ˜in —m ™—ll(ƒ.0.sigm—.time. double u = 100. u=100.r.25. europe—n ™—lla IRFWSHS —meri™—n ™—lla IRFWSHS —meri™—n put a TFSRTWI w—tl—˜ program: ƒ=100.u.0.no steps) € = ˜in —m put(ƒ.1.no steps) Output from w—tl—˜ program: g a IRFWSI € a TFSRTW 118 .u. ™out << " american call= " << option pri™e ™—ll —meri™—n ˜inomi—l(ƒ.no steps) << endl. no steps=100.time. int no steps = 100. r=0.u. double r = 0. double sigm— = 0.time.time. Output from C++ program: double ƒ = 100. sigm—=0. C++ program: ™out << " european call= " << option pri™e ™—ll europe—n ˜inomi—l(ƒ.sigm—. time=1.sigm—. K a IHH.25.u.sigm—.r.time.u. Price American calls and puts using binomial approximations with 100 steps.0. double time=1.no steps) << endl.sigm—. r a H:I.Example You are given the following information about an option: S a IHH. ™out << " american put = " << option pri™e put —meri™—n ˜inomi—l(ƒ.r.no steps) << endl.  a H:PS and time to maturity is 1 year.r.

3 How good is the binomial approximation? To illustrate the behaviour of the binomial approximation gure 12. the number of steps in the binomial approximation. Note the sawtooth pattern.5 c 15 14.5 14 13. the binomial approximation jumps back and forth around the true value for small values of value as the n increases.5 0 10 20 30 40 binomial 50 n 60 Black Scholes 70 80 90 100 119 .12.5 16 15. and the true n.1: Illustrating convergence of binomial to Black Scholes 17 16. but rapidly moves towards the Black Scholes (Black Scholes) value of the option.1 plots a comparison with the binomial approximation as a function of n. Figure 12.

Let us start with Delta. pri™es[0] = ƒ*pow(d. ‚inv = 1. The binomial methods gives us ways to approximate these as well. for (int i=0.3 is for the nondividend case. no steps). d = 1. for (int i=1.1 Estimating partials. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv. v—lues[1] ™—ll v—lues[0])/(ƒ*u ƒ*d). the derivative of the option price with respect to the underlying. = (™—ll }. p…p = (‚ d)/(u d). sigm—. t. double option pri™e delt— —meri™—n ™—ll ˜inomi—l(const const const const const const double double double double double double double double& double& double& double& double& int& no ƒ. i<=gurrƒtep.0   p…p. ++i) pri™es[i] = uu*pri™es[i 1]. gurrƒtep>=1.0/‚.0/u. steps){ GG steps in ˜inomi—l ‚ = exp(r*(t/no steps)). uu= u*u. (pri™es[i] u)).12. ve™tor<double> pri™es (no steps+1). How to nd them in the binomial case are described in Hull (2006). i<=no steps. i<=no steps. #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. GG ™he™k for exer™ise ™—ll v—lues[i] = m—x(™—ll v—lues[i].0. = ve™tor<double> ™—ll v—lues (no steps+1).4 120 . u = exp(sigm—*sqrt(t/no steps)). r. }.3. }. phown = 1. The implementation in C++ Code 12. double delt— return delt—. It is always necessary to calculate the partial derivatives as well as the option price. ++i) {     gurrƒtep) { pri™es[i] = d*pri™es[i+1]. pri™es[i] u). for (int gurrƒtep=no steps 1 . C++ Code 12. u. for (int i=0. ++i) ™—ll v—lues[i] m—x(0.3: Calculation of all the derivatives are shown in Delta C++ Code 12.

no steps). GG p—rti—l wrt ƒ double& g—mm—.0 p…p. double delt— t =(time/no steps). GG p—rti—l wrt sigm— double& rho){ GG p—rti—l wrt r ve™tor<double> pri™es(no steps+1). ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv.   pri™es[0] = ƒ*pow(d. no steps). GG steps in ˜inomi—l double& delt—. tmp pri™es = option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. for (int i=0. double uu= u*u. double ‚ = exp(r*delt— t). double ‚inv = 1. i<=no steps. double fPH = ™—ll v—lues[0]. GG time to m—turity const int& no steps.sigm—.tmp r. double h = 0. delt— = (fII fIH)/(ƒ*u ƒ*d). i<=gurrƒtep. i<=no steps.u.5 * ƒ * ( uu   d*d). g—mm— = ( (fPP fPI)/(ƒ*(uu 1))   (fPI fPH)/(ƒ*(1 d*d)) ) / h.no steps).05. (pri™es[i] u)).   gurrƒtep) { for (int i=0. GG se™ond prt wrt ƒ double& thet—. ™—ll v—lues[i] = m—x(™—ll v—lues[i]. ƒ u). GG p—rti—l wrt time double& veg—.02.time.4: Hedge parameters 121 .i++) { pri™es[i] = d*pri™es[i+1].r. double phown = 1. pri™es[i] u). double tmp sigm— = sigm—+di' . ™—ll v—lues[0] = m—x(™—ll v—lues[0]. double di' = 0. rho = (tmp pri™es fHH)/di' . di' = 0.tmp sigm—. ve™tor<double> ™—ll v—lues(no steps+1). gurrƒtep>=2.time.0.     double fPP = ™—ll v—lues[2].h" void option pri™e p—rti—ls —meri™—n ™—ll ˜inomi—l(const double& ƒ. ++i) pri™es[i] = uu*pri™es[i 1].0/‚. GG spot pri™e const double& u. ™—ll v—lues[0]. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv. pri™es[i] u).#include <™m—th> #include <—lgorithm> #include "fin_recipes. for (int i=1. pri™es[0] = d*pri™es[1]. double tmp pri™es = option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. GG ™he™k for exer™ise }. }. double p…p = (‚ d)/(u d). double fII double fIH C++ Code 12. ++i) { pri™es[i] = d*pri™es[i+1]. GG vol—tility const double& time. = = }. }. GG interest r—te const double& sigm—.i<=1. GG ™he™k for exer™ise on (rst d—te double fHH = ™—ll v—lues[0].0/u. double fPI = ™—ll v—lues[1]. double u = exp(sigm—*sqrt(delt— t)). ™—ll v—lues[1]. for (int i=0. double tmp r = r+di' . for (int gurrƒtep=no steps 1. double d = 1.u. ™—ll v—lues[0] = (phown*™—ll v—lues[0]+p…p*™—ll v—lues[1])*‚inv. GG ixer™ise pri™eD const double& r. ++i) ™—ll v—lues[i] = m—x(0. GG ™he™k for exer™ise ™—ll v—lues[i] = m—x(™—ll v—lues[i]. thet— = (fPI fHH) / (2*delt— t). veg— = (tmp pri™es fHH)/di' .

thet—. time=1.Example Given the following information: S a IHH.25. Discuss sources of dierences in the estimated prices. thet—. 100 and 1000 steps in the approximation. 1. ™out << " Call price partials " << endl. delt—. ™out << " delta = " << delt— << endl. rho). option pri™e p—rti—ls —meri™—n ™—ll ˜inomi—l(ƒ. K a IHH. Calculate the price using a binomial approximation. 3. 100 steps in the binomial approximation. delt—. Use ¡). 122 . where @T   tA a I and r a H:I. r a H:I. using 10. ™out << " gamma = " << g—mm— << endl. sigm—. S a IHH. theta. time. Consider an American call option on non-dividend paying stock. double sigm— = 0.1.  a H:PS and time to maturity is 1 year. ™out << " rho = " << rho << endl. veg—. veg—. vega and rho. r = 0.0.1. 1. int no steps = 100. double u = 100.r. Estimate all the greeks for the option: delta( C++ program: ƒ = 100.u.  a H:P. g—mm—. no steps. g—mm—. ™out << " vega = " << veg— << endl. rho. gamma. ™out << " theta = " << thet— << endl.0. K a IHH.0. double double double double Output from C++ program: g—ll pri™e p—rti—ls delt— a HFTWWUWP g—mm— a HFHIRHRHU thet— a EWFVWHTU veg— a QRFVSQT rho a STFWTSP Exercise 12. Calculate the price of this option using Black Scholes 2.

}. GG spot pri™e const double& u. i<=steps. ++i) ™—ll v—lues[i] = m—x(0. GG ™he™k for exer™ise }. GG ™—ll p—yo's —t m—turity   for (int step=steps 1. step>=0. GG pri™e of underlying         for (int i=1. double d = 1.5: Binomial option price with continous payout 123 . i<=steps. (pri™es[i] u)). double p down = 1. GG ™ontinous p—yout const double& sigm—. GG time to m—turity const int& steps) { GG no steps in ˜inomi—l tree double ‚ = exp(r*(t/steps)). return ™—ll v—lues[0]. GG up movement double uu = u*u.0/‚. C++ Code 12. GG exer™i™e pri™e const double& r. GG inverse of interest r—te double u = exp(sigm—*sqrt(t/steps)).12. ++i) pri™es[i] = uu*pri™es[i 1]. #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std.0/u. GG interest r—te for e—™h step double ‚inv = 1. ™—ll v—lues[i] = m—x(™—ll v—lues[i]. GG st—nd—rd m—them—ti™—l li˜r—ry GG de(nes the m—x@A oper—tor GG ƒ„v ve™tor templ—tes double option pri™e ™—ll —meri™—n ˜inomi—l( const double& ƒ. pri™es[i] = d*pri™es[i+1]. ++i) {     step) { ™—ll v—lues[i] = (p up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv. a continous payout of y. pri™es[0] = ƒ*pow(d. }. GG (ll in the endnodesF ve™tor<double> ™—ll v—lues(steps+1). GG interest r—te const double& y. GG vol—tility const double& t.4 Adjusting for payouts for the underlying The simplest case of a payout is the similar one to the one we saw in the Black Scholes case.0.pri™es[i] u). double p up = (exp((r y)*(t/steps)) d)/(u d).0 p up. GG v—lue of ™orresponding ™—ll for (int i=0. ve™tor<double> pri™es(steps+1). i<=step. for (int i=0. steps).

the adjustment for dividends depend on whether the dividends are discrete or proportional.1 Checking for early exercise in the binomial model. If the underlying asset is a stock paying dividends during the maturity of the option.12.2 Proportional dividends. we simply multiply with an adjustment factor the stock prices at the ex dividend date. 12.5.5.5 Pricing options on stocks paying dividends using a binomial approximation 12. and we can use the same rolling back procedure. which means that the option value will reect the dividend payments. For proportional dividends. In the binomial model. the terms of the option is not adjusted to reect this cash payment. the nodes in the binomial tree will link up again. 124 .

C++ Code 12.u. GG ™he™k for exer™ise }. ve™tor<int> dividend steps(no dividends). i<=no steps. ++i) { ™—ll pri™es[i] = (phown*™—ll pri™es[i]+p…p*™—ll pri™es[i+1])*‚inv.++j) {      pri™es[j]*=(1. d = 1.++i) { GG ™he™k whether dividend p—id if (step==dividend steps[i]) { for (int j=0. i<=no steps. const double& sigm—. const double& time. }.0/(1.h" <iostre—m> double option pri™e ™—ll —meri™—n proportion—l dividends ˜inomi—l(const double& ƒ. ++i) { pri™es[0]*=(1. phown = 1. if (no dividends == 0) { return option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. ++i) ™—ll pri™es[i] = m—x(0. }. ve™tor<double> pri™es(no steps+1).0 dividend yields[i])). ve™tor<double> ™—ll pri™es(no steps+1). step) { for (int i=0.time. }.j<=(step+1). { delt— t = time/no steps. const double& r.0/u.0. pri™es[i] u). i<no dividends. }.no steps). ™—ll pri™es[i] = m—x(™—ll pri™es[i]. for (int i=0. const ve™tor<double>& dividend times. }. const double& u. }. }. const ve™tor<double>& dividend yields) GG note th—t the l—st dividend d—te should ˜e ˜efore the expiry d—teD pro˜lems if dividend —t termin—l node int no dividends=dividend times.size(). i<=step. double double double double double double double double }. pri™es[i] = d*pri™es[i+1]. for (int i=1. uu= u*u.6: Binomial option price of stock option where stock pays proportional dividends 125 .0   p…p. no steps). step>=0.0 dividend yields[i]).i<no dividends. ‚ = exp(r*delt— t). GG when dividends —re p—id for (int i=0.0/‚. pri™es[0] = ƒ*pow(d. ‚inv = 1. ++i) { dividend steps[i] = (int)(dividend times[i]/time*no steps). GG pri™e wGo dividends }. for (int step=no steps 1. for (int i=0.#include #include #include #include #include <™m—th> <—lgorithm> <ve™tor> "fin_recipes. ++i) { pri™es[i] = uu*pri™es[i 1]. return ™—ll pri™es[0]. i<no dividends. const int& no steps. p…p = (‚ d)/(u d).r. (pri™es[i] u)). GG —djust downw—rd termin—l pri™es ˜y dividends for (int i=0. u = exp(sigm—*sqrt(delt— t)).sigm—.

It is a instructive example of using recursion in simplifying calculations. it has a cost in computing time. and then. In that case the nodes of the binomial tree do not link up. with no linkup. but as with most recursive solutions.5.7 implements this case.3 Discrete dividends The problem is when the dividends are constant dollar amounts. The algorithm presented in C++ Code 12. and time to maturity the time remaining at the ex-dividend date. and the number of branches increases dramatically. which means that the time to do the calculation is increased.12. call itself with one less dividend payment. which is then compared to the value of exercising just before the ex-dividend date. at the terminal nodes of that tree. 126 . by constructing a bi- nomial tree up to the ex-dividend date. For large binomial trees and several dividends this procedure is costly in computing time. Doing that calculates the value of the option at the ex-dividend date.

i<=steps ˜efore dividend. pri™es[i] u). const double& sigm—.r. ve™tor<double> tmp dividend times(no dividends 1).u.   step) { pri™es[i] = d*pri™es[i+1]. const double d = 1. ++i) pri™es[i] = u*u*pri™es[i 1]. t dividend times[0]. const double& r.7: Binomial option price of stock option where stock pays discrete dividends 127 . const double& u. }.i<(no dividends 1). const double phown = 1. const int& steps. tmp dividend times[i] = dividend times[i+1]   dividend times[0]. }.u. ++i){ double v—lue —live = option pri™e ™—ll —meri™—n dis™rete dividends ˜inomi—l(pri™es[i] dividend —mount. i<=step.(pri™es[i] u)). const ve™tor<double>& dividend times.++i){ tmp dividend —mounts[i] = dividend —mounts[i+1].GG just do regul—r int steps ˜efore dividend = (int)(dividend times[0]/t*steps). steps ˜efore dividend). ™—ll v—lues[i] = m—x(v—lue —live. const double ‚inv = 1. step>=0. r.#include <™m—th> #include <ve™tor> #include "fin_recipes. const double p…p = (‚ d)/(u d). return ™—ll v—lues[0]. const double u = exp(sigm—*sqrt(t/steps)). tmp dividend —mounts). ™—ll v—lues[i] = m—x(™—ll v—lues[i]. double dividend —mount = dividend —mounts[0]. GG tempor—ries with ve™tor<double> tmp dividend —mounts(no dividends 1).h" #include <iostre—m> double option pri™e ™—ll —meri™—n dis™rete dividends ˜inomi—l(const double& ƒ.0/‚.t. for (int i=1. const double& t.GG time —fter (rst dividend steps steps ˜efore dividend.size(). for (int step=steps ˜efore dividend for (int i=0.sigm—. for (int i=0. pri™es[0] = ƒ*pow(d. }. C++ Code 12. i<=steps ˜efore dividend.steps).0/u. const double ‚ = exp(r*(t/steps)). tmp dividend times. ve™tor<double> ™—ll v—lues(steps ˜efore dividend+1). if (no dividends==0) return option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. ve™tor<double> pri™es(steps ˜efore dividend+1). }. GG ™omp—re to exer™ising now }. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv. sigm—. ++i) {  1. const ve™tor<double>& dividend —mounts) { int no dividends = dividend times.0   p…p. GG one less dividend for (int i=0.

25.025). no steps=100.025).push ˜—™k(0. ve™tor<double> dividend yields.time.push ˜—™k(2. r a H:HV. K a RS:H. dividend —mounts. ™out << " call price with continuous dividend payout = " << option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. double double double int no double Output from C++ program: ™—ll pri™e with ™ontinuous dividend p—yout a IQFSWPT ™—ll pri™e with proporti—l dividend yields —t dis™rete d—tes a IIFVTHR ™—ll pri™e with proporti—l dividend —mounts —t dis™rete d—tes a IPFHPQQ 12.08.sigm—. ™out << " call price with proportial dividend yields at discrete dates = " << option pri™e ™—ll —meri™—n proportion—l dividends ˜inomi—l(ƒ.no steps) << endl.5. dividend —mounts.no steps. Price the futures option C++ program: double double double int no p = 50.u. steps=100. dividend yields) << endl. ve™tor<double> dividend times. r = 0. dividend yields. time=0. dividend times.push ˜—™k(0.02.u.r. double u = 100. d a H:HPS at times H:PS and H:US.push ˜—™k(2.0.r.time. Output from C++ program: europe—n futures ™—ll option a SFURPSR 128 .r. because of the feasibility of early exercise. time=1. dividend yields. Discrete payout. K a IHH. double u = 45.75).5).u. dividend —mounts) << endl. r = 0.time.sigm—.25).sigm—. double sigm— = 0. C++ program: d a H:HP. dividend times.2.10.Example Given the following information S a IHH. r a H:I.5).0. the binomial model is used to approximate the option value for both puts and calls.push ˜—™k(0. dividend times. Example F a SH:H.d.u.push ˜—™k(0.sigm—. sigma a H:P.5. steps = 100.no steps.6 Option on futures For American options. ve™tor<double> dividend —mounts. Continuous payout 2.no steps) << endl.time.0. time=0. ƒ = 100.r.  a H:PS and time to maturity is 1 year. dividend times. double sigm— = 0. Calculate option price with two dierent assumptions about dividends: 1. ™out << " call price with proportial dividend amounts at discrete dates = " << option pri™e ™—ll —meri™—n dis™rete dividends ˜inomi—l(ƒ. d=0.0. ™out << " european futures call option = " << futures option pri™e ™—ll —meri™—n ˜inomi—l(p.0.

GG time to m—turity const int& no steps) { GG num˜er of steps ve™tor<double> futures pri™es(no steps+1). futures pri™es[i] u).#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std.   step) { for (i=0.     return ™—ll v—lues[0]. GG vol—tility const double& time. double ‚inv = exp( r*(t delt—)). double uu= u*u. ++i) { futures pri™es[i] = d*futures pri™es[i+1]. (futures pri™es[i] u)). double p…p = (1 d)/(u d). i<=no steps.0 p…p. for (i=1. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv. GG termin—l tree nodes for (i=0. double d = 1. i<=no steps. double futures option pri™e ™—ll —meri™—n ˜inomi—l(const double& p. GG interest r—te const double& sigm—. GG ™he™k for exer™ise }. GG exer™ise pri™e const double& r. double u = exp(sigm—*sqrt(t delt—)). ++i) ™—ll v—lues[i] = m—x(0. step>=0. GG pri™e futures ™ontr—™t const double& u. }.8: Pricing an american call on an option on futures using a binomial approximation 129 . C++ Code 12. int i. GG note how pro˜—˜ility is ™—l™ul—ted double phown = 1.0/u. ve™tor<double> ™—ll v—lues (no steps+1). double t delt—= time/no steps. ™—ll v—lues[i] = m—x(™—ll v—lues[i]. for (int step=no steps 1. }.     futures pri™es[0] = p*pow(d.0. no steps). ++i) futures pri™es[i] = uu*futures pri™es[i 1]. i<=step.

™out << " european currency option call = " << ™urren™y option pri™e ™—ll —meri™—n ˜inomi—l(ƒ.0/u. const double& time. for (int step=no steps for (i=0. rf a H:HS.0.0. double uu= u*u. for (i=1.08. double t delt—= time/no steps. i<=step. double u = exp(sigm—*sqrt(t delt—)). r = 0. const int& no steps) { ve™tor<double> ex™h—nge r—tes(no steps+1).time.r. double double double int no ƒ = 50.sigm—. i<=no steps. number of steps = 100. }. ex™h—nge r—tes[i] u). double rf =0. C++ Code 12.9: Example Pricing an american call on an option on currency using a binomial approximation Price a futures currency option with the following information: time=0.0.   step) { ++i) m—x(0. no steps). double ‚inv = exp( r*(t delt—)).no steps) << endl. return ™—ll v—lues[0].   int i. }. double d = 1. checking for early exercise due to the interest rate dierential.u. }. ++i) { ex™h—nge r—tes[i] = d*ex™h—nge r—tes[i+1].5.7 Foreign Currency options For American options. ve™tor<double> ™—ll v—lues(no steps+1). the usual method is approximation using binomial trees. const double& r.0 p…p. C++ program: S a SH. steps = 100. ex™h—nge r—tes[0]         = ƒ*pow(d. double p…p = (exp((r r f )*t delt—) d)/(u d). ™—ll v—lues[i] = m—x(™—ll v—lues[i].12.rf. const double& u. double u = 52.05. r a H:HV. GG termin—l tree nodes ™—ll v—lues[i] = } for (i=0. Output from C++ program: europe—n ™urren™y option ™—ll a PFPQIPW 130 . #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv.2. K a SP. GG —djust for foreign intFr—te double phown = 1. GG ™he™k for exer™ise  1. (ex™h—nge r—tes[i] u)). const double& sigm—. const double& r f.5. i<=no steps. step>=0. sigm— = 0. double time=0. ++i) { ex™h—nge r—tes[i] = uu*ex™h—nge r—tes[i 1]. double ™urren™y option pri™e ™—ll —meri™—n ˜inomi—l(const double& ƒ.  a H:P.

8 References The original source for binomial option pricing was the paper by Cox et al. Textbook discussions are in Cox and Rubinstein (1985).12. (1979). 131 . Bossaerts and Ødegaard (2001) and Hull (2006).

. . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Finite Dierences . . . . . . . . . . . . . A problem with the explicit version is that it may not converge for certain combinations 132 . . . . . . . . . . . . . . . . . . . . . 13. . .1 Explicit Finite dierences The method of choice for any engineer given a dierential equation to solve is to numerically approximate it using a nite dierence scheme. . . . . . . . . . . 13.Chapter 13 Finite Dierences Contents 13. . . . . . . . . . . . 13. . . . . . . . . . . . . 13. . .8 European Options . . We show the case of an explicit nite dierence scheme in C++ Code 13. .2 European Options. . . . . . . .9 References . . . . . . . . 13. . . . of inputs. . . . . . . . . . . . . . . . . . . . . . . . . but we show how one would nd the european price for comparison purposes. . . . . . . . . For European options we do not need to use the nite dierence scheme. . . . . . . . . . . . . 13. . . . . . . . 13. . . . . . . . and solve this dierence equation. . . . . . . which is to approximate the continous dierential equation with a discrete dierence equation. . . . . . . . . . . . . .5 An example matrix class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 European Options. . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . 13. . . . . 132 132 134 137 137 137 137 140 141 13. . . . . . . . . . . . . . . . . 13. . . . . . . . . .3 American Options. . . . . . . . . . . . . . . . . . .4 Implicit nite dierences . . . . . . . . . . . . . . . . . . . . .7 American Options .1 Explicit Finite dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

double rP=delt— t/(1.j<w.m<=w. }. } GG need no ƒ steps to ˜e evenX double delt— ƒ = 2.0. ve™tor<double> ˜(w).++m) }.m<=w. }. const double& time. for (unsigned m=0. int w=no ƒ steps. for (unsigned m=0.2). { f next[m] = f [m]. for (unsigned m=1. ve™tor<double> f next(w+1).m++) { ƒ v—lues[m] = m*delt— ƒ.1: Explicit nite dierences calculation of european put option 133 . C++ Code 13.5*j*(r+sigm— sqr*j).m<w. if ((no ƒ steps%2)==1) { ++w.0 sigm— sqr*j*j*delt— t). for (int t=x 1.#include <™m—th> #include <ve™tor> using namespace std. }. }. ™[j] = rP*0.ˆ ƒ v—lues[m]). int x=no t steps. for (unsigned int j=1.0*ƒ/w.0/(1. const int& no t steps) { double sigm— sqr = pow(sigm—. ˜[j] = rI*(1.0+r*delt— t). ve™tor<double> ™(w). f [w] = 0. }. for (unsigned m=0.  t) { f [0]=ˆ.t>=0.j++){ —[j] = rP*0.m<=w.++m) { f next[m]=m—x(0. const double& sigm—. double option pri™e put europe—n (nite di' expli™it(const double& ƒ. ve™tor<double> —(w). }. double rI=1. const double& r.0+r*delt— t). double f [w+1]. double delt— t = time/x. const double& ˆ. return f [w/2]. const int& no ƒ steps. ve™tor<double> ƒ v—lues(w+1).5*j*( r+sigm— sqr*j).++m) { f [m]=—[m]*f next[m 1]+˜[m]*f next[m]+™[m]*f next[m+1].

#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. ve™tor<double> ™(w).j++){ —[j] = rP*0. const double& r. ve™tor<double> ˜(w).0*ƒ/w.0+r*delt— t).u ƒ v—lues[m]). const int& no t steps) double sigm— sqr = sigm—*sigm—. f [w] = 0.++m) }. for (int j=1.m<=w. ve™tor<double> f (w+1). We now compare the American versions of the same algoritms. }. GG ™he™k for exer™ise }.m++) { ƒ v—lues[m] = m*delt— ƒ. for (int m=1. ˜[j] = rI*(1. ™[j] = rP*0. f [m] = m—x(f [m].0. return f [w/2]. shows the same C++ Code 13. ve™tor<double> f next(w+1).2: Explicit nite dierences calculation of american put option 134 . { f next[m] = f [m]. double rI=1. int w=no ƒ steps+(no ƒ steps%2). double rP=delt— t/(1. ve™tor<double> ƒ v—lues(w+1). C++ Code 13. const double& sigm—. GG need no ƒ steps to ˜e evenX double delt— ƒ = 2.++m) { f next[m]=m—x(0. double delt— t = time/x. { ve™tor<double> —(w).j<w. const double& time.m<=w.5*j*(r+sigm— sqr*j). }. }.t>=0.13.5*j*( r+sigm— sqr*j). for (int t=x 1.u ƒ v—lues[m]).  t) { f [0]=u.0/(1. for (int m=0.m<w. double option pri™e put —meri™—n (nite di' expli™it( const double& ƒ. }. const int& no ƒ steps.3 American Options.0+r*delt— t). for (int m=0.1 implemented in w—tl—˜. for (int m=0. the only dierence being the check for exercise at each point. }.2 shows the C++ code for an american put option and w—tl—˜ Code 13.++m) { f [m]=—[m]*f next[m 1]+˜[m]*f next[m]+™[m]*f next[m+1]. int x=no t steps.m<=w. const double& u.0 sigm— sqr*j*j*delt— t).

r. for j=1:w 1 —(j) = rP*0. ™=zeros(w 1. for t=x 1: 1:0 f = [ u. w—tl—˜ Code 13. delt— t = time/x.function € = (ndi' exp —m put(ƒ. endfor f next = max(0.*f next(3:w+1).1).no t steps) sigm— sqr = sigm—^2. rP=delt— t/(1+r*delt— t). x=no t steps.sigm—. rI=1/(1+r*delt— t). # need no ƒ steps to ˜e even: delt— ƒ = 2*ƒ/w.*f next(2:w)+™.2). ˜(j) = rI*(1.1: Explicit nite dierences calculation of American put option 135 .u ƒ v—lues).5*j*(r+sigm— sqr*j). endfun™tion 0].1). —=zeros(w 1. f next=f . endfor €=f (1+w/2).u.time.1). —. ƒ v—lues = delt— ƒ * (0:w)'.5*j*( r+sigm— sqr*j). ™(j) = rP*0.u ƒ v—lues). f = max(f.0 sigm— sqr*j*j*delt— t). ˜=zeros(w 1. w=no ƒ steps + rem(no ƒ steps.*f next(1:w 1)+˜.no ƒ steps.

sigm—. double double double double double int no int no Output from C++ program: expli™it finite differen™esD europe—n put pri™e a RFHQTTU expli™it finite differen™esD —meri™—n put pri™e a RFPSHVS Readings Brennan and Schwartz (1978) is one of the rst nance applications of nite dierences.u.4167.time.no t steps) << endl. C++ program: S dimension and ƒ = 50.no ƒ steps. european put price = ".7 of Hull (1993) has a short introduction to nite dierences.0. and Howison (1994) is an exhaustive source on option pricing from the perspective of solving partial dierential equations.r. ™out << option pri™e put europe—n (nite di' expli™it(ƒ.sigm—.time. ™out << " explicit finite differences. r = 0. time=0.4167.Example Given the following parameters: S a SH. 136 .no t steps) << endl.4.u. K a SH. Section 14.0. r a IH7 and  a H:R.r. american put price = ". ™out << option pri™e put —meri™—n (nite di' expli™it(ƒ. ™out << " explicit finite differences. u = 50. t steps=11.1. Wilmott.no ƒ steps. The time to maturity is 0. sigm— = 0. Dewynne. Price European and American put option prices using nite dierences with 20 steps in the 11 steps in the time dimenstion. ƒ steps=20.

u ƒ v—lues). endfor €= p(w/2). and solve this dierence equation.3 using the xewm—t library and C++ Code 13. which is to approximate the continous dierential equation with a discrete dierence equation.j) = 1.5*j*delt— t*(r sigm— sqr*j). 13. However. for j=2:w e(j.sigm—. A library is a collection of classes and routines for one particular purpose. p = inv(e)*f.w+1)=1.5 An example matrix class Use xewm—t as an example matrix class. It is just as well to use somebody else's class.7 American Options Let us rst look at how this pricing is implemented in tion.time. In the following we implement implicit nite dierences. endfun™tion w—tl—˜ Code 13.w+1). 13. one should not necessarily always go ahead and create such classes from scratch. ƒ v—lues = delt— ƒ* (1:w+1)'. we postponed the implicit case to now because it is much simplied by a matrix library.13. 13. delt— t = time/x.j 1) = 0.5*j*delt— t*( r sigm— sqr*j).u ƒ v—lues).0*ƒ/dou˜le(w). p = inv(e)*f. w=no ƒ steps + rem(no ƒ steps. w—tl—˜ Code 13.no t steps) sigm— sqr = sigm—^2. Implementation of the same calculation in using IT++. as long as it is correct and well documented and fullls a particular purpose. e(j. for t=x 1: 1:1 f = p.2: Calculation of price of American put using implicit nite dierences 137 . f = max(0.1)=1. p=max(p. x=no t steps.4 Implicit nite dierences What really distinguishes C++ from standard g is the ability to extend the language by creating classes and collecting these classes into libraries.no ƒ steps.2).r.j+1) = 0.0 + delt— t*(r+sigm— sqr*j*j). w—tl—˜. We have already seen this idea when creating the d—te and term•stru™ture classes.u. The method of choice for any engineer given a dierential equation to solve is to numerically approximate it using a nite dierence scheme.0. endfor e(w+1.2 shows the implementaC++ Code 13. Explicit nite dierences was discussed earlier. e(1. e(j. e = zeros(w+1. # need no ƒ steps to ˜e even: delt— ƒ = 2.4 function € = (ndi' imp —m put(ƒ.6 Finite Dierences We use the case of implicit nite dierence calculations to illustrate matrix calculations in action.0.

e.0. { GG int wano ƒ stepsY if @@no ƒ steps7PAaaIA { CCwY }Y GG need no ƒ steps to ˜e evenX = m*delt— ƒ.++m) { GG now ™he™k for exer™ise p.++m){ f.i()*f. double ƒ v—lues[w+1]. u ƒ v—lues[m]). const int& no ƒ steps.0) = 1.  t) { f = p. GG need no ƒ steps to ˜e evenX double delt— ƒ = 2. for(int t=x 1.3: matrix library Calculation of price of American put using implicit nite dierences with the xewm—t 138 . GG ™‘j“Y }. for (int m=0.element(m) = m—x(0.0. for (int m=1.h" GG de(nitions for newm—t m—trix li˜r—ry using namespace xi‡we„. double delt— t = time/x. }.5*j*delt— t*( r sigm— sqr*j). const int& no t steps) double sigm— sqr = sigm—*sigm—.m++) { ƒ v—lues[m] int x=no t steps.5*j*delt— t*(r sigm— sqr*j).j) = 1. for (int j=1.0*ƒ/double(w).m<=w.element(w/2). e.element(m) = m—x(p.0 + delt— t*(r+sigm— sqr*j*j). #include <ve™tor> #include <—lgorithm> using namespace std.++j) { e. golumn†e™tor f(w+1). }. }.element(j. p = e.w)=1.m<w. f—ndw—trix e(w+1. return p.j+1) = 0.element(j. GG ˜‘j“Y e.j 1) = 0.element(j.u ƒ v—lues[m]). e=0. }.j<w.0.element(m). const double& sigm—.element(0.1. const double& u.t>0. golumn†e™tor p=e.#include <™m—th> #include "newmat. C++ Code 13. int w=no ƒ steps + (no ƒ steps%2). const double& r.1). for (int m=0.0. const double& time.m<=w.element(w.i()*f. double option pri™e put —meri™—n (nite di' impli™it(const double& ƒ. }. GG —‘j“ e.

m++) { ƒ v—lues[m] int x=no t steps. double delt— t = time/x. { = m*delt— ƒ.m<=w. const double& sigm—. }.5*j*delt— t*( r sigm— sqr*j). p = snve*f.t>0.  t) { f = p.j) = 1.j<w. const double& u. for (int m=0. for (int m=1.h> using namespace itpp. double option pri™e put —meri™—n (nite di' impli™it itpp(const double& ƒ.4: library Calculation of price of American put using implicit nite dierences with the IT++ matrix 139 .0. return p(w/2).++m){ f(m) = m—x(0. for (int j=1. for(int t=x 1.j+1) = 0. for (int m=0.0. m—t e = zeros(w+1. u ƒ v—lues[m]).m<=w.++j) { e(j. int w=no ƒ steps + (no ƒ steps%2).0. const int& no ƒ steps. C++ Code 13. GG ˜‘j“Y e(j. m—t snve = inv(e).0 + delt— t*(r+sigm— sqr*j*j). #include <itpp/it˜—se.0*ƒ/double(w).++m) { GG now ™he™k for exer™ise p(m) = m—x(p(m). e(0. ve™ f(w+1). ve™ p=snve*f. double ƒ v—lues[w+1]. }.w+1).u ƒ v—lues[m]). }. e(w. }. GG need no ƒ steps to ˜e evenX double delt— ƒ = 2. }.w)=1.j 1) = 0.#include <™m—th> GG#in™lude <ve™tor> GG#in™lude <—lgorithm> using namespace std.5*j*delt— t*(r sigm— sqr*j). GG ™‘j“Y }. const int& no t steps) double sigm— sqr = sigm—*sigm—.0) = 1. const double& time. const double& r.m<w. GG —‘j“ e(j.

i()*f.0*ƒ/w. }. { GG int wano ƒ stepsY if @@no ƒ steps7PAaaIA { CCwY }Y GG need no ƒ steps to ˜e evenX = m*delt— ƒ. GG need no ƒ steps to ˜e evenX double delt— ƒ = 2.0 + delt— t*(r+sigm— sqr*j*j). double option pri™e put europe—n (nite di' impli™it(const double& ƒ.t>0. const int& no t steps) double sigm— sqr = sigm—*sigm—. = m—x(0.5*j*delt— t*( r sigm— sqr*j).m<=w.0. e=0. but for comparison purposes C++ Code 13. f—ndw—trix e(w+1. int w=no ƒ steps + (no ƒ steps%2). const double& r.0.h" GG de(nitions for newm—t m—trix li˜r—ry using namespace xi‡we„.0. for(int t=x 1.element(0. const int& no ƒ steps.m++) { ƒ v—lues[m] int x=no t steps.0) = 1. const double& sigm—. return p. }.j+1) = 0.5 show how one would nd the European price.j 1) = 0. for (int m=0.1).5: Calculation of price of European put using implicit nite dierences 140 . const double& u.13.i()*f. C++ Code 13.element(w/2).u ƒ v—lues[m]). double delt— t = time/x.element(m) golumn†e™tor p=e. GG —‘j“ e. const double& time.0.element(j. e. p = e.++m){ f. }.5*j*delt— t*(r sigm— sqr*j). GG ™‘j“Y }. golumn†e™tor f(w+1).  t) { f = p. for (int j=1.++j) { e. #include <™m—th> #include "newmat. ve™tor<double> ƒ v—lues(w+1).element(j. }.w)=1.1.element(j. for (int m=0.j) = 1. GG ˜‘j“Y e. #include <ve™tor> GG st—nd—rd ƒ„v ve™tor templ—te #include <—lgorithm> using namespace std.m<=w.8 European Options For European options we do not need to use the nite dierence scheme.element(w. e.j<w.

5. Are there alternative. no S steps=200.no ƒ steps.sigm—. double sigm— = 0.time)<< endl. K a SH.no ƒ steps. option pri™e put europe—n (nite di' impli™it(ƒ.4.1. double u = 50.r. int no ƒ steps=200. no t steps=200. 141 .0. double r = 0. The xewm—t library is only one of a large number of available matrix libraries.0.u.5.4. 13. int no t steps=200. See the natbib documentation. Price European put options using both Black Scholes and implicit nite dierences. " implicit American put price = ".no t steps) Output from w—tl—˜ program: € a RFTHHT Exercise 13. Output from C++ program: ˜l—™k s™holes put pri™e a RFQSITT impli™it iuro put pri™e a RFQRUQI impli™it emeri™—n put pri™e a RFTHHTR w—tl—˜ program: ƒ = 50.r. C++ program: ™out ™out ™out ™out ™out double ƒ = 50. u = 50.time. time=0.0.9 References Hull (2006). both public domain and commercial oerings.Exercise 13. The routines above uses direct multiplication with the inverse of stable ways of doing it? A.0. option pri™e put —meri™—n (nite di' impli™it(ƒ.time. Price the American put option using implicit nite dierences.2.no t steps) << endl. 1.5.1.sigm—. no ƒ steps=200.u. 2.u.u. r = 0.sigm—. numerically more Example Given the parameters S a SH.no ƒ steps. " implicit Euro put price = ". €= (ndi' imp —m put(ƒ. Look into alternative libraries and replace What needs changing in the option price formulas? xewm—t with one of these alternative libraries.no t steps) << endl.time. double time=0.r. r a H:I. no t steps=200.  a H:R. << << << << << " black scholes put price = " << option pri™e put ˜l—™k s™holes(ƒ. sigm— = 0. time=0.sigm—.r.1.

.5. where the rate of convergence will depend on how many simulations we perform. . . . . . .Chapter 14 Option pricing by simulation Contents 14. . . . . .1 Control variates. .7 References . . . . . . . and let us rst consider the case of the usual European Call. . .4 More general payos. 151 152 We now consider using Monte Carlo methods to estimate the price of an European option. . . . . . . . . . . . . . . . ST   X A At an earlier date t. . . . . . . . . which implies that we can treat the (suitably transformed) problem as the decision of a risk neutral decision maker. . . . if we also modify the expected return of the underlying asset such that this earns the risk free rate. 14. . . . . . a call option is worth cT a m—x@H. . .2 Antithetic variates. . . . . . 14. . . . . Function prototypes . . . . . . . . . . . . . . . . . . . . . . . . .1 Simulating lognormally distributed random variables . . . . . . .3 Hedge parameters . . . . . . . . . . but we use the case of the standard call for illustrative purposes. . . . . . ST   X A“ Now. . . 14. . . . . . . . . . . . it is not really necessary to use simulations. ST   X A“. . . By appealing to a law of large numbers. . . 143 143 144 146 147 14. . . . . .5 Improving the eciency in simulation . . . . ct a E ‘P V @m—x@H. . the option value will be the expected present value of this. . . . . . . . . . . . . . . . . . .6 More exotic options . . . . .2 Pricing of European Call options . . . . . . . . . E £ ‘¡“ is a transformation of the original expectation. . . 14. . . . . . . . . . . . 147 14. . . . . . . . 14. . . . . . . . . . 148 14. . . . . . . . . . . . . . . . which can priced by the Black Scholes equation. . . . . an important simplifying feature of option pricing is the risk neutral result. . . . . . . . . . . . . . . . . . . . . . . . . . . . . At maturity. . . . . . One way to estimate the value of the call is to simulate a large number of sample values of ST according to the assumed price process. . . . . . ct a e r@T  tA E £ ‘m—x@H. . .5. . . . . . . . this average will converge to the actual call value. . . . . . . . . . . . . . . . . . . . and nd the where estimated call price as the average of the simulated values. . 142 . . . . . . . . . . . . . . . Since there is already a closed form solution for this case. . . . . . . . . . . .

m—x @H.h" double simul—te lognorm—l r—ndom v—ri—˜le(const double& ƒ. with a time between t and T @T   tA. which gives us a set of observations of the terminal price ST. GG interest r—te const double& sigm—.1: Simulating a lognormally distributed random variable 14. If we let of option payos at maturity. ST. : : : ST.P .I . If x be normally distributed with mean zero and variance ~ St follows a lognormal distribution.2) )*time. then the one-period-later price StCI is simulated as t and terminal date is T . we will estimate E £ ‘m—x@H.14. if the current time is of p ~ 1 2 ST a St e@r  2  A@T  tAC T  tx Simulation of lognormal random variables is illustrated by C++ Code 14. ST .5 * pow(sigm—. the price of the We proceed by simulating lognormally distributed random variables. Price put and call option using Black Scholes and simulation.Q . double ƒh = sigm— * sqrt(time). ST.i   X A 3 C++ Code 14. Use 5000 simulations. K a IHH.1. ST   X A“. 143 . return ƒ * exp(‚ + ƒh * r—ndom norm—l()). S a IHH. #include "normdist.2 Example Given shows the implementation of a Monte Carlo estimation of an European call option.  a H:PS. discounted at the risk free rate.   }. underlying at any time between t and T is not relevant for pricing. time=1. Let one. GG ™urrent v—lue of v—ri—˜le const double& r. 1 2 ~ StCI a St e@r  2  ACx . or more generally. #include <™m—th> using namespace std. ST.1 Simulating lognormally distributed random variables Lognormal variables are simulated as follows.2 Pricing of European Call options For the purposes of doing the Monte Carlo estimation of the price of an European call ct a e r@T  tA E ‘m—x@H.n denote the n simulated values. C++ Code 14. GG vol—titily const double& time) { GG time to (n—l d—te double ‚ = (r 0. r a H:I. note that here one merely need to simulate the terminal price of the underlying. ST   X A“ as the average ct a e r@T  tA ” 2 n ˆ iaI ST .

double sigm—=0. return exp( r*time)   * (sum p—yo's/double(no sims)). and f @S C qA   f @S A q estimate the option delta as ˜ ¡a 144 .r.r. ™out << " simulated price = " << option pri™e put europe—n simul—ted(ƒ. double sum p—yo's = 0. }.sigm—. n<=no sims.sigm—. for (int n=1.sigm—.u. double time=1.2))*time.1.time.u. just as in the standard case.0. we see that we can evaluate the price at two dierent values of the underlying. S and S C q . ™out << " put: black scholes price = " << option pri™e put ˜l—™k s™holes(ƒ. Output from C++ program: double ƒ=100. const int& no sims){ double ‚ = (r 0. const double& time. ƒ „ u). @T   tAA. the rst derivative of the call this.time) << endl.u. double u=100.0. @S delta.h" GG de(nition of r—ndom num˜er gener—tor double option pri™e ™—ll europe—n simul—ted( const double& ƒ. where q is a small quantity.#include <™m—th> GG st—nd—rd m—them—ti™—l fun™tions #include <—lgorithm> GG de(ne the m—x@A fun™tion using namespace std.0.5 * pow(sigm—. const double& sigm—.time) << endl.sigm—. let us recall that the rst derivative of a function f To understand how one goes about estimating is dened as the limit f H @xA a h3H lim Thinking of option f @x C hA   f @xA h f @S A as the option price formula ct a f @S Y X. double ƒh = sigm— * sqrt(time). int no sims=5000.0.time.0. desirable to estimate hedge parameters as well as option prices.2: C++ program: European Call option priced by simulation ™out << " call: black scholes price = " << option pri™e ™—ll ˜l—™k s™holes(ƒ. const double& r. }. #include "normdist.3 Hedge parameters It is of course. r. ™—llX putX ˜l—™k s™holes pri™e a IRFWUSV simul—ted pri™e a IRFVRHR ˜l—™k s™holes pri™e a SFRSWSR simul—ted pri™e a SFURSVV 14. ™out << " simulated price = " << option pri™e ™—ll europe—n simul—ted(ƒ. C++ Code 14. We will show how one can nd an estimate of the option price with respect to the underlying security: ¡a @ct . const double& u.   sum p—yo's += m—x(0. .no sims) << endl.r. double r=0.25.u. n++) { double ƒ „ = ƒ* exp(‚ + ƒh * r—ndom norm—l()). no sims) << endl.r.

0.sigm—.5 * pow(sigm—. double u=100.time. sims){ sum p—yo's += m—x(0.0.r. int no sims=5000. sigm—.u. r a H:I.sigm—. u.u. double ƒ „ q = (ƒ+q)* exp(‚ + ƒh * ).3: Estimate Delta of European Call option priced by Monte Carlo One can estimate other hedge parameters in a simular way. n++) { double  = r—ndom norm—l(). Example Given S a IHH.3 S and S C q.r. ™out << " call: bs delta = " << option pri™e delt— ™—ll ˜l—™k s™holes(ƒ.       }.0. return (™ q ™)/q.r. Calculate deltas of put and call option using Black Scholes and simulation. double ™ q = exp( r*time) * (sum p—yo's q/no sims). double time=1. double r=0.u. double sigm—=0. C++ program: double ƒ=100. for (int n=1. ™out << " put: bs delta = " << option pri™e delt— put ˜l—™k s™holes(ƒ.1.0. double q = ƒ*0. #include "normdist.no sims) << endl. C++ Code 14.time.r. ƒ „ q u). double& double& double& double& double& int& no   ƒ.sigm—. #include <™m—th> GG st—nd—rd m—them—ti™—l fun™tions #include <—lgorithm> GG de(ne the m—x@A fun™tion using namespace std.2))*time. K a IHH. sum p—yo's q += m—x(0.u.In the case of Monte Carlo estimation.time) << " sim delta = " << option pri™e delt— ™—ll europe—n simul—ted(ƒ. }.0. double ƒh = sigm— * sqrt(time). double sum p—yo's = 0. it is very important that this is done by using the same sequence of random variables to estimate the two option prices with prices of the underlying C++ Code 14.0.0. Output from C++ program: ™—llX ˜s delt— a HFUHHPHV putX ˜s delt— a EHFPWWUWP sim delt— a HFUHIRVR sim delt— a EHFQHUPII 145 .sigm—.time) << " sim delta = " << option pri™e delt— put europe—n simul—ted(ƒ. double sum p—yo's q = 0.25. time.h" GG de(nition of r—ndom num˜er gener—tor double option pri™e delt— ™—ll europe—n simul—ted(const const const const const const double ‚ = (r 0.  a H:PS. n<=no sims.no sims) << endl. Use 5000 simulations. double ƒ „ = ƒ* exp(‚ + ƒh * ). r. implements this estimation of the option delta.01. ƒ „ u). time=1. double ™ = exp( r*time) * (sum p—yo's/no sims).

}. that in the call to to the subroutine/function one provides a function instead depend on the value of the underlying of a variable. At maturity each option only ST and the exercise price X through the relations CT a m—x@ST   X. only. sum p—yo's += p—yo' (ƒ „. C++ Code 14. C++ Code 14. #include <—lgorithm> using namespace std.   }. for (int n=0. const double& u) return m—x(0.h" double deriv—tive pri™e simul—te europe—n option generi™(const double& ƒ. n++) { double ƒ „ = simul—te lognorm—l r—ndom v—ri—˜le(ƒ.14. const double& ˆ). If we want to price other types of options. or some other function describing a payo which only depends on the price of the underlying and some constant. n<no sims.e. const double& u){ return m—x(0.4: Payo call and put options The interesting part comes when one realises one can write a generic simulation routine to which one provide one of these functions.time). double p—yo' ™—ll(const double& ƒ. * (sum }. Let us now move toward a generic routine for pricing derivatives with Monte Carlo. But this would be wasteful. This relies on the ability of C++ to write subroutines which one call with function prototypes. const double& time. Function prototypes The above shows the case for a call option. const double& r.u). instead a bit of thought allows us to write option valuations for any kind of option whose payo depend on the value of the underlying at maturity.4 shows two C++ functions which calculates this. const int& no sims) { double sum p—yo's=0. HA PT a m—x@X   ST . #include <™m—th> using namespace std. const double& sigm—. Consider pricing of standard European put and call options. double p—yo' (const double& pri™e. return exp( r*time)   p—yo's/no sims). double p—yo' put (const double& ƒ. const double& u.r.4 More general payos.u ƒ). HA C++ Code 14.sigm—.   { }. C++ Code 14.ƒ u).5: Note the presence of the line Generic simulation pricing 146 .0.5 shows how this is done. with dierent payos we could write similar routines for every possible case. #include "fin_recipes.0. i.

The next example shows a complete example of how this is done.time) << endl.time. If it turns out that the Monte Carlo estimate overvalues the option price.u.dou˜le p—yoff@™onst dou˜le8 ƒD ™onst dou˜le8 uAD in the subroutine call. Example Given S a IHH. One is the method of control variates.no sims) << endl. What if one of the derivatives we value using the terminal values is one which we have an analytical solution to? For example. double sigm— = 0. C++ program: ™out << "Black Scholes call option price = " << option pri™e ™—ll ˜l—™k s™holes(ƒ.0.p—yo' put.time) << endl. derivative of interest downwards.u.sigm—. ™out << "Black Scholes put option price = " << option pri™e put ˜l—™k s™holes(ƒ. the option prices estimated using Monte Carlo still diers substantially from the true values. we think that this will also be the case for other derivatives valued using the same set of simulated terminal values. double u = 100. int no sims = 50000. suppose we want to value an European put and we use the price of an at the money European call as the control variate. double time = 1. double r = 0.no sims) << endl.u. fl—™k ƒ™holes ™—ll option pri™e ƒimul—ted ™—ll option pri™e fl—™k ƒ™holes put option pri™e ƒimul—ted put option pri™e a a a a IRFWUSV IRFWWS SFRSWSR SFSSWW As we see. Output from C++ program: double ƒ = 100. The idea is simple. When this function is called. Thus. When one generates the set of terminal values of the underlying security. Using the same set of simulated terminal values options using Monte Carlo as: We therefore move the estimate of the price of the ST.  a H:PS. suppose we calculate the value of an at the money European call option using both the (analytical) Black Scholes formula and Monte Carlo simulation.sigm—.1. ™out << "Simulated put option price = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.000 simuations. X   ST.25.r. K a IHH. the calling program will need to provide a function to put there.i A 3 147 . 14.1 Control variates.sigm—.time.r.p—yo' ™—ll.5 Improving the eciency in simulation There are a number of ways of improving the implementation of Monte Carlo estimation such that the estimate is closer to the true value. one can value several derivatives using the same set of terminal values.r. time=1. r a H:I.sigm—.r. such as the Black Scholes example above. 14.i . ™out << "Simulated call option price = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.u. we estimate the two pt a e r@T  tA ” 2 n ˆ iaI m—x @H.5. even with as many as 50. no sims=5000.

n<no sims.sigm—. and calculate pcv .   ™ sim += (™ ˜s ™ ˜s sim). const double& r.sigm—.h" double deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(const double& ƒ. Here we are simulating unit normal random variables. #include <™m—th> using namespace std. 148 . sum p—yo's += p—yo' (ƒ „. as follows cbs .time). the estimate of the put price with ”t t pcv a pt C @cbs   ct A ”t ” ” t One can use other derivatives than the at-the-money call as the control variate. double ™ sim = exp( r*time) * (sum p—yo's/no sims). C++ Code 14. An alternative to using control variates is to consider the method of antithetic variates. for (int n=0. Boyle (1977) shows that the eciency gain with antithetic variates is not particularly large. n++) { double ƒ „= simul—te lognorm—l r—ndom v—ri—˜le(ƒ.i   X A 3 We calculate the Black Scholes value of the call a control variate adjustment.r. One property of the normal is that it is symmetric around zero. sum p—yo's ˜s += p—yo' ™—ll(ƒ „.ƒ.5.ct a e r@T  tA ” 2 n ˆ iaI m—x @H.6 shows the implementation of a Monte Carlo estimation using an at-the-money European call as the control variate. double sum p—yo's ˜s=0. The idea behind this is that Monte Carlo works best if the simulated variables are spread out as closely as possible to the true distribution. }. sometimes called pseudo Monte Carlo.7 shows the implementation of this idea. There are other ways of ensuring that the simulated values really span the whole sample space.6: Generic with control variate 14. const double& ˆ. and then use both Z and  Z to generate the lognormal random variables. const double& time. GG simul—te —t the money fl—™k ƒ™holes pri™e }. return ™ sim.r. const int& no sims) { double ™ ˜s = option pri™e ™—ll ˜l—™k s™holes(ƒ. C++ Code 14.ˆ).GG pri™e —n —t the money fl—™k ƒ™holes ™—ll double sum p—yo's=0. const double& sigm—. #include "fin_recipes. ST. const double& ˆ). double p—yo' (const double& ƒ.   C++ Code 14. double ™ ˜s sim = exp( r*time) * (sum p—yo's ˜s/no sims).2 Antithetic variates.time). Why don't we enforce this in the simulated terminal values? An easy way to do this is to rst simulate a unit random normal variable Z . and the median value is zero.ƒ). the only limitation being that it has a tractable analytical solution.

const double& u.h" #include <™m—th> using namespace std.7: Generic with antithetic variates 149 . double ƒh = sigm— * sqrt(time). const double& sigm—.h" #include "normdist.#include "fin_recipes. return exp( r*time)   * (sum p—yo's/(2*no sims)). n++) { double x=r—ndom norm—l(). sum p—yo's += p—yo' (ƒI. n<no sims. sum p—yo's += p—yo' (ƒP. C++ Code 14. for (int n=0. }. const double& r.u). const double& time. double p—yo' (const double& ƒ.u). const int& no sims) { double ‚ = (r   0. double deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(const double& ƒ. const double& ˆ).5 * pow(sigm—.2) )*time. double ƒI = ƒ * exp(‚ + ƒh * x). }. double sum p—yo's=0. double ƒP = ƒ * exp(‚ + ƒh * ( x)).

p—yo' ™—ll. no sims=50000.sigm—.time. CV = " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ.no sims) << endl. AV = " << deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(ƒ.sigm—.u.sigm—.time. Output from C++ program: double ƒ = 100. ™out << "Simulated put option price.sigm—.r. int no sims = 50000. The simulation is to use both control variates and anthitetic methods. AV = " << deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(ƒ.no sims) << endl. C++ program: ™out << "Black Scholes call option price = " << option pri™e ™—ll ˜l—™k s™holes(ƒ. CV = " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ.no sims) << endl.r.no sims) << endl. p—yo' ™—ll.time. time=1. ™out << "Black Scholes put option price = " << option pri™e put ˜l—™k s™holes(ƒ.u.time) << endl. double u = 100.time. double sigm— = 0.u.sigm—.r.time. p—yo' put.u.time.25. p—yo' ™—ll. ™out << "Simulated call option price. ™out << "Simulated call option price.r.r.r.u.1.sigm—.no sims) << endl.no sims) << endl. ™out << "Simulated put option price = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ. Price put and call option using Black Scholes and simulation.r. ™out << "Simulated call option price = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ. p—yo' put. fl—™k ƒ™holes ™—ll option pri™e ƒimul—ted ™—ll option pri™e ƒimul—ted ™—ll option pri™eD g† ƒimul—ted ™—ll option pri™eD e† fl—™k ƒ™holes put option pri™e ƒimul—ted put option pri™e ƒimul—ted put option pri™eD g† ƒimul—ted put option pri™eD e† a a a a a a a a IRFWUSV IRFWWS IRFWUSV IRFWWIW SFRSWSR SFRIVTI SFRPSRI SFRTHRQ 150 . K a IHH.Example Given S a IHH.p—yo' put.sigm—.u.  a H:PS.u.time) << endl. ™out << "Simulated put option price.sigm—.u. r a H:I. double r = 0. double time = 1.r.

For example options that depend on the average of the price of the underlying (Asian options). return 0. r a H:I. Any European option that only depends on the terminal value of the price of the underlying security can be valued. double p—yo' —sset or nothing ™—ll(const double& ƒ. otherwise nothing. const double& u){ if (ƒ>=u) return ƒ. Consider the discussed by e. In both cases compare results using control variate and anthitetic methods. time=1. Both of these options are easy to implement using the generic routines above. binary options Q if the price of the asset is An asset or nothing call pays the price of the asset if the price is above the exercise price at maturity. return 0. }. but depend on the evolution of the price from now till the terminal date of the option. otherwise nothing. Use 5000 simulations. Hull (2006). all that is necesary is to provide the payo functions as shown in C++ Code 14. C++ Code 14. double p—yo' ™—sh or nothing ™—ll(const double& ƒ.g. Price cash or nothing option Price asset or nothing option.8: Payo binary options Now. many exotic options are not simply functions of the terminal price of the underlying security. For such cases one will have to simulate the whole path. Example Given with S a IHH.14. K a IHH.  a H:PS. Q a I. const double& u){ if (ƒ>=u) return 1. We will return to these cases in the chapter on pricing of exotic options.6 More exotic options These generic routines can also be used to price other options. 151 . An cash or nothing call pays a xed amount above the exercise price at maturity.8. }.

0.r. ™out << " antithetic variate " << deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(ƒ. Why can one argue that the rst implementation is more ecient than the other? 14. ™out << " control variate " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ. double time=1.sigm—.r.time. double sigm—=0.0.7 References Boyle (1977) is a good early source on the use of the Monte Carlo technique for pricing derivatives. no sims) << endl. p—yo' —sset or nothing ™—ll. no sims) << endl. as implemented in code 14. no sims) << endl.r.25.1. ™out << " asset or nothing: " << deriv—tive pri™e simul—te europe—n option generi™(ƒ. no sims) << endl.0. p—yo' —sset or nothing ™—ll.sigm—.u.1.sigm—. p—yo' ™—sh or nothing ™—ll.time. no sims) << endl. p—yo' ™—sh or nothing ™—ll. double r=0. double u=100. no sims) << endl.time. int no sims=5000.u. ™out << " antithetic variate " << deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(ƒ.sigm—.time. ™out << " cash or nothing.u.u. Output from C++ program: ™—sh or nothingD aIX HFSRURPU ™ontrol v—ri—te IFHPSSP —ntitheti™ v—ri—te HFSRWSWV —sset or nothingX UHFSPWP ™ontrol v—ri—te TWFVRSI —ntitheti™ v—ri—te UHFPPHS Exercise 14.r.time.sigm—.time. and the generic formula for pricing with Monte Carlo for European options that only depend on the terminal value of the underlying security. Note the dierence in the implementation of the lognormal simulation of terminal values.r.u. Simulation is also covered in Hull (2006).C++ program: double ƒ=100. Q=1: " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.r. p—yo' —sset or nothing ™—ll.2.5.u. p—yo' ™—sh or nothing ™—ll. 152 .sigm—. ™out << " control variate " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ. Consider the pricing of an European Call option as implemented in code 14.

. . . and the early exercise premium. . .) 15. . 153 . an approximation works well within a range of parameter values. . The Barone-Adesi and Whaley (1987) approximation decomposes the American option into two. 15. . . . . The early exercise premium is relatively small. . .5 Readings .4 An alternative approximation to american options due to Bjerksund and Stensland (1993) . . . 15. . X a I. . . in several of the following routines values are checked against Black Scholes values. Finally. . . . . . As soon as the exercise strategy is known. . . but they should be used with caution. . . . . . . . . . 15. but can go seriously wrong for some unfortunate combination of parameters. . . The rst we will look at is the Johnson (1983) approximation to an American put. . .2 An approximation to the American Put due to Geske and Johnson (1984) . There has been developed some useful 153 156 159 162 165 approximations to various specic options. . We will look at a number of approximations. . Typically. 15. both for their intrinsic usefulness. . . . . . . . . .  a H:S and time to maturity of one year. . .1 provides the details. . the European value.3 A quadratic approximation to American prices due to BaroneAdesi and Whaley. Approximations are useful. The American value is found by interpolating forward the Bermudan values. . . Formula 15. . . . . and C++ Code 15. . . calculate the price of an american call using the Johnson (1983) approximation. (In fact. . . . . . . Example Using the parameters r a H:IPS. and is easier to approximate. . . . . The user is well advised to to consider alternative approximations. .1 The Johnson (1983) approximation An early attempt at an analytical approximation to the price of an American put is provided by Johnson (1983).1 The Johnson (1983) approximation . . A typical approach to doing so is to specify some (suboptimal) exercise strategy. . . . the Bjerksund and Stensland (1993) is an example of bounding the option value by nding a lower bound on its value. . and at a minimum use the price of the corresponding European option as a sanity check in the calculations. . . the option is easily valued. . . S a I:I. . . .1 provides the implementation. . This is a purely empirical approach to estimating the functional forms. . . . . . . . . . . .Chapter 15 Pricing American Options  Approximations Contents 15. . with parameters estimated using regressions. The Geske and Johnson (1984) approach is to view the American option as a the limit of a sequence of Bermudan options with increasing number of exercise dates. . It is of course Amer- ican options that are approximated. . but also as examples of dierent approaches to generating an approximated value.

X : Exercise price of american put. double sigm—=0.1. @T   tA: Time to maturity for option.1: The functional form of the Johnson (1983) approximation to the value of an American put C++ program: double r=0. ™out << " American put price using Johnson approximation = " << option pri™e —meri™—n put —pproxim—ted johnson(ƒ. : Volatility of underlying. double ˆ=1.5. bI and bP are constants. aH a Q:WTRW aI a H:HQPQPS bH a I:HRHVHQ bI a H:HHWTQ S : Current value of underlying security. where la ln@S=Sc A ln@X=Sc A IC m .P @X A a p Xer@T  tA C @I   Ap @X A r@T   tA a aH r@T   tA C aI Sc a X   l   . double time = 1. time) << endl. Formula 15.125. sigm—. ˆ. r: risk freee interest rate. r. double ƒ=1. 154 . where ma P @T   tA a Pr=P bH P @T   tA C bI Their parameter values are estimated as The constants aH . Output from C++ program: emeri™—n put pri™e using tohnson —pproxim—tion a HFIISVP Barone-Adesi (2005) notes that this approximation is inaccurate outside of the parameter range considered in the paper. aI .

double —I = 0.sigm—. + (1  —lph—)*option pri™e put ˜l—™k s™holes(ƒ.1: The Johnson (1983) approximation to an american put price 155 . GG for s—fety use the fl—™k ƒ™holes —s lower ˜ound return m—x(p.time).r.r.032325.sigm—. double l = (log(ƒ/ƒ™))/(log(ˆ/ƒ™) ). double —lph— = pow( ( (r*time)/(—H*r*time+—I) ).€). const double& time ){ double sigm— sqr=pow(sigm—.00963.h" double option pri™e —meri™—n put —pproxim—ted johnson( const double& ƒ. double ƒ™ = ˆ * pow (((g—mm—)/(1+g—mm—)). double m = (sigm— sqr*time)/(˜H*sigm— sqr*time+˜I). double ˜I = 0. const double& sigm—. C++ Code 15. double —H= 3. l ).9649 .time).#include <™m—th> #include "fin_recipes. double € = —lph—*option pri™e put ˜l—™k s™holes(ƒ. double g—mm— = 2*r/sigm— sqr.m).ˆ. }.r.sigm—. const double& r.time) double p=option pri™e put ˜l—™k s™holes(ƒ.ˆ*exp(r*time). double ˜H = 1.2).ˆ. const double& ˆ.040803.

15. T 3 3 Q Q       2T T PT C Xe r 3 NP dP S T . The solution technique is to view the American put as an sequence of Bermudan options. T . An approximation involving 3 option evaluations is ” P a PQ C @PQ   PP A   @PP   PI A To calculate these. PP PI is then the price of an is the price of an option that can be exercised twice.  IQ . Q PQ a PI is the ordinary (european) Black Scholes value: PI a Xe rT NI @ dP @X.   SNI  dI S T . X.  a S T 2 P To calculate   PQ : T T PQ a Xe r 3 NI  dP S T . I IQ a p . once halfway between now and expiry. . dI S 23T .  IQ .  dI @X. T A Y  IP C Xe rT NP dP S T . T AA To calculate PP : T T PP a Xe r 2 NI  dP S T . with the one exercise date the expiry date.  PQ 3 Q       T   SNP dI S . Y  IP 3 Q Q       T PT C Xe rT NQ dI S T . . r dP @q. T AY IP .  dP @X. Dene Pi to be the price of the put option with i dates of exercise left. Geske-Johnson shows how these options may be priced. 2 2 P P       and ST 2 solves T S a X   p S. T .  dI @X.  dP S 23T .2 An approximation to the American Put due to Geske and Johnson (1984) Geske and Johnson (1984) develop an approximation for the American put problem. The correct value is the limit of this sequence.  PQ 3 Q Q       T   SNQ dP S T . PQ Y  IP Q T  3   2T 3    156 . rst dene U P I P dI @q. T AY IP . T 2 2 P P         T T . r. T AY  IP   SNP dI S T .  A a and ln     S C rC q p   I P ¡  P .   SNI  dI S T . european option. P In this notation.  dI S . T AA   SNI @dI @X. with the number of exercise dates increasing. PQ . .  dP @X. the other at expiry. and then develops a sequence of approximate prices that converges to the correct price. dP S 23T . .  A a dI     P Q p I IP a p . .

. X. . .   PT . 157 . r.where the critical stock prices solves S a X   PP S. since it involves calls to external routines for numerical intergration. r.  P Iterate on   S g Si a Si   H g until g is equal to zero with some given tolerance. The evaluation To solve for involves Newton steps. X. r. X. since it involves the evaluation of a trivariate normal cumulative distribution. Dene T g@S A a S   X C p S.  a S PT=Q Q The main issue in implementation of this formula (besides keeping the notation straight) is the evalutation of of NQ @A is described later. T S a X   p S.  a S T 2 P   PQ .  a S T=Q Q   T S a X   p S. r. X.

€Q  = ƒ*xQ(dP(ƒ.sigm—.ƒPQ ˜—r. const double& time. while (f—˜s(g)>egg…‚eg‰){ g=ƒi ˆ+option pri™e put ˜l—™k s™holes(ƒi.rhoIP).ƒQ ˜—r.ˆ.r.0/3. return €P.tP)).ƒPQ ˜—r.0/sqrt(3. inline double dI(const double& ƒ.ƒQ ˜—r. g=1. dP(ƒ.tQ).const double& ˆ.sigm—.tPQ).ˆ.rhoIP.ƒQ ˜—r.sigm—.0+option pri™e delt— put ˜l—™k s™holes(ƒi.r.0).r. const double& ƒP ˜—r. const double& sigm—. rhoIQ.sigm—.tP).ƒP ˜—r.0+option pri™e delt— put ˜l—™k s™holes(ƒi.€Q).5*pow(sigm—.r.sigm—.ˆ.sigm—. const double& t—u){ return (log(ƒ/ˆ) + (r+0.sigm—.r.r.r. inline double dP(const double& ƒ.0.dP(ƒ.ˆ.dI(ƒ. GG for s—fetyD use one less step —s lower ˜ound double ƒPQ ˜—r=ƒP ˜—r. rhoIP). }. C++ Code 15.€P).tQ).2))*t—u)/(sigm—*sqrt(t—u)).tQ). €Q += ˆ*exp( r*time)*x(dP(ƒ. €Q += ˆ*exp( r*tPQ)*xQ(dI(ƒ.sigm—. dI(ƒ. ƒi=ƒi g/gprime. ƒi=ƒi g/gprime. €P  = ƒ*x( dI(ƒ.sigm—.tQ).0/3.r.sigm—. const double& r.tQ).ˆ.ƒQ ˜—r.ƒP ˜—r.sigm—. const double& tP. rhoIP). inline double ™—l™€P(const double& ƒ. double option pri™e —meri™—n put —pproxim—ted geske johnson( const double& ƒ.sigm—.r. double g=1.t—u) sigm—*sqrt(t—u). }. €Q  = ƒ*x(dI(ƒ.#include #include #include #include <™m—th> "normdist.r. double €Q = ˆ * exp( r*tQ) * x( dP(ƒ.ƒPQ ˜—r.2: Geske Johnson approximation of American put 158 . double tP = time/2.tP). double gprime=1.sigm—.5*(€P €I).     }. const double& r. const double& ˆ. double rhoIP=1.tPQ).tPQ).ˆ.sigm—.tP).time. gprime=1. g=1.sigm—.r.0.r.r.ˆ. ƒQ ˜—r=ƒi. }.0).time). gprime=1. const double& r.r. ƒPQ ˜—r=ƒi.ˆ.ƒQ ˜—r.ƒP ˜—r.r.time).ˆ.time).sigm—. const double& r. €P=m—x(€I. €Q  = ƒ * x( dI(ƒ.tP. const double& ˆ. €Q=m—x(€P.sigm—.r. double ƒQ ˜—r=ƒPQ ˜—r.sigm—.r.h" "fin_recipes. rhoPQ).sigm—. while (f—˜s(g)>egg…‚eg‰){ g=ƒi ˆ+option pri™e put ˜l—™k s™holes(ƒi.r. double €P = ™—l™€P(ƒ. rhoPQ). const double& t—u){ return dI(ƒ.ƒPQ ˜—r.sigm—. while (f—˜s(g)>egg…‚eg‰){ g=ƒi ˆ+option pri™e put ˜l—™k s™holes(ƒi. rhoIQ. gprime=1. dI(ƒ. const double& rhoIP){ double €P = ˆ*exp( r*tP)*x( dP(ƒ.sigm—. double ƒP ˜—r=ƒ.0/sqrt(2.tQ)).r. const double& sigm—. double rhoPQ=sqrt(2. rhoIP).r. const double& sigm—. dP(ƒ.ˆ.sigm—. }.ƒQ ˜—r. dI(ƒ.   }.sigm—.tQ). const double& sigm—. ƒi=ƒi g/gprime.sigm—. double ƒi=ƒ.h" <iostre—m> const double egg…‚eg‰=1e  6. }.tPQ). ƒP ˜—r=ƒi.r.tQ)).r.r.tP)). double tPQ = time*2.r.0+option pri™e delt— put ˜l—™k s™holes(ƒi. €P += ˆ*exp( r*time)*x(dP(ƒ.time).0). const double& ˆ.r.r.rhoIP.tPQ).sigm—. dP(ƒ. double tQ = time/3.ƒP ˜—r.sigm—. €P  = ƒ*x(dI(ƒ.sigm—. rhoIP).0. double rhoIQ=1.ˆ.tP).ˆ. GG for s—fetyD use one less step —s lower ˜ound return €Q+3.5*(€Q €P) 0.ƒP ˜—r.ˆ.time).tPQ).r. const double& time ){ double €I = option pri™e put ˜l—™k s™holes(ƒ.

This is the classical g@S £ A a S £   X   c@S £ A    S£  I   e@b rA@T  tA N @dI @S £ AA a H qP 1 „he —pproxim—tion is —lso dis™ussed in rull @PHHTAF 159 . removed these. T A C AP S X r   S ¡q2 S£ if if S < S£ S ! S£ 3 I qP a P 2 M  @N   IA C @N   IAP C RK and S £ solves  S£  AP a I   e@b rA@T  tA N @dI @S £ AA qP Pr Pb M a P .2: call In implementing this formula.15. The functional form of the Barone Adesi Whaley approximation to the value of an American Formula 15. For an European option the value of V has a known solution.3 A quadratic approximation to American prices due to BaroneAdesi and Whaley. The insight used by BAW is that "C must also satisfy the same partial dierential equation. I P P  S VS S C bSVS   rV C Vt a H P Here (15. T A C Notation:  S£  I   e@b rA@T  tA N @dI @S £ AA qP S Stock price. T A a where & c@S. T A C "C @S. which may be exercised early. To do their approximation. The functional form of the approximation is shown in formula 15. C @S.2. N a P . T A Here "C is the early exercise premium. X : Exercise price.1) into one where the terms involving Vt are neglible. which has a known solution. there is no known analytical solution. T A a c@S. b. To come up with an approximation BAW transformed equation (15.1) V is the (unknown) formula that determines the price of the contingent claim. 1 The commodity is assumed to have a continuous payout The starting point for the approximation is the (Black-Scholes) stochastic dierential equation valid for the value of any derivative with price V. We now discuss an approximation to the option price of an American option on a commodity. BAW decomposes the American price into the European price and the early exercise premium C @S. For American options. the adjusted Black Scholes formula. the only problem is nding the critical value problem of nding a root of the equation S£. and ended up with a standard linear homeogenous second order equation. described in Barone-Adesi and Whaley (1987) (BAW). K @T A a I   e r@T  tA   S £   X a c @S £ .

by approximating the value of the early exercise premium.ˆ.r. Price a call option with time to maturity of 3 months. double sigm— = 0.3 shows the implementation of this formula for the price of a call option. X a IHH.This is solved using Newton's algorithm for nding the root. double time = 0. double ˜ =  0. where now one would use  S I   e@b rA@T  tA N @ dI A qI  g@S A a X   S   p@S A C g H @S A a @ I    IA I   e@b rA@T  tA N @ dI A qI C qI I @b rA@T  tA e  T  t pI n@ dI A 1. 160 .˜.20. b a  H:HR.04. T A C AI X  S   S ¡q1 S ££ if if S > S ££ S S ££ S ££ AI a   @I   e@b rA@T  tA N @ dI @S ££ AA qI One again solves iteratively for S ££ . Output from C++ program: double ƒ = 100. used as an example in the Barone-Adesi and Whaley (1987) paper: S a IHH. g@A SiCI a Si   H g At each step we need to evaluate g@A and its derivative gH @A. double ˆ = double r = 0. r a H:HV.1. For a put option the approximation is P @S A a p@S. 100. Example Consider the following set of parameters. C++ program: ™out << " Call price using Barone-Adesi Whaley approximation = " << option pri™e —meri™—n ™—ll —pproxim—ted ˜—w(ƒ. Implement the calculation of the price of an American put option using the BAW approach. Code 15.sigm—. The Barone-Adesi  Whaley insight can also be used to value a put option.25. 1.time) << endl. for example by Newton's procedure.  a H:PH. We start by nding a rst seed value The next estimate of Si is found by: SH . g—ll pri™e using f—roneEedesi ‡h—ley —pproxim—tion a SFURQQW Exercise 15.08.   g@S A a S   X   c@S A   gH @S A a @I   where qP I S I   e@b rA@T  tA N @dI A  qP I A I   e@b rA@T  tA N @dI A C  qP I @b rA@T  tA @e n@dI AA  T  t pI c@S A is the Black Scholes value for commodities.

0 exp(hP)).0/qP inf ).ˆ. gprime=( 1.0 1. double eP = (1. g=(1. } else { double dI = (log(ƒ st—r/ˆ)+(˜+0. }.5*sigm— sqr)*time)/(sigm—*time sqrt).r.˜.0/qP)*ƒi ˆ ™+(1.0/qP)*ƒi*exp((˜ r)*time)*x(dI). const double& sigm—. double g=0. const double& ˜. double ™ = option pri™e europe—n ™—ll p—yout(ƒ.3: Barone Adesi quadratic approximation to the price of a call option 161 .0)) { double ™ = option pri™e europe—n ™—ll p—yout(ƒi.5 * (  (nn 1) + sqrt(pow((nn 1).sigm—. if (f—˜s(g)>egg…‚eg‰) { ƒ st—r = ƒ seed.™).0*m)). }. double g=1.0/qP)*exp((˜ r)*time)*n(dI)*(1.2. double nn = 2.qP). double time sqrt = sqrt(time). double option pri™e —meri™—n ™—ll —pproxim—ted ˜—w( const double& ƒ. const double& r. ƒi=ƒi (g/gprime).0 exp((˜ r)*time)*x(dI)) +(1. const double& time) { double sigm— sqr = sigm—*sigm—. double qP = ( (nn 1)+sqrt(pow((nn 1).0 1.0)+(4*m/u)))*0. double gprime=1.h" #include "fin_recipes. } GG did not ™onverge else { ƒ st—r = ƒi. GG know v—lue will never ˜e less th—n fƒ v—lue C++ Code 15.r. return m—x(g.0 exp((˜ r)*time)*x(dI))* (ƒ st—r/qP). double m = 2.0/qP)*(1. #include "normdist. double ƒ st—r = 0. while ((f—˜s(g) > egg…‚eg‰) && (f—˜s(gprime) && ( >egg…‚eg‰) GG to —void exploding xewton9s no iter—tions++<500) && (ƒi>0.2.0*sigm—*time sqrt)*(ˆ/(ƒ st—r inf  ˆ)).0/(sigm—*time sqrt)). double u = 1. ƒ seed = ˆ + (ƒ st—r inf  ˆ)*(1.0   1.0.     }. double dI = (log(ƒi/ˆ)+(˜+0. int no iter—tions=0. hP =  (˜*time+2.0*˜/sigm— sqr. }.time).˜.time).sigm—.#include <™m—th> #include <—lgorithm> using namespace std. GG iter—te on ƒ to (nd ƒ st—rD using xewton steps double ƒi=ƒ seed.           double double double double qP inf = 0. g=™+eP*pow((ƒ/ƒ st—r).0e  6.h" GG norm—l distri˜ution GG de(ne other option pri™ing formul—s const double egg…‚eg‰=1. const double& ˆ.5. GG seed v—lue from p—per ƒ st—r inf = ˆ / (1. if (ƒ>=ƒ st—r) { g=ƒ ˆ.0 exp( r*time).0*r/sigm— sqr.5*sigm— sqr)*time)/(sigm—*time sqrt).ˆ.0)+4.

 b. X. A a C @X. S. T. Their approximation is an example of calculating a lower bound for the option value. r   b. A 162 . Their valua- tion relies on using an exercise strategy that is known. close enough to the (unknown) exercise strategy that the approximated value is The corresponding put option can be estimated as P @S.4 An alternative approximation to american options due to Bjerksund and Stensland (1993) Bjerksund and Stensland (1993) provides an alternative approximation to the price of American options. b.15. and although suboptimal. T. r.

b. Y X A a @X AS .The call option is found as C @S. T. r. K.

  @X A'@S. T j.

K. X A where @X A a @X   K AX  . X A C '@S. T jI. T jH. X A   X'@S. K. X. T jH. X A C X'@S.. X. X A  '@S. T jI. X.

I b C   .

T j . H. X A a  e S X N @dI A   S    N @dP A ! I  a  r C b C @   IAP T P dI a   dP a   I ln@S=H A C b C @   P A P T ln@X P =SH A C b C @   I A P T P    T   p ¡  T p ¡ Pb  a P C @P   IA  XT a BH C BI   BH A@I   eh@T A h@T A a   bT C P T      p p  BI   BH KP  BH or (suggested in a later paper Bjerksund and Stensland (2002)) h@T A a   bT C P T BI a .a P P   s   r b I P   CP P P P  '@S.

K .

K r b Formula 15. I   BI   BH r BH a m—x K. K : Exercise price. The Bjerksund and Stensland (1993) lower bound approximation to the value of an Amer- 163 .3: ican Call    S : Price of underlying security.

5).2).(r/(r ˜)*u)). double k—pp— = 2.„). double fH=m—x(u. g  = phi(ƒ. double r. double dP= (log((ˆ*ˆ)/(ƒ*r))+(˜+(g—mm— 0.„. g += phi(ƒ.0.r. double sigm—){ double sigm— sqr=pow(sigm—. const double& „ ){ double sigm— sqr=pow(sigm—.5: Approximation of American put due to Bjerksund and Stensland (1993) 164 .0 exp(h„)).˜. double ˆ.ˆ„.ˆ„. const double& ˜. double option pri™e —meri™—n ™—ll —pproxim—ted ˜jerksund stensl—nd( const double& ƒ. double g—mm—.sigm—).h" #include <™m—th> #include "normdist.k—pp—) * x(dP)).1. double l—m˜d— = ( r + g—mm— * ˜ + 0. double „. GG ™he™k thisD s—ys l—m˜d— in text double dI= (log(ƒ/r)+(˜+(g—mm— 0.sigm—. g += u*phi(ƒ. }. double —lph— = (ˆ„ u)*pow(ˆ„.r q.0.h" inline double phi(double ƒ. double finf = ˜et—/(˜et— 1.5)*sigm— sqr)*„)/(sigm—*sqrt(„)). const double& r.h" double option pri™e —meri™—n put —pproxim—ted ˜jerksund stensl—nd( const double& ƒ.g—mm—) * (x(dI) pow((ˆ/ƒ). const double& q.˜.0*˜/sigm— sqr + 2.ˆ„.ˆ„.       }.5*g—mm—*(g—mm— 1. const double& sigm—.„.r.                 }.„. g  = u*phi(ƒ.ˆ„.r (r q).g).˜et—).u.ƒ. double r.˜.4: Approximation of American Call due to Bjerksund and Stensland (1993) #include "fin_recipes. const double& „ ){ return option pri™e —meri™—n ™—ll —pproxim—ted ˜jerksund stensl—nd(ˆ. GG for s—fety use the fl—™k ƒ™holes —s lower ˜ound return m—x(™. double g=—lph—*pow(ƒ. double ˜et— = (0.˜. double phi = exp(l—m˜d—) * pow(ƒ.5 ˜/sigm— sqr) + sqrt( pow((˜/sigm— sqr 0.sigm—) .2). double ˜. double ™=option pri™e europe—n ™—ll p—yout(ƒ. double h„= (˜*„ + 2. double ˆ„ = fH+(finf fH)*(1. const double& u.r.                     g  = —lph—*phi(ƒ.r. C++ Code 15.ˆ„.sigm—.0*sigm—*sqrt(„))*((u*u)/(finf fH)). const double& ˆ.„).5)*sigm— sqr)*„)/(sigm—*sqrt(„)).ˆ„.0 * r/sigm— sqr).0*g—mm— 1.r. const double& sigm—.ˆ„.0)*u.sigm—).„.0.˜.0)*sigm— sqr)*„.2) + 2. const double& r.u. C++ Code 15.sigm—). ˜et—). return phi.r.u.1.˜et—.„.sigm—).˜.#include "fin_recipes.

An option is At the Money Forward if the forward price F equals the exercise price. 1.5 Readings See Broadie and Detemple (1996) for some comparisions of various approximations.2. including American options. Barone-Adesi (2005) summarizes the history of approximating the American put. T   t is the time to maturity 15. P V @¡A signies the present value operator. is Broadie and Detemple (2004). F is the forward price. Show that a reasonable approximation to the Black Scholes value of a call option on a non-dividend paying asset that is At the Money Forward is C a H:R T   tP V @F A where and p  is the volatility.Exercise 15. A survey of the pricing of options. 165 .

. . . . . . . . .Chapter 16 Average. . 16. . . . . . . . . . .1 Bermudan options . . . . . . . . Example Price a Bermudan put. . . . . . . . . . . . . . . . . . . . . The distinguishing factor of these options is that they depend on the today and the option maturity.6 References . .  a H:PS. . . . . . . . . . . . . K a IHH r = 0. . . .1 shows the calculation of the Bermudan price using binomial approximations. . time = 1. .3 Lookback options . .4. . . The times as which exercise can happen is passed as a vector argument to the routine. . . . . . . . . . .5 and 0. . . . . . . . . . . . . . . . . S a VH. as the name implies. . 1 a mix of an European and American option. . . q a H:H. . . .4 Monte Carlo Pricing of options whose payo depend on the whole price path . . . 1 ƒin™e fermud— is somewhere ˜etween emeri™— —nd iuropeFFF 166 . whole price path of the underlying security between 16. . Potential exercise times = 0. . . . . . . . . .1 Bermudan options A Bermudan option is. . . . . 172 We now look at a type of options that has received a lot of attention in later years. .20. . . . . . . . . . lookback and other exotic options Contents 16. . . . . . . . . . .1 Generating a series of lognormally distributed variables . .25. . The simplest way to do the pricing of this is again the binomial approximation. . . . . . . 16. . . . . . . The following informaton is given steps = 500. . 166 169 170 172 175 176 16. .75. . . . . . . . . . . . . . . . It is a standard put or call option which can only be exercised at discrete dates throughout the life of the option. . . . . . 16. C++ Code 16. . but now. . . . . . . . . . . .2 Asian options . 0. . . only check at the nodes corresponding to the potential exercise times. . . . . . . . . . . . . . . . . . instead of checking at every node whether it is optimal to exercise early. . . . . . .5 Control variate . . . 16. . . . . . . . . . . 16. . . . . and in the binomial a list of which nodes exercise can happen is calculated and checked at every step. . . .

sigm—.0. potenti—l exer™ise times.25.r. double q=0.C++ program: double ƒ=80.potenti—l exer™ise times. ve™tor<double> potenti—l exer™ise times.q.5). potenti—l exer™ise times.push ˜—™k(0.u. double sigm— = 0.25).steps) << endl. double u=100. int steps = 500.push ˜—™k(0. potenti—l exer™ise times.75). ™out << " Bermudan put price = " << option pri™e put ˜ermud—n ˜inomi—l(ƒ.20.time.0. Output from C++ program: fermud—n put pri™e a ISFWHUW 167 . double r = 0. double time = 1.push ˜—™k(0.

double ‚inv = 1.#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. if ( (t>0. const int& steps) { double delt— t=time/steps. }.0/u. GG st—nd—rd g m—them—ti™—l li˜r—ry GG de(nes the m—x@A oper—tor GG ƒ„v ve™tor templ—tes double option pri™e put ˜ermud—n ˜inomi—l( const double& ƒ. const double& r. double d = 1. }. pri™es[i] = d*pri™es[i+1]. }. double ‚ = exp(r*delt— t). }. for (int i=0.ˆ pri™es[i]). i<=steps.1: Binomial approximation to Bermudan put option 168 . const double& ˆ.push ˜—™k(int(t/delt— t)). double u = exp(sigm—*sqrt(delt— t)). pri™es[0] = ƒ*pow(d. ++i) pri™es[i] = uu*pri™es[i 1].i<potenti—l exer™ise times. steps).         ve™tor<int> potenti—l exer™ise steps. GG ™re—te list of steps —t whi™h exer™ise m—y h—ppen for (int i=0. step>=0. if (™he™k exer™ise this step) put v—lues[i] = m—x(put v—lues[i]. GG put p—yo's —t m—turity for (int step=steps 1. const double& time. GG (ll in the endnodesF          }. for (int i=1.0 p up. for (int i=0. (ˆ pri™es[i])).j<potenti—l exer™ise steps.++i){ double t = potenti—l exer™ise times[i]. ++i) put v—lues[i] = m—x(0. ++i) { put v—lues[i] = (p up*put v—lues[i+1]+p down*put v—lues[i])*‚inv.size(). step) { bool ™he™k exer™ise this step=false. const double& sigm—. return put v—lues[0]. }. i<=steps. i<=step. }. C++ Code 16.0. double uu = u*u. ve™tor<double> pri™es(steps+1). for (int j=0.0)&&(t<time) ) { potenti—l exer™ise steps. const ve™tor<double>& potenti—l exer™ise times.++j){ if (step==potenti—l exer™ise steps[j]) { ™he™k exer™ise this step=true. double p up = (exp((r q)*delt— t) d)/(u d). const double& q.0/‚. double p down = 1.size(). ve™tor<double> put v—lues(steps+1).

ST   S A There are dierent types of Asians depending on how the average " S is calculated. For the case of S being " being a geometric average. }. double time sqrt = sqrt(time).h" GG norm—l distri˜ution de(nitions double option pri™e —si—n geometri™ —ver—ge pri™e ™—ll(const double& ƒ. there is an analytic formula due to Kemna and lognormal and the average S Vorst (1990). double u=100. C++ program: double ƒ=100. double dI = (log(ƒ/u) + (r —dj div yield + 0. ™out << " Analytical geometric average = " << option pri™e —si—n geometri™ —ver—ge pri™e ™—ll(ƒ.0.r.time) << endl. double dP = dI (—dj sigm—*time sqrt).0). shows the calculation of the analytical price of an Asian geometric average price call. r a H:HT.0). Price an Asian geometric average price call. C++ Code 16.2   = Q and the dividend yield to p in the case of continous sampling of the underlying price distribution.16. const double& time){ double sigm— sqr = pow(sigm—. const double& u. double ™—ll pri™e = ƒ * exp( —dj div yield*time)* x(dI)   u * exp( r*time) * x(dP). return ™—ll pri™e. K a IHH. double time=1.25. Output from C++ program: en—lyti™—l geometri™ —ver—ge a TFURVUT 169 . double —dj sigm—=sigm—/sqrt(3.  a H:PS and time to maturity is one year.5*(r+q+sigm— sqr/6. double sigm—=0.2 Asian options The payo depends on the average of the underlying price. #include <™m—th> using namespace std.5*—dj sigm— sqr)*time)/(—dj sigm—*time sqrt).u.sigm—. const double& r.2). double —dj sigm— sqr = pow(—dj sigm—. double r=0. Hull (2006) also discusses this case.2: Example Relevant parameters: Analytical price of an Asian geometric average price call S a IHH.06.2). #include "normdist. const double& sigm—. It turns out that one can calculate this option using the regular Black Scholes formula adjusting the volatility to I I r C q C P P T C++ Code 16. S   X A. Another Asian is the average strike call " CT a m—x@H. double q=0. const double& q. An average price call has payo " CT a m—x@H.q. double —dj div yield=0. where " S is the average of the underlying in the period between t and T . q a H.

0)*log(ƒ/ƒmin)/sigm— sqr. due to Goldman. Sosin. const double& q. double —I = (log(ƒ/ƒmin) + (r q+sigm— sqr/2.1: Analytical formula for a lookback call #include <™m—th> using namespace std.0. const double& ƒmin. time = 1. C++ Code 16. double ‰I = 2. Smin a S q a H.0*(r q)))*x( —I)             ƒmin * exp( r*time)*(x(—P) (sigm—      sqr/(2*(r q)))*exp(‰I)*x( —Q)).3: Example Parameters Price of lookback call option S a IHH. const double& time){ if (r==q) return 0. #include "normdist. double time sqrt = sqrt(time).     }.1 and implemented in C++ Code 16.3 Lookback options The payo from lookback options depend on the maximum or minimum of the underlying achieved through the period. and Gatto (1979). double —Q = (log(ƒ/ƒmin) + ( r+q+sigm— sqr/2. double —P = —I sigm—*time sqrt. const double& r.0)*time)/(sigm—*time sqrt). r a H:HT. const double& sigm—. The payo from the lookback call is the terminal price of the undelying less the minimum value CT a m—x@H.  a H:QRT.h" double option pri™e europe—n look˜—™k ™—ll(const double& ƒ.3.16.0 * (r q sigm— sqr/2.0)*time)/(sigm—*time sqrt). ST   min S A  P‘t. 170 .T “ For this particular option an analytical solution has been found. C a Se q@T  tA N @aI A   Se q@T  tA aI a ln  S Smin    P  P Y1 N @ aI A   Smin e r@T  tA N @aP A   e N @ aQA P@r   q A P@r   q A C @r   q C I  P A@T   tA P aP a aI    T   t aQ a YI a ln  S Smin p  T  t   p  C  r C q C I P @T   tA P p  T  t ¡  Smin S ¡ P r   q   I  P ln P    P Formula 16. return ƒ * exp( q*time)*x(—I) ƒ*exp( q*time)*(sigm— sqr/(2. which is shown in Formula 16. double sigm— sqr=sigm—*sigm—. Price an European lookback call.

double ƒmin=ƒ. Output from C++ program: vook˜—™k ™—ll pri™e a PUFHUIQ 171 .0.346. ™out << " Lookback call price = " << option pri™e europe—n look˜—™k ™—ll(ƒ.r. 0.C++ program: double ƒ=100.ƒmin.q.sigm—. double r = 0. double q = double sigm— = 0.time) << endl. double time = 1.06.

shown in Another is the payo for a lookback. In chapter 14 we looked at a general simulation case where we wrote a generic routine which we passed a payo function to.4 Monte Carlo Pricing of options whose payo depend on the whole price path Monte Carlo simulation can be used to price a lot of dierent options. The limitation is that the options should be European. instead of just generating the terminal value of the underlying security from the lognormal assumption. shown in C++ Code 16. This code is then used in the generic routine to do calculations.3 2 xote the use of the accumulate() fun™tionD whi™h is p—rt of the g++ st—nd—rdF 3 xote the use of the min_element() —nd max_element fun™tionsD whi™h —re p—rt of the g++ st—nd—rdF 172 .6.2 C++ Code 16. The only dierence to the previous case is that we now have to generate a price sequence and write the terminal payo of the derivative in terms of that. There is (at least) two reasons for this.1 Generating a series of lognormally distributed variables Recall that one will generate lognormally distributed variables as p ~ 1 2 ST a St e@r  2  A@T  tAC T  tx where the current time is into say N t and terminal date is T . We consider a couple of examples. approximations using Monte Carlo relies on a law of large numbers. To simulate a price sequence one splits this period periods. 16.4 shows how one would simulate a sequence of lognormally distributed variables. the LLN would be invalidated.5. One is the case of an Asian option. each of length ¡t a T  t N t t C ¡t t C P¡t t C Q¡t ¡ ¡ ¡ T E Time Each step in the simulated price sequence is p ~ 1 2 StC¡t a St e@r  2  A¡C ¡tx C++ Code 16.7. The payo function in that case was a function of the terminal price of the underlying security. American options can not be priced by simulation methods. To price an option we are then only in need of a denition of a payo function. Second. as shown in C++ Code 16.4. But if the exercise policy was known there would be an analytical solution. But if some of the sample paths were removed. and the payo function was all that was necessary to dene an option value. the optimal exercise policy would have to be known.16. First.

r. return pri™es. const double& sigm—. const int& no sims) { double sum p—yo's=0. }.#include <™m—th> #include <ve™tor> using namespace std. GG initi—lize —t ™urrent pri™e for (int i=0. n<no sims. C++ Code 16. sum p—yo's += p—yo' (pri™es.5*pow(sigm—. const double& ˆ). }. double ƒh = sigm— * sqrt(delt— t). return exp( r*time)   * (sum p—yo's/no sims).h" double deriv—tive pri™e simul—te europe—n option generi™(const double& ƒ. #include "fin_recipes.sigm—.4: Simulating a sequence of lognormally distributed variables #include <™m—th> using namespace std. double ƒ t = ƒ.5: Generic routine for pricing European options 173 . ++i) { ƒ t = ƒ t * exp(‚ + ƒh * r—ndom norm—l()). const double& time. i<no steps. #include "normdist. GG time to (n—l d—te const int& no steps){ GG num˜er of steps ve™tor<double> pri™es(no steps). for (int n=0. double ‚ = (r 0.2))*delt— t.h" ve™tor<double> simul—te lognorm—lly distri˜uted sequen™e(const double& ƒ. double p—yo' (const ve™tor<double>& pri™es. }. const double& r. n++) { ve™tor<double>pri™es = simul—te lognorm—lly distri˜uted sequen™e(ƒ. const double& sigm—.u). C++ Code 16. const double& time. const int& no steps.no steps). const double& r. pri™es[i]=ƒ t. double delt— t = time/no steps. }.time. const double& u.

C++ Code 16.0. double p—yo' look˜—™k put(const ve™tor<double>& pri™es.end()).size(). pri™es. const double& unused v—ri—˜le) double m = *m—x element(pri™es. double p—yo' look˜—™k ™—ll(const ve™tor<double>& pri™es.pri™es. for (unsigned i=1.˜egin(). double —vg = exp(logsum/pri™es. double p—yo' —rithmetri™ —ver—ge ™—ll(const ve™tor<double>& pri™es. C++ Code 16.—vg u).0.size()). GG —lw—ys positive or zero {   }.end()). }. double p—yo' geometri™ —ver—ge ™—ll(const ve™tor<double>& pri™es. double —vg = sum/pri™es.—vg u).0). {   }. return m—x(0.˜—™k() m. {   }.size().6: Payo function for Asian call option #include <ve™tor> #include <—lgorithm> using namespace std.++i){ logsum+=log(pri™es[i]).pri™es. return m pri™es. GG m—x is —lw—ys l—rger or equ—lF {   }.˜—™k(). return m—x(0. return pri™es. const double& u) double sum=—™™umul—te(pri™es. const double& unused v—ri—˜le) double m = *min element(pri™es. const double& u) double logsum=log(pri™es[0]).7: Payo function for lookback option 174 .i<pri™es.0.end().˜egin().#include <™m—th> #include <numeri™> #include <ve™tor> using namespace std.˜egin().

time = 1. C++ Code 16. return ™ sim.GG pri™e —n —t the money fl—™k ƒ™holes ™—ll double sum p—yo's=0. #include "fin_recipes. double ™ sim = exp( r*time) * (sum p—yo's/no sims). double p—yo' (const ve™tor<double>& pri™es.r.0  a H:PS.sigm—. n<no sims.   C++ Code 16.sigm—. q a H. }. const double& r. r a H:IH. double sum p—yo's ˜s=0.5 Control variate As discussed in chapter 14.8 shows the Black Scholes price used as a control variate. K a IPH.r.ƒ. double deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(const double& ƒ.8: Example Control Variate Using the parameters S a IHH. 175 . const int& no sims) { double ™ ˜s = option pri™e ™—ll ˜l—™k s™holes(ƒ. n++) { ve™tor<double> pri™es = simul—te lognorm—lly distri˜uted sequen™e(ƒ. no steps = 250. The dierences between these two prices is a measure of the bias in the Monte Carlo estimate.ƒ). const double& time.   ™ sim += (™ ˜s ™ ˜s sim). or the analytical solution for a geometric average price call shown earlier. const double& sigm—. sum p—yo's += p—yo' (pri™es. GG simul—te —t the money fl—™k ƒ™holes pri™e }.˜—™k(). and is used to adjust the Monte Carlo estimate of other derivatives priced using the same random sequence. double ™ ˜s sim = exp( r*time) * (sum p—yo's ˜s/no sims). const double& ˆ). a control variate is a price which we both have an analytical solution of and nd the Monte Carlo price of. const double& u. An alternative could have been the analytical lookback price.h" #include <™m—th> using namespace std. sum p—yo's ˜s += p—yo' ™—ll(ƒI.time). const int& no steps.u). price arithmetric and geometric average calls by generic simulation. double ƒI= pri™es. no sims = 10000. no steps).16. for (int n=0.time.

r.r.ƒ.no sims) << endl. int no sims = 10000. double sigm— = 0.sigm—.q.0. p—yo' look˜—™k put.sigm—.r. Gray and Gray (2001) also looks at some analytical solutions. ™out << " simulated lookback call = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.sigm—.time. int no steps = 250. ™out << " simulated arithmetric average " << " S= " << ƒ << " r= " << r << " price=" << deriv—tive pri™e simul—te europe—n option generi™(ƒ.no sims) << endl.ƒ.no sims) << endl.25. 176 .time. double ƒ=100. ™out << " simulated geometric average = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.10.time.6 References Exotic options are covered in Hull (2006).time) << endl.q.sigm—. Rubinstein (1993) has an extensive discussion of analytical solutions to various exotic options. ™out << " analytical lookback call = " << option pri™e europe—n look˜—™k ™—ll(ƒ.0.no sims) << endl. no steps.r.0.sigm—.sigm—.r. double q=0.time.r. no steps.r. p—yo' —rithmetri™ —ver—ge ™—ll. ™out << " simulated lookback put = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ. p—yo' look˜—™k ™—ll. ™out << " analytical lookback put = " << option pri™e europe—n look˜—™k put(ƒ. Output from C++ program: „esting gener—l simul—tion of iurope—n options simul—ted —rithmetri™ —ver—ge ƒa IHH ra HFI pri™eaIFRWTWT simul—ted geometri™ —ver—ge a IFQVHIU —n—lyti™—l look˜—™k put a ITFPTTS simul—ted look˜—™k put a IRFWVRT —n—lyti™—l look˜—™k ™—ll a PPFVHVW simul—ted look˜—™k ™—ll a PIFWQQT simul—ted look˜—™k ™—ll using ™ontrol v—ri—tes a PPFHTVS 16.C++ program: ™out << "Testing general simulation of European options " << endl.time) << endl. double time = 1. ™out << " simulated lookback call using control variates = " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ.sigm—. no steps. double u=120. no steps.u.0.u. p—yo' look˜—™k ™—ll. p—yo' geometri™ —ver—ge ™—ll.no sims) << endl. no steps.time. double r = 0.

. . Consider the binomial approximation of an American call in Chapter 12's C++ Code 12. . . . .2. . . . . . . 177 . 17. The key to building a generic binomial routine lies in replacing this calculation with a generic routine. . . . .1 Introduction In earlier chapters we have seen a large number of dierent versions of the binomial pricing formula. . . . . . . . . . . . .2 shows how the generic ruotine is implemented. . C++ Code 17. . .1 Introduction . . . . . . . . . . . . . . . . . . .2 Delta calculation .Chapter 17 Generic binomial pricing Contents 17. . . . The terms of the derivative only appears when calculating the value at the nodes. . . . . The important feature that lets us write such a generic routine is that the only place the terms of the derivative appears in the calculation is the calculation of the value at each node. . . . . . . . 177 182 17. . . In this chapter we see how we can build a framework for binomial pricing that lets us write a single generic routine that can be used for a binomial approximation of all sorts of derivatives. .1 for convenience. . . . . . . . . . . . where the calculation m—x@pri™es‘“EuDHA appears. . . . . . repeated below as C++ Code 17. .

}. (pri™es[i] ˆ)). GG ™he™k for exer™ise ™—ll v—lues[i] = m—x(™—ll v—lues[i].       ve™tor<double> pri™es(steps+1).1: Binomial price of American Call 178 .0. GG st—nd—rd m—them—ti™—l li˜r—ry GG de(nes the m—x@A oper—tor GG ƒ„v ve™tor templ—tes double option pri™e ™—ll —meri™—n ˜inomi—l( const double& ƒ. for (int i=0. ++i) pri™es[i] = uu*pri™es[i 1].pri™es[i] ˆ). double p down = 1. GG ™—ll p—yo's —t m—turity for (int step=steps 1. GG pri™e of underlying pri™es[0] = ƒ*pow(d.0/‚. double p up = (‚ d)/(u d). GG interest r—te for e—™h step double ‚inv = 1. GG interest r—te const double& sigm—. return ™—ll v—lues[0].0/u. GG vol—tility const double& t. i<=steps. }. steps). GG (ll in the endnodesF double uu = u*u. i<=step. GG v—lue of ™orresponding ™—ll for (int i=0. GG time to m—turity const int& steps) { GG no steps in ˜inomi—l tree double ‚ = exp(r*(t/steps)). pri™es[i] = d*pri™es[i+1].#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std.0 p up. ++i)     step) { { ™—ll v—lues[i] = (p up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv. GG spot pri™e const double& ˆ. step>=0. ++i) ™—ll v—lues[i] = m—x(0. }. GG inverse of interest r—te double u = exp(sigm—*sqrt(t/steps)). C++ Code 17. ve™tor<double> ™—ll v—lues(steps+1). i<=steps. for (int i=1. GG exer™i™e pri™e const double& r. GG up movement double d = 1.

2: Generic binomial calculation 179 .0 p up. GG inverse of interest r—te double u = exp(sigm—*sqrt(t/steps)). GG ™he™k for exer™ise }. GG p—yo's —t m—turity for (int step=steps 1. const int& steps) { double ‚ = exp(r*(t/steps)). i<=step. GG pri™e of underlying pri™es[0] = ƒ*pow(d. GG st—nd—rd m—them—ti™—l li˜r—ry GG de(nes the m—x@A oper—tor GG ƒ„v ve™tor templ—tes double option pri™e generi™ ˜inomi—l( const double& ƒ. ++i)     step) { { v—lues[i] = (p up*v—lues[i+1]+p down*v—lues[i])*‚inv. for (int i=0. return v—lues[0]. steps). C++ Code 17. }. const double& u.u). const double& r.generi™ p—yo' (pri™es[i]. const double& u). GG v—lue of ™orresponding ™—ll for (int i=0. v—lues[i] = m—x(v—lues[i].u)). const double& t. double generi™ p—yo' (const double& ƒ. step>=0. ++i) v—lues[i] = generi™ p—yo' (pri™es[i].0/‚. i<=steps. ve™tor<double> v—lues(steps+1).#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. ++i) pri™es[i] = uu*pri™es[i 1].       ve™tor<double> pri™es(steps+1). GG v—lue ˜y not exer™ising pri™es[i] = d*pri™es[i+1]. }. const double& sigm—. GG interest r—te for e—™h step double ‚inv = 1. GG (ll in the endnodesF double uu = u*u. i<=steps.0/u. double p up = (‚ d)/(u d). for (int i=1. double p down = 1. GG up movement double d = 1.

double p—yo' ™—ll(const double& ƒ.0.   { }. const double& u) return m—x(0. Output from C++ program: —meri™—n ™—ll pri™e a IRFWSHS —meri™—n put pri™e a TFSRTWI More exotic options can also be calculated using the same approach. where @T   tA a I and r a H:I.p—yo' put.ƒ u). r. r. K or above during  a H:P. @T   tA a I and 180 . 1. shows how the payos are dened for standard put and call options. C++ Code 17.Using this routine is then merely a matter of providing a denition of the derivative payo. ™out << " american put price = " << option pri™e generi™ ˜inomi—l(ƒ. S a IHH.25. double sigm— = 0. S S a IHH.0.u. options that pay o one dollar if the price of the underlying is above K (call) or below K (put).  a H:P. the check for whether the option is in the money happens at maturity. but one can also think of cases where the binary option pays o one dollar as soon as S . double u = 100. Example Consider binary options that pays one dollar if the price of the underlying increases to Using some time period. double r = 0. C++ Code 17. time to m—turity. hits the barrier K . Price the options using binomial approximations with 100 steps. For example. sigm—. const double& u){ return m—x(0.3 Pricing American put and call options is then merely a matter of supplying these payo denitions to the generic binomial routine. double p—yo' put (const double& ƒ. #include <—lgorithm> using namespace std. time to m—turity.0. Suppose the current price of the underlying is r a H:I. sigm—. C++ program: double ƒ = 100.0.0. The typical such option is European. price such a binary option when K a IPH.3: Example Payo denitions for put and call options Consider American call and put option on non-dividend paying stock. double time to m—turity=1. the price of the underlying. K a IHH. steps) << endl.4 shows payo denitions for two binary options. C++ Code 17. int steps = 100.p—yo' ™—ll.   }. steps) << endl. ™out << " american call price = " << option pri™e generi™ ˜inomi—l(ƒ.1.u ƒ).u.

C++ Code 17.0.0.p—yo' ˜in—ry ™—ll. steps) << endl. Output from C++ program: ˜in—ry option pri™e a HFRWVVSV 181 . ™out << " binary option price = " << option pri™e generi™ ˜inomi—l(ƒ. double p—yo' ˜in—ry put(const double& ƒ. double sigm— = 0.25. time to m—turity. const double& u){ if (ƒ>=u) return 1. }.4: C++ program: Payo denitions for binomial options double ƒ = 100. int steps = 100. double r = 0. return 0.1. r.double p—yo' ˜in—ry ™—ll(const double& ƒ. return 0.0. sigm—. double u = 120. double time to m—turity=1. const double& u){ if (ƒ<=u) return 1. }.u.

generi™ p—yo' (pri™es[i]. v—lues[i] = m—x(v—lues[i]. double d = 1. to calculate delta using the same generic approach. v—lues[i] = (phown*v—lues[i]+p…p*v—lues[i+1])*‚inv. generi™ p—yo' (pri™es[i]. const double& u.0/‚. = for (int gurrƒtep=no steps 1 .5: Generic binomial calculation of delta Exercise 17. i<=no steps.0/u. pri™es[0] = ƒ*pow(d. gurrƒtep>=1. double p…p = (‚ d)/(u d). i<=gurrƒtep. no steps). C++ Code 17. ++i) pri™es[i] ve™tor<double> v—lues (no steps+1). const double& r.  v—lues[0])/(ƒ*u ƒ*d).0 p…p. }. How would you modify them to account for European options? 182 . const int& no steps){ double ‚ = exp(r*(t/no steps)).17. for (int i=1.u).1. double uu= u*u. const double& t. The generic routines discussed in this chapter have been for American options. double u = exp(sigm—*sqrt(t/no steps)). double option pri™e delt— generi™ ˜inomi—l(const double& ƒ. }. double phown = 1. const double& sigm—.2 Delta calculation Deltas and other greeks are calculated using the same style of generic routine. = (v—lues[1] }.u)).5 shows how #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. double ‚inv = 1. const double& u). double delt— return delt—.       ve™tor<double> pri™es (no steps+1). double generi™ p—yo' (const double& ƒ. ++i) {     gurrƒtep) { pri™es[i] = d*pri™es[i+1]. for (int i=0. for (int i=0. C++ Code 17. i<=no steps. ++i) v—lues[i] = uu*pri™es[i 1].

. . . . . . . . . . . . . . . . . . . . . . 18. . . . . . . . 18. . . . . .3 Further reading . . At each point of time there are three possible future values of the underlying S. . . . . . . . . . . . . . 183 183 186 18.1 Intro . . . . . . . . .1 Intro A trinomial tree is similar to a binomial tree. . . . .2 Implementation . . . . . . . . . . .Chapter 18 Trinomial trees Contents 18. . . . SH B ¨ ¨ ¨¨ ¨ ¨ ¨¨ E rr r rr r r j r Su a uSH Sm a SH Sd a dSH 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . We will show the calulation using the following parameterization: p u a e Q¡t ea u I pu a   pm a pu a r ¡t I P r q  C P IP P T   r P Q ¡t P I P r q  P C T IP   183 . . . just with one more branch. . . . .2 Implementation A trinomial tree can be implemented with various parameterizations. . . . . . .

We calculate the option price using the usual roll back procedure with the continuation value e r¡t @pu fu C pm fm C pd fd A #include <ve™tor> #include <™m—th> using namespace std. r a H:I.size() 1]*u). const double& t.++step){ ƒtree.0 + sqrt(delt— t/(12. v—lues next=v—lues.5*sigm—  q 0. d = 1. v—lues = ve™tor<double> (m). const int& steps) { double delt— t = t/steps. 184 . p d = 1.0*delt— t)). i<m. const double& r. ƒve™. const double& sigm—. K a IHH. for (int step=1.  a H:PS and time to maturity is 1 year. sqr).0/6. double option pri™e put —meri™—n trinomi—l( const double& ƒ. GG ™he™k for exer™ise }. }.step<=steps. double sigm— sqr=pow(sigm—. step>=0. * (r ve™tor< ve™tor<double> > ƒtree. const double& u. ƒve™. ve™tor<double> v—lues next = ve™tor<double>(m).size(). for (int step=steps 1. }. u ƒve™[i]). double ‚inv = exp( r*(delt— t)).0*sigm— sqr)) p m = 2.0/u.5*sigm— sqr).push ˜—™k(ƒ). const double& q. v—lues[i] = m—x(v—lues[i].ƒve™[0]*d). GG v—lue of option next step for (int i=0.u ƒtree[step][i]). GG v—lue of option for (int i=0. GG pri™e of underlying in — tree ve™tor<double> ƒve™.0/3. return v—lues[0].0*sigm— sqr)) * (r  q 0.push ˜—™k(ƒve™[ƒve™.   step) { m = ƒtree[step]. GG use the f—™t th—t only the extreme v—lues ™h—ngeF ƒve™. ++i) v—lues next[i] = m—x(0.0/6.push ˜—™k(ƒve™).0. i<m.˜egin().0   sqrt(delt— t/(12.insert(ƒve™.2). }. int m = ƒve™.1: Example Price of american put using a trinomial tree You are given the following information about an option: S a IHH.size(). GG ™—ll p—yo's —t m—turity ve™tor<double> v—lues. Price an American put using a trinomial approximation with 100 steps. ++i) { v—lues[i] = (p u*v—lues next[i+2]+p m*v—lues next[i+1] + p d*v—lues next[i])*‚inv.0. C++ Code 18.   double double double double double u = exp(sigm—*sqrt(3. p u = 1.

ƒtree = [ ƒve™ ]. q. ƒu = ƒ. end end € = v—lues.no steps) << endl. ƒve™.25.time.u. ƒu ]. q=0.1.u ƒve™). p u = 1/6 + sqrt(delt— t/(12*sigm— sqr)) * (r q 0. no steps=100.0. d = 1. sigm— sqr=sigm—^2. double u = 100.step+1)). sigm—=0.time.q. for step=1:steps+1 ƒu = ƒu*u. r. t.5*sigm— sqr). p m = 2/3. € = opt pri™e trinom —m put(ƒ.1: C++ program: Price of american put using a trinomial tree double ƒ = 100. zeros(2. u. u = exp(sigm—*sqrt(3. time=1. for step = steps: 1:0 m = 2*step+1.u. —meri™—n put a TFSPUIW w—tl—˜ program: ƒ=100.q.5*sigm— sqr). ƒd = ƒd*d. steps) delt— t = t/steps.1. ™out << " american put = " << option pri™e put —meri™—n trinomi—l(ƒ.r.r. since the only changes when you add one step is to add one price at the top 185 . int no steps = 100. ƒd = ƒ.sigm—.sigm—. double sigm— double time=1. u ƒtree(1:m.no steps) Output from w—tl—˜ program: € a TFSRTV Exercise 18.0/u. end v—lues next = max(0. v—lues next = v—lues.function € = opt pri™e trinom —m put(ƒ. ƒtree=[ [ƒtree. u=100. end w—tl—˜ Code 18.0*delt— t)).step)] ƒve™ ]. v—lues = max(v—lues. Output from C++ program: = 0.1. r=0. sigm—. This can be collapsed into a single array.0. ‚inv = exp( r*delt— t). v—lues = ‚inv*(p u*v—lues next(3:m+2)+p m*v—lues next(2:m+1)+p d*v—lues next(1:m)). In the code for the trinomial tree the price of the underlying is put into a triangular data structure. p d = 1/6   sqrt(delt— t/(12*sigm— sqr)) * (r q 0. ƒve™ = [ ƒd.0.25. ƒve™ = [ ƒ ]. double q = 0. double r = 0.

If you keep track of the top and bottom of the current array you can access the prices of the underlying through some clever indexing into the single vector of prices of the underlying.and at the bottom. Exercise 18.3 Further reading Hull (2006) 186 . Similarly to the binomial case.2. Implement such a generic trinomial tree. 18. one can build a generic trinomial tree where the payo function is passed as a parameter to the routine.

. . . . . . pg 454). . rn . them have seen any widespread use. . The risk of these jumps is assumed to not be priced.1 Formula 19. where the size of the jump has a normal distribution. .1  and  are parameters of the and implemented in ca where I ˆ eH  @H  An naH n3 P CBS @S. X. 19. but we will look at some of these alternatives.Chapter 19 Alternatives to the Black Scholes type option formula Contents 19. . . . . . Merton (1976) has proposed a model where in addition to a Brownian Motion term. . . The price of an European call option is given in C++ Code 19. But since the 187 . . . . . we need to terminate the innite sum at some point. . 1993.1 Merton's Jump diusion model. . the price process of the underlying is allowed to have jumps. . . . . .2 Hestons pricing formula for a stochastic volatility model . . . . . . . . . n . . . .1: The option pricing formula of the Merton (1976) model In implementing this formula. 187 189 Few of A large number of alternative formulations to the Black Scholes analysis has been proposed. . . . . . . . . . . . . . .1 Merton's Jump diusion model. described in (Hull. and n P P n a P C  n ln@I C A rn a r    C  Formula 19. T   tA  aT  t H a @I C A CBS @¡A is the Black Scholes formula. . In the following we look at an implementation of a special case of Merton's model. 19. . jump distribution.

const double& r.n<=weˆx. for (int n=1. C++ Code 19.sigm—. Output from C++ program: werton tump diffusion ™—ll a PQFPHUR 188 . K a IHH. double ™ = exp( l—m˜d—prime*t—u)*option pri™e ™—ll ˜l—™k s™holes(ƒ.r.     ™ += exp( l—m˜d—prime*t—u+n*log(l—m˜d—prime*t—u) log n)* option pri™e ™—ll ˜l—™k s™holes(ƒ.  a H:S. double r n = r l—m˜d—*k—pp—+n*g—mm—/t—u. that is no problem. double r=0.5.h" 2 2 H 33 ˆ a exp  H  C n ln@H  A   ln i iaI 2 n 3 double option pri™e ™—ll merton jump di'usion( const double& ƒ.sigm— n.  a H:S. double log n = 0. double sigm— n = sqrt( sigm— sqr+n*delt— sqr/t—u ). terminating at nabout n a SH H should be on the conservative side. double l—m˜d—=0. }. using the parameters S a IHH. time to maturity=1.t—u). ™out << " Merton Jump diffusion call = " << option pri™e ™—ll merton jump di'usion(ƒ. const double& sigm—.05. double u=100. double delt—=0. double k—pp—=0. use the following method for calculation of e  @H  An e  @H  An a exp ln n3 n3 #include <™m—th> #include "fin_recipes.   }.5. r a H:HS.ˆ. const double& delt—) { const int weˆx=50. const double& time to m—turity.l—m˜d—.u.1: Example Mertons jump diusion formula Price an option using Merton's jump diusion formula. double sigm—=0. const double& l—m˜d—. double delt— sqr = delt—*delt—.delt—) << endl. return ™.factorial function is growing at a much higher rate than any other. double g—mm— = log(1+k—pp—). double t—u=time to m—turity.r l—m˜d—*k—pp—. const double& k—pp—.3.time to m—turity.t—u). double sigm— sqr = sigm—*sigm—. To avoid numerical diculties.  a H:S.  a H:Q. double l—m˜d—prime = l—m˜d— * (1+k—pp—). const double& ˆ.r n. double time to m—turity=1.sigm—.5. ++n) { log n += log(double(n)).k—pp—. C++ program: double ƒ=100.ˆ.

2 Hestons pricing formula for a stochastic volatility model Heston (1993) relaxes the Black-Scholes assumption of a constant volatility by introducing a stochastic volatility. Let S be the stock price and v the volatility. dS @tA a Sdt p v@tASdzI @tA C p d v@tA a  . He nds exact solutions for European options.19.

v. tA a SPI   KP @t. A a uI a . K : exercise price. T. v. v. and are accessed by including the 5in™lude `™omplexb 189 . v. Under a constant interest rate r Consider a call option with strike price Its price is given by Formula 19. Price of Call option using Hestons formula The option price is C @s. ln@K AA a C Re d P  H i fj @x. ! The two processes zI and zP have correlation . v. it illustrates calculations of of complex variables. Complex numbers is part of the C++ standard. v@tAdt C v@tASdzP @tA p These two variables are assumed to follow joint stochastic processes. First. A a eC @. The implementation of this pricing formula has some instructive C++ features. T APP where !  I I I e i ln@K A fj @x. A Pj @x.ACD@.2. A a ri C P @bj   i C dA   P ln  I g D@. T. tA be the price of volatility risk. p Rewrite the process for the volatility as dv@tA a  @   v@tAA dt C  v@tAdzP Let @S.AvCix & a I   ged C @. P @t. T A a e r@T  tA K. a a  bI a  C     bP a  C  x a ln@S A ga bj   i C d bj   i   d q !' bj   i C d I   ed P I   ged uP a   I P ! I P d a @i   bj AP   P @Puj i   P A Notation: S : price of undelying security. T.

rho. double thet—=0. thet—. u. ™out << "heston call price " << heston ™—ll option pri™e( ƒ.01. k—pp—.  a P. Complex numbers are templated. double rho=0. v a H:HI.01. 1 To evaluate the price it is also necessary to do a numerical integration. it is necessary to specify what type of oating point type to use. t—u. Output from C++ program: heston ™—ll pri™e QFHTWRR 1 en ex—mple —ltern—tives would h—ve ˜een xumeri™—l ‚e™ipes in gCC9s qu—dr—tureF 190 . r a H:HI. double l—m˜d—=0.01. double r=0. double v=0. double u=100. K a IHH. double sigm—=0. We use a routine provided by the Gnu GSL project. double t—u=0.  a H:S.  a H. sigm—) << endl.5.  a H. Example Given the following set of parameters:  a H:HI and  a H:HI. r. double k—pp—=2.statement.01. v.0. In the calculation this is solved by a call to an external routine. l—m˜d—. price a call option using the Heston formula C++ program: S a IHH. such as ™omplex`dou˜leb or ™omplex`dou˜le dou˜leb. double ƒ=100.

double k—pp— = (p—rms >k—pp—).u.1e 7. double — = k—pp—*thet—. thet—. double thet—.0 g))). double rho. p.t—u.5.k—pp—. ™omplex<double> p = exp( phi*i*log(u))*fI/(i*phi). if (j==1){ uj=0.sigm—.0*log((1. ™omplex<double> fI = exp(g+h*v+i*phi*x). const double& u. double r.v.p—r—ms=&p—rms. double uj.rho. v.v.}.thet—. double u = (p—rms >u). j}. }. size t n=10000.0 exp(d*t—u))/(1. double thet—. ™omplex<double> g = r*phi*i*t—u+(—/sigm— sqr)*((˜j rho*sigm—*phi*i+d)*t—u 2.1e 7. double heston ™—ll option pri™e(const double& ƒ. ˜j=k—pp—+l—m˜d— rho*sigm—.}. ™omplex<double> g = (˜j rho*sigm—*phi*i+d)/(˜j rho*sigm—*phi*i d).1). const double& rho. }. extern "C"{ double heston integr—nd j(double phi.l—m˜d—. double €P = heston €j(ƒ. double sigm—.2: Hestons pricing formula for a stochastic volatility model 191 . double l—m˜d— = (p—rms >l—m˜d—). return re—l(p).     }. void *p){ struct heston p—rms* p—rms = (struct heston p—rms*)p. ˜j=k—pp—+l—m˜d—. double sigm— sqr = pow(sigm—. const double& r.2). double j = (p—rms >j). ™omplex<double> h = (˜j rho*sigm—*phi*i+d)/sigm— sqr * ( (1. double result.2) sigm— sqr*(2*uj*phi*i pow(phi. gsl integr—tion q—giu(&p. const double& t—u.0 g*exp(d*t—u)) ).fun™tion = &heston integr—nd j. p. GG integr—l to in(nity st—rting —t zero return 0.u. rho. ™omplex <double> i(0. double v.k—pp—.w. gsl fun™tion p. double rho = (p—rms >rho).2). C++ Code 19. sigm—. double k—pp—. r.&error). double rho. double thet— = (p—rms >thet—). const double& sigm—){ double €I = heston €j(ƒ. double x. int j. double r.thet—. double t—u.h" struct heston p—rms {double u.t—u. const double& thet—. double u. t—u.l—m˜d—. x. error.#include <iostre—m> #include <™m—th> #include <™omplex> using namespace std. double l—m˜d—. int j){ double x=log(ƒ). gsl integr—tion worksp—™e* w = gsl integr—tion worksp—™e —llo™(n).                                                       }. double k—pp—.2)) ).&result. return g. double x = (p—rms >x).r. double sigm—.1).5 + result/w €s. double t—u = (p—rms >t—u). ™omplex<double> d = sqrt( pow(rho*sigm—*phi*i ˜j. #include "gsl/gsl_integration. const double& v. const double& k—pp—. inline double heston €j(double ƒ.0 g*exp(d*t—u))/(1. l—m˜d—. double g=ƒ*€I u*exp( r*t—u)*€P. struct heston p—rms p—rms = { u. double t—u. double v = (p—rms >v). const double& l—m˜d—. double v.0. k—pp—. double sigm— = (p—rms >sigm—).r.5.sigm—.n. double r = (p—rms >r). } else { uj= 0.rho. double ˜j. double l—m˜d—.

. . . . basic models Contents 20. . . . . . double dI = (log(f/ˆ)+r*time)/(sigm—*time sqrt) + 0. prices of European Bond Options can be found using the usual Black Scholes formula. . . . . . .1 Black Scholes bond option pricing . . const double& ˆ. . The focus of the modelling in this area is on modelling the term structure of interest rates and its evolution over time. . suppose that the price of a Bond follows a Geometric Brownian Motion process. . . The Geometric Brownian motion may be OK for the case of short term options on long term bonds. . . .           }. .5*sigm—*time sqrt. . C++ Code 20. C++ Code 20. . . . . . . . . const double& r. .2 Binomial bond option pricing . return p. 20. . just like the case we have studied before.2 for the #include <™m—th> #include "normdist. . . const double& time){ double time sqrt = sqrt(time). const double& sigm—. This is not a particularly realistic assumption for the long term behaviour of bond prices.1 for a zero coupon bond and C++ Code 20. . double dP = dI (sigm—*time sqrt).Chapter 20 Pricing of bond options. . 192 194 The area of xed income securities is one where a lot of work is being done in creating advanced mathematical models for pricing of nancial securities. . . . . .h" double ˜ond option pri™e put zero ˜l—™k s™holes(const double& f. . . . . . as shown in case of an option on a coupon bond. . . . . . .1 Black Scholes bond option pricing Given the assumed Brownian Motion process. in particular xed income derivatives. . and price derivatives by modelling the evolution of the bond price directly. However. Specically.1: Black scholes price for European put option on zero coupon bond 192 . . since any bond price converges to the bond face value at the maturity of the bond. which is then used to price both bonds and xed income derivatives. . . . . . 20. in some cases one does not need the machinery of term structure modelling which we'll look at in later chapters. . . double p = ˆ * exp( r*time) * x( dP) f * x( dI). . .

const ve™tor<double> ™oupon times.#include <™m—th> #include <ve™tor> using namespace std. }. #include "normdist. C++ Code 20.time). const double& time.h" #include "fin_recipes.r.i++) { if (™oupon times[i]<=time) { —djusted f  = ™oupon —mounts[i] * exp( r*™oupon times[i]). const double& ˆ. const double& r. const ve™tor<double> ™oupon —mounts){ double —djusted f=f.sigm—.2: Black scholes price for European put option on coupon bond 193 . }.size(). }. for (unsigned int i=0.i<™oupon times. return ˜ond option pri™e put zero ˜l—™k s™holes(—djusted f.h" double ˜ond option pri™e put ™oupon ˜ond ˜l—™k s™holes( const double& f. const double& sigm—.ˆ.

++i) put v—lues[i] = m—x(0. step>=0. i<=steps.0 p up. (u pri™es[i])).   step) { for (int i=0.0/u. C++ Code 20. put v—lues[i] = m—x(put v—lues[i]. for (int i=0. double d = 1. steps). ++i) pri™es[i] = uu*pri™es[i 1].(u pri™es[i])). GG inverse of interest r—te double u = exp(sigm—*sqrt(t/steps)).3: Binomial approximation to american put bond option price 194 . GG interest r—te const double& sigm—. of a put price C++ Code 20.3 shows the calculation #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. the usual binomial approximation can be used to price American options. return put v—lues[0]. GG interest r—te for e—™h step double ‚inv = 1. GG ™he™k for exer™ise }. where the bond is the underlying security. double p down = 1. GG (ll in the endnodesF for (int i=1. GG st—nd—rd m—them—ti™—l li˜r—ry GG de(ning the m—x@A oper—tor GG ƒ„v ve™tor templ—tes double ˜ond option pri™e put —meri™—n ˜inomi—l( const double& f. }. GG exer™ise pri™e const double& r. GG fond pri™e const double& u.0/‚. GG time to m—turity const int& steps){ GG no steps in ˜inomi—l tree double ‚ = exp(r*(t/steps)).0. i<=step.2 Binomial bond option pricing Since we are in the case of geometric Brownian motion. double p up = (‚ d)/(u d). }. i<=steps. ve™tor<double> pri™es(steps+1). GG up movement double uu = u*u. ++i) { put v—lues[i] = (p up*put v—lues[i+1]+p down*put v—lues[i])*‚inv. GG v—lue of ™orresponding put       pri™es[0] = f*pow(d. GG vol—tility const double& t. GG put p—yo's —t m—turity for (int step=steps 1. GG pri™e of underlying ve™tor<double> put v—lues(steps+1). pri™es[i] = d*pri™es[i+1].20.

push ˜—™k(1).5). time=1. 3. binomial = " << ˜ond option pri™e put —meri™—n ˜inomi—l(f. time=1.steps) << endl.r.05.™oupon times.sigm—. 2.u. Price a an European put option on the coupon coupon bond using Black Scholes. 1. ™oupon times. r=0. ™out << " zero coupon american put option price. ™oupons.r. int steps=100. sigm—=0. Price a an European put option on the zero coupon bond using Black Scholes.sigm—. but paying coupon of H:S at date 1.u. C++ program: f=100.r.  a H:I.1.time. ™out << " zero coupon put option price = " << ˜ond option pri™e put zero ˜l—™k s™holes(f.Example Parameters: B a IHH. u=100.™oupons). K a IHH.time. ™out << " coupon bond put option price = " << ˜ond option pri™e put ™oupon ˜ond ˜l—™k s™holes(f. double double double double double ve™tor<double> ™oupon times.u.push ˜—™k(0. r a H:HS. ™out << endl.sigm—. There is also a coupon bond with the the same bond price. ve™tor<double> ™oupons. Output from C++ program: zero ™oupon put option pri™e a IFWPUWI ™oupon ˜ond put option pri™e a PFPPVSP zero ™oupon —meri™—n put option pri™eD ˜inomi—l a PFRQPVP 195 .time) << endl. Price a an European put option on the zero coupon bond using binomial approximation with 100 steps.

. . . . . . . The bond is due on a given date T. Debt is issued as a zero coupon bond. . . . who discussed the view of the rm as a call option. . . . . . . . Assume debt structure: There is a single debt issue. similar in structure to the Black Scholes equation for a call option. . . Assuming the rm value V follows the usual Brownian motion proces. The Black Scholes formula for a call option is B of risk free debt. . . . . 196 197 21. . reinterpret S as V . . 21. . . . Price debt by the price Scholes formula. Easiest seen from the interpretation of rm debt as the price of risk free debt. . . . . .1 The Merton Model This builds on the Black and Scholes (1973) and Merton (1973) framework to nd the value of the debt issued by the rm. . . and then subtract the price of the put. .Chapter 21 Credit risk Contents 21. . . . . . . . . . . debt is found as a closed form solution.1 The Merton Model . . . minus the value of a put option. . . . using the Black c a S ¡ N @dI A   K ¡ e r@T  tA N @dP A where I p P A@T   tA  T  t p dP a dI    T   t dI a ln  S¡ K C @r C N @¡A a The cumulative normal distribution p a Ke r@T  tA N @ dP A   SN @ dI A In the context here.2 Issues in implementation . Option pricing has obvious applications to the pricing of risky bonds. The put is priced as p a Ke r@T  tA N @ dP A   Vt N @ dI A 196 . . . . . . . . . . . . . . . . rm value. . . . . . . . . The ideas were already in Black and Scholes. .

where dI a ln  V ¡ t K C @r C I p P A@T   tA  T  t Note on interpretation: The spread between risky and risk free debt determined solely by the price of the put option. ™out << " Debt value = " << exp( r*„)*p   p << endl. Example The current value of the rm V a IHH. The model assumes a simple debt structure. double r=0.p. The risk free interest rate is 5% and the volatility of the rms value is 25%.05. most debt structures tend to be more complex.2 Issues in implementation   Firm value and rm volatility is unobservable.r. C++ program: double †=100. double sigm—=0. The rm has issued one bond with face value 90.„). double p=90. Output from C++ program: gredit ‚isk g—l™ul—tion he˜t v—lue a VIFVSWP 21.25. ™out << " Credit Risk Calculation " << endl.sigm—. 197 . Determine the value of the debt. double „=1. which is due to be paid one year from now. double p = option pri™e put ˜l—™k s™holes(†.

. . Again. . . as functions of term to maturity. 22. and the term structure models of Cox. . . . . . . . . . . . This is because they are prices. . . . . . . . . . . . . 22. . . . Since the relationship is nonlinear. . . . 22. Here are some considerations. . . One has to choose a functional form to estimate. The focus of this chapter is empirical. . .3 Cubic spline. . . . . . . . . . . . . . . this is a nontrivial problem. In the earlier case we considered two particular implementations of the term structure: A at term structure or a term structure estimated by linear interpolations of spot rates. The value of a payment today is the payment today. . . . Ingersoll. . . . . . . . . . . . . . . Nominal interest rates can not be negative. . . . . . . ( avoid arbitrage. . . . . and Ross (1985) and Vasicek (1977) are examples of the second kind. . . dynamic term structure models. . .5 Vasicek . . . . . . we consider ways in which on one can specify a term structure in a lower dimensional way. . 198 . . . . . . . ( of arbitrage opportunities. . dH a I. . 22. . . . We now consider a number of alternative term structure models. . . . Of A number of alternative ways of estimating the term structure has been considered. . . . . . . of estimating a nonlinear relationship between time and discount factors. . .g. . . . . . . . . . . . . . . yield on zero coupon bonds (spot rates) or forward rates. . the approximating function proposed in Nelson and Siegel (1987) and the cubic spline used by e. . . .1 The Nelson Siegel term structure approximation . dt ! dtCk V k > H). the prices of zero coupon bonds (discount factors). . . . . . . . . . . . . .Chapter 22 Term Structure Models Contents 22. . . . .4 Cox Ingersoll Ross. . this is to rt ! H V tA This is another implication of the absence Both discount factors and interest rates must be smooth functions of time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 201 203 206 209 211 We now expand on the analysis of the term structure in chapter 5. . but not so exible that it violates the economic restrictions on the term structure. . . the term structure is best viewed as an abstract class providing. . . . . . . . McCulloch (1971) are examples of the rst kind. . . . . . dt > H). while others are fully specied. . . . . Essentially we are looking at ways of doing curve-tting. .6 Readings . . . negative prices allow Discount factors must be a nonincreasing function of time. . . . . . . . or between time and spot rates. . . . . . . . . . . . which allows enough exibility to t the term structure. .2 Extended Nelson Siegel models . . . 22. . . As shown there. . . . . . . . . . . Some are purely used as interpolation functions. ( for abritrage. the models that follow.      Discount factors must be positive.

typically a set of treasury bonds. 22. Observing the prices of these bonds. Or: What term structure approximations provides the best t to this set of observed bond prices.1 The Nelson Siegel term structure approximation Nelson and Siegel (1987) proposes the parameterization shown in FormulaRefns 4 r@tA a . one asks: What set of discount factors is most likely to have generated the observed prices.What is the typical use of the functions we consider here? One starts with a set of xed income securities.

H C @

I C

P A
Formula 22.1:

t I   e  

5

t 

t C

P e  

h

i

Notation: t: Time to maturity. r spot interest rate,

0 ;

1 . .

const double& ˜et—H. }. }. double r = ˜et—H + (˜et—I+˜et—P) * ((1 exp( tl))/tl) + ˜et—P return r. const double& ˜et—P. #include <™m—th> using namespace std. double tl = t/l—m˜d—. l—m˜d— . const double& ˜et—P.1: Header le dening a term structure class wrapper for the Nelson Siegel approximation 199 . Nelson and Siegel (1987) parameterization of term structure The implementation of this calculation is shown in C++ Code 22.     * exp( tl). ˜et—I . Header le 22.1 { and C++ Code 22. ˜et—P . C++ Code 22. const double& l—m˜d—) { if (t==0. const double& l—m˜d—). public: term stru™ture ™l—ss nelson siegel(const double& ˜et—H. class term stru™ture ™l—ss nelson siegel X public term stru™ture ™l—ss private: double ˜et—H . const double& ˜et—I.1: Calculation of the Nelson and Siegel (1987) term structure model This is wrapped in a term structure class as shown in Header File 22.2 and : constants. const double& ˜et—I.0) return ˜et—H.2. double term stru™ture yield nelson siegel(const double& t. virtual double yield(const double& „) const.1.

2: Dening a term structure class wrapper for the Nelson Siegel approximation 200 . double term stru™ture ™l—ss nelson siegelXXr(const double& t) const { if (t<=0.l—m˜d— }. ˜et—I =˜I. const double& l) { ˜et—H =˜H. }.#include "fin_recipes. const double& ˜P.0) return ˜et—H . return term stru™ture yield nelson siegel(t. ˜et—P =˜P.h" term stru™ture ™l—ss nelson siegelXXterm stru™ture ™l—ss nelson siegel( const double& ˜H. l—m˜d— =l. C++ Code 22. ). const double& ˜I.˜et—I .˜et—P .˜et—H .

Example Using the parameters .

.H a H:HI.

I a H:HI. .

such as humped shapes.l—m˜d—) << endl.˜et—P. ™out << " forward rate (t1=1.l—m˜d—). double l—m˜d—=5. with parameters with clear obvious economic interpretations.01. C++ program: ™out << "Example calculations using the Nelson Siegel term structure approximation" << endl. Output from C++ program: double ˜et—H=0.P a H:HI. term stru™ture ™l—ss nelson siegel ns(˜et—H.d(t) << endl.˜et—I. ™out << " yield (t=1) = " << ns. It does have the problem that the term structure shapes that it allows is limited. To allow for more complex shapes. approximation was introduced by Lars Svensson. double ˜et—I=0.0.2 2 r@tA a .˜et—H. double ˜et—P=0.01. t2=2) = " << ns.˜et—I. it has been extended in various ways. parameterized as shown in A popular Formula 22. ™out << " using a term structure class" << endl.01.˜et—P. nd the 1 year discount factor and spot rate.2 Extended Nelson Siegel models The Nelson and Siegel (1987) model is simple. ix—mple ™—l™ul—tions using the xelson ƒiegel term stru™ture —pproxim—tion dire™t ™—l™ul—tionD yield a HFHQTQIRP using — term stru™ture ™l—ss yield @taIA a HFHQTQIRP dis™ount f—™tor @taIA a HFWTRQQU forw—rd r—te @tIaID tPaPA a HFHQHHTHP 22. ™out << " direct calculation.f (1.  a S:H and t a I in the Nelson Siegel approximation. double t=1.0. ™out << " discount factor (t=1) = " << ns.2) << endl. yield = " << term stru™ture yield nelson siegel(t.r(t) << endl. and the forward rate between years 1 and 2.

H C .

I Formula 22.2: t 3 I   e  1 2 t  C .

P t I   e  1 t 1   e  t1 3 2 C .

r spot interest rate. .Q t I   e  2 t 2   e  t2 3 Notation: t: Time to maturity.

0 . .

.1 .

4. Svensson's extension of the Nelson and Siegel (1987) parameterization of term structure This is wrapped in a term structure class as shown in Header File 22.2 and C++ Code 22.2 and : constants. 201 .

˜et—Q . t—uP =t—uP.#include <™m—th> using namespace std. double term stru™ture yield svensson(const double& t.2: Header le dening a term structure class wrapper for the Svensson model #include "fin_recipes.t—uI .˜et—H . t—uI public: term stru™ture ™l—ss svensson(const double& const double& const double& const double& const double& const double& virtual double yield(const double& „) const. ˜et—Q. const double& ˜et—P. const double& t—uI. const double& t—uP){ if (t==0. ˜et—P . t—uP). ˜et—Q .0) return ˜et—H. ˜et—P * ( ((1 exp( t/t—uI))/(t/t—uI)) ˜et—Q * ( ((1 exp( t/t—uP))/(t/t—uP)) r. double r = ˜et—H.3: Calculation of Svensson's extended Nelson and Siegel (1987) term structure model class term stru™ture ™l—ss svenssonXpu˜li™ term private: double ˜et—H . const double& ˜I. t—uI. C++ Code 22. }. { t—uP . C++ Code 22. const double& t—uP) { ˜et—H =˜H.0) return ˜et—H .   exp( t/t—uI) ).˜et—I . ˜et—P =˜P.t—uP }. ˜et—H. ˜et—I .   exp( t/t—uP) ). const double& t—uI. const double& ˜Q. const double& ˜et—Q. const double& ˜et—H. t—uI =t—uI. double term stru™ture ™l—ss svenssonXXr(const double& t) const { if (t<=0. const double& ˜et—I. return term stru™ture yield svensson(t. ˜et—P.h" term stru™ture ™l—ss svenssonXXterm stru™ture ™l—ss svensson( const double& ˜H. ˜et—Q =˜Q. Header le 22.4: Dening a term structure class wrapper for the Svensson model 202 . }. stru™ture ™l—ss . ). }. ˜et—I.˜et—P . const double& ˜P. ˜et—I =˜I. r += r += r += return ˜et—I* ((1 exp( t/t—uI))/(t/t—uI)) .

3 and Approximating a discount function using a cubic spline wraps this calculations into a term structure class. FI . double term stru™ture dis™ount f—™tor ™u˜i™ spline(const double& t. for (int i=0.3: Term structure class wrapping the cubic spline approximation 203 . const double& dI. const double& ™I. double ™ . #include <™m—th> #include <ve™tor> using namespace std. return d.h" #include <ve™tor> using namespace std. const double& ˜I. const ve™tor<double>& f.   }. He later added taxes in McCulloch (1975).size(). } else { break. parameters: fbI .5 shows the calculation using this approximation.3)). virtual double d(const double& „) const. virtual £term stru™ture ™l—ss ™u˜i™ spline(). ve™tor<double> f . dI .6 #include "fin_recipes. double d . this is a simple linear regression. not the yields.i<knots. ¡ ¡ ¡ . }.2)) + dI*(pow(t. C++ Code 22. }.0 + ˜I*t + ™I*(pow(t. const ve™tor<double> & knots). Cubic splines are well known for their good interpolation behaviour. The cubic spline parameterization was rst used by McCulloch (1971) to estimate the nominal term structure. Header le 22. class term stru™ture ™l—ss ™u˜i™ spline X public term stru™ture ™l—ss { private: double ˜ . }. const ve™tor<double>& knots){ double d = 1.22. and we have K knots . const ve™tor<double>& f. C++ Code 22. C++ Code 22.5: Header File 22. FK g If the spline knots are known. const double& d. ˆ d@tA a I C bI t C cI tP C dI tQ C Fj @t   tj AQ Ift<tj g j aI Here K IfAg is the indicator function for an event To estimate this we need to nd the QCK A.3)). The cubic spline was also used by Litzenberger and Rolfo (1984). cI .3 Cubic spline. ve™tor<double> knots . public: term stru™ture ™l—ss ™u˜i™ spline(const double& ˜. In this case the qubic spline is used to approximate the discount factor.i++) { if (t >= knots[i]) { d += f [i] * (pow((t knots[i]). const double& ™.

push ˜—™k(knots[i]).size(). d = d.™ . const double& ™. for (int i=0. }. const ve™tor<double>& knots) ˜ = ˜. const ve™tor<double>& f. knots . { double term stru™ture ™l—ss ™u˜i™ splineXXd(const double& „) const { return term stru™ture dis™ount f—™tor ™u˜i™ spline(„.f .˜ . ™ = ™. ).size()){ return.h" term stru™ture ™l—ss ™u˜i™ splineXX term stru™ture ™l—ss ™u˜i™ spline ( const double& ˜. const double& d.d .size()!=knots.knots }.6: Term structure class wrapping the cubic spline approximation 204 . knots .™le—r().™le—r().push ˜—™k(f [i]).#include "fin_recipes.i<f. C++ Code 22. }. f . if (f.++i) { f . }.

double d= 0. and the forward rate between 1 and 2 years.1. knots. ™out << " discount factor (t=1) = " << ™s. C++ program: ™out << "Example term structure calculations using a cubic spline " << endl.™. f. ™out << " direct calculation.d. term stru™ture ™l—ss ™u˜i™ spline ™s(˜. knots.d(1) << endl. d a  H:I. double ˜=0. P f aR H:HI H:HI  H:HI P Q S knots a R P U IP Q S Find short rates and discount factors for 1 year.Example Using the parameters b a H:I c a H:I.01).push ˜—™k(2).knots) << endl.01). ™out << " forward (t1=1. ve™tor<double> knots. f. ™out << " yield (t=1) = " << ™s.knots). t2=2) = " << ™s. double ™=0.push ˜—™k(7).d.push ˜—™k(12). knots.1.push ˜—™k( 0.push ˜—™k(0.f.push ˜—™k(0. Output from C++ program: ix—mple term stru™ture ™—l™ul—tions using — ™u˜i™ spline dire™t ™—l™ul—tionD dis™ount f—™tor @taIA IFI …sing — term stru™ture ™l—ss yield @taIA a EHFHWSQIHP dis™ount f—™tor @taIA a IFI forw—rd @tIaID tPaPA a HFQIVRSR 205 .2) << endl. ™out << " Using a term structure class " << endl.˜.01).r(1) << endl. ve™tor<double> f . f.™.1. discount factor (t=1) " << term stru™ture dis™ount f—™tor ™u˜i™ spline(1.f.f (1.

double term stru™ture dis™ount f—™tor ™ir(const double& t. the market  the longrun mean of the process and . T Ae B@t. .5*(k—pp—+l—m˜d—+g—mm—)*t). Pe @T  tA   I @ C  C A@e@T  tA   IA C P risk Five parameters: r.2). const double& r. double e = pow((enumI/denum). double enumI= 2*g—mm—*exp(0.p). It is commonly used in academic work because it is a general equilibrium model that still is simple enough to let us nd closed form expressions for derivative securities. T A a A@t. dr@tA a @   r@tAAdt C  r@tAdW The discount factor for a payment at time T.22. double g—mm— = sqrt(pow((k—pp—+l—m˜d—). T A a @ C  C A@e@T  tA   IA C P 1 4 5 2 2  and B @t. The short interest rate.       }.T Ar@tA where p a @ C AP C PP P e 2 @CC A@T  tA A@t. The Cox et al. #include <™m—th> using namespace std. const double& sigm—){ double sigm— sqr=pow(sigm—. C++ Code 22. double denum = (g—mm—+k—pp—+l—m˜d—)*(exp(g—mm—*t) 1)+2*g—mm—. the mean reversion parameter. p d@t. const double& k—pp—.2)+2. (1985) model is the best known example of a continuous time. T A a parameter.0*sigm— sqr).7: Calculation of the discount factor using the Cox et al. const double& l—m˜d—. double df—™t=e*exp( f*r). const double& thet—. double f = (2*(exp(g—mm—*t) 1))/denum. general equilibrium model of the term structure. . double p=2*k—pp—*thet—/sigm— sqr.4 Cox Ingersoll Ross. the short term interest rate. return df—™t. the variance rate of the process. (1985) model 206 .

public: £term stru™ture ™l—ss ™ir(). const double& th.sigm— }. Cox et al. l—m˜d— =l. double thet— .4: Class denition. header le #include "fin_recipes. const double& sigm—). const double& k. const double& l. const double& k. GG me—n reversion p—r—meter GG risk —version double l—m˜d— . }. const double& th. GG long run me—n GG vol—tility double sigm— . C++ Code 22. sigm— =sigm—.8: Class denition. (1985) model 207 . thet— =th. GG interest r—te double k—pp— .k—pp— . const double& sigm—) { r =r. ).l—m˜d— . }. const double& l. Cox et al.thet— . (1985) model. term stru™ture ™l—ss ™ir(const double& r.#include "fin_recipes.r . double term stru™ture ™l—ss ™irXXd(const double& „) const{ return term stru™ture dis™ount f—™tor ™ir(„. k—pp— =k. Header le 22. virtual double d(const double& „) const.h" GGterm stru™ture ™l—ss ™irXX£term stru™ture ™l—ss ™ir@A{Y}Y term stru™ture ™l—ss ™irXXterm stru™ture ™l—ss ™ir(const double& r.h" class term stru™ture ™l—ss ™ir X public term stru™ture ™l—ss { private: double r .

 a H:HI. double k—pp—=0.08. double thet—=0. ™out << " discount factor (t=1) = " << ™ir.sigm—).k—pp—. double l—m˜d—=0.  a H:I.r(1) << endl.d(1) << endl. ™out << " direct calculation. discount factor (t=1): " << term stru™ture dis™ount f—™tor ™ir(1.f (1. ™out << " forward (t1=1. = 0. t2=2) = " << ™ir.  a H:HV and  a H:H.thet—. t a I. Find ™out << "Example calculations using the Cox Ingersoll Ross term structure model " << endl. sigm—) << endl. thet—. and forward rate between years 1 and 2. ™out << " using a class " << endl.Example Parameters: short rate and discount factor for C++ program: r a H:HS.2) << endl.1.05.l—m˜d—. Use the CIR term structure model. term stru™ture ™l—ss ™ir ™ir(r. k—pp—. ™out << " yield (t=1) = " << ™ir. double r Output from C++ program: ix—mple ™—l™ul—tions using the gox sngersoll ‚oss term stru™ture model dire™t ™—l™ul—tionD dis™ount f—™tor @taIAX HFWSIITT using — ™l—ss yield @taIA a HFHSHHTTV dis™ount f—™tor @taIA a HFWSIITT forw—rd @tIaID tPaPA a HFHRWVUST 208 . l—m˜d—. double sigm—=0.01. r.0.

((f time)*(——*˜ 0. r. ˜.h" class term stru™ture ™l—ss v—si™ek X public term stru™ture ™l—ss { private: double r . } else { f e = (1.0 = exp( =   exp( —*time))/—. Header le 22. double term stru™ture dis™ount f—™tor v—si™ek(const const const const const double e. double — . double sigm— .0){ double& double& double& double& double& time.f.5 Vasicek #include <™m—th> using namespace std. const double& —. double —— = —*—. double df—™t return df—™t.5*sigm— e*exp( f*r). virtual double dis™ount f—™tor(const double& „) const. if (—==0. exp(sigm— sqr*pow(time.9: Calculating a discount factor using the Vasicek functional form #include "fin_recipes.0. sigm—){ f e = = time. public: term stru™ture ™l—ss v—si™ek(const double& r. double ˜ . —.22. } C++ Code 22. const double& sigm—). Vasicek (1977) model 209 . }. double sigm— sqr = sigm—*sigm—. }.5: Class denition.3))/6. sqr))/——  ((sigm— sqr*f*f)/(4*—))). const double& ˜.

Vasicek (1977) model 210 .h" term stru™ture ™l—ss v—si™ekXXterm stru™ture ™l—ss v—si™ek(const double& r.r . sigm— =sigm—. const double& —. ).— .10: Class denition. C++ Code 22.#include "fin_recipes. — =—. const double& sigm—) r =r. ˜ =˜. const double& ˜.sigm— }. }.˜ . { double term stru™ture ™l—ss v—si™ekXXd(const double& „) const{ return term stru™ture dis™ount f—™tor v—si™ek(„.

™out << " discount factor (t=1) = " << v™.1.f (1. double —= 0. t a I.sigm—). A textbook treatment of estimation and tting of term structure models can be found in (Martinelli.05. double ˜=0.1. r.1. double r=0.—. ™out << " using a term structure class " << endl. Priaulet.Example Parameters discount factor for C++ program: r a H:HS. t2=2) = " << v™. and forward rate between years 1 and 2. ™out << " direct calculation. 2003.d(1) << endl. sigm—) << endl. Find short rate and ™out << "Example term structure calculation using the Vasicek term structure model" << endl. a a  H:I. which lead to the paper published as Green and Ødegaard (1997). ™out << " forward rate (t1=1. Ch 4) 211 . Output from C++ program: ix—mple term stru™ture ™—l™ul—tion using the †—si™ek term stru™ture model dire™t ™—l™ul—tionD dis™ount f—™tor @taIAX HFWSSRHV using — term stru™ture ™l—ss yield @taIA a HFHRSTITV dis™ount f—™tor @taIA a HFWSSRHV forw—rd r—te @tIaID tPaPA a HFHPVIRUT 22.r(1) << endl. term stru™ture ™l—ss v—si™ek v™(r. discount factor (t=1): " << term stru™ture dis™ount f—™tor v—si™ek(1.6 Readings The methods in this chapter I rst studied in my dissertation at Carnegie Mellon University in 1992. and Priaulet. double sigm—=0. —. ˜. b a H:I.2) << endl. ™out << " yield (t=1) = " << v™.˜.  a H:I Use the Vasicek term structure model.

Chapter 23 Binomial Term Structure models Contents 23. . . C++ Code 23. . it is to apply the same binomial approach that is used to approximate options in the Black Scholes world. . . . . . . it ignores the fact that at the maturity of the bond. . does not always get it right. . the unifying theme of which is that they are built by building of the interest rate. . . . . . . but the random variable is now the interest rate. as done in chapter 20. . In the next chapter we illustrate this more generally. . . 212 . . For example. . Essentially. . . . . and it may be necessary to keep track of the whole tree of interest rates. . Such a tree can then be used to price various xed income securities. . . . . . . the bond volatility is zero. . . . . . . trees 23.1 The Rendleman and Bartter model . . 212 214 Pricing bond options with the Black Scholes model. This behaviour is not captured by the assumptions underlying the Black Scholes assumption. . . . . . This has implications for multiperiod discounting: Taking the present value is now a matter of choosing the correct sequence of spot rates. . . . . or its binomial approximation. . . . . . . . . .1 The Rendleman and Bartter model The Rendleman and Bartter approach to valuation of interest rate contingent claims (see Rendleman and Bartter (1979) and Rendleman and Bartter (1980)) is a particular simple one. . . . . . The bond volatility decreases as one gets closer to the bond maturity. We therefore look at more complicated term structure models. . . .2 Readings . . . here we show a direct implementation of the original model.1 implements the original algorithm for a call option on a (long maturity) zero coupon bond. . . . . . . 23. .

1: RB binomial model for European call on zero coupon bond 213 . p down = 1. double ˜ond option pri™e ™—ll zero —meri™—n rendlem—n ˜—rtter(const double& ˆ. exp( r[i]*delt— t)*(p up*g[i+1]+p down*g[i])). GG term stru™ture p—r—mters const double& interest.i<™urr step. }. for (int ™urr step=no steps. ve™tor<double> r(no steps+1).i<™urr step. const double& option m—turity. int no ™—ll steps=int(no steps*option m—turity/˜ond m—turity).™urr step>no ™—ll steps.0.}. ve™tor<double> €(no steps+1). GG ™urrent short interest r—te const double& ˜ond m—turity. }. }. double double double double u=exp(ƒ*sqrt(delt— t)).€[i] ˆ). for (int i=0.++i){ €[i] = m—turity p—yment.i++) { }. }. for (int i=1. d=1/u. const int& no steps) { double delt— t = ˜ond m—turity/no steps. p up = (exp(w*delt— t) d)/(u d).i<=no steps. €[i] = exp( r[i]*delt— t)*(p down*€[i]+p up*€[i+1]). €[i] = exp( r[i]*delt— t)*(p down*€[i]+p up*€[i+1]). }.i<=no ™—ll steps.i<=no steps. g[i]=m—x(€[i] ˆ.0 p up.#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std.i++) { r[i] = r[i]*u. }. ™urr step) { for (int ™urr step=no ™—ll steps. { ve™tor<double> g(no ™—ll steps+1).  ™urr step) for (int i=0. return g[0].™urr step>=0. GG time to m—turity for underlying ˜ond const double& m—turity p—yment. r[0]=interest*pow(d.      r[i] = r[i]*u. const double& w. for (int i=0.++i){ g[i]=m—x(0. const double& ƒ.no steps).++i){ r[i]=r[i 1]*uu. for (int i=0. double uu=u*u. C++ Code 23.

Example Parameters: K a WSH. double ƒ=0. ™out << ˜ond option pri™e ™—ll zero —meri™—n rendlem—n ˜—rtter( u.10. the bond matures in year 5. option m—turity. ˜ond m—turity p—yment. double option m—turity=4. double ˜ond m—turity=5. int no steps=100. double interest=0. Rendleman and Bartter (1979) and Rendleman and Bartter (1980) are the original references for building standard binomial interest rate trees. w. Output from C++ program: ‚endlem—n f—rtter pri™e of option on zero ™oupon ˜ondX HFHHUIQTTI 23. C++ program: double u=950. ƒ. interest. double ˜ond m—turity p—yment=1000. S a H:IS and M a H:HS The interest rate is 10%. no steps).05.15. 214 .2 Readings General references include Sundaresan (2001). The option matures in 4 years. with a bond maturity payment of 1000. double w=0. Price the option on the zero coupon bond using a RandlemanBartter approximation with 100 steps. ™out << " Rendleman Bartter price of option on zero coupon bond: ". ˜ond m—turity.

. . . . 24. . . . . . .Chapter 24 Interest rate trees Contents 24. . . . . . . . . 24. . . . . . . . . . . . . . . . . . . . . . . . . . . This leads to the same binomial approximation. .1 The movement of interest rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24. . . The rst need in such a procedure is to specify the future evolution of interest rates. 215 217 217 219 221 In this chapter we show a way of building interest rate trees and apply it to the pricing of various xed income securities. . . . . . . . . . . . . . . . 24. . 24. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . for one period: rH ¨¨ r rr B ¨ ru ¨ ¨ r j r rd or several periods: 215 . . . . . . . . . .1 The movement of interest rates We will assume that interest rates follow a Geometric Brownian Motion process dr a rdt C rdZ This is the same assumption which was used for stock prices in the Black Scholes case. . . . . . . . . . . . . . .3 Pricing bonds .5 Readings . . . . . . . . . . . . .4 Callable bond . . . .2 Discount factors . .

++i) { double rtop=r[r. const double& u.j<i. Build a 2 period interest rate tree.i<=n. u a I:HP.tree] r ]. 216 . rtop=rH.i).1.push ˜—™k(r). return tree. tree. ve™tor<ve™tor<double> > interest r—te trees g˜m ˜uild(const double& rH.push ˜—™k(rtop). }. ve™tor<double> r(1). const int& n){ ve™tor< ve™tor<double> > tree. r = [rtop. we therefore separate the building of the tree in one routine. r[0]=rH.push ˜—™k(r).1: Building interest rate tree = interest r—te trees g˜m ˜uild(rH. tree.++j){ r[j] = d*r[j]. as shown in C++ Code 24. }.d. C++ Code 24. r.1: Example Parameters: Building interest rate tree rH   IH7. tree=[r].d*r].n) r=[rH]. d a H:WW. for (int i=1. #include <ve™tor> #include <™m—th> using namespace std. for i=1:n rtop = u * rtop. for (int j=0. const double& d. }.u. endfor endfun™tion function tree w—tl—˜ Code 24. tree=[ [zeros(1.size() 1]*u.rH B ¨¨ ru¨¨¨ B ¨ rr r ¨¨ r j r ¨¨ r B ¨ rr ¨ r rd ¨¨ j r¨ rr rr j r ruu rud rdd When using this approach it turns out to be useful to keep the whole tree around.

1. T A be the discount factor at time t for a time T du @I.99. ™out << " Time 0: " << tree[0][0] << endl. Instead of interest rates we need prices.02. PA a e r0 @qdu @I. we need the following set of discount factors ¨ ¨¨ ¨ d@H rr . u a I:HP.3). ™out << " Interest rate tree: " << endl. If we at time 0 want to price cash ows at time 2. i.2 Discount factors We want to price bonds and other xed income securities. PA r rr B ¨ ¨ ¨¨ r r j r dd @I. with maturities 1 and 2. not interest rates. Let q a H:S. Let d@t. and for all relevant maturities. PAA The parameter q serves the same purpose as the state price probability. Suppose you have q and the tree of short interest rates. but it is found dierently. ™out << " Time 2: " << tree[2][0] << " " << tree[2][1] << " " << tree[2][2] << endl.3 Pricing bonds Pricing straight bonds is then just a matter of the usual recursive valuation Example Parameters: rH   IH7.0. ™out << " Time 1: " << tree[1][0] << " " << tree[1][1] << endl.1. discount factors. which needs to be specied at every point of the tree. q? Exercise 24. how would you back out Exercise 24. The interest rate tree therefore needs to be used to generate discount factors. PA C @I C qAdd @I. Output from C++ program: snterest r—te treeX „ime HX HFI „ime IX HFHWW HFIHP „ime PX HFHWVHI HFIHHWV HFIHRHR 24. which are used as follows: In constructing trees of discount we need one additional piece of information. which contains sets of future cash ows.2.1. 217 .C++ program: ve™tor< ve™tor<double> > tree = interest r—te trees g˜m ˜uild(0. How would you calculate the t-period spot rate? 24. d a H:WW.e. Determine the price of a 3 period coupon bond with coupon of 10 and face value of 100. PA q. PA payment. Given the prices of two discount bonds. d@H.

d.i++){ v—lue[i]=™)ow[n 1]. double d=0. double q=0.0). double interest r—te trees g˜m v—lue of ™—sh)ows(const ve™tor<double>& ™)ow.02. ve™tor< ve™tor<double> > tree ve™tor<double> ™—sh)ows. v—lues[n 1]=v—lue.t>0.u. = interest r—te trees g˜m ˜uild(rH. int n=3. ve™tor<double> v—lue(n). ™—sh)ows. by adjusting the inputs to the routine? 218 .++i){ v—lue[i]=™)ow[t 1]+exp( r tree[t 1][i])*(q*v—lues[t][i]+(1 q)*v—lues[t][i+1]). }. ™out << "Bond price B = " << interest r—te trees g˜m v—lue of ™—sh)ows(™—sh)ows. How would you modify the code to allow for dierences in timing of interest rate changes and cashows.push ˜—™k(0).3. for (int i=0.2: C++ program: Valuing cash ows double rH=0. }. return v—lues[0][0].q).size(). for (int t=n 1. double u=1.0. Or can you do this alternatively. }.tree. }.push ˜—™k(10). ™—sh)ows.#include <ve™tor> #include <™m—th> using namespace std. for (int i=0. ™—sh)ows.   v—lues[t 1]=v—lue.99. ve™tor< ve™tor<double> > v—lues(n).i<t.  t){ ve™tor<double> v—lue(t. ™—sh)ows. Output from C++ program: fond pri™e f a WVFSWWU Exercise 24.1.n). C++ Code 24.push ˜—™k(10). The example just presented assumes cash ows dates matches the dates of interest rate changes.i<n. const ve™tor< ve™tor<double> const double& q){ int n=™)ow.push ˜—™k(110).5. >& r tree.

the face value plus the currently due coupon are paid at that time and the bond is canceled. Valuing the noncallable bond The cash ow lattice 219 .3: Example Valuing callable bond Construct a short rate lattice for periods (years) 0 through 9 with an initial rate of rates determined by a multiplicative factors u a I:P or d a H:W.4 10. double& ™—ll pri™e){ v—lues[n 1]=v—lue.i<t. ve™tor< ve™tor<double> > v—lues(n). return v—lues[0][0]. }.9 11.4 8.4 13. Using this lattice. }.++i){ v—lue[i]=™)ows[t 1]+exp( r tree[t 1][i])*(q*v—lues[t][i]+(1 q)*v—lues[t][i+1]).2 17.3 5. Suppose this bond can be called by the issuing party at any time after 5 years.6 0 1 2 3 4 5 6 7 8 9 31.1 12.5 17.0 23.   v—lues[t 1]=v—lue.4 6.5 4.3 7. for (int t=n 1.0. ve™tor<double>& ™)ows.0 5.3 3.7 4.2 16. Assign q a H:S.6 5. double interest r—te trees g˜m v—lue of ™—ll—˜le ˜ond(const const const const const int n=™)ows.4 2. 2. ve™tor< ve™tor<double> >& r tree.) What is the fair value of this bond? The interest rate lattice: step: nodes: 25.1 9.9 7.i<n.4 10.0).1 9.4 9.1 2.8 2. }.4 6.3 1.5 10.5 13.1 6.t>0.  t){ ve™tor<double> v—lue(t.2 6.7 3.3 4.3 14.5 4.6 3.8 7.9 14.0 5.8 4.2 6. }. }.size(). int& (rst ™—ll time.8 5.1 7.8 5.2 8. double& q. C++ Code 24.24.8 21.1 3.1 3.9 19.6 7. if (t>=(rst ™—ll time){ v—lue[i]=min(v—lue[i]. (When the bond is called.4 Callable bond A slightly more involved example is a callable bond.™—ll pri™e). ve™tor<double> v—lue(n). for (int i=0.2 3. #include <ve™tor> #include <™m—th> using namespace std. for (int i=0.i++){ v—lue[i]=™)ows[n 1].9 12.9 8. nd the value of a 10-year 6% bond. rH a T7 and with successive 1.1 4.

04 95.46 96.00 106.70 81. The following set of values is calculated step: nodes: 83.31 79.00 106.19 101.00 106.00 106.88 101.45 98.79 113.08 104.11 104.90 102.89 89.59 77.00 106.18 101.29 111.28 88.07 82.00 106.67 67.39 107.36 108.00 106.00 0 1 2 3 4 5 6 7 8 9 10 106.08 96.71 108.80 100.00 The value of the bond is B a VW:WH.04 95.32 107.03 95.39 109.00 106.00 106.32 89.00 106.01 104. 2.00 106.32 106.19 81.28 88.21 110.02 102.53 88.13 89.09 79.84 69. The callable will be called when the value of the bond is above par.46 96.78 115.19 101.24 105.05 95.00 106. because the issuing company can issue a bond at a lower interest rate.11 104.02 102.78 73.49 106.35 101.00 106.00 106.29 114.00 106.14 102.00 The value of the bond is B a VW:QS.45 92.93 96.00 106.00 106.04 105.27 89.44 89.00 79.78 73.59 77.03 106.57 112.38 90.45 92.20 105.14 68.00 82.42 106.84 69.00 106.56 0 1 2 3 4 5 6 7 8 9 10 106.93 96.56 108.00 106.00 106.06 99.00 106.27 89.00 106.07 82.26 79.10 110.14 68.59 107.21 105.38 72. 220 .06 99.49 106.00 106.45 98.00 106.32 89.38 72.09 96.37 111.00 106.00 106.19 101.22 85.00 106.00 90.step: nodes: 0 1 2 3 4 5 6 7 8 9 10 106 6 6 6 6 6 6 6 6 6 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 106 106 106 106 106 106 106 106 106 106 The value lattice: step: nodes: 83.37 108.00 106.70 89.77 109.05 85.32 82.00 106.20 105.57 88.67 67.14 102.96 115.15 108.

push ˜—™k(0).tree. ƒtr—ight ˜ond pri™e a VWFWHIU g—ll—˜le ˜ond pri™e a VWFPRVQ Exercise 24. ™out << "Straight bond price = " << interest r—te trees g˜m v—lue of ™—sh)ows(™—sh)ows. = interest r—te trees g˜m ˜uild(rH.5 Readings General references include Sundaresan (2001).tree. double ™—ll pri™e = 106.u. int n=10. ™out << "Callable bond price = " << interest r—te trees g˜m v—lue of ™—ll—˜le ˜ond(™—sh)ows. (rst ™—ll time.4.q) << endl. ve™tor< ve™tor<double> > tree ve™tor<double> ™—sh)ows. How would you price a call option on a coupon bond in this setting? 24.q.push ˜—™k(6).2. double q=0.push ˜—™k(106). Output from C++ program: for (int t=1.t<=9. }. ™—sh)ows.9. ™—ll pri™e) << endl. double u=1.n). double d=0. int (rst ™—ll time = 6.06.d.++t){ ™—sh)ows. ™—sh)ows. Rendleman and Bartter (1979) and Rendleman and Bartter (1980) are the original references for building standard binomial interest rate trees.5.C++ program: double rH=0. 221 .

Chapter 25 Building term structure trees using the Ho and Lee (1986) approach 25. 25.1 Intro In this section we build interest rate trees following the orgiginal paper of Ho and Lee (1986). We will follow the analysis in the paper.3 Ho Lee term structure class 222 . and use it to illustrate how yu can build trees of more complex term structures than the simple binomial trees of the interest rate. The selling point of the original paper was that one could t an initial term structure and then specify an evolution of the term structure consistent with this initial term structure.2 Building trees of term structures 25.

const double& u. C++ Code 25. const double& delt—. }. pi =pi. const double& delt—. i =i. double delt— double pi . int & i. const double& pi){ initi—l term =(tted term. stru™ture ™l—ss* (tted term. double pri™e europe—n ™—ll option on ˜ond using ho lee(term stru™ture ™l—ss* initi—l.1: Term structure class for Ho-Lee 223 . double& l—m˜d—. const double& option time to m—turity). . const int & i. const ve™tor<double>& underlying ˜ond ™)ows. int i .1: Term structure class for Ho-Lee #include "fin_recipes. const double& pi). Header le 25. n =n.#include "fin_recipes. public: { term stru™ture ™l—ss* initi—l term . term stru™ture ™l—ss ho lee(term const const const const double d(const double& „) const.h" class term stru™ture ™l—ss ho lee X public term stru™ture ™l—ss private: int n . }. const int & n. const int& no steps. double& pi). ve™tor< ve™tor<term stru™ture ™l—ss ho lee> > term stru™ture ho lee ˜uild term stru™ture tree(term stru™ture ™l—ss* initi—l.h" term stru™ture ™l—ss ho leeXXterm stru™ture ™l—ss ho lee(term stru™ture ™l—ss* (tted term. int & n. delt— =delt—. const double& pi. const ve™tor<double>& underlying ˜ond ™)ow times. const double& delt—.

}.j. }. }.   }.delt— )). return d.pi).delt—.delt— .j<=t.#include "fin_recipes. for (int t=0. calculation of discount function #include "fin_recipes.++t){ hl tree.pi ) .„))). const double& pi){ return (1.j<n .++j){ term stru™ture ™l—ss ho lee hl(initi—l. hl tree[t].d(„+n )/(*initi—l term ).t<5.++j){ d *= h„(„+(n  j). }.push ˜—™k(ve™tor<term stru™ture ™l—ss ho lee>()).d(n ). for (int j=0. return hl tree. const double& delt—.„*(n  i C++ Code 25.h" ve™tor< ve™tor<term stru™ture ™l—ss ho lee> > term stru™ture ho lee ˜uild term stru™ture tree(term stru™ture ™l—ss* initi—l. double term stru™ture ™l—ss ho leeXXd(const double& „) const{ double d=(*initi—l term ).pi ) / h„(n  j. }.t. const int& no steps. d *= h„(„.pi )*pow(delt— . const double& pi){ ve™tor< ve™tor<term stru™ture ™l—ss ho lee> > hl tree. C++ Code 25. .delt— .3: Building a term structure tree 224 . const double& delt—.push ˜—™k(hl).2: Term structure class for Ho-Lee. for (int j=1.0/(pi+(1 pi)*pow(delt—.h" GG#in™lude term stru™ture ™l—ss ho leeFh inline double h„(const double& „.

iA“ Pi@nA @IA where C @n. iA a ‘C @n C I. but the timing of cash ows changes as you move in the tree. and use it. The value of the bond at the dierent nodes change because the term structure you use for discounting is changing. together with the term structures in the individual nodes. t: What are the future cash ows We build a small class that contains this information. Its cash ows at each future date does not depend on the state. What we are pricing are typically state and time-contingent claims to cash ows. iA is the value of a security at time n at node i. 225 . Let us illustrate pricing of an (European) call option on some underlying bond. i C IA C @I   AC @n C i. Suppose this bond is risk free. to nd the bond price at each node.25.4 Pricing things We now have access to what we need to do pricing through the recursive relationship C @n. This bond price is then used to nd the option value at each node. It is therefore necessary to some way gure out at date when you want to price the underlying bond at that date.

size().i<=t.0) { tmp times. while (times.push ˜—™k(time ™ontingent ™—sh )ows(times. ve™tor<double> v—lues(„+1). }. C++ Code 25.push ˜—™k(times[i] 1).™—sh )ows. hl tree[„+1][i]) }.times. for (int i=0.„+1. const ve™tor<double>& initi—l ™)ows){ ve™tor<time ™ontingent ™—sh )ows> ve™ ™f . const double& pi. double pri™e europe—n ™—ll option on ˜ond using ho lee(term stru™ture ™l—ss* initi—l.™)ows)). t){ ve™tor<double> v—lues this(t+1). ve™tor<double> ™—sh )ows.i<times. return ve™ ™f .4: Pricing of European call option on straight bond using Ho-Lee 226 . int no ™)ows(){ return times.++i){ v—lues this[i]=(pi*v—lues[i+1]+(1. for (int i=0. }.++i){ if (times[i] 1.h" class time ™ontingent ™—sh )ows{ public: ve™tor<double> times. }.   u).0>=0. const double& delt—.size()>0){ ve™ ™f. }.    v—lues=v—lues this.push ˜—™k(™)ows[i]). underlying ˜ond ™)ows). tmp ™)ows. ve™ ™f [„+1]. const double& u. ve™tor<time ™ontingent ™—sh )ows> ve™ ™f = ˜uild time series of ˜ond time ™ontingent ™—sh )ows(underlying ˜ond ™)ow times.++i){ v—lues[i]=m—x(0. }. }. ve™tor<time ™ontingent ™—sh )ows> ˜uild time series of ˜ond time ™ontingent ™—sh )ows(const ve™tor<double>& initi—l times.˜onds pri™e(ve™ ™f [„+1]. ™—sh )ows=in ™)ows.size(). const ve™tor<double>& underlying ˜ond ™)ows. for (int t=„. times }. const ve™tor<double>& underlying ˜ond ™)ow times. ve™tor<double> times = initi—l times.0001). time ™ontingent ™—sh )ows(const ve™tor<double>& in times. }.t>=0. ve™tor<double> tmp ™)ows.   }.#include "fin_recipes. = tmp times. const ve™tor<double>& in ™)ows){ times=in times.d(1). ve™tor<ve™tor<term stru™ture ™l—ss ho lee> > hl tree = term stru™ture ho lee ˜uild term stru™ture tree(initi—l.pi).i<=„. return v—lues[0]. }. const double& time to m—turity){ int „ = int(time to m—turity+0. for (int i=0.0.0 pi)*v—lues[i])*hl tree[t][i].delt—. ™)ows = tmp ™)ows. ve™tor<double> ™)ows = initi—l ™)ows. ve™tor<double> tmp times.

You will price the options using a Ho-Lee approach with parameters  a H:S and  a H:WV. The term structure is at with an interest rate of 10% (continously compounded). Price the option using two dierent assumptions about the current term structure: 1.Example You are pricing options on a 5 year zero coupon risk free bond. 2. The options are European calls with a time to maturity of 3 years. The current term structure has been estimated using a Nelson Siegel parameterization with parameters .

.H a H:HW.

.I a H:HI.

double ˜et—P=0.u.˜et—I.3. C++ program: term stru™ture ™l—ss* initi—l=new term stru™ture ™l—ss )—t(r).delt—.delt—. In the Ho and Lee (1986) paper there is a typo in equation (22). What additional informaiton must be kept track of ? Exercise 25. delete (initi—l).98. initi—l = new term stru™ture ™l—ss nelson siegel(˜et—H. double time to m—turity=3. To see that it is correct us it to price a (straight) bond and then compare the value calculated in the tree with the value using the current term structure. times.1. double l—m˜d—=5. Implement such a procedure.09. times.5 References The discussion in this chapter follows closely the original paper Ho and Lee (1986) 227 . ™out << " Flat term structure " << endl.time to m—turity). ve™tor<double> ™)ows.˜et—P.™)ows. ™out << endl.™)ows. double r=0.u.l—m˜d—). times. pi. ve™tor<double> times.5. Output from C++ program: double delt—=0.0). pi. Then modify the code to build in a callable bond feature. ™out << endl. double u=80.P a H:HI and  a S:H. pl—t term stru™ture ™a TFRTQPQ xelson ƒiegel term stru™ture ™a TFQQPQV Exercise 25. double pi=0.time to m—turity).1. What changes do you need to make to call? C++ Code 25. If you for example want to price a bond.01. ™)ows. ™out << " c= " << pri™e europe—n ™—ll option on ˜ond using ho lee(initi—l.push ˜—™k(100).push ˜—™k(5.0. ™out << " Nelson Siegel term structure " << endl.4 to price an American call option instead of an European Exercise 25.2. double ˜et—I=0. double ˜et—H=0. Can you see what it is? 25.01. ™out << " c= " << pri™e europe—n ™—ll option on ˜ond using ho lee(initi—l. you need to keep track of intermediate payments of coupon.

. T AB @T. . . sA I   e a@T  tA B @t. Under Vacisek's model the process for the short rate is assumed to follow. .1 Vasicek bond option pricing If the term structure model is Vasicek's model there is a solution for the price of an option on a zero coupon bond. . b a H:I. . dr a a@b   rAdt C dZ where a. . . We have seen earlier how to calculate the discount factor in this case. . P @t. . v@t. . 228 26. . The price at time t of a European call option maturing at time T on on a discount bond maturing at time s is (See Jamshidan (1989) and Hull (1993)) Let P @t. . r a H:HS. . . . . . T AX P P a v@t.  a H:HP. . T A a a P @I   e a@T  tA A v@t. 228 Price a Vacicek call on a zero. X a H:W.1 Vasicek bond option pricing . . .Chapter 26 Term Structure Derivatives Contents 26. . . . . . sA be the time t price of a zero coupon bond with a payment of $1 at time s (the discount factor). . . sA C P P @t. sAN @hA   XP @t. T A a  T   t P a @s   T A T   t Example Parameters: p p a a H:I. . . . T AP a Pa In the case of a a H. T AN @h   P A where ha P I ln I P @t. b and  are constants. . . We now want to consider an European Call option in this setting. . . due to Jamshidan (1989). .

Output from C++ program: †—si™ek ™—ll option pri™e HFHHHPPTVQQ 229 . (term }.05. double ™ = term stru™ture dis™ount f—™tor v—si™ek(s t.˜.h" #include <™m—th> using namespace std. double s t = ˜ond time to m—turity.5.0.˜.sigm—)*x(h sigm— €). double „ s = s t „ t.r.02. double ˜ond option pri™e ™—ll zero v—si™ek(const double& ˆ. = (1 exp( —*„ s))/—. double h C++ Code 26. double ˆ=0.0) {   v t „ = sigm— * sqrt ( „ t ) . double sigm— €.—.sigm—)/ stru™ture dis™ount f—™tor v—si™ek(„ t. double r = 0.#include "normdist. ™out << " Vasicek call option price " << ˜ond option pri™e ™—ll zero v—si™ek(ˆ.1: C++ program: Bond option pricing using the Vasicek model double — = 0.1.˜.h" #include "fin_recipes.r.—.—. double ˜ = 0.—. double v t „. if (—==0. const double& ˜ond time to m—turity. GG ™urrent interest r—te const double& option time to m—turity.sigm—)*ˆ) ) + sigm— €/2.r. GG p—r—meters const double& ˜. double sigm— = 0.1.1. v t „ } else { double f „ s }.0/sigm— €) * log (term stru™ture dis™ount f—™tor v—si™ek(s t. const double& —. sigm— € = v t „*f „ s.r.9. return ™. sqrt (sigm—*sigm—*(1 exp( 2*—*„ t))/(2*—)).sigm—)*x(h)  ˆ*term stru™ture dis™ount f—™tor v—si™ek(„ t. const double& sigm—){ double „ t = option time to m—turity. GG exer™ise pri™e const double& r. = = (1. sigm— € = sigm—*„ s*sqrt(„ t).sigm—) << endl.˜.˜.r.—.

. . . . GG whi™h is p—rt of the st—nd—rd n—mesp—™e GG most g ™ompilers de(ne €sD ˜ut just in ™—se it doesn9t #ifndef €s #dene €s 3.1 The normal distribution function The nurmal distribution function n@xA a e  2 is calculated as x2 #include <™m—th> GG ™ li˜r—ry of m—th fun™tions using namespace std. . . . . . . . . . . . . . . . . . . . . A. . . . . . . . . . . . . .0*€s))*exp( 0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Appendix A Normal Distribution approximations. . . . . . . .1 The normal distribution function . . . . . .4 Calculating cumulative bivariate normal probabilities . . . Contents A. . . . .5 Simulating random normal numbers . . . . .2 The cumulative normal distribution . .7 References . . . there are a number of well known sources for such. A. . . . 230 231 231 232 234 235 235 We will in general not go into detail about more standard numerical problems not connected to nance. . . . . A.6 Cumulative probabilities for general multivariate distributions . .   }. . . . .141592653589793238462643 #endif double n(const double& z) { GG norm—l distri˜ution fun™tion return (1. . . . . . . . . . . . . . . . . . . . . . . . . . . A. . A. . . . . . . . .5*z*z). . . . . . . .1: The normal distribution function 230 . . . but we show the example of calculations involving the normal distribution. . . . . . . . . . . . . . . A. . C++ Code A. . . . A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .0/sqrt(2. . .3 Multivariate normal . . . .

˜R =  1.0+—*p). but a large number of well known approximations exists. t = 1. return n. Q U U U S A probability statement about this vector is a joint statement about all elements of the vector. }.3989423.0 ) n = 1.31938153. —=f—˜s(z).3 Multivariate normal The normal distribution is also dened for several random variables.2: The cumulative normal A. . We then characterise the random variables vector of P XaT T T R xI xP xn . C++ Code A.0/(1. ™P = 0.2316419. if ( z < 0. double x(const double& z) { if (z > 6.330274429.1) distribution. GG this gu—rds —g—inst over)ow if (z < 6.781477937. N @z A. ˜S = 1.0   n. n = ((((˜S*t+˜R)*t+˜Q)*t+˜P)*t+˜I)*t.2 The cumulative normal distribution The solution of a large number of option pricing formulas are written in terms of the cumulative normal distribution.   double double double double double double double double double double double ˜I = 0. #include <™m—th> GG m—th fun™tionsF using namespace std. For a random variable is lower than a given value with mean H and unit variance is less than z . ˜Q = 1.821255978.0) { return 0. one have to evaluate the integral z. ˜P =  0.356563782.0 ˜*n. n = 1.A. ˜ = ™P*exp(( z)*(z/2. it being pretty accurate and relatively fast. }.0.0.0) { return 1. . 231 . p = 0. The arguments to the function are assumed normalized to a (0. The following is probably the most used such approximation. x the cumulative probability is the probability that the outcome To calculate the probability that a normally distubuted random variable €ro˜@x z A a N @z A a  z  I n@xAdx a  z  I e  2 dx x2 There is no explicit closed form solution for calculation of this integral.0)). }. Abramowiz and Stegun (1964) is a good source for these approximations.

By the denition of correlation  P ‘ I. discussed in (Hull. I“. shown in C++ Code A. b. A a  a  b I p exp  I  I P I   P  I P xy P   P x  IP  PC y dxdy  There are several approximations to this integral. ™out << " N(0.A.0. 1993. and assume the two variables have correlation of . the calculation of cumulative probabilites is a nontrivial problem. where we let x and y be bivariate normally distributed. Output from C++ program: x@HA a HFS x@HDHDHA a HFPS 232 . Ch 10).0) = " << x(0.0. each with mean 0 and variance 1. y < bA a N @a. We will consider this. but then it is necessary to rst consider simulation of random normal variables. Example Calculate N(0) and N(0.0) << endl.0. If one has more than two correlated variables.0) C++ program: ™out << " N(0) = " << x(0) << endl.3. One common method involves Monte Carlo estimation of the denite integral.4 Calculating cumulative bivariate normal probabilities The most used multivariate normal calculation is the bivariate case. The cumulative probability distribution P @x < a. We pick one such.

{ GG sign fun™tion   }.0) return 1.3: Approximation to the cumulative bivariate normal 233 . ˜.rhoI) + x(˜.0 ) && (rho>=0.0) && (rho<=0.0) && (˜<=0. 0.0.0. }.3425378.2626645 }.0*(1. ˜. j<4.0 + x( —.4211071. 2. 0.       ) { } else if ( (—>=0.i<4. #endif inline double f (const double& x. } * ( sqrt(1. return 1. double delt—=(1. const double& rho) { double r = —prime*(2*x —prime) + ˜prime*(2*y ˜prime) return exp(r). 0.0) ) { double —prime = —/sqrt(2. } else if ( — * ˜ * rho >= 0.           } else } { ™out << " unknown " << endl.0 ) { double denum = sqrt(—*— 2*rho*—*˜ + ˜*˜).0) return x(—) x(—.006374323}.0) return x(˜) x( —.0 rho*rho)).0) && (˜>=0. GG de(ne the univ—ri—te ™umul—tive norm—l distri˜ution —s — sep—r—te fun™tion #ifndef €s const double €s=3.i++) { for (int j=0. return x(—.0. double sum = 0.1334425.0) && (rho<=0.       ) { } else if ( (—>=0.6243247.0 rho*rho)/€s).0 sgn(—)*sgn(˜))/4. GG should never get hereD —ltern—tively throw ex™eption C++ Code A. const double& ˜prime.0. return }. rho).3253030. 0.rho).     + 2*rho*(x  —prime)*(y ˜prime).0*(1.0. }. double rhoI = ((rho * — ˜) * sgn(—))/denum. const double& y.9. rho).0) return x(—) + x(˜) 1. double ˜prime = ˜/sqrt(2. const double& ˜.0.#include <™m—th> GG in™lude the st—nd—rd li˜r—ry m—them—ti™s fun™tions using namespace std. const double& rho) { if ( (—<=0.  99.       ) { }. sum = sum return sum.0) && (rho>=0. ˜. 1. double x(const double& —.0 ) { if ( ( —<=0. j++) {     sum += e[i]*e[j]* f (f[i].—prime. else if ( — * ˜ * rho <= 0.0) && (˜<=0. rho).˜prime.0.0 ) && ( ˜>=0. inline double sgn(const double& x) if (x>=0.0 rho*rho)). GG whi™h —re in the st—nd—rd n—mesp—™e #include <iostre—m> double x(const double&). double rhoP = ((rho * ˜ —) * sgn(˜))/denum. double e[4]={0.1337764.rhoP) delt—. double f[4]={0.f[j]. }. for (int i=0.141592653589793238462643. const double& —prime.

they will be generated according to some reproducible algorithm and after a (large) number of random number generations the sequence will start repeating itself.  2.4: Exercise A. Generate 5 random N(0.0. #include <™stdli˜> using namespace std.5: Example Pseudorandom numbers from a normal 1. These uniformly distributed distributed random variates are used as a basis for the polar method for normal densities discussed in Knuth (1997) and inplemented as shown in #include <™m—th> #include <™stdli˜> using namespace std.2). double ˆI=†I*sqrt(( return ˆI. …P.A. while (ƒ>=1) { …I = r—ndom uniform H I().0*log(ƒ))/ƒ). The number of iterations before replication starts is a measure of the quality of a random number generator.4.0*…I 1. ƒ = pow(†I. double r—ndom uniform H I(void). as shown in C++ Code A. double ƒ=2. …P = r—ndom uniform H I(). C++ Code A. IA distribution r—ndom•uniform function here by an alternative of higher quality. For anybody requiring high-quality random number generators the r—nd@A function provided by the standard C++ library should be avoided. GG this uses the g li˜r—ry r—ndom num˜er gener—torF }. Generate 5 random uniform numbers (0. }. Replace the Pseudorandom numbers from an uniform ‘H. but for not getting into involved discussion of random number generations we use this function as a basis for the generation of uniformly distributed numbers in the interval ‘H.1. C++ Code A. 234 . IA distribution C++ Code A.1) numbers. only pseudo-random. }. The generated numbers can never be truly random. or by downloading a high quality random number generator from such places as st—tli˜. †P. by looking into what numerical m—thli˜ or libraries is available on your computing platform.0*…P 1.2)+pow(†P.5. †I = 2. †P = 2. double r—ndom norm—l(void){ double …I.0. @H.5 Simulating random normal numbers Generation of random numbers is a large topic and is treated at length in such sources as Knuth (1997). †I. IA.1) 2. double r—ndom uniform H I(void){ return double(r—nd())/double(‚exh weˆ).

235 . ™out << " 5 random normal(0.1) numbers: " << endl. A typical tool is Monte Carlo integration. for (int i=0.++i){ ™out << " " << r—ndom uniform H I(). }. ™out << endl. Output from C++ program: S r—ndom uniform num˜ers ˜etween H —nd IX HFVRHIVV HFQWRQVQ HFUVQHWW HFUWVRR HFWIITRU S r—ndom norm—l@HDIA num˜ersX EIFHUPPR HFWPSWRT PFUHPHP IFQTWIV HFHIVUQIQ A.7 References Tong (1990) discusses the multivariate normal distribution. ™out << " ".i<5.i<5.6 Cumulative probabilities for general multivariate distributions When moving beyond the bivariate case calculation of probability integrals become more of an exercise in general numerical integration. }. possibility. ™out << " ". ™out << endl. for (int i=0. but that is not the only A.C++ program: ™out << " 5 random uniform numbers between 0 and 1: " << endl.++i){ ™out << " " << r—ndom norm—l() . and is a good reference.

An integer with a limited number of signicant digits. (basic type). Well for historical eciency were implemented using pointers. A oating point number with high accuracy. and then adding pointers to nd the indexed element.Appendix B C++ concepts This chapter contains a listing of various g/C++ concepts and some notes on each of them. —™™umul—te@A ˜ool Function accumulating the elements of a sequence. (basic type). implemented by inlining Hint to the optimizer that this function is most eciently it. ex . hence the rst element was indexed by zero. (basic type). use e‘iEI“. Dened in dou˜le exp@xA f—˜s flo—t for <cmath>. (C function). (C function). or putting the full code of the function into each instance of its calling. The rst element is of course found by adding nothing to the rst elment. An integer that can contain a large number. int (basic type). (qualifyer to variable in C++ function call). Arrays in To access element number g g i in an array from other languages. Calculates the natural logarithm ln@xA of its argument. Present in g e. known trap for people coming to reasons. taking on the two values use the values zero and one for f—lse and true true. Has the side eect of making the function local to the le in which it is dened. Indexing was done by nding the rst element of the array. (C++ function) min•element@A 236 . A oating point number with limited accuracy. For historical reasons one can also ™l—ss ™onst (C++ keyword). Dened in log@xA long <cmath>. in™lude inline (qualifyer to C++ function name). Boolean variable. Returns the natural exponent e to the given power x. Loop he—der file if Indexation (in vectors and matrices). and f—lse.

m—x•element n—mesp—™e return (C++ function) (C++ concept) st—nd—rd n—mesp—™e string using (C++ concept) (C++ basic type) (C++ concept) (C++ container class). Dened in ve™tor while <ve™tor> 237 .

. .4 Internet links . . . . . . . . a trivariate normal needs to be evaluated. . . . . . . . . C. . . .Appendix C Interfacing to external libraries Contents C. . . . . . . C. . . . . p IP P p PQ P I   PQ I   IQ I   IQ I   PQ  I This is an univariate integral. . . . . . . . . . .3. . . C. . . . . . . PQ A a n@z ANP p PQP . . . . C. . . . . . in that one can dene matrices and vectors. . . . . . . . . . . and some comments about linking to them. . . . . . . . . . . . . . .1 Newmat . . . .3. . . In this appendix there are some notes about the libraries which are referenced. . . . . . . . . . . . . . . . 238 238 238 239 C. . .3 GSL C. . . this is evaluated as k  z h  z    IQ  NQ @h. . . . . . . . .1 The evaluation of N 3 In the calculation of the American Put approximation of Geske and Johnson (1984). . . . . . and can be evaluated using quadrature. . . 238 In various places we have used routines from other public domain packages. .1 Newmat xewm—t is a matrix library that attempts to do matlab-like operations in C++. . . . . . . . . . . . . Following the discussion in the paper. . .2 IT++ IT++ is a large library with various dierent C.3 GSL . . .  j 2 3 238 . . . k. . . instead writing the operations in a more mathematically oriented way. . . . . . . . . . . . . . . . . . . . . . .1 The evaluation of N3 . . . . .2 IT++ . . . . . . . . . . . . . . . p IQP . and then multiply them and so on without needing to explicitly call subroutines. IQ . . . . . . . . . . . . . C. . j Y IP . . . . . . . . . . . . . . . . . . . .

&result.&error). double k.n. p. double result. return f . (h rhoIQ*z)/(sqrt(1. double f = n(z). double rhoPQ = (p—rms >rhoPQ). 20.. gsl fun™tion p. rhoPQ}.0 rhoPQ*rhoPQ))). size t n=1000. gsl integr—tion q—gs(&p. const double& rhoIP. gsl integr—tion worksp—™e* w = gsl integr—tion worksp—™e —llo™(n).0 rhoIQ*rhoIQ)*sqrt(1.j. }.0. double k = (p—rms >k). p. double h = (p—rms >h). k. const double& k.0 rhoPQ*rhoPQ).1: Approximating NQ @A using the method of Geske and Johnson (1984) C. double rhoIP. }.1e 7. const double& j.#include <™m—th> #include <iostre—m> using namespace std. rhoIP. extern "C"{ double fQ(double z. the matrix class used as an example. error. 239 . return result. #include "gsl/gsl_integration. double rhoPQ.fun™tion = &fQ.h" #include "normdist. double rhoIQ. }.1e 7. void *p){ struct nQ p—rms* p—rms = (struct nQ p—rms*)p. C++ Code C. }. (rhoIP rhoIQ*rhoPQ)/(sqrt(1.           f *=x( (k rhoPQ*z)/sqrt(1. double rhoIQ = (p—rms >rhoIQ).0 rhoIQ*rhoIQ)).p—r—ms=&p—rms. double rhoIP = (p—rms >rhoIP). rhoIQ. const double& rhoIQ. const double& rhoPQ){ struct nQ p—rms p—rms = { h.h" struct nQ p—rms {double h.w. double xQ(const double& h.4 Internet links Some useful internet links  httpXGGwwwFro˜ertnzFnet: Homepage for xewm—t.

const double& r). const double& r). GGGGGGGGG present v—lue GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG dis™rete ™oumpounding GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG dis™reteD —nnu—l ™ompounding const ve™tor<double>& ™)ow times. double ™—sh )ow irr dis™rete(const ve™tor<double>& ™)ow times. const ve™tor<double>& —mounts. const ve™tor<double>& ™oupon —mounts. double ™—sh )ow pv dis™rete ( GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG ™ontinous ™ompoundingF double ™—sh )ow pv(const ve™tor<double>& ™)ow times. double ˜onds yield to m—turity dis™rete(const ve™tor<double>& times. double ˜onds dur—tion dis™rete(const ve™tor<double>& times. const ve™tor<double>& ™)ow —mounts). const double& ˜ondpri™e). double ˜onds dur—tion m—™—ul—y dis™rete(const ve™tor<double>& ™—sh)ow times. const double& r). const double& ˜ond pri™e). const ve™tor<double>& ™)ow —mounts. const ve™tor<double>& ™—sh)ows. double ˜onds ™onvexity dis™rete(const ve™tor<double>& ™)ow times. const double& r). const ve™tor<double>& prin™ip—l times. double ˜onds dur—tion modi(ed dis™rete (const ve™tor<double>& times. const ve™tor<double>& prin™ip—l —mounts.h. const ve™tor<double>& ™—sh)ows. double ˜onds pri™e(const ve™tor<double>& ™oupon times. double ˜onds pri™e dis™rete(const ve™tor<double>& ™—sh)ow times. const double& r). const ve™tor<double>& —mounts. This appendix shows this le. GG (leX (n re™ipesFh GG —uthorX fernt erne yedeg——rd GG de(nes —ll routines in the (n—n™i—l numeri™—l re™ipes ˜ook #ifndef psx ‚igs€iƒ r #dene psx ‚igs€iƒ r #include <ve™tor> #include <™m—th> using namespace std. double ™—sh )ow irr(const ve™tor<double>& ™)ow times. double ˜onds pri™e(const ve™tor<double>& ™—sh)ow times. const double& r). const double& r). const ve™tor<double>& ™—sh)ows. bool ™—sh )ow unique irr(const ve™tor<double>& ™)ow times. const double& ˜ond pri™e). fin_recipes. 240 .const ve™tor<double>& ™)ow —mounts. const ve™tor<double>& ™—sh)ows. const ve™tor<double>& ™)ow —mounts). To simplify the matter all routines are summarised in one header le. const ve™tor<double>& ™)ow —mounts.Appendix D Summarizing routine names In many of the algorithms use is made of other routines. const ve™tor<double>& ™)ow —mounts).

const double& t). const ve™tor<double>& ™—sh)ows. const double& r tP. const double& ˜ond pri™e). const term stru™ture ™l—ss& d). virtual double r(const double& t) const. const ve™tor<double>& o˜s times. term stru™ture ™l—ss interpol—ted(const term stru™ture ™l—ss interpol—ted&). const double& time). { class term stru™ture ™l—ss interpol—ted X public term stru™ture ™l—ss private: ve™tor<double> times . double ˜onds yield to m—turity(const ve™tor<double>& ™—sh)ow times.double ˜onds dur—tion(const ve™tor<double>& ™—sh)ow times.const ve™tor<double>& ™—sh)ow —mounts. 241 . GG — term stru™ture ™l—ss class term stru™ture ™l—ss { public: virtual £term stru™ture ™l—ss(). GG interest r—te public: term stru™ture ™l—ss )—t(const double& r). double term stru™ture dis™ount f—™tor from yield(const double& r. const ve™tor<double>& ™—sh)ows. const term stru™ture ™l—ss& d). GG short r—teD yield on zero ™oupon ˜ond virtual double d(const double& t) const. double ˜onds dur—tion(const ve™tor<double>& ™—sh)ow times. ve™tor<double>& yields). double ˜onds dur—tion m—™—ul—y(const ve™tor<double>& ™—sh)ow times. double ˜onds ™onvexity(const ve™tor<double>& ™—sh)ow times. const double& ˜ondpri™e). virtual double r(const double& t) const. const ve™tor<double>& ™—sh)ow —mounts. double term stru™ture forw—rd r—te from yields(const double& r tI. const double& tP) const. const double& d tP. virtual £term stru™ture ™l—ss )—t(). GG use to keep — list of yields ve™tor<double> yields . const double& tI. const ve™tor<double>& o˜s yields). const ve™tor<double>& ™—sh)ows. GGG term stru™ture ˜—si™s double term stru™ture yield from dis™ount f—™tor(const double& df—™t. GG dis™ount f—™tor virtual double f (const double& tI. GG using the term stru™ture ™l—sses double ˜onds pri™e(const ve™tor<double>& ™—sh)ow times. void set int r—te(const double& r). const ve™tor<double>& ™—sh)ow —mounts. }. const double& tP). virtual double r(const double& „) const. const double& t). GG forw—rd r—te }. term stru™ture ™l—ss interpol—ted operator= (const term stru™ture ™l—ss interpol—ted&). void ™le—r(). public: { term stru™ture ™l—ss interpol—ted(). class term stru™ture ™l—ss )—t X public term stru™ture ™l—ss private: double ‚ . virtual £term stru™ture ™l—ss interpol—ted(). const double& y ). }. double term stru™ture forw—rd r—te from dis™ount f—™tors(const double& d tI. const double& r). term stru™ture ™l—ss interpol—ted(const ve™tor<double>& times. }.size(). double term stru™ture yield line—rly interpol—ted(const double& time. void set interpol—ted o˜serv—tions(ve™tor<double>& times. int no o˜serv—tions() const { return times . const ve™tor<double>& yields).

const double& time) . const double& time. const double& u. double& helt—. const double& time). double option pri™e implied vol—tility put ˜l—™k s™holes ˜ise™tions( const double& ƒ. double& „het—. const double& time. const double& u. const double& u. double option pri™e delt— ™—ll ˜l—™k s™holes(const double& ƒ. const double& time). double& ‚ho). const double& u. const double& r. const double& option pri™e). GG one periode ˜inomi—l GG multiple periode ˜inomi—l double option pri™e ™—ll europe—n ˜inomi—l multi period given ud( const double& ƒ. double option pri™e put ˜l—™k s™holes (const double& ƒ. const double& no w—rr—nts outst—nding. const double& r. const double& u. const double& u. const double& time to m—turity). const double& time. const double& time.double ˜onds ™onvexity(const ve™tor<double>& ™—sh)ow times. no w—rr—nts outst—nding. GG multiple periode ˜inomi—l ve™tor< ve™tor<double> > ˜inomi—l tree(const double& ƒH. const double& sigm—. const double& u. const double& time. const double& time. const int& no periods). const double& r. const double& sigm—. const double& u. GGG finomi—l option pri™ing double option pri™e ™—ll europe—n ˜inomi—l single period( const double& ƒ. GGGG putures pri™ing double futures pri™e(const double& ƒ. double& q—mm—. void option pri™e p—rti—ls put ˜l—™k s™holes(const double& ƒ. const double& sigm—. const double& u. const double& r. const double& u. const double& sigm—. const double& r. const double& sigm—. 242 . const double& u. const double& d. const double& sigm—. const double& r. const double& r. double& „het—. const double& r. double& †eg—. r. const int& no steps). const double& u. const double& u. GGG w—rr—nt pri™e double w—rr—nt pri™e —djusted ˜l—™k s™holes(const double& ƒ. double& helt—. const double& u. double option pri™e implied vol—tility ™—ll ˜l—™k s™holes newton( const double& ƒ. const double& q.const double& d. const double& u. const double& time) . double option pri™e implied vol—tility put ˜l—™k s™holes newton( const double& ƒ. double& ‚ho). double& q—mm—. const double& d). double& †eg—. const term stru™ture ™l—ss& d). const double& no sh—res outst—nding). const double& time. sigm—. const double& sigm—. const double& r. double w—rr—nt pri™e —djusted ˜l—™k s™holes(const const const const double& double& double& double& ƒ. const ve™tor<double>& ™—sh)ow —mounts. const double& option pri™e). const double& time. const double& option pri™e). const double& r. GGG fl—™k ƒ™holes formul— GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG double option pri™e ™—ll ˜l—™k s™holes(const double& ƒ. const double& r. double option pri™e delt— put ˜l—™k s™holes (const double& ƒ. const double& r. const double& u. void option pri™e p—rti—ls ™—ll ˜l—™k s™holes(const double& ƒ. const double& r. const double& r. double option pri™e implied vol—tility ™—ll ˜l—™k s™holes ˜ise™tions( const double& ƒ. const double& u. const double& option pri™e).

const double& r. const double& sigm—. const double& r. const double& u. const double& t. const double& r. double ™urren™y option pri™e put europe—n(const double& ƒ. const double& t. const double& y. double option pri™e ™—ll —meri™—n ˜inomi—l(const double& ƒ. const double& r. const double& r. const ve™tor<double>& dividend times. const double& r f. double ™urren™y option pri™e ™—ll europe—n(const double& ƒ. const double& u. const double& r. const double& sigm—. double option pri™e put —meri™—n ˜inomi—l (const double& ƒ. const ve™tor<double>& dividend —mounts). const double& hI. double option pri™e —meri™—n perpetu—l put(const double& ƒ. const double& t. const double& u. const double& time). double option pri™e ™—ll —meri™—n dis™rete dividends ˜inomi—l( const double& ƒ. const double& u. double option pri™e europe—n ™—ll dividends(const double& ƒ. const double& sigm—. const double& t. const double& u. const double& t—u.const double& no sh—res outst—nding). const double& time). const double& ˜. const double& u. const int& steps. const int& no steps. const ve™tor<double>& dividend times. double option pri™e put europe—n ˜inomi—l (const double& ƒ. const double& r. const double& time). const int& steps). const ve™tor<double>& dividend times. const ve™tor<double>& dividend —mounts). const double& r. const double& sigm—. double option pri™e put —meri™—n ˜inomi—l (const double& ƒ. const double& sigm—. const double& u. const double& sigm—). const ve™tor<double>& dividend times. const double& sigm—. double option pri™e —meri™—n ™—ll one dividend(const double& ƒ. const double& y. const double& u.const double& time. const int& steps). const int& steps). const double& time). const double& r. const double& t. const double& u. const double& r. const double& u. const double& r. double option pri™e ™—ll —meri™—n ˜inomi—l(const double& ƒ. const double& sigm—. const double& r. const double& r. const double& u. const double& sigm—. const double& r. const double& r. const int& steps). const double& t. const ve™tor<double>& dividend —mounts). const double& r. const double& u. const double& time). const double& u. const double& sigm—. double futures option pri™e ™—ll europe—n ˜l—™k(const double& p. const double& t. const double& t—uI). double option pri™e ™—ll —meri™—n proportion—l dividends ˜inomi—l(const double& ƒ. const double& sigm—). const double& sigm—. const double& q. const ve™tor<double>& dividend times. const double& u. const double& r f. const double& r. const double& u. const double& sigm—. const double& u. const int& steps). double option pri™e put —meri™—n dis™rete dividends ˜inomi—l(const double& ƒ. const double& u. const double& sigm—. 243 . const double& q. const double& sigm—. const double& sigm—. const double& time). const double& sigm—. const double& time. const double& u. const double& sigm—. const double& t. const int& steps). const double& ˜. GG ˜inomi—l option —pproxim—tion GGGGGGGGGGGGGGGG double option pri™e ™—ll europe—n ˜inomi—l(const double& ƒ. const ve™tor<double>& dividend —mounts ). const double& r. const int& steps. GGG ixtensions of the fl—™k ƒ™holes model GGGGGGGGGGGGGG double option pri™e europe—n ™—ll p—yout(const double& ƒ. const double& r. double option pri™e europe—n put dividends( const double& ƒ. const double& r. double futures option pri™e put europe—n ˜l—™k(const double& p. const double& sigm—. const double& sigm—. double option pri™e europe—n put p—yout (const double& ƒ. const double& u. const double& u. const double& time. double option pri™e —meri™—n perpetu—l ™—ll(const double& ƒ.

const double& sigm—. const double& time. const int& no ƒ steps. const double& t. double& veg—. const double& time. const double& time. const double& t. const int& no steps). const double& time. const int& no ƒ steps. const double& time. const int& no ƒ steps. const double& u. const int& no ƒ steps. double& rho). const double& u. double& rho). const double& r. void option pri™e p—rti—ls —meri™—n ™—ll ˜inomi—l(const double& ƒ. double option pri™e put europe—n (nite di' impli™it( const double& ƒ. const double& r. const double& u. double& delt—. const double& u. const double& r. double option pri™e delt— —meri™—n put ˜inomi—l(const double& ƒ. const int& no steps. const double& sigm—. 244 . const int& no steps. const double& sigm—. const double& u. const double& sigm—. const int& no ƒ steps. const int& no t steps). double& thet—. const double& time. const double& sigm—. const double& r f. const int& no t steps). const double& r f. const double& u. const int& no t steps). const double& u. const double& u. const int& n). const double& sigm—. const double& r. const int& no t steps). const double& time. const ve™tor<double>& dividend yields). double& g—mm—. double& delt—. const double& u. const double& sigm—. const double& r. const int& no t steps). const double& time. const int& no steps. double option pri™e put —meri™—n (nite di' expli™it( const double& ƒ. const double& time. double futures option pri™e put —meri™—n ˜inomi—l( const double& p. void option pri™e p—rti—ls —meri™—n put ˜inomi—l(const double& ƒ. const double& r. const double& u. const double& sigm—. double option pri™e put europe—n (nite di' expli™it( const double& ƒ. const double& r. const int& no steps). const double& u. const double& r. const double& u.const ve™tor<double>& dividend yields). double option pri™e ™—ll europe—n (nite di' impli™it( const double& ƒ. const double& u. double option pri™e ™—ll europe—n (nite di' expli™it( const double& ƒ. const double& time. const double& u. const double& r. const double& r. const double& time. double ™urren™y option pri™e put —meri™—n ˜inomi—l( const double& ƒ. const double& sigm—. double& veg—. double option pri™e ™—ll —meri™—n (nite di' impli™it( const double& ƒ. const double& u. double option pri™e delt— —meri™—n ™—ll ˜inomi—l(const double& ƒ. const double& r. const double& r. const int& no t steps). const double& time. const double& u. const double& sigm—. const int& n). double option pri™e put —meri™—n proportion—l dividends ˜inomi—l( const double& ƒ. const int& no ƒ steps. const ve™tor<double>& dividend times. const double& t. const double& sigm—. double ™urren™y option pri™e ™—ll —meri™—n ˜inomi—l( const double& ƒ. double futures option pri™e ™—ll —meri™—n ˜inomi—l(const double& p. const double& sigm—. const int& no steps). const double& sigm—. GGGGGGGGGGGGGGGGGGGG (nite di'eren™es GGGGGGGGGGGGGGGGGG double option pri™e ™—ll —meri™—n (nite di' expli™it( const double& ƒ. const int& no t steps). const double& t. const double& r. const double& r. const int& no ƒ steps. double& g—mm—. const double& time. const double& sigm—. double option pri™e put —meri™—n (nite di' impli™it( const double& ƒ. const double& sigm—. double& thet—. const double& sigm—. const int& no ƒ steps. const int& no t steps). const double& r. const double& u. const double& r. const double& r. const double& sigm—. const int& no steps).

double option pri™e —meri™—n ™—ll —pproxim—ted ˜jerksund stensl—nd( const double& ƒ. const double& u). 245 . const double& ˆ. double deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(const double& ƒ. const double& time). const double& sigm—. const double& time ). const double& r. const double& u).const double& sigm—. const double& ˆ. const double& ˜. const double& u. const double& ˆ. const double& r. const double& time to m—turity. const double& r. double option pri™e delt— ™—ll europe—n simul—ted(const double& ƒ. const double& sigm—. const int& no sims). const int& no sims). const int& no sims). const double& sigm—. const double& q. double p—yo' (const double& ƒ. const double& time. GGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG p—yo's of v—rious optionsD to ˜e used —s fun™tion —rguments in —˜ove simul—tions double p—yo' ™—ll(const double& ƒ. const double& sigm—. const double& time to m—turity. const double& r. const double& r. const double& r. const double& time. const double& sigm—. double option pri™e put europe—n simul—ted(const double& ƒ. const double& u). const double& sigm—. const double& u). const int& no sims). const double& time). const double& sigm—. const double& r. const double& sigm—. const int& no sims). double option pri™e —meri™—n put —pproxim—ted ˜—w(const double& ƒ.GGGGGGGGGGGGGGGGGGGGGGGGG simul—ted option pri™es GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG €—yo' only fun™tion of termin—l pri™e double option pri™e ™—ll europe—n simul—ted(const double& ƒ. const double& r. const double& u. const double& time ). double p—yo' —sset or nothing ™—ll(const double& ƒ. double option pri™e delt— put europe—n simul—ted(const double& ƒ. const double& time. double simul—te lognorm—l r—ndom v—ri—˜le(const double& ƒ. const double& u). const double& sigm—. const double& time ). GGGGGGGGGGG —pproxim—ted option pri™es GGGGGGGGGGGGGGGGGGGGGGGG double option pri™e —meri™—n put —pproxim—ted johnson( const double& ƒ. const double& r. double deriv—tive pri™e simul—te europe—n option generi™( const double& ƒ. const double& r. const double& time). const double& time to m—turity. const double& r. double p—yo' ™—sh or nothing ™—ll(const double& ƒ. const double& sigm—. double p—yo' (const double& ƒ. const double& u). const double& r. double p—yo' (const double& ƒ. const double& time to m—turity. double option pri™e —meri™—n put —pproxim—ted geske johnson( const double& ƒ. const double& u. const double& u). const int& no sims). double p—yo' put (const double& ƒ. const double& r. double deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(const double& ƒ. const double& u. const double& sigm—. const double& u. const int& no sims). const double& u. const double& u. const double& ˜. double option pri™e —meri™—n ™—ll —pproxim—ted ˜—w(const double& ƒ. const double& u. const double& sigm—. const double& u.

const int& steps). 246 . const double& t. double option pri™e put ˜ermud—n ˜inomi—l( const double& ƒ. const double& u). const double& time). const double& sigm—. double p—yo' (const ve™tor<double>& ƒ. const double& time. const double& q. const double& sigm—. double p—yo' ˜in—ry put(const double& ƒ. look˜—™k put(const ve™tor<double>& pri™es. const double& r. double p—yo' ˜in—ry ™—ll(const double& ƒ. const double& u). const double& sigm—. const double& u). GGGGGGGGGGGGGG p—th dependent —nd other exoti™ options GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG double option pri™e ™—ll ˜ermud—n ˜inomi—l(const double& ƒ. double option pri™e europe—n look˜—™k ™—ll(const double& ƒ. const double& u). const double& ƒmin. const double& sigm—. double deriv—tive pri™e simul—te europe—n option generi™( const double& ƒ. const int& nosims). double deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(const double& ƒ. const double& sigm—. const ve™tor<double>& potenti—l exer™ise times. double p—yo' (const ve™tor<double>& ƒ. const double& u. const double& u. const double& sigm—. const int& no steps). const int& steps). const double& unused v—ri—˜le). const double& ˆ. const double& r. const double& time. const double& u. const double& sigm—. const double& ƒmin. const double& r. const double& time). const double& q.double option pri™e —meri™—n put —pproxim—ted ˜jerksund stensl—nd( const double& ƒ. double option pri™e europe—n look˜—™k put(const double& ƒ. const double& unused v—ri—˜le). const double& u). const double& r. GGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG p—yo's of v—rious optionsD to ˜e used —s fun™tion —rguments in —˜ove simul—tions double double double double p—yo' p—yo' p—yo' p—yo' —rithmetri™ —ver—ge ™—ll(const ve™tor<double>& pri™es. const double& sigm—. geometri™ —ver—ge ™—ll(const ve™tor<double>& pri™es. double generi™ p—yo' (const double& ƒ. const double& u. const double& q. const double& time. const double& r. const ve™tor<double>& potenti—l exer™ise times. const double& u). const int& nosteps. double option pri™e —si—n geometri™ —ver—ge pri™e ™—ll(const double& ƒ. const double& sigm—. const double& r. const double& u. const double& r. const double& time. const double& „ ). const double& q. GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG generi™ ˜inomi—l trees double option pri™e generi™ ˜inomi—l( const double& ƒ. ve™tor<double> simul—te lognorm—lly distri˜uted sequen™e(const double& ƒ. const double& time. const double& time). const double& sigm—. const int& no sims). const int& steps). const double& q. const double& r. const double& q. const double& u). const int& no steps. const double& u. look˜—™k ™—ll(const ve™tor<double>& pri™es. const double& r. const double& r.

const double& u. const double& t. const double& u. const double& t. const double& l—m˜d—. const double& t—uI. GGGGGGGGGGGGGGGGGGG —ltern—tive sto™h—sti™ pro™esses GGGGGGGGGGGGGGGG double option pri™e ™—ll merton jump di'usion( const double& ƒ. const double& r. const double& u. const double& u. double term stru™ture yield svensson(const double& t. const double& k—pp—. const double& sigm—. const double& r. const double& dI. const double& l—m˜d—. const double& r. const double& sigm—). const double& r. const double& sigm—. const int& steps) . double term stru™ture dis™ount f—™tor v—si™ek(const double& time. 247 . const double& time to m—turity. const double& time. const double& ™I. const double& ˜et—P. const ve™tor<double> ™oupon —mounts). const double& ˜I. const double& ˜et—Q. const double& sigm—. const int& steps) . const double& sigm—. const ve™tor<double> ™oupon times. const double& u. const double& u. const int& steps). double ˜ond option pri™e ™—ll —meri™—n ˜inomi—l( const double& f. const double& q. const double& u. double heston ™—ll option pri™e(const double& ƒ. const double& ˜et—P. const ve™tor<double>& knots). const double& ˜et—I. const double& t. const double& u. GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG term stru™ture models GGG formul—s for ™—l™ul—tion double term stru™ture yield nelson siegel(const double& t. const double& delt—). const double& r. const double& r. const double& time). const double& time. const double& v. const double& thet—. const double& ˜et—H. const ve™tor<double> ™oupon times. const double& sigm—. const double& u. const double& r. const double& sigm—. double term stru™ture dis™ount f—™tor ™u˜i™ spline(const double& t. double ˜ond option pri™e put zero ˜l—™k s™holes(const double& f. const ve™tor<double> ™oupon —mounts). double option pri™e put —meri™—n trinomi—l( const double& ƒ. const double& r. double ˜ond option pri™e ™—ll ™oupon ˜ond ˜l—™k s™holes(const double& f. double ˜ond option pri™e put ™oupon ˜ond ˜l—™k s™holes(const double& f. const double& r. const double& time). const double& ˜et—I. double term stru™ture dis™ount f—™tor ™ir(const double& t. const int& steps). const double& r. const double& thet—. const double& t. const double& sigm—. const double& u. GG (xed in™ome deriv—tivesD qfw —ssumption on ˜ond pri™e double ˜ond option pri™e ™—ll zero ˜l—™k s™holes(const double& f. const double& t—uP ).GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG trinomi—l trees double option pri™e ™—ll —meri™—n trinomi—l( const double& ƒ. const ve™tor<double>& f. const double& ˜et—H. const double& sigm—. const double& r. const double& t—u. double ˜ond option pri™e put —meri™—n ˜inomi—l( const double& f. const double& r. const double& l—m˜d— ). const double& k—pp—. const double& q. const double& rho. const double& sigm—). const double& sigm—. const double& k—pp—. const double& l—m˜d—.

const double& ˜et—P. const double& —. class term stru™ture ™l—ss svenssonXpu˜li™ term stru™ture ™l—ss { private: double ˜et—H .const double& —. public: term stru™ture ™l—ss svensson(const double& ˜et—H. public: term stru™ture ™l—ss v—si™ek(const double& r. }. const double& d. const double& t—uP). public: term stru™ture ™l—ss ™ir(const double& r. GG dis™ount f—™tor }. class term stru™ture ™l—ss v—si™ek X public term stru™ture ™l—ss { private: double r .const double& sigm—). GGGGGGGGGGGGGGGGG GGG ˜inomi—l term stru™ture models GGG ˜ond optionD rendlem—nn ˜—rtter @˜inomi—lA double ˜ond option pri™e ™—ll zero —meri™—n rendlem—n ˜—rtter(const double& u. const double& u. GGG de(ning ™l—sses wr—pping the —˜ove term stru™ture —pproxim—tions class term stru™ture ™l—ss nelson siegel X public term stru™ture ™l—ss { private: double ˜et—H . const ve™tor< ve™tor<double> >& r tree.const double& ˜. const double& ƒ. double sigm— . t—uI . virtual double r(const double& „) const. t—uP . ve™tor<double> knots . const double& ˜ond m—turity. double ˜ . const double& ˜et—Q. const double& ˜et—P. const double& m—turity p—yment. const double& w. double l—m˜d— . double — . const double& ˜. const double& l—m˜d—). const ve™tor<double>& f. const int& n). const int& no steps). double sigm— . ˜et—P . virtual double d(const double& t) const. 248 . virtual double d(const double& t) const. ˜et—P . double ™ . const double& sigm—). }. public: term stru™ture ™l—ss nelson siegel(const double& ˜et—H. const double& sigm—). const double& l. const double& k. const double& ™. GG dis™ount f—™tor }. virtual double d(const double& „) const. double d . ˜et—I . ˜et—I . class term stru™ture ™l—ss ™u˜i™ spline X public term stru™ture ™l—ss { private: double ˜ . const double& t—uI. const ve™tor<double> & knots). const double& option m—turity. }. virtual double r(const double& t) const. const double& ˜et—I. const double& ˜et—I. ve™tor< ve™tor<double> > interest r—te trees g˜m ˜uild(const double& rH. const double& th. l—m˜d— . public: term stru™ture ™l—ss ™u˜i™ spline(const double& ˜. double thet— . const double& d. double k—pp— . double interest r—te trees g˜m v—lue of ™—sh)ows(const ve™tor<double>& ™)ow. ˜et—Q . class term stru™ture ™l—ss ™ir X public term stru™ture ™l—ss { private: double r . const double& interest. ve™tor<double> f .

const double& delt—. const ve™tor<double>& underlying ˜ond ™)ow times. GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG ho —nd lee modelling class term stru™ture ™l—ss ho lee X public term stru™ture ™l—ss private: int n . const double& —. const double& option time to m—turity. GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG term stru™ture deriv—tivesD —n—lyti™—l solutions double ˜ond option pri™e ™—ll zero v—si™ek(const double& ˆ. ve™tor< ve™tor<double> >& r tree. const double& u. stru™ture ™l—ss* (tted term. public: { term stru™ture ™l—ss* initi—l term . double interest r—te trees g˜m v—lue of ™—ll—˜le ˜ond(const const const const const ve™tor<double>& ™)ows. const double& pi. const double& sigm—). double ˜ond option pri™e put zero v—si™ek(const double& ˆ. const double& ˜. const int& no steps. ve™tor< ve™tor<term stru™ture ™l—ss ho lee> > term stru™ture ho lee ˜uild term stru™ture tree(term stru™ture ™l—ss* initi—l. const double& u. const double& —. const ve™tor<double>& underlying ˜ond ™)ows. const double& option time to m—turity). double& ™—ll pri™e). const ve™tor<double>& underlying ˜ond ™)ows. double pri™e europe—n ™—ll option on ˜ond using ho lee(term stru™ture ™l—ss* initi—l. const double& option time to m—turity. int & i. int & n. const double& r. const double& r. double delt— double pi . term stru™ture ™l—ss ho lee(term const const const const double d(const double& „) const. const double& pi). double& pi). const double& ˜ond time to m—turity. const double& option time to m—turity). const ve™tor<double>& underlying ˜ond ™)ow times. }. int& (rst ™—ll time. const double& ˜ond time to m—turity. const double& ˜. const double& pi. double& l—m˜d—. const double& delt—. double& q.const double& q). int i . double pri™e europe—n ™—ll option on ˜ond using ho lee(term stru™ture ™l—ss* initi—l. const double& sigm—). const double& delt—. . #endif 249 .

If your compiler complains about missing header les you may want to check if the STL header les have dierent names on your system. Alternatively. The algorithm les comply with the current ANSI standard for C++ libraries. the GNU compiler g™™ is available for free on the internet.1 Source availability The algorithms are available from my home page as a ZIP le containing the source code. If the compiler is more than a couple of years old. for most current operating systems. other compilers may not be able to compile all the les directly. As the algorithms in places uses code from the Standard Template Library. 250 . it will not have STL. E. These have been tested with the latest version of the GNU C++ compiler.Appendix E Installation The routines discussed in the book are available for download.

. . . . . Bond convexity calculation with continously compounded interest and a at term structure .4 7.2 8. . . . . . annual compounding. . . . . . . . . . . Calculating a bonds convexity with a term structure class . . . . . . Implementing term structure class using a at term structure . . . . . . . . . . . . Calculating the unconstrained frontier portfolio given an expected return using IT++ . . . . Calculation of implied volatility of Black Scholes using bisections . . . . . . . . . . . . . . . . . . . . . . . . . .8 4. . . . . . . . . . . . . . . . . . . . . . . . .8 6. . . . . . . . . . . . . . Futures price . . . . . . . . . . . . . . . . . . . . . . .3 5. . . . . . . . . . . . Calculating the Macaulay duration of a bond . . . . . . . . . . . . . Present value calculation with continously compounded interest .3 9. Binomial multiperiod pricing of European call option . . . .1 11. . . . . . . . . . . .4 3. Term structure class using linear interpolation between spot rates . . . . . . . . . . . . . . . . . . . . . Term structure transformations . . . . . . . . . . . . . . . . Bond price calculation with continously compounded interest and a at term structure . . . . .1 6. . . . . . . . . . . . . . . . . Bond yield calculation with discrete. .5 5. . .9 4. . . . . . . . . . . . . . . . . . .4 4. . . . . . . . . . . . . . . . . Calculation of implied volatility of Black Scholes using Newton-Raphson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calculating the partial derivatives of a Black Scholes call option . . . . . . . . . .10 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adjusted Black Scholes value for a Warrant . . . . . . . .4 9. . . .6 4. . . . . . Estimation of the internal rate of return . . . . . . . . . . . . . . . . . . . . . . . . . . .3 6. . . Basic operations for the date class . . . . Building a binomial tree . . . . . . . . . . . . . . . . . . . . . . Price of European Call option on Futures contract . . . Interpolated term structure from spot rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Price of European call option using the Black Scholes formula .1 5. . . . . . . . . . . . . . . . Binomial European. . . . . European option price. . . . . . . . . . Pricing a bond with a term structure class . . . . Bond duration using discrete. . . . . . . . . . . . . spot rates and forward rates in a term structure class . . . . . . . . . . . .2 5. . . . . . . . . . . . . . . . RollGeskeWhaley call formula for dividend paying stock . . . . . . . . . . . . . . . . . . . . . . .2 4. . . . . . . . . . . . . . . . . . . . . . . . . . . .3 3. . . . . . . Bond convexity with a at term structure and annual compounding . . . . . . . . . . . . . . . Bond duration calculation with continously compounded interest and a at term structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Present value with discrete compounding . . . . . .1 8. . . . .2 11. . Modied duration . . . . . . . . . . . . . . . . . . .4 4. . . . . . . . . . Mean variance calculations using IT++ . .1 9. . . . . . . . . . . . . . . .5 4. . . . . . .4 A complete program . dividend paying stock .List of C++ Codes 1. . . . . . . . . . . . . . . Calculating the unconstrained frontier portfolio given an expected return using Newmat . . . . . . . . . . annual compounding . . . . . . . . . . . . . . . . . . . . . .2 6. . . . . . . . . . .3 9. . . . . .7 4. . . . .1 3. . . Calculating the delta of the Black Scholes call option price . . . . . Default code for transformations between discount factors. . . . . . . . . . . . . Comparison operators for the date class . . . . . . . . . .1 4. . . . . . . . . . . . . . . . . . Option price. . . . . . . . . . . . . . . . . . . .6 5. . . . . . Calculating a bonds duration with a term structure class . . . . . 9 12 13 14 27 31 33 35 38 39 41 42 43 44 47 48 48 48 53 56 57 60 62 64 65 65 77 78 79 80 81 84 87 88 90 94 95 96 97 101 103 104 107 108 251 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . continous payout from underlying . . . . . . . . . annual compounding and a at term structure . . . . . . . . . . . . . . . . . . . . . Test for uniqueness of IRR . . . . . . . . . . . . . . . . . . . . .4 5. . . . . .1 11. . . . . . . . . . . .1 1. . . . . . . . . . . . . . . . . Calculating the Macaulay duration of a bond with continously compounded interest and a at term structure . . . . . . . . . one period . . .3 11. . .2 9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 5. . . . . . . . . . . . . . . . . . . . . . . . . Mean variance calculations using Newmat . . . . . . .2 3. . . . . . . . . .3 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 10. . . . . . . . . . .3 4. .1 8. . Bond price calculation with discrete.2 1. . . Option price. . . . . . Iterative operators for the date class . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Price for an american perpetual call option . . . . . . 133 13. . . .4 Calculation of price of American put using implicit nite dierences with the IT++ matrix library 139 13. . . . . . . .9 Pricing an american call on an option on currency using a binomial approximation .8 Class denition. . . . . . . 146 14. . . . . . .5 Calculation of price of European put using implicit nite dierences . . . . . . . . . .6 Term structure class wrapping the cubic spline approximation . . . Vasicek (1977) model . . .1 The Johnson (1983) approximation to an american put price . . 182 18. . . . . . . . . . . . 140 14. . . . . . .7 Binomial option price of stock option where stock pays discrete dividends . . . .4 Simulating a sequence of lognormally distributed variables . . . . . . . . . . . . . . . . .7 Payo function for lookback option . . . . . . . . . . .7 Generic with antithetic variates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Price of american put using a trinomial tree . . . . . . . . . . . . . . . . . 120 12. . . . . .4 Payo call and put options . . . . 168 16. . . 134 13. . . . . . . . . . . . . . . . . .1 Explicit nite dierences calculation of european put option . . . . . . . . . . . . . . . . . . . . . . .2 Explicit nite dierences calculation of american put option . . 129 12. 188 19. . . . . . . . . . . . . . . . . . . . . . . . . . . 144 14. . . . .8 Pricing an american call on an option on futures using a binomial approximation . . . . . . . . . . . . . . .10Class denition. . . . .8 Control Variate . . 210 252 . . . . . . . . . . . . . . . . 178 17. . . . 164 16. . . . . 174 16. . . . . . . . . . . . . . . . . . . .5 Generic binomial calculation of delta . . 127 12. . . . . .1 Black scholes price for European put option on zero coupon bond . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 20. . . . . .2 Black scholes price for European put option on coupon bond . . . . . . . . . . . . . . . . .3 Binomial approximation to american put bond option price . . . . . . . . . . . .5 Approximating a discount function using a cubic spline . . . 125 12. . . . . . . . . . . . . . . . . . . . . . . . . . . 145 14. . . . . Cox et al. . . . . . .1 Calculation of the Nelson and Siegel (1987) term structure model . . . . . . . . . .1 Mertons jump diusion formula . . . . . . . . .6 Generic with control variate . . . . . . . . . . . . . .11. . . . . . . . . . . . . . . . . . . . . 143 14. . . . 209 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 22. . . . . . . . . . . . .4 Hedge parameters . . . . . . . . . . . . . . .5 European Futures Call option on currency . . 181 17. . . . . . 149 14. . . .5 Generic simulation pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 12. . . . . . . . . . . . . . . . 175 17. . . . . . . . . . . . . . . . . . . . . . . . 204 22.4 Approximation of American Call due to Bjerksund and Stensland (1993) . . . . . . . . . . . . . . . . . . . . 130 13. . . . 173 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 22. . . . . . . . . . . .6 Payo function for Asian call option . . . . . . . . . . .9 Calculating a discount factor using the Vasicek functional form . . . 161 15. . . . . . . . . . . . . . . . . . . . . . . . . . . 170 16. . . . . .2 Analytical price of an Asian geometric average price call . .3 Estimate Delta of European Call option priced by Monte Carlo . .8 Payo binary options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Payo denitions for put and call options . . .3 Delta . . . . . .1 Binomial price of American Call . . . . . . . . 180 17. . . . . .1 Simulating a lognormally distributed random variable . . . . . . 206 22. 174 16. . . . . . . . . . . . 114 12.5 Generic routine for pricing European options . . . .2 Price of American call option using a binomial approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Price of lookback call option . . . 164 15. . . . . . . . 173 16. . . . . . . 158 15. . . . . . . . . . . .3 Calculation of price of American put using implicit nite dierences with the Newmat matrix library138 13. . . . . . . . . . . . 109 11. . . . . . . . . . . . . . . . . . . . 155 15. . (1985) model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Binomial option price with continous payout . . . . . . . . . . . . . . . . . . . . . .3 Calculation of Svensson's extended Nelson and Siegel (1987) term structure model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Dening a term structure class wrapper for the Nelson Siegel approximation . . . . . . . .2 European Call option priced by simulation . . . . . 121 12. . .3 Barone Adesi quadratic approximation to the price of a call option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 16. . . . . . . 110 12.6 Binomial option price of stock option where stock pays proportional dividends . . . . . .5 Approximation of American put due to Bjerksund and Stensland (1993) . . 207 22. . . . . . . . . .2 Generic binomial calculation . 115 12. . . . . . . . . . . . . . . . . . . . . . . . . . . .4 Dening a term structure class wrapper for the Svensson model . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 14. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 22. . . . . . . . . . . . . . . . .2 Geske Johnson approximation of American put . . . . . . (1985) model . . . .1 Option price for binomial european . . . . . . 194 22. 199 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 19. . . . . . . . . . . . . . . 202 22. . . . . . .1 Binomial approximation to Bermudan put option . . . . . . . . . . . 193 20. 191 20. . . .7 Calculation of the discount factor using the Cox et al. . . . . . . . . . . . . . . . 148 14. . . . . . . . . . . . . . . . . . . . .4 Payo denitions for binomial options . . . . . . . . . . . . 179 17. .2 Hestons pricing formula for a stochastic volatility model . . . . . . . . . . . 151 15. . . . . . . . . . . . .

. . . . . .3 25. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Term structure class for Ho-Lee . . . . . . . . . .4 26. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 216 218 219 223 224 224 226 229 230 231 233 234 234 239 253 . . . . . . . . . . . . . . . . . . . . . . . .1 24. . . . . . . . . .3 25. . . . . . . . . . . . Building interest rate tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 A. . . . . . . . .2 24. . . . . . . The normal distribution function . . . . . . . . . . . . . . . . . . . . . . . 1) distribution . . . . . . . . . . . . . . . . . . . . . . . . .2 25. . . . Approximating N3 () using the method of Geske and Johnson (1984) . Valuing callable bond . . . . . . . . . Bond option pricing using the Vasicek model . . . . . . . . . . . . . . . . . . . . .23. . . . . Valuing cash ows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1) distribution . . . . . . .3 A. . . . . . .2 A. . . . . . . . . . . . . . . . . . . . Approximation to the cumulative bivariate normal . . . . Building a term structure tree . . .1 A. . . . . . . .5 C. . . . . . . . . . . . . . . . . . . . . . . . Pseudorandom numbers from an uniform [0. . . . . . . . . . . . . . The cumulative normal . . . . . . . . . . . . . . . . . .1 RB binomial model for European call on zero coupon bond . .1 24. . . . . . . . . . . .1 25. Term structure class for Ho-Lee. . . Pseudorandom numbers from a normal (0. Pricing of European call option on straight bond using Ho-Lee . . . . . . calculation of discount function . . . . . . . .1 A. .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 13. . . . . . . . . . . . Calculation of price of American put using implicit nite dierences Price of american put using a trinomial tree . . . . . . . . . . . . . Price of American call using a binomial approximation . . . . . . . . . . . . . . . . . . Price of American put using a binomial approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .List of Matlab Codes 6. . . . .2 6. . . . . . . . . . . . . . . . . . . . . . . . .2 13. . . . . . . Sharpe Ratio .4 9. . . . . . .1 Calculation of minimum variance portfolio for given return . . . . . . . . . . . . Price of European call option using the Black Scholes formula . . . . . . . . . . . . . . . . . . Treynor Ratio . . . . . . . . Explicit nite dierences calculation of American put option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 18.1 6. . . . . . . . . . . . . . . . . . . . .1 12. Jensens alpha . . . . . . . . . . . . . . . . . . . .1 24. .1 12. . . . . . . . . . . . . . . . . . . Building interest rate tree . . . . . . . . . .3 6. . . . . . . . . . . . . . . . . . . . 71 76 76 76 91 116 117 135 137 185 216 254 . . .

I've had quite a few emails about them. pointed out bugs and other inaccuracies. Italy Tuan Nguyen Michael R Wayne Some of them has 255 . After this paper was put up on the net. Milano.Appendix F Acknowledgements. Among the ones I want to say thanks to for making improving suggestions and pointing out bugs are Ariel Almedal Andrei Bejenari Steve Bellantoni Jean-Paul Beveraggi Lars Gregori Daniel Herlemont Lorenzo Isella Jens Larsson Garrick Lau Steven Leadbeater Michael L Locher Lotti Luca.

44 146. 6 duration. 12 213. 158 Black Scholes. 31 cash_ow_pv. 94 A. 130 currency_option_price_call_european. 112 binomial term structure models. 109. 109 currency_option_price_call_american_binomial. 66. 57. 241 discount factor. 9 cmath. bonds_convexity_discrete. 130 European. 6 bool (C++ type). 38 bond convexity. 195 Black Scholes. 35 cash_ow_pv_discrete.date::year. 65 derivative_price_simulate_european_option_generic_with_antithetic_ bonds_duration_discrete. 41. 48. 44 Cox Ingersoll Ross term structure model. 209 bonds_yield_to_maturity_discrete. 27. 38 discount_factor. 108 Black Scholes option pricing formula. 41 256 . 151 cash_ow_irr_discrete. 39. 194 bond_option_price_put_coupon_bond_black_scholes. 63. 248 date::month. 12 delta. 228 date::date. 43 Discount factor. 12 bond_option_price_put_american_binomial. 42 148. 120 bond_option_price_put_zero_black_scholes. 28. 44 bond option d. 147 convexity of bond. date::day. 42. 135 antithetic variates. 41 price. 94 . 151 binomial option price. 94 . 192 d2. 82. 176 bonds_duration. 45 149 bonds_duration_macaulay. 12 bond_option_price_call_zero_vasicek. 194 d1. 7 Complex numbers in C++. 248 basic binomial. 159 binary option. 226 calcP2. 137 a. 12 bond_option_price_call_zero_american_rendleman_bartter. 37 yield to maturity. 36 bonds_price. 40 double (C++ type). 110 BaroneAdesi and Whaley. 36 Promised payments. 192. 93 bonds_convexity. 229 date::valid. 32. 148 asset or nothing call. 89 Bond Price Flat term structure. 82 cash ow. 158 call option. 26 bonds_price_discrete. 175 bonds_duration_modied_discrete. 109 currency option American. 49. 214. 64. 173. 33 class. 152. 206 currency option. 48. 47. 93 193 binomial. 158 Vasicek. 48 derivative_price_simulate_european_option_generic_with_control_va bonds_duration_macaulay_discrete. 65 derivative_price_simulate_european_option_generic. 190 control variates. 37. 212 binomial_tree. 151 build_time_series_of_bond_time_contingent_cash_ows. 87 Black futures option. 36 bond duration.Index . 26 cash or nothing call. 240 cash_ow_unique_irr.

30 154. 132 antithetic variates. 191 simulated. 144 Jump Diusion. 41 modied. 216 option_price_american_put_approximated_geske_johnson. 159 exp. 78. 188 modied duration. 90. 230 futures_option_price_call_european_black. 108 call. 8 no_observations. 239 n. 82 Option price hedging parameters Black Scholes. 230 nite dierences. 123. 147. 239 option_price_asian_geometric_average_price_call. interest_rate_trees_gbm_value_of_callable_bond. 110 include (C++ statement). 108 option futures_option_price_put_european_black. 187 option_price_call_american_proportional_dividends_binomial. 30 option_price_call_american_binomial. 7 explicit nite dierences. 156 put. 129 approximations. 224 161 option_price_american_call_approximated_bjerksund_stensland. 107 calculation. 94 futures. 78 f. 241 function prototypes (C++ concept). 108 geometric Brownian motion. 81 currency. internal rate of return. 79 early exercise premium. 79. 89 Black Scholes. 142 heston_Pj. 14 option_price_call_american_discrete_dividends_binomial. 233 N. 144. 146 Normal distribution futures Simulation. 6 option_price_call_european_binomial_multi_period_given_ud. 7 option_price_american_put_approximated_bjerksund_stensland. 187 option_price_call_merton_jump_diusion. 43 option_price_delta_american_call_binomial. 127 Jump Diusion. 109 gamma. 155 Internet links. 147 mv_calculate_mean. 191 option_price_american_call_approximated_baw. 14 for (C++ statement). 169 irr. 160. 218. 170 Geske and Johnson.Macaulay. 114. 239 explicit. 108 normal distribution futures_option_price_call_american_binomial. 115. main. 82 futures_price. hT. 92. 191 binomial. 128. 239 option_price_call_european_binomial. 132. 106. 128. 9 84. 219 158 interest_rate_trees_gbm_value_of_cashows. 87 Merton option_price_call_european_simulated. 148 monte carlo control variates. 93 option price heston_call_option_price. 112 heston_integrand_j. 96 option_price_american_perpetual_call. 77. 93 lookback. 137 N3. 77. 231233 f3. 221 option_price_american_put_approximated_johnson. 6 164 interest_rate_trees_gbm_build. 80 mv_calculate_st_dev. 132 next_date. 13 164 implied volatility option_price_american_call_one_dividend. if. 43 e. lookback option. 61. 78 mv_calculate_portfolio_given_mean_unconstrained. 150 Internet. 197 exp() (C++ statement). 234 option. 125 Links option_price_call_black_scholes. iteration operator 178 denition of (C++ concept). 78 mv_calculate_variance. 170 88 option_price_call_european_binomial_single_period. 118 long (C++ type). 77. 190. 120 Monte Carlo 257 . int (C++ type).

249 relative pricing. 9 term_structure_class_svensson::term_structure_class_svensson. 209. 234 224. 181 term_structure_class_interpolated::set_interpolated_observations. 204. 211 quadratic approximation. 7 term_structure_class_svensson::r. 202 power. 241 term_structure_forward_rate_from_yields. 212 258 . 151 term_structure_class_interpolated::r. 226 210 prices. 164 term_structure_class_svensson. 174 term_structure_class_interpolated::clear. 170. 173 option_price_implied_volatility_call_black_scholes_bisections. 57. 138 term structure models option_price_put_american_nite_di_implicit_itpp. 141 option_price_put_european_nite_di_explicit. 98 option_price_partials_american_call_binomial. Simulation 96 Random normal numbers. 168 term_structure_class::r. 75 option_price_european_lookback_call. 228 option_price_partials_call_black_scholes. 180 200 phi. 223. 174 term_structure_class_nelson_siegel::term_structure_class_nelson_sie payo_put. 82 term_structure_discount_factor_vasicek. 146. 203. 93 223 payo_arithmetric_average_call. 30 option_price_delta_call_european_simulated. 142 97. 143 option_price_generic_binomial. 94. 14 price_european_call_option_on_bond_using_ho_lee. 62 payo_asset_or_nothing_call. 207. 93 term_structure_class_ho_lee::d. term_structure_class_vasicek::d. 159 term_structure_forward_rate_from_discount_factors. string (C++ type). 208 pricing term_structure_discount_factor_cubic_spline. 200 payo_lookback_put. 134 Term structure model Cox Ingersoll Ross. 94 option_price_delta_generic_binomial. 104 Sharpe Ratio. random_uniform_0_1. 248 pow() (C++ statement). 82 term_structure_discount_factor_from_yield. payo_binary_put. 224 partials term_structure_class_ho_lee::term_structure_class_ho_lee. 204 partial derivatives term_structure_class_at::r.return option_price_delta_call_black_scholes. 145 rho. 182 option_price_european_call_dividends. 145 internal rate of. 61. 117 term_structure_discount_factor_cir. 248 term_structure_class_cir::d. 180 term_structure_class_interpolated::term_structure_class_interpolated payo_cash_or_nothing_call. 104 sgn. 184. 116. 199 payo_lookback_call. 146. 56 option_price_put_black_scholes. 234 term_structure_ho_lee_build_term_structure_tree. 133. 207 136 option_price_put_european_nite_di_implicit. 212 139 term_structure_class::d. 185 term_structure_class::f. 26 202 previous_date. 202. 56 option_price_put_bermudan_binomial. 206 option_price_put_american_nite_di_implicit. 6 122 term structure derivatives. 121. 234 option_price_implied_volatility_call_black_scholes_newton. binomial. 82 term_structure_yield_from_discount_factor. 210 term_structure_class_vasicek::term_structure_class_vasicek. term_structure_class_cir. 55. 203. 174 term_structure_class_nelson_siegel::r. 248 term_structure_class_cubic_spline::d. 140 term_structure_class_cir::term_structure_class_cir. 174 term_structure_class_nelson_siegel. 167. 56 option_price_put_american_trinomial. 206. simulation. 53 random_normal. 62 payo_binary_call. 53. 103. 95 option_price_put_american_nite_di_explicit. 181 62 payo_call. 54 r. present value. 223 Black Scholes. 53 Rendleman and Bartter model. 207 term_structure_class_cubic_spline. Black Scholes. 57 binomial. 151 62 payo_geometric_average_call. 53 put option. 171 simulate_lognormal_random_variable. 179181 simulate_lognormally_distributed_sequence. 205 relative. 233 option_price_european_call_payout. 120 term_structure_class_ho_lee.

term_structure_yield_linearly_interpolated. 226 underlying security. 60 term_structure_yield_nelson_siegel. 209 vega. 89 valid. 26 time_contingent_cash_ows. 96 warrant_price_adjusted_black_scholes. 101 259 . 94 time value of. 94 volatility implied. 199. 10 Vasicek. 201 term_structure_yield_svensson. 202 theta.

tohn g goxD ton—th—n i sngersollD —nd ƒtephen e ‚ossF e theory of the term stru™ture of interest r—tesF i™onometE ri™—D SQXQVS!RHVD IWVSF w f q—rm—n —nd ƒ ‡ uohlh—genF poreign ™urren™y option v—luesF tourn—l of sntern—tion—l woney —nd pin—n™eD PX PQI!QUD IWVQF Bibliography wilton e˜r—mowiz —nd srene e ƒtegunF r—nd˜ook of w—thE em—ti™—l pun™tionsF x—tion—l fure—u of ƒt—nd—rdsD IWTRF qiov—nni f—roneEedesiF „he s—g— of the emeri™—n putF tourE n—l of f—nking —nd pin—n™eD PWXPWHW!PWIVD PHHSF qiov—nni f—roneEedesi —nd ‚o˜ert i ‡h—leyF i0™ient —nE —lyti™ —pproxim—tion of emeri™—n option v—luesF tourn—l of pin—n™eD RP@PAXQHI!PHD tune IWVUF €etter fjerksund —nd qunn—r ƒtensl—ndF glosed form —pE proxim—tions of —meri™—n optionsF ƒ™—ndin—vi—n tourn—l of w—n—gementD PH@SAXUTI!UTRD IWWQF €etter fjerksund —nd qunn—r ƒtensl—ndF glosed form v—luE —tion of —meri™—n optionsF ‡orking €—perD xrrD y™to˜er PHHPF pisher fl—™kF „he pri™ing of ™ommodity ™ontr—™tsF tourn—l of pin—n™i—l i™onomi™sD QXITU!UWD IWUTF pisher fl—™k —nd wyron ƒ ƒ™holesF „he pri™ing of options —nd ™orpor—te li—˜ilitiesF tourn—l of €oliti™—l i™onomyD UXTQU!SRD IWUQF vi fodieD elex u—neD —nd el—n t w—r™usF snvestmentsF w™qr—w rillD T editionD PHHSF €eter v foss—erts —nd fernt erne Ødeg——rdF ve™tures on gorpor—te pin—n™eF ‡orld ƒ™ienti(™ €ressD ƒing—poreD PHHIF €helim € foyleF yptionsX e wonte g—rlo —ppro—™hF tourn—l of pin—n™i—l i™onomi™sD RXQPQ!QVD IWUUF ‚i™h—rd e fre—ley —nd ƒtew—rt g wyersF €rin™iples of gorE por—te pin—n™eF w™qr—w!rillD seventh editionD PHHPF wi™h—el frenn—n —nd idu—rdo ƒ™hw—rtzF pinite di'eren™e methods —nd jump pro™esses —rising in the pri™ing of ™onE tingent ™l—imsX e synthesisF tourn—l of pin—n™i—l —nd u—ntit—tive en—lysisD IQXRTI!URD IWUVF w—rk fro—die —nd terome hetempleF emeri™—n option v—lE u—tionX xew ˜oundsD —pproxim—tionsD —nd — ™omp—rison of existing methodsF ‚eview of pin—n™i—l ƒtudiesD W@RAX IPII!IPSHD ‡inter IWWTF w—rk fro—die —nd terome hetempleF yption pri™ingX †—luE —tion models —nd —ppli™—tionsF w—n—gement ƒ™ien™eD SH @WAXIIRS!IIUUD ƒeptem˜er PHHRF tohn gox —nd w—rk ‚u˜insteinF yptions m—rketsF €renti™e! r—llD IWVSF tohn g goxD ƒtephen e ‚ossD —nd w—rk ‚u˜insteinF ypE tion pri™ingX e simpli(ed —ppro—™hF tourn—l of pin—n™i—l i™onomi™sD UXPPW!PTQD IWUWF ‚o˜ert qeskeF „he v—lu—tion of ™ompound optionsF tourn—l of pin—n™i—l i™onomi™sD UXTQ!VID w—r™h IWUWF ‚o˜ert qeske —nd r i tohnsonF „he —meri™—n put v—lued —n—lyti™—llyF tourn—l of pin—n™eD ˆˆˆsˆ@SAD he™em˜er IWVRF w f—rry qoldm—nD row—rd f ƒosinD —nd w—ry enn q—ttoF €—th!dependent optionsX fuy —t the lowD sell —t the highF tourn—l of pin—n™eD QRD he™em˜er IWUWF t y qr—˜˜eF „he pri™ing of ™—ll —nd put options on foreign ex™h—ngeF tourn—l of sntern—tion—l woney —nd pin—n™eD PXPQW!SQD IWVQF €hilip qr—y —nd ƒtephen p qr—yF e fr—mework for v—luing deriv—tive se™uritiesF pin—n™i—l w—rketsD snstitutions —nd snstrumentsD IH@SAXPSQ!PUTD he™em˜er PHHIF ‚i™h—rd g qreen —nd fernt erne Ødeg——rdF ere there t—x e'e™ts in the rel—tive pri™ing of …FƒF qovernment ˜ondsc tourn—l of pin—n™eD SPXTHW!TQQD tune IWWUF ‚o˜ert e r—ugenF wodern snvestment „heoryF €renti™e! r—llD (fth editionD PHHIF ƒteven v restonF e ™losedEform solution fo option™ with sto™h—sti™k vol—tility with —ppli™—tions to ˜ond —nd ™urE ren™y optionsF ‚eview of pin—n™i—l ƒtudiesD T@PAXQPU!QRQD IWWQF „ ƒ ro —nd ƒ veeF „erm stru™ture movement —nd pri™ing interest r—te ™ontingent ™l—imsF tourn—l of pin—n™eD RQX IHII!PWD IWVTF ghiEfu ru—ng —nd ‚o˜ert r vitzen˜ergerF pound—tions for (n—n™i—l e™onomi™sF xorth!roll—ndD IWVVF tohn rullF yptionsD putures —nd other heriv—tivesF €renti™e!r—llD sixth editionD PHHTF tohn rullF yptionsD putures —nd other heriv—tive ƒe™uritiesF €renti™e!r—llD se™ond editionD IWWQF p t—mshid—nF en ex—™t ˜ond option pri™ing formul—F tourE n—l of pin—n™eD RRXPHS!WD w—r™h IWVWF r i tohnsonF en —n—lyti™ —pproxim—tion of the —meri™—n put pri™eF tourn—l of pin—n™i—l —nd u—ntit—tive en—lyE sisD IV@IAXIRI!RVD IWVQF e uemn— —nd e †orstF e pri™ing method for options ˜—sed on —ver—ge —sset v—luesF tourn—l of f—nking —nd pin—n™eD IRXIIQ!PWD w—r™h IWWHF hon—ld i unuthF „he ert of gomputer €rogr—mming †olume PD ƒeminumeri™—l elgotithmsF eddison!‡esleyD third editionD IWWUF ƒt—nley f vippm—nF gCC primerF eddison!‡esleyD P ediE tionD IWWPF ƒt—nley f vippm—n —nd tos9ee v—joieF eddison!‡esleyD third editionD IWWVF gCC primerF 260 .

‚o˜ert r vitzen˜erger —nd t—ques ‚olfoF en intern—tion—l study of t—x e'e™ts on government ˜ondsF tourn—l of pin—n™eD QWXI!PPD IWVRF r—rry w—rkowitzF €ortfolio sele™tionF tourn—l of pin—n™eD UXUU!WID IWSPF vionel w—rtinelliD €hilippe €ri—uletD —nd ƒtéph—ne €ri—uletF pixed sn™ome ƒe™uritiesF †—lu—tionD ‚isk w—n—gement —nd €ortfolio ƒtr—tegiesF ‡iley pin—n™eD PHHQF t rouston w™gullo™hF we—suring the term stru™ture of inE terest r—tesF tourn—l of fusinessD RRXIW!QID IWUIF t rouston w™gullo™hF „he t—x —djusted yield ™urveF tourn—l of pin—n™eD QHXVII!VPWD IWUSF ‚o˜ert w™hon—ld —nd h—niel ƒiegelF „he v—lue of w—iting to investF u—rterly tourn—l of i™onomi™sD p—ges UHU!UPUD xovem˜er IWVTF ‚o˜ert v w™hon—ldF heriv—tives w—rketsF €e—rsonD se™ond editionD PHHTF ‚o˜ert g wertonF en —n—lyti™ deriv—tion of the e0™ient portfolio frontierF tourn—l of pin—n™i—l —nd u—ntit—tive en—lysisD UXIVSI!UPD ƒeptem˜er IWUPF ‚o˜ert g wertonF „he theory of r—tion—l option pri™ingF fell tourn—lD RXIRI!IVQD IWUQF ‚o˜ert g wertonF yption pri™ing when underlying sto™k reE turns —re dis™ontinousF tourn—l of pin—n™i—l i™onomi™sD QXIPS!RRD IWUTF pr—n™o wodigli—ni —nd werton w willerF „he ™ost of ™—pE it—lD ™orpor—tion (n—n™e —nd the theory of investmentF emeri™—n i™onomi™ ‚eviewD RVXPTI!WUD IWSVF gh—rles ‚ xelson —nd endrew p ƒiegelF €—rsimonious modE elling of yield ™urvesF tourn—l of fusinessD TH@RAXRUQ!VWD IWVUF g—rl t xorstromF e su0™ient ™onditions for — unique nonE neg—tive intern—l r—te of returnF tourn—l of pin—n™i—l —nd u—ntit—tive en—lysisD U@QAXIVQS!QWD IWUPF ‡illi—m €ressD ƒ—ul e „eukolskyD ‡illi—m „ †etterlingD —nd fri—n € pl—nneryF xumeri™—l ‚e™ipes in gF g—m˜ridge …niversity €ressD se™ond editionD IWWPF ‚i™h—rd t ‚endlem—n —nd frit t f—rtterF „wo!st—te option pri™ingF tourn—l of pin—n™eD QR@SAXIHWQ!IIIHD he™em˜er IWUWF ‚i™h—rd t ‚endlem—n —nd frit t f—rtterF „he pri™ing of opE tions on de˜t se™uritiesF tourn—l of pin—n™i—l —nd u—nE tit—tive en—lysisD IS@IAXII!PRD w—r™h IWVHF ‚i™h—rd ‚ollF e ™ritique of the —sset pri™ing theory9s tests! €—rt sX yn p—st —nd potenti—l test—˜ility of the theoryF tourn—l of pin—n™i—l i™onomi™sD RXIPW!IUTD IWUU—F ‚i™h—rd ‚ollF en —n—lyti™—l formul— for unprote™ted emeriE ™—n ™—ll options on sto™ks with known dividendsF tourn—l of pin—n™i—l i™onomi™sD SXPSI!SVD IWUU˜F ƒtephen e ‚ossD ‚—ndolph ‡ester(eldD —nd te'rey p t—'eF gorpor—te pin—n™eF w™qr—sErillD seventh editionD PHHSF w—rk ‚u˜insteinF „he v—lu—tion of un™ert—in in™ome stre—ms —nd the v—lu—tion of optionsF fell tourn—lD UX RHU!PSD IWUTF w—rk ‚u˜insteinF ixoti™ optionsF …niversity of g—liforni—D ferkeleyD working p—perD IWWQF ‡illi—m p ƒh—rpeD qordon t elex—nderD —nd te'ery † f—iE leyF snvestmentsF €renti™e r—llD sixth editionD IWWWF ‚o˜ert tF ƒhillerF „he term stru™ture of interest r—tesF sn f w priedm—n —nd p r r—hnD editorsD r—nd˜ook of wonE et—ry i™onomi™sD volume PD ™h—pter IQD p—ges TPU!UPPF ilsevierD IWWHF fj—rne ƒtroustrupF „he gCC €rogr—mming l—ngu—geF eddison!‡esleyD third editionD IWWUF ƒuresh ƒund—res—nF pixed sn™ome w—rkets —nd their heriv—E tivesF ƒouthE‡esternD P editionD PHHIF ‰ v „ongF „he wultiv—ri—te xorm—l histri˜utionF ƒpringerD IWWHF y †—si™ekF en equili˜rium ™h—r—™teriz—tion of the term stru™tureF tourn—l of pin—n™i—l i™onomi™sD SXIUU!VVD IWUUF ‚o˜ert i ‡h—leyF yn the v—lu—tion of emeri™—n ™—ll options on sto™ks with known dividendsF tourn—l of pin—n™i—l i™onomi™sD WXPHU!ID IWVIF €—ul ‡ilmottD te' hewynneD —nd ƒ—m rowisonF yption €ri™ingD w—them—ti™—l models —nd ™omput—tionF yxford pin—n™i—l €ressD IWWRF sƒfx H WSPPHVP HPF 261 .

Sign up to vote on this title
UsefulNot useful