Financial Numerical Recipes in C++.

Bernt Arne Ødegaard January 2006

7.3.3

Implied Volatility. . . . . . . . . . . . . .

61

Contents
1 On C++ and programming.
1.1 1.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 1.3.1 date, an example class . . Const references . . . . . . . . . . Other C++ concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . concept. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4 4 4 5 5 6 6 7 7 8 8 14 14

8 Warrants 4
8.1 8.2 8.3

Warrant value in terms of assets . . . . . . . . . Valuing warrants when observing the stock value Readings . . . . . . . . . . . . . . . . . . . . . .

64

64 64 65

9 Extending the Black Scholes formula
9.1

9.2 9.3 9.4 9.5 9.6

1.3 1.4 1.5 2.1 3.1 3.2

Adjusting for payouts of the underlying. . . . . . 9.1.1 Continous Payouts from underlying. . . . 9.1.2 Dividends. . . . . . . . . . . . . . . . . . American options. . . . . . . . . . . . . . . . . . 9.2.1 Exact american call formula when stock is paying one dividend. . . . . . . . . . . . Options on futures . . . . . . . . . . . . . . . . 9.3.1 Black's model . . . . . . . . . . . . . . . Foreign Currency Options . . . . . . . . . . . . Perpetual puts and calls . . . . . . . . . . . . . Readings . . . . . . . . . . . . . . . . . . . . . .

67

67 67 68 69 69 73 73 75 77 78

10 Option pricing with binomial approximations

2 Matrix Tools

The rst screen . . . . . . . . . . . . . . . . . .

15 16

15

3 The value of time

3.3

3.4

Present value . . . . . . . . . . . . . . . . . . . One interest rate with annual compounding . . . 3.2.1 Internal rate of return. . . . . . . . . . . 3.2.2 Bonds . . . . . . . . . . . . . . . . . . . 3.2.3 Measuring bond sensitivity to interest rate changes . . . . . . . . . . . . . . . . . . . Continously compounded interest . . . . . . . . 3.3.1 Present value . . . . . . . . . . . . . . . 3.3.2 Bond pricing and analysis . . . . . . . . Further readings . . . . . . . . . . . . . . . . . .

16 16 18 21 25 29 29 30 32

4 The term structure of interest rates and an object lesson 33 11 Finite Dierences
4.1 4.2 The interchangeability of discount factors, spot interest rates and forward interest rates . . . . . The term structure as an object . . . . . . . . . 4.2.1 Base class . . . . . . . . . . . . . . . . . 4.2.2 Flat term structure. . . . . . . . . . . . . Using the currently observed term structure. . . 4.3.1 Linear Interpolation. . . . . . . . . . . . 4.3.2 Interpolated term structure class. . . . . Bond calculations with a general term structure and continous compounding . . . . . . . . . . . Pricing of futures contract. . . . . . . . . . . . . Multiperiod binomial pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 36 36 38 40 40 42 45

10.1 Introduction . . . . . . . . . . . . . . . . . . . . 10.2 Pricing of options in the Black Scholes setting . 10.2.1 European Options . . . . . . . . . . . . . 10.2.2 American Options . . . . . . . . . . . . . 10.2.3 Estimating partials. . . . . . . . . . . . . 10.3 Adjusting for payouts for the underlying . . . . 10.4 Pricing options on stocks paying dividends using a binomial approximation . . . . . . . . . . . . . 10.4.1 Checking for early exercise in the binomial model. . . . . . . . . . . . . . . . . . . . 10.4.2 Proportional dividends. . . . . . . . . . . 10.4.3 Discrete dividends . . . . . . . . . . . . . 10.5 Option on futures . . . . . . . . . . . . . . . . . 10.6 Foreign Currency options . . . . . . . . . . . . . 10.7 References . . . . . . . . . . . . . . . . . . . . .

79

79 80 80 80 83 86 87

87 87 87 91 92 93

11.1 Explicit Finite dierences . . . . . . . . . . . . . 11.2 European Options. . . . . . . . . . . . . . . . . 11.3 American Options. . . . . . . . . . . . . . . . .

94
94 94 96

4.3

12 Option pricing by simulation

4.4

5 Futures algoritms.
5.1 6.1 7.1 7.2

47
47

6 Binomial option pricing

48

50

12.1 Simulating lognormally distributed random ables . . . . . . . . . . . . . . . . . . . . . 12.2 Pricing of European Call options . . . . . . 12.3 Hedge parameters . . . . . . . . . . . . . . 12.4 More general payos. Function prototypes 12.5 Improving the eciency in simulation . . . 12.5.1 Control variates. . . . . . . . . . . 12.5.2 Antithetic variates. . . . . . . . . . 12.5.3 Example . . . . . . . . . . . . . . . 12.6 More exotic options . . . . . . . . . . . . .

vari. . . . . . . . . . . . . . . . . . . . . . . . . . .

98
98 98 99 102 103 103 104 106 107

7 Basic Option Pricing, the Black Scholes formula 54 13 Approximations
The formula . . . . . . . . . . . . . . . . . Understanding the why's of the formula . . 7.2.1 The original Black Scholes analysis 7.2.2 The limit of a binomial case . . . . 7.2.3 The representative agent framework Partial derivatives. . . . . . . . . . . . . . 7.3.1 Delta . . . . . . . . . . . . . . . . . 7.3.2 Other Derivatives . . . . . . . . . . 54 57 57 57 58 58 58 58

13.1 A quadratic approximation to American prices due to BaroneAdesi and Whaley. . . . . . . . .

109
109

14 Average, lookback and other exotic options
14.1 14.2 14.3 14.4 Bermudan options . . . . . . . . . . . Asian options . . . . . . . . . . . . . Lookback options . . . . . . . . . . . Monte Carlo Pricing of options whose pend on the whole price path . . . . .

7.3

. . . . . . . . . . . . . . . . . . payo de. . . . . .

113

113 116 117 119

I

14.4.1 Generating a series of lognormally distributed variables . . . . . . . . . . . . . 14.5 Control variate . . . . . . . . . . . . . . . . . .

119 122

20 Term Structure Models
20.1 20.2 20.3 20.4 20.5

15 Alternatives to the Black Scholes type option formula 124
15.1 Merton's Jump diusion model. . . . . . . . . . 16.1 16.2 16.3 16.4 An example matrix class Finite Dierences . . . . European Options . . . . American Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

The Nelson Siegel term structure approximation Bliss . . . . . . . . . . . . . . . . . . . . . . . . Cubic spline. . . . . . . . . . . . . . . . . . . . . Cox Ingersoll Ross. . . . . . . . . . . . . . . . . Vasicek . . . . . . . . . . . . . . . . . . . . . . .

144

144 144 147 149 151

16 Using a library for matrix algebra

126 21 Binomial Term Structure models
126 126 126 128

21.1 The Rendleman and Bartter model . . . . . . . 21.2 Readings . . . . . . . . . . . . . . . . . . . . . .

154

154 154

22 Term Structure Derivatives

17 The Mean Variance Frontier

17.1 Setup . . . . . . . . . . . . . . . . . . . 17.2 The minimum variance frontier . . . . . 17.3 Calculation of frontier portfolios . . . . 17.4 The global minimum variance portfolio 17.5 Ecient portfolios . . . . . . . . . . . . 17.6 The zero beta portfolio . . . . . . . . . 17.7 Allowing for a riskless asset. . . . . . . 17.8 Ecient sets with risk free assets. . . . 17.9 The Sharpe Ratio . . . . . . . . . . . . 17.10Short-sale constraints . . . . . . . . . .

130

22.1 Vasicek bond option pricing . . . . . . . . . . .

157
157

130 131 132 133 134 135 135 136 137 137

A Normal Distribution approximations.
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 . . . . . . . . . . . . . . . . . . . . .

159

159 159 159 160 163

163 163

18 Pricing of bond options, basic models 19 Credit risk

18.1 Black Scholes bond option pricing . . . . . . . . 18.2 Binomial bond option pricing . . . . . . . . . . . 19.1 The Merton Model . . . . . . . . . . . . . . . . 19.2 Issues in implementation . . . . . . . . . . . . .

138
138 140

B C++ concepts C Summarizing routine names D Installation
D.1 Source availability . . . . . . . . . . . . . . . . .

165 166 174
174

142
142 142

E Acknowledgements.

178

P

„his ˜ook is — — dis™ussion of the ™—l™ul—tion of spe™i(™ formul—s in (n—n™eF „he (eld of (n—n™e h—s seen — r—pid development in re™ent ye—rsD with in™re—sing m—them—ti™—l sophisti™—tionF ‡hile the form—liz—tion of the (eld ™—n ˜e tr—™ed ˜—™k to the work of w—rkowitz @IWSPA on investors me—nEv—ri—n™e de™isions —nd wodigli—ni —nd willer @IWSVA on the ™—pit—l stru™ture pro˜lemD it w—s the solution for the pri™e of — ™—ll option ˜y fl—™k —nd ƒ™holes @IWUQAY werton @IWUQA whi™h re—lly w—s the st—rting point for the m—them—ti™—liz—tion of (n—n™eF „he (elds of deriv—tives —nd (xed in™ome h—ve sin™e then ˜een the m—in (elds where ™ompli™—ted formul—s —re usedF „his ˜ook is intended to ˜e of use for people who w—nt to ˜oth underst—nd —nd use these formul—sD whi™h expl—ins why most of the —lgorithms presented l—ter —re deriv—tives pri™esF „his proje™t st—rted when s w—s te—™hing — ™ourse in deriv—tives —t the …niversity of fritish golum˜i—D in the ™ourse of whi™h s s—t down —nd wrote ™ode for ™—l™ul—ting the formul—s s w—s te—™hingF s h—ve —lw—ys found th—t implement—tion helps underst—nding these thingsF por te—™hing su™h ™ompli™—ted m—teri—l it is often useful to —™tu—lly look —t the implement—tion of how the ™—l™ul—tion is done in pr—™ti™eF „he purpose of the ˜ook is therefore prim—rily ped—gogi™—lD —lthough s ˜elieve —ll the routines presented —re ™orre™t —nd re—son—˜ly e0™ientD —nd s know they —re —lso used ˜y people to pri™e re—l optionsF „o implement the —lgorithms in — ™omputer l—ngu—ge s ™hoose g++F wy students keep —sking why —ny˜ody would w—nt to use su™h — ˜—™kwoods ™omputer l—ngu—geD they think — spre—dsheet ™—n solve —ll the worlds pro˜lemsF s h—ve some experien™e with —ltern—tive systems for ™omputingD —nd no m—tter wh—tD in the end you end up ˜eing frustr—ted with higher end l—ngu—gesD su™h —s Matlab og Gauss @xot to mention the str—itj—™ket whi™h is is — spre—dsheetFA —nd going ˜—™k to implement—tion in — st—nd—rd l—ngu—geF sn my experien™e with empiri™—l (n—n™e s h—ve ™ome to re—lize th—t nothing ˜e—ts knowledge — real ™omputer l—ngu—geF „his used to ˜e FORTRAND then CD —nd now it is C++ F ell ex—mple —lgorithms —re therefore ™oded in g++F s do —™knowledge th—t m—trix tools like Matlab—re very good for r—pid prototyping —nd ™omp—™t ™—l™ul—tionsD —nd will in —ddition to g++ in pl—™es —lso illustr—te the use of MatlabF „he m—nus™ript h—s ˜een sitting on the internet for — num˜er of ye—rsD during whi™h it h—s ˜een visited ˜y — l—rge num˜er of peopleD to judge ˜y the num˜er of m—ils s h—ve re™eived —˜out the routinesF „he present @PHHSA version m—inly exp—nds on the ˜—™kground dis™ussion of the routinesD this is mu™h more extensiveF s h—ve —lso —dded — good de—l of introdu™tory m—teri—l on how to progr—m in g++D sin™e — num˜er of questions m—ke it o˜vious this m—nus™ript is used ˜y — num˜er of people who know (n—n™e ˜ut not g++F ell the routines h—ve ˜een m—de to ™on(rm to the new sƒyGexƒs g++ st—nd—rdD using su™h ™on™epts —s n—mesp—™es —nd the st—nd—rd templ—te li˜r—ryF „he ™urrent m—ns™ript therefore h—s v—rious intented —udien™esF €rim—rily it is for students of (n—n™e who desires to see — ™omplete dis™ussion —nd implement—tion of some formul—F fut the m—nus™ript is —lso useful for students of (n—n™e who w—nts to le—rn g++D —nd for ™omputer s™ientists who w—nt to underst—nd —˜out the (n—n™e —lgorithms they —re —sked to implent —nd em˜ed into their progr—msF sn doing the implement—tion s h—ve tried to ˜e —s generi™ —s possi˜le in terms of the g++ usedD ˜ut s h—ve t—ken —dv—nt—ge of — some of the possi˜ilities the l—ngu—ge provides in terms of —˜str—™tion —nd modul—riz—tionF „his will —lso serve —s — lesson in why — real ™omputer l—ngu—ge is usefulF por ex—mple s h—ve en™—psul—ted the term stru™ture of interest r—te —s —n ex—mple of the use of classesF „his is not — text˜ook in the underlying theoryD for th—t there —re m—ny good —ltern—tivesF por mu™h of the m—teri—l the ˜est text˜ooks to refer to —re rull @PHHTA —nd w™hon—ld @PHHTAD whi™h s h—ve used —s referen™esF „he not—tion of the present m—nus™ipt is —lso simil—r to these ˜ooksF

Q

Chapter 1

On C++ and programming.
sn this ™h—pter s introdu™e g++ —nd dis™uss how to run progr—ms written in g++F „his is ˜y no me—ns — ™omplete referen™e to progr—mming in g++D it is designed to give enough inform—tion to underst—nd the rest of the ˜ookF „his ™h—pter —lso only dis™usses — su˜set of g++D it ™on™entr—tes on the p—rts of the l—ngu—ge used in the rem—inder of this ˜ookF por re—lly le—rning g++ — text˜ook is ne™ess—ryF s h—ve found vippm—n —nd v—joie @IWWVA —n ex™ellent introdu™tion to the l—ngu—geF „he —uthor—tive sour™e on the l—ngu—ge is ƒtroustrup @IWWUAF

1.1

Compiling and linking

„o progr—m in g++ one h—s to (rst write — sep—r—te (le with the progr—mD whi™h is then compiled into lowElevel instru™tions @m—™hine l—ngu—geA —nd linked with li˜r—ries to m—ke — ™omplete exe™ut—˜le progr—mF „he me™h—ni™s of doing the ™ompiling —nd linking v—ries from system to systemD —nd we le—ve these det—ils —s —n exer™ise to the re—derF

1.2

The structure of a C++ program

„he (rst thing to re—lize —˜out g++ is th—t it is — strongly typed l—ngu—geF iverything must ˜e de™l—red ˜efore it is usedD ˜oth v—ri—˜les —nd fun™tionsF g++ h—s — few ˜—si™ ˜uilding ˜lo™ksD whi™h ™—n ˜e grouped into typesD oper—tions —nd fun™tionsF

1.2.1 Types
„he types we will work with in this ˜ook —re boolD intD longD double —nd stringF rere —re some ex—mple de(nitions

bool this_is_true=true; int i = 0; long j = 123456789; double pi = 3.141592653589793238462643; string s("this is a string");

classesD of whi™h more l—terF

„he most import—nt p—rt of g++ ™omes from the f—™t th—t these ˜—si™ types ™—n ˜e exp—nded ˜y use of

1.2.2 Operations
„o these ˜—si™ types the ™ommon m—them—ti™—l oper—tions ™—n ˜e —ppliedD su™h —s —dditionD su˜tr—™tionD multipli™—tion —nd divisionX

int int int int

i j n m

= = = =

100 100 100 100

+ * /

50; 50; 2; 2;

„hese oper—tions —re de(ned for —ll the ™ommon d—t—typesD with ex™eption of the string typeF ƒu™h oper—tions ™—n ˜e de(ned ˜y the progr—mmer for other d—t—types —s wellF

R

Increment and decrement
int i=0; i = i+1; i = i-1;

sn —ddition to these ˜—si™ oper—tions there —re some —ddition—l oper—tions with their own shorth—ndF en ex—mple we will ˜e using often is in™rementing —nd de™rementing — v—ri—˜leF ‡hen we w—nt to in™re—se the v—lue of one item ˜y oneD in most l—ngu—ges this is writtenX

sn C++ this oper—tion h—s its own shorth—nd

int i=0; i++; i--;
‡hile this does not seem intuitiveD —nd it is ex™us—˜le to think th—t this oper—tion is not re—lly ne™ess—ryD it does ™ome in h—ndy for more —˜str—™t d—t— ™onstru™tsF por ex—mpleD —s we will see l—terD if one de(nes — date ™l—ss with the ne™ess—ry oper—tionsD to get the next d—te will simply ˜e — m—tter of

date d(1,1,1995); d++;
„hese two st—tements will result in the d—te in d ˜eing Pj—nWSF

1.2.3 Functions and libraries
sn —ddition to the ˜—si™ m—them—ti™—l oper—tions there is — l—rge num˜er of —ddition—l oper—tions th—t ™—n ˜e performed on —ny typeF roweverD these —re not p—rts of the ™ore l—ngu—geD they —re implemented —s st—nd—lone fun™tions @most of whi™h —re —™tu—lly written in C or g++AF „hese fun™tions —re in™luded in the l—rge library th—t ™omes with —ny g++ inst—ll—tionF ƒin™e they —re not p—rt of the ™ore l—ngu—ge they must ˜e de(ned to the ™ompiler ˜efore they ™—n ˜e usedF ƒu™h de(nitions —re performed ˜y me—ns of the include st—tementF por ex—mpleD the m—them—ti™—l oper—tions of t—king powers —nd performing exponenti—tion —re de(ned in the m—them—ti™—l li˜r—ry cmathF sn the g++ progr—m one will write

#include <cmath> cmath is —™tu—lly — (le with — l—rge num˜er of fun™tion de(ntionsD —mong whi™h one (nds pow(x,n) whi™h ™—l™ul—tes xn D —nd exp(r) whi™h ™—l™ul—tes er F „he following progr—mming stu˜ ™—l™ul—tes a = 22 —nd b = e1 F #include <cmath> double a = pow(2,2); double b = exp(1);
whi™h will give the v—ri—˜les a —nd b v—lues of R —nd PFUIVPVIVPVFFFD respe™tivelyF

1.2.4 Templates and libraries
„he use of li˜r—ries is not only limited to fun™tionsF elso in™luded in the st—nd—rd li˜r—ry is generi™ d—t— stru™turesD whi™h ™—n ˜e used on —ny d—t— typeF „he ex—mple we will ˜e ™onsidering the most is the vector<>D whi™h de(nes —n —rr—yD or ve™tor of v—ri—˜lesF

#include <vector> vector<double> M(2); M[0]=1.0; M[1]=2.0; M.push_back(3);
S

}.2.push_back(3).0. i++) { some_operation(i). i<n. „o write to — (le 4test. lies one of the prime tr—ps for progr—mmers ™oming to C or g++ from —nother l—ngu—geF sndexing of —rr—ys st—rts —t zeroD not —t oneF M[0] re—lly me—ns the rst element of the —rr—yF „he l—st st—tementD M. „he for st—tement h—s tree p—rtsF „he (rst p—rt gives the initi—l ™ondition @i=0AF „he next p—rt the termin—l ™ondition @i<nAD whi™h s—ys to stop when i<n is not ful(lledD whi™h is —t the n9th iter—tionF „he l—st p—rt is the in™rement st—tement @i++AD s—ying wh—t to do in e—™h iter—tionF sn this ™—se the v—lue of i is in™re—sed ˜y one in e—™h iter—tionF „his is the typi™—l for st—tementF yne of the ™—uses of C9s reput—tion for terseness is the possi˜ility of el—˜or—te for ™onstru™tsD whi™h end up ˜eing —lmost impossi˜le to re—dF sn the —lgorithms presented in this ˜ook we will try to —void —ny o˜fus™—ted for st—tementsD —nd sti™k to the ˜—si™ ™—sesF 1. we de(ned —n —rr—y of P elements of type doubleD whi™h we then pro™eeded to (ll with the v—lues I —nd PF ‡hen (lling the —rr—y we —ddressed e—™h element dire™tlyF xote th—t in the st—tement M[0]=1.5 Flow control „o repe—t st—tements sever—l times one will use on of the possi˜ilities for )ow ™ontrolD su™h —s the for or while ™onstu™tsF por ex—mpleD to repe—t —n oper—tion n times one ™—n use the following for loopX for (int i=0. shows the —˜ility of the progr—mmer of ™h—nging the size of the —rr—y —fter it h—s ˜een de(nedF push_back is — st—nd—rd oper—tion on —rr—ys whi™h pushes the element onto the ˜—™k of the —rr—yD extending the size of the —rr—y ˜y one elementF wost progr—mming l—ngu—ges do not —llow the progr—mmer to spe™ify v—ri—˜leEsized —rr—ys on the )yF sn FORTRAN or Pascal we would usu—lly h—ve to set — m—ximum length for e—™h —rr—yD —nd hope th—t we would not need to ex™eed th—t lengthF „he vector<> templ—te of g ++ gets rid of the progr—mmers need for ˜ookkeeping in su™h —rr—y m—nipul—tionsF 1.„his ex—mple de(nes —n —rr—y with three elements of type dou˜le   1 M = 2  3 xote some pe™ul—rities hereF ‡hen (rst de(ning the ve™tor with the st—tement vector<double> M(2).out4D one will do —s followsX T .6 Input Output por —ny progr—m to do —nything useful it needs to ˜e —˜le to output its resultsF snput —nd output oper—tions is de(ned in — ™ouple of li˜r—riesD iostream —nd fstreamF „he (rst ™overs inGoutput to st—nd—rd termin—ls —nd the se™ond inGoutput to (lesF „o write to st—nd—rd output cout @the termin—lAD one will do —s followsX #include <iostream> cout << "This is a test" << endl.2.

n<6.n++){ ™out << " 2^" << n << " = " << power(2. C++ Code 1. outf.8 Namespaces „o help in ˜uilding l—rge progr—msD the ™on™ept of — namespace w—s introdu™edF x—mesp—™es —re — me—ns of keeping the v—ri—˜les —nd fun™tions de(ned lo™—l to the ™ontext in whi™h they —re usedF por now it is ne™ess—ry to know th—t —ny fun™tion in the st—nd—rd g++ li˜r—ry lies in its own n—mesp—™eD ™—lled the st—nd—rd n—mesp—™eF „o —™tu—lly —™™ess these li˜r—ry fun™tons it is ne™ess—ry to expli™itly spe™ify th—t one w—nts to —™™ess the st—nd—rd n—mesp—™eD ˜y the st—tement using namespace std.close().clear().#include <fstream> ofstream outf. outf. double n){ exp(n*log(x)). snste—d of su™h — gener—l —ppro—™hD one ™—n —lso spe™ify the n—mesp—™e on —n element ˜y element ˜—sisD ˜ut this is more — topi™ for spe™i—lized g++ textsD for the ™urrent purposes we will —llow —ll routines —™™ess to the whole st—nd—rd n—mesp—™eF U .7 Splitting up a program eny nontrivi—l progr—m in g++ is split into sever—l pie™esF …su—lly e—™h pie™e is written —s — fun™tion whi™h returns — v—lue of — given typeF „o illustr—te we provide — ™omplete ex—mple progr—mD shown in Code 1. }. // dene a simple power function power(double x.2. outf. m—in(){ n=1. // the above is part of the standard namespace double double p = return p.n) whi™h ™—lE ™ul—tes xn through the identity xn = en ln(x) F „his fun™tion is then used to ™—l™ul—te —nd print the (rst S powers of PF #include <iostre—m> // input output operations #include <™m—th> // mathematics library using namespace std. }. 1.2.1F „he progr—m de(nes — fun™tion performing the m—them—ti™—l power oper—tionD power(x.n) << endl.out").open("test. outf << "This is a test" << endl. int for (int }.1: e ™omplete progr—m ‡hen ™ompiledD linked —nd runD the progr—m will provide the following output 2^1 2^2 2^3 2^4 2^5 = = = = = 2 4 8 16 32 1.

1 date.2001). the class concept. would result in the date o˜je™t d ™ont—ining the d—te P j—nu—ry PHHIF eny g++ progr—mmer who w—nt to use this date o˜je™t will only need to look —t the he—der (le to know wh—t —re the possi˜le fun™tions one ™—n use with — date o˜je™tD —nd ˜e h—ppy —˜out not needing to know —nything —˜out how these fun™tions —re implementedF „his is the en™—psul—tion p—rt of o˜je™t oriented progr—mmingD —ll relev—nt inform—tion —˜out the date o˜je™t is spe™i(ed ˜y the he—der (leF „his is the only point of inter—™tionD —ll det—ils —˜out implement—tion of the ™l—ss o˜je™ts —nd its fun™tions is not used in ™ode using this o˜je™tF V . yne of the m—jor —dv—n™es of g++ rel—tive to other progr—mming l—ngu—ges is the progr—mmers —˜ility to extend the l—ngu—ge ˜y ™re—ting new d—t— types —nd de(ning st—nd—rd oper—tions on these d—t— typesF „his —˜ility is why g++ is ™—lled —n o˜je™t oriented progr—mming l—ngu—geD sin™e mu™h of the work in progr—mming is done ˜y ™re—ting objectsF en o˜je™t is ˜est though of —s — d—t— stru™ture with oper—tions on it de(nedF row one uses —n o˜je™t is ˜est shown ˜y —n ex—mpleF 1. • pun™tions outputting the d—te ˜y the three integer fun™tions day()D month() —nd year()F • pun™tions setting the d—te set_day(int)D set_month(int) —nd set_year(int)D whi™h —re used ˜y providing —n integer —s —rguments to the fun™tionF • sn™rement —nd de™rement fun™tions ++ —nd  • gomp—rison fun™tions <D <=D >D >=D == —nd !-F efter in™luding this he—der (leD progr—mmers using su™h — ™l—ss will then tre—t —n o˜je™t of type date just like —ny otherF por exmpleD date d(1. const int& m. ++d.1.1.3. const int& y).3 Extending the language. an example class gonsider the —˜str—™t ™on™ept of — d—teF e d—te ™—n ˜e spe™i(ed in —ny num˜er of w—ysF vet us limit ourselves to the qregori—n ™—lend—rF IP —ugust PHHQ is — ™ommon w—y of spe™ifying — d—teF roweverD it ™—n —lso ˜e represented ˜y the stringsX  2003/8/12D  12/8/2003 —nd so onD or ˜y the num˜er of ye—rs sin™e I j—nu—ry IWHHD the num˜er of months sin™e t—nu—ryD —nd the d—y of the month @whi™h is how — …xsˆ progr—mmer will think of itAF roweverD for most people writing progr—ms the represent—tion of — d—te is not relev—ntD they w—nt to ˜e —˜le to enter d—tes in some —˜str—™t w—yD —nd then —re ™onserned with su™h questions —sX • ere two d—tes equ—lc • ss one d—te e—rlier th—n —notherc • row m—ny d—ys is it ˜etween two d—tesc e g++ progr—mmer will pro™eed to use — class th—t em˜odies these uses of the ™on™ept of — d—teF „ypi™—lly one will look —round for —n ext—nt ™l—ss whi™h h—s —lre—dy implemented thisD ˜ut we will show — trivi—l su™h d—te ™l—ss —s —n ex—mple of how one ™—n ™re—te — ™l—ssF e ™l—ss is de(ned in — he—der (leD —s shown in ™ode IFPF e num˜er of things is worth noting hereF es intern—l represent—tion of the d—te is ™hosen the three integers day_D month_ —nd year_F „his is the d—t— stru™ture whi™h is then m—nipul—ted ˜y the v—rious fun™tions de(ned ˜elowF „he fun™tions —re used to • gre—te — d—te v—ri—˜leX date(const int& d.

3 de(nes the ˜—si™ oper—tionsD initi—liz—tionD setting the d—teD —nd ™he™king whether — d—te is v—lidF W . d—y() const. // postx prex // postx bool bool bool bool bool bool operator operator operator operator operator operator == ( != ( const d—te&. set d—y (const int& d—y ). void void void d—te d—te d—te d—te }. // comparison operators C++ Code 1. const d—te&). // prex ++( −−(). public: bool int int int .2: he(ning — date ™l—ss vet us look —t the implement—tion of thisF Code 1. d—te(). set month (const int& month set ye—r (const int& ye—r ). >= (const d—te&. operator operator operator operator ++(). int month int d—y . v—lid() const. ye—r() const. month() const. const d—te&). ). const d—te&). < (const d—te&. <= (const d—te&. const d—te&). > (const d—te&. const d—te&. const int& m.class d—te { protected: int ye—r . d—te(const int& d. const d—te&). int). const d—te&). // −−(int). const int& y).

}. }. ye—r = ye—r. d—teXXv—lid() }. }. though (month (ye—r const { if if if if if <0) return false.#include "date. d—y = d—y. >12 | | month <1) return false. month = month. return false. . d—y = 0. }.h" d—teXXd—te(){ ye—r = 0.}. d—teXXmonth() const { return month d—teXXye—r() const { return ye—r . void void void bool // d—teXXset d—y (const int& d—y) { d—teXXd—y = d—y. return true. ==6 | | month ==9 | | month ==11) ) ) ==30 && month ==2) // should also check for leap years. d—teXXset ye—r (const int& ye—r) { d—teXXye—r = ye—r. month = 0. d—teXXd—te(const int& d—y. // This function will check the given date is valid or not. }. Need some more checks on the year. but for now allow for feb 29 in any year return false. }. const int& ye—r){ int int int d—teXXd—y() const { return d—y . C++ Code 1. (d—y >31 | | d—y <1) ((d—y ==31 && ( month ==2 | | month ==4 | | month ( d—y return false. const int& month. d—teXXset month(const int& month) { d—teXXmonth = month.3: f—si™ oper—tions for the d—te ™l—ss IH . // If the date is not valid then it will return the value false. }.

ye—r()) { // same year if (dI. return { // dierent year (dI. // remaining operators dened in terms of the above bool operator <=(const d—te& if (dI==dP) { return true.d—y()<dP. not clear what to do.d—y()) && (dI.month()) { // same month return (dI. ((dI. const const d—te& dP) { return !(dI<=dP).} C++ Code 1.4: gomp—rison oper—tors for the d—te ™l—ss II . return }.d—y()). !=( const d—te& dP){ return !(dI==dP).v—lid() && (dP.h" bool operator == (const d—te& dI. } return (dI<dP). } // see above remark else { return }.month()<dP.ye—r()<dP.v—lid())) ) { return false.}. } (dI.ye—r()).por m—ny —˜str—™t types it ™—n ˜e possi˜le to de(ne —n orderingF por d—tes there is the n—tur—l orderingF Code 1.const d—te& dP){ // check for equality if (! (dI.}.month()==dP. }. return (dI>dP).d—y()==dP. d—te& dP) { bool operator bool operator > ( const d—te& dI. const d—te& dP){ if (! (dI.ye—r()==dP. }. }.v—lid() && (dP.v—lid())) ) { return false. /* if dates not valid. const if (dI==dP) { return true.ye—r())). d—te& dI.month()). }.month()) && (dI.4 shows how su™h ™omp—rison oper—tions is de(nedF #include "date. } dI. const d—te& dP){ bool operator >=(const d—te& dI.month()==dP. else }. alternative: throw exception */ bool operator < (const d—te& dI. if (dI.ye—r()==dP.

return new value return *this.(d.month()−1). }. month d—te d—teXXoper—tor ++(int){ d—te d = *this.v—lid()) return nd—t.d.12.ye—r()).v—lid()) return nd—t. // return the default date d—te pd—t = d—te((d. // must be next year return nd—t.d. if (pd—t. }.month().v—lid()) { return d—te(). return current value d—te d—teXXoper—tor −−(){ // prex *this = previous d—te(*this). pd—t = d—te(29.(d.5 shows oper—tions for (nding previous —nd next d—teD ™—lled —n iteration #include "date.(d.ye—r()). } postx operator. // then try adding a month if (nd—t.ye—r()).ye—r()+1)). // d—te nd—t=d—te((d. if (pd—t.(d.(d.v—lid()) return pd—t. // rst try adding if (nd—t.ye—r()−1)).d—y()+1).d.month()+1).d.(d. pd—t = d—te(31. prex operator return *this.Code 1.h" d—te next d—te(const d—te& d){ if (!d.1.d.month()−1).month(). }. // try previous year return pd—t. nd—t=d—te(1.v—lid()) return pd—t.d. } d—te d—teXXoper—tor −−(int){ // d—te d = *this.ye—r()).month()−1). } oper—torF a day d—te previous d—te(const d—te& d){ if (!d.d. if (pd—t. return d.d.ye—r()).5: ster—tive oper—tors for the d—te ™l—ss IP . *this = next d—te(d). return d.(d. // try previous month pd—t = d—te(30. // try same pd—t = d—te(31.v—lid()) return pd—t. }.v—lid()) return pd—t. if (pd—t.v—lid()) return pd—t.v—lid()) { return d—te(). C++ Code 1.d. *this = previous d—te(*this). pd—t = d—te(28. nd—t = d—te(1.ye—r()). } // postx operator d—te d—teXXoper—tor ++(){ // *this = next d—te(*this).d—y()−1). operator.ye—r()).month()−1). if (pd—t.

"sun"} 3."tue"."wed". which your typical C++ implementation can call. Implement a function querying the operating system for the weekday of a given date. Find the relevant functions in your implementation. Add a given number of days to a date? 2. Reimplement the valid() function using a system call. Go to the end or beginning of a month? 3. 2. a number of obvious functions begs to be implemented.Exercise 1. Modify the function to return a false if the year is not a leap year. How would you 1. Exercise 2. A typical operating system has functions for dealing with dates. and 1."fri". Find the distance betwen two dates (in days or in years)? 4. The function valid() in the date class accepts february 29'th in every year. Implement a function querying the operating system for the current date."thu". and return this date. and return a representation of the weekday as a member of the set: {"mon". Once the date class is available."sat". Exercise 3. but this should ideally only happen for leap years. Extract a date from a string? (Here one need to make some assumptions about the format) IQ .

1. some_function(const double& r).5 Other C++ concepts e num˜er of other g++ ™on™eptsD su™h —s fun™tion prototypes —nd templ—tesD will ˜e introdu™ed l—ter in p—rti™ul—r ™ontextsF „hey only —ppe—r in — few pl—™es —nd is ˜etter introdu™ed where they —re usedF IR .4 Const references vet us now dis™uss — ™on™ept of more te™hni™—l n—tureF gonsider two —ltern—tive ™—lls to — fun™tionD de(ned ˜y fun™tion ™—llsX some_function(double r). „hey ˜oth —re ™—lled ˜y —n —rgument whi™h is — dou˜leD —nd th—t —rgument is gu—r—nteed to not ˜e ™h—nged in the ™—lling fun™tionD ˜ut they work di'erentlyF sn the (rst ™—se — ™opy of the v—ri—˜le referen™ed to in the —rgument is ™re—ted for use in the fun™tionD ˜ut in the se™ond ™—se one uses the s—me v—ri—˜leD the —rgument is — reference to the lo™—tion of the v—ri—˜leF „he l—tter is more e0™ientD in p—rti™ul—r when the —rgument is — l—rge ™l—ssF roweverD one worries th—t the v—ri—˜le referred to is ™h—nged in the fun™tionD whi™h in most ™—ses one do not w—ntF „herefore the const qu—li(erD it s—ys th—t the fun™tion ™—n not modify its —rgumentF „he ™ompiler will w—rn the progr—mmer if —n —ttempt is m—de to modify su™h — v—ri—˜leF por e0™ien™yD in most of the following routines —rguments —re therefore given —s —s ™onst—nt referen™esF 1.

6] „his p—rti™ul—r ™omm—nd de(nes — m—trix AD the m—trix tool will respond to this ™omm—nd ˜y printing the m—trix th—t w—s just de(nedX A = 1 2 3 4 5 6 IS . 2.1 The rst screen „hese tools —re inter—™tiveD they present you with — promptD —nd expe™t you to st—rt writing ™omm—ndsF s will denote > —s the promptD whi™h me—ns th—t the progr—m is re—dy to re™eive ™omm—ndsF sn the text output of the m—trix tool will ˜e shown typewritten —sX > A = [1. 3. 4.Chapter 2 Matrix Tools feing ™omputer liter—te ent—ils ˜eing —w—re of — num˜er of ™omputer tools —nd ˜eing —˜le to ™hoose the most suit—˜le tool for the pro˜lem —t h—ndF ‡—y to m—ny people turns this —roundD —nd w—nt to (t —ny pro˜lem to the ™omputer tool they knowF „he tool th—t very often is the tool for ˜usiness s™hool students is — spre—dsheet like ExcelF roweverD this is not the ˜est tool for more ™omput—tion—lly intensive t—sksF ‡hile the ˜ulk of the present ˜ook ™on™erns itself with g++D in m—ny —ppli™—tions in (n—n™e — very h—ndy tool is — l—ngu—ge for m—nipul—ting ve™tors —nd m—tri™es using line—r —lge˜r—F „here —re — lot of di'erent possi˜le progr—ms th—t ˜eh—ves very simil—rlyD with — synt—x t—ken from the m—them—ti™—l formul—tion of line—r —lge˜r—F en e—rly tool of this sort w—s matlabD with — l—rge num˜er of progr—ms ™opying mu™h of the synt—x of this progr—mF es — result of this there is — prolifer—tion of progr—ms with simil—r synt—x to m—tl—˜ doing simil—r —n—lysisF qener—l tools in™lude the ™ommer™i—l version of matlab sold ˜y w—thworksD the pu˜li™ dom—in progr—ms octave —nd scilabF „ools th—t —re simil—rD ˜ut more ge—red tow—rds e™onometri™sD in™lude S with its pu˜li™ dom—in ™lone RD q—uss —nd yxF es for wh—t progr—m to inst—llD there is no right —nswerF por the ˜—si™ le—rning of how these tools workD —ny of the mentioned p—™k—ges will do the jo˜F por students on — limited ˜udget the pu˜li™ dom—in tools octave —nd scilab —re o˜vious ™—ndid—tesF foth of them perform the ˜—si™ oper—tions done ˜y the ™ommer™i—l m—tl—˜ p—™k—geD —nd good for le—rning the ˜—si™s of su™h — m—trix toolF sn the rest of this ™h—pter s will give —n introdu™tion to — tool like thisF 2. 5.

.Chapter 3 The value of time pin—n™e —s — (eld of study is sometimes somewh—t )ipp—ntly s—id to de—l with the v—lue of two thingsX time —nd riskF ‡hile this is not the whole storyD there is — de—l of truth in itF „hese —re the two issues whi™h is —lw—ys presentF ‡e st—rt our dis™ussion ˜y ignoring risk —nd only ™onsidering the impli™—tions of the f—™t th—t —ny˜ody prefers to get something e—rlier r—ther th—n l—terD or the v—lue of timeF 3. .2 One interest rate with annual compounding „he ˜est known w—y to simplify the present v—lue ™—l™ul—tion is to rewrite the dis™ount f—™tors in terms of interest r—tesD or yieldsD through the rel—tionshipX dt = 1 (1 + rt )t IT . tN F C1 0 t1 C2 t2 CN E tN time „o (nd the present v—lue of these future ™—sh )ows one need — set of pri™es of future ™—sh )owsF ƒuppose dt is the pri™e one would p—y tod—y for the right to re™eive one doll—r —t — future d—te tF ƒu™h — pri™e is —lso ™—lled — discount factorF „o ™ompli™—te m—tters further su™h pri™es will di'er depending on the riskiness of the future ™—sh )owsF por now we ™on™entr—te on one p—rti™ul—r set of pri™esD the pri™es of riskless future ™—sh )owsF ‡e will return to how one would —djust the pri™es for risky ™—sh )owsF sf one knows the set of pri™es for future ™l—ims of one doll—rD d1 . t2 .1 Present value „he present v—lue is the ™urrent v—lue of — stre—m of future p—ymentsF vet Ct ˜e the ™—sh )ow —t time tF ƒuppose we h—ve N future ™—sh )ows th—t o™™ur —t times t1 .D one would ™—l™ul—te the present v—lue —s the sum of the present v—lues of the di'erent elementsF N PV = i=1 dti Cti Ct1 0 t1 Ct2 t2 CtN E tN time dt1 Ct1 ' ' dt2 Ct2 dtN CtN ' roweverD knowing this set of ™urrent pri™es for ™—sh )ows —t —ll future d—tes is not —lw—ys fe—si˜leD —nd some w—y h—s to ˜e found to simplify the d—t— need inherent in su™h gener—l present v—lue ™—l™ul—tionsF 3. · · · . d2 . . .

(1 + r)t sn this ™—se one would ™—l™ul—te the present v—lue of — stre—m of ™—sh )ows p—id —t dis™rete d—tes t = 1. 1. 2. the time 2 payment is X(1+g). Suppose there is a xed interest rate r. . where the payment the rst year is X and each consequent payment grows by a constant rate g . Perpetuity [5] A perpetuity is a promise of a payment of a xed amount X each period for the indenite future. t<™)ow times. const ve™tor<double>& ™)ow —mounts. }. const double& r){ double €†=0. 1. Growing perpetuity [6] A growing perpetuity is again an innite sequence of cashows. Show that the present value of this perpetuity simplies to ∞ PV = t=1 X(1 + g)t−1 X1 = t (1 + r) r−g 1 „his is termed — )—t term stru™tureF ‡e will in the next ™h—pter rel—x this simplifying —ssumptionF IU . #include <iostre—m> double ™—sh )ow pv dis™rete(const ve™tor<double>& ™)ow times.size(). return €†. for (int t=0.t++) { €† += ™)ow —mounts[t]/pow(1. and so on. (1 + r)t „he implement—tion of this ™—l™ul—tion is shown in ™ode QFIF #include <™m—th> #include <ve™tor> using namespace std. Show that the present value of this sequence of cash ows is calculated simply as ∞ PV = t=1 X X = 1+r r Exercise 5. }.0+r. N —s N PV = t=1 Ct . . .0.where rt is the interest r—te @usu—lly termed the spot r—teA relev—nt for — tEperiod investmentF „o further simplify this ™—l™ul—tion one ™—n impose th—t this interest r—te r is ™onst—nt for —ll periodsF1 „he pri™es for v—luing the future p—yments dt is ™—l™ul—ted from this interest r—teX dt = 1 .1: €resent v—lue with dis™rete ™ompounding qiven the —ssumption of — dis™reteD —nnu—l interest r—teD there —re — num˜er of useful spe™i—l ™—ses of ™—sh )ows where one ™—n ™—l™ul—te the present v—lue in — simpli(ed m—nnerF ƒome of these —re shown in the following exer™isesF Exercise 4. the time 3 payment is X(1 + g)2 . i. C++ Code 3.™)ow times[t]).e.

A perpetuity with an annual payment of $100. say T periods into the future. where the rst payment is $75. periods into the future. C1 . A 10-year annuity with an annual payment of $90. say T an annuity paying a xed amount X each period. the payments grows at a rate of g per year. The interest rate is r. Use an interest rate of 5%. 3. After that. where the rst paymet is $85. the third X(1 + g)2 . sn —ddition to its role in simplifying present v—lue ™—l™ul—tionsD the interest r—te h—s some further useF „he per™ent—ge return on —n investment is — summ—ry me—sure of the investment9s pro(t—˜ilityF ƒ—ying th—t —n investment e—rns IH7 per ye—r is — good w—y of summ—rizing the ™—sh )ows in — w—y th—t does not depend on the —mount of the initi—l investmentF „he return is thus — rel—tive me—sure of pro(t—˜ilityF „o estim—te — return for — set of ™—sh )ows we ™—l™ul—te the internal rate of returnF „he intern—l r—te of return for — set of ™—sh )ows is the interest r—te th—t m—kes the present v—lue of the ™—sh )ows equ—l to zeroF ƒuppose the ™—sh )ows —re C0 . 1. and so on.Exercise 6. and each subsequent payment grows by 2%. Show that the present value of this sequence of cash ows can be simplied as T PV = t=1 1 1 1 X =X − (1 + r)t r r (1 + r)T Exercise 7. i. and each subsequent payment grows by 5%. A growing perpetuity. C2 . A 10 year growing annuity. the second year the cash ow is X(1 + g). . 3. where each payment grows by a given factor each year.1 Internal rate of return. 4. Consider 1. Annuity [5] An annuity is a sequence of cashows for a given number of years. Rank the following cash ows in terms of present value. . Show that the present value of this growing annuity can be simplied as T PV = t=1 X(1 + g)(t−1) 1 =X − (1 + r)t r−g 1+g 1+r T 1 r−g Exercise 8. 2. 1.2. CT F pinding —n intern—l r—te of return is thus to (nd — solution y of the equ—tion T t=1 Ct − C0 = 0 (1 + y)t xote th—t this is — polynomi—l equ—tionD —nd —s T ˜e™omes l—rgeD there in no w—y to (nd —n expli™it solution to the equ—tionF st therefore needs to ˜e solved numeri™—llyF por rel—tively well ˜eh—ved ™—sh )owsD where we know th—t there is one s‚‚D the method implemented in ™ode QFP is suit—˜leD it is —n iter—tive pro™ess ™—lled ˜ise™tionF st is —n —d—ption of the ˜r—™keting —ppro—™h dis™ussed in @€ressD „eukolskyD †etterlingD —nd pl—nneryD IWWPD gh—pterWAD IV . .e. Growing Annuity [6] An growing annuity is a sequence of cashows for a given number of years. We Consider a T -period annuity that pays X the rst period.

5. if (f <0.0) { break.i++) { if ( (fI*fP) < 0. const int weˆ s„i‚e„syxƒ = 50. Will nd one root (if it exists. return i‚‚y‚.6*(xI−xP)). rt˜ = xP. if (™)ow times.top times.0e−5.™)ow —mounts.i<weˆ s„i‚e„syxƒ. dx=xP−xI. }.i++){ *= 0. xP). for (i=0. double dx=0.size()!=™)ow —mounts.) ™—sh )ow irr dis™rete(const ve™tor<double>& ™)ow times.6*(xP−xI)).2.i<weˆ double x mid = rt˜+dx. ™—sh )ow pv dis™rete(™)ow times. else }. }. double f = ™—sh )ow pv dis™rete(™)ow double rt˜.0) { rt˜ = x mid.™)ow —mounts. }. if (f mid<=0.0) { return i‚‚y‚. }. double fI = ™—sh )ow pv dis™rete(™)ow double fP = ™—sh )ow pv dis™rete(™)ow int i. with a root somewhere between bot.#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. double xI=0.2: istim—tion of the intern—l r—te of return ‡hen there is — uniquely de(ned intern—l r—te of return we get — rel—tive me—sure of the pro(t—˜ility of — set of ™—sh )owsD me—sured —s — returnD typi™—lly expressed —s — per™ent—geF xote some of the impli™it —ssumptions m—de hereF ‡e —ssume th—t the s—me interest r—te —pplies —t —ll future d—tes @iFeF — )—t term stru™tureAF „he s‚‚ method —lso —ssumes intermedi—te ™—sh )ows —re reinvested —t the intern—l r—te of returnF IW . double f mid = ™—sh )ow pv dis™rete(™)ow times. else }.h" const double double i‚‚y‚=−1e30.™)ow —mounts. dx s„i‚e„syxƒ. xP+=1.0. #include "fin_recipes. { // simple minded irr function. // create an initial bracket. } if ( (f—˜s(f mid)<egg…‚eg‰) | | (f—˜s(dx)<egg…‚eg‰) ) return x mid. times. { } times. ™)ow —mounts. xI). // error. xI+=1. const ve™tor<double>& ™)ow —mounts) i‚‚y‚.size()) return const double egg…‚eg‰ = 1. ™)ow —mounts. fP { = ™—sh )ow pv dis™rete(™)ow times. double xP = 0. xI). C++ Code 3. for (i=0.™)ow —mounts. dx = xI−xP. }.0) { rt˜ = xI. x mid). if (fP*fI>0. // if (f—˜s(fI)<f—˜s(fP)) { fI = } // adapted from routine in Numerical Recipes in C.

™out << " internal rate of return = ". 5% discretely compounded interest = 9. times.push ˜—™k(1).push ˜—™k(10. ™)ows) << endl.0). 5\% discretely compounded interest = " . ve™tor<double> times.push ˜—™k(110.push ˜—™k(0. ™out << ™—sh )ow pv dis™rete(times.ƒuppose we —re ™onsidering —n investment with the following ™—sh )ows —t d—tes 0D 1 —nd 2X C0 = −100.05.1: €resent v—lue ™—l™ul—tion PH .push ˜—™k(2). ™out << ™—sh )ow irr dis™rete(times. ™)ows.29705 internal rate of return = 0. ™)ows. yutput from g++ progr—mX present value.0).0). ™)ows.0). times. C1 = 10. ™)ows. r) << endl. ™out << " present value. times. double r=0. C2 = 110 IF ƒuppose the ™urrent interest r—te is S7F hetermine the present v—lue of the ™—sh )owsF PF pind the intern—l r—te of return of this sequen™e of ™—sh )owsF g++ progr—mX void test present v—lue(){ ve™tor<double> ™)ows. }.1 Example 3.push ˜—™k(−100.

const ve™tor<double>& ™)ow —mounts) { int sign ™h—nges=0. }.size(). double due to Norstrom if (sign ™h—nges<=1) return true. (sign (sign ™h—nges==0) ™h—nges==1) return false. if if }.++t){ if (sgn(e) != sgn(e+=™)ow —mounts[t])) sign ™h—nges++. ™—sh )ow unique irr(const ve™tor<double>& ™)ow times.2.t<™)ow times.size(). // rst check Descartes rule for (int t=1. sign ™h—nges=0. C1 = 10.3: „est for uniqueness of s‚‚ e ˜etter w—y to g—in —n underst—nding for the rel—tionship ˜etween the interest r—te —nd the present v—lue is simply to plot the present v—lue —s — fun™tion of the interest r—teF „he following pi™ture illustr—tes the method for two di'erent ™—sh )owsF xote th—t the set of ™—sh )ows on the left h—s two poss˜le interest r—tes th—t sets the present v—lue equ—l to zeroF C0 = −100. for (int t=1.++t){ if (sgn(™)ow —mounts[t−1]) !=sgn(™)ow —mounts[t])) sign ™h—nges++.}. C2 = 100 C0 = −100. C2 = −100 3. } C++ Code 3. return true.} else {return −1. }. // can not nd any irr e = ™)ow —mounts[0].sn —ddition to the —˜ove e™onomi™ qu—li(™—tions to interpret—tions of the intern—l r—te of returnD we —lso h—ve to de—l with te™hni™—l pro˜lem stemming from the f—™t th—t —ny polynomi—l equ—tion h—s potenti—lly sever—l solutionsD some of whi™h m—y ˜e im—gin—ryF2 „o see whether we —re likely to h—ve pro˜lems in identifying — single me—ningful s‚‚D the ™ode shown in ™ode QFQ implements — simple ™he™kF st is only — ne™ess—ry ™ondition for — unique s‚‚D not su0™ientD so you m—y still h—ve — wellEde(ned s‚‚ even if this returns f—lseF „he (rst test is just to ™ount the num˜er of sign ™h—nges in the ™—sh )owF prom hes™—rtes rule we know th—t the num˜er of re—l roots is one if there is only one sign ™h—ngeF sf there is more th—n one ™h—nge in the sign of ™—sh )owsD we ™—n go further —nd ™he™k the aggregated ™—sh )ows for sign ™h—nges @ƒee xorstrom @IWUPAAF #include <™m—th> #include <ve™tor> using namespace inline int bool std. return false. // check the aggregate cash ows. C1 = 201.t<™)ow times. sgn(const double& r){ if (r>=0) { return 1.2 Bonds e prime —ppli™—tion of present v—lue ™—l™ul—tions is the pri™ing of ˜onds —nd other (xed in™ome se™uritiesF ‡h—t distinguishes ˜onds is th—t the future p—yments —re set when the se™urity is issuedF „he simplestD 2 fy im—gin—ry here we me—n th—t we move —w—y from the re—l line to the set of ™omplex num˜ersF PI .

—nd most typi™—l ˜ondD is — (xed interestD ™onst—nt m—turity ˜ond with no def—ult riskF „here is however — l—rge num˜er of —ltern—tive ™ontr—™tu—l fe—tures of ˜ondsF „he ˜ond ™ould for ex—mple ˜— —n —nnuity ˜ondD p—ying — (xed —mount e—™h periodF por su™h — ˜ond the prin™ip—l —mount outst—nding is p—id gr—du—lly during the life of the ˜ondF „he interest r—te the ˜ond p—ys need not ˜e (xedD it ™ould ˜e — )o—ting r—teD the interest r—te p—id ™ould ˜e — fun™tion of some m—rket r—teF w—ny ˜onds —re issued ˜y ™orpor—tionsD —nd in su™h ™—ses there is — risk th—t the ™omp—ny issued the ˜ond def—ultsD —nd the ˜ond does not p—y the ™omplete promised —mountF enother thing th—t m—kes ˜ond pri™ing di0™ult in pr—™ti™eD is th—t interest r—tes tend to ™h—nge over timeF Bond Price ‡e st—rt ˜y ™onsidering — (xed interest ˜ond with no def—ult riskF ƒu™h ˜onds —re typi™—lly ˜onds issued ˜y governmentsF „he ˜ond is — promise to p—y — f—™e v—lue F —t the m—turity d—te T periods from nowF i—™h period the ˜ond p—ys — (xed per™ent—ge —mount of the f—™e v—lue —s ™oupon C F „he ™—sh )ows from the ˜ond thus look —s followsF t= 0 1 goupon C p—™e v—lue 2 C 3 C ··· T ··· C F „he ™urrent ˜ond pri™e @B0 A is the present v—lue of these ™—sh )owsX T B0 = t=1 Ct . for (int i=0.4: Yield to maturity fond pri™e ™—l™ul—tion with dis™reteD —nnu—l ™ompoundingF ƒin™e ˜onds —re issued in terms of interest r—teD it is —lso useful to (nd —n interest r—te num˜er th—t summ—rizes the terms of the ˜ondF „he o˜vious w—y of doing th—t is —sking the questionX ‡h—t is the intern—l r—te of return on the investment of ˜uying the ˜ond now —nd keeping the ˜ond to m—turityc „he —nswer to th—t question is the yield to m—turity of — ˜ondF „he yield to m—turity is the interest r—te th—t m—kes the present v—lue of the future ™oupon p—yments equ—l to the ™urrent ˜ond pri™eD th—t isD for — known pri™e B0 D the yield is the solution y to the equ—tion T B0 = t=1 Ct (1 + y)t @QFIA „his ™—l™ul—tion therefore h—s the s—me qu—li(™—tions —s dis™ussed e—rlierD it supposes reinvestment of ™oupon —t the ˜ond yieldF „here is mu™h less likelihood we9ll h—ve te™hni™—l pro˜lems with multiple PP . const ve™tor<double>& ™—sh)ows. ˜onds pri™e dis™rete(const ve™tor<double>& times. const double& r) { double p=0.times[i])). (1 + r)t where Ct = C when t < T —nd CT = C + F F „he ™—l™ul—tion of the ˜ond pri™e with dis™rete —nnu—l ™ompounding is shown in ™ode QFRF #include <™m—th> #include <ve™tor> using namespace double std.i<times. }. return }. p.size(). C++ Code 3.i++) { p += ™—sh)ows[i]/(pow((1+r).

5 * (top+˜ot). ™—sh)ows.solutions when doing this yield estim—tion for ˜ondsD sin™e the stru™ture of ™—sh )ows usu—lly is su™h th—t there exist only one re—l solution to the equ—tionF „he —lgorithm for (nding — ˜onds yield to m—turity shown in ™ode QFS is thus simple ˜ise™tionF ‡e know th—t the ˜ond yield is —˜ove zero —nd set zero —s — lower ˜ound on the ˜ond yieldF ‡e then (nd —n upper ˜ound on the yield ˜y in™re—sing the interest r—te until the ˜ond pri™e with this interest r—te is neg—tiveF ‡e then ˜ise™t the interv—l ˜etween the upper —nd lower until we —re ™lose enoughF #include <™m—th> using namespace std. return r.push ˜—™k(2). ™)ows. 9% discretely compounded interest = 102.5: fond yield ™—l™ul—tion with dis™reteD —nnu—l ™ompounding e Q ye—r ˜ond with — f—™e v—lue of 6IHH m—kes —nnu—l ™oupon p—yments of IH7F „he ™urrent interest r—te @with —nnu—l ™ompoundingA is W7F IF pind the ˜ond9s ™urrent pri™eF PF pind the ˜ond9s yield to m—turityF g++ progr—mX void test ˜onds pri™e dis™rete(){ ve™tor<double> ™)ows.r) − ˜ondpri™e.531 bond yield to maturity = 0. ve™tor<double> times. f) << endl. ™)ows.0.push ˜—™k(110). }. 9\% discretely compounded interest = " << f << endl. while (˜onds pri™e dis™rete(times. }. times. const ve™tor<double>& ™—sh)ows. if (di' >0. const ve™tor<double>& times.push ˜—™k(3). const int weˆ s„i‚e„syxƒ = 200. top=1. ™)ows. }. ™out << " bond yield to maturity = " << ˜onds yield to m—turity dis™rete(times.} else { top=r. ™)ows. ™out << " Bond price.0) { ˜ot=r.09 Duration ‡hen holding — ˜ond one would like to know how sensitive the v—lue of the ˜ond is to ™h—nges in e™onomi™ environmentF „he most relevent pie™e of the e™onomi™ environment is the ™urrent interest r—teF PQ . }. r). const double& ˜ondpri™e) { top*2. double ˜ot=0.push ˜—™k(1).push ˜—™k(10).h" double ˜onds yield to m—turity dis™rete( const double egg…‚eg‰ = 1e−5. yutput from g++ progr—mX Bond price. times. if (f—˜s(di' )<egg…‚eg‰) return r. times.09. #include "fin_recipes. top) > ˜ondpri™e) { top = double r = 0. for (int i=0.5 * (top+˜ot). r = 0. }. ™—sh)ows. ™)ows. double r=0. double f = ˜onds pri™e dis™rete(times. C++ Code 3.push ˜—™k(10).i++){ double di' = ˜onds pri™e dis™rete(times.i<weˆ s„i‚e„syxƒ.

for (int i=0. const ve™tor<double>& ™—sh)ows.7: g—l™ul—ting the w—™—ul—y dur—tion of — ˜ond xote thoughD th—t in the present ™—seD with — )—t term stru™tureD these should produ™e the s—me num˜erF sf the ˜ond is pri™ed ™orre™tlyD the yield to m—turity must equ—l the ™urrent interest r—teF sf r = y the two ™—l™ul—tions in equ—tions AQFPA —nd @QFQA o˜viously produ™es the s—me num˜erF PR . C++ Code 3. f += ™—sh)ows[i] / pow(1+r.i<times. }. ™—sh)ows. h/f. // use YTM in duration calculation }.en import—nt ™omponent of su™h ™—l™ul—tion is the duration of — ˜ondF „he dur—tion of — ˜ond should ˜e interpreted —s the weighted —ver—ge m—turity of the ˜ondD —nd is ™—l™ul—ted —s hur—tion = Ct t t (1+r)t fond €ri™e where Ct is the ™—sh )ow in period tD —nd r the interest r—teF …sing the ˜ond pri™e ™—l™ul—ted in equ—tion QFI we ™—l™ul—te dur—tion —s D= tCt t (1+r)t Ct t (1+r)t @QFPA whi™h is shown in ™ode QFT #include <™m—th> #include <ve™tor> using namespace double std. return ˜onds dur—tion dis™rete(times. ˜ond pri™e). C++ Code 3.h" double ˜onds dur—tion m—™—ul—y dis™rete(const ve™tor<double>& times.size(). const ve™tor<double>& ™—sh)ows. const double& r) { double f=0. double h=0. return }.times[i]). y). const double& ˜ond pri™e) { double y = ˜onds yield to m—turity dis™rete(times.times[i]).i++){ h += times[i] * ™—sh)ows[i] / pow(1+r. ™—sh)ows. ˜onds dur—tion dis™rete(const ve™tor<double>& times.6: fond dur—tion using dis™reteD —nnu—l ™ompounding —nd — )—t term stru™ture en —ltern—tive —ppro—™h to ™—l™ul—ting dur—tion is ™—l™ul—te the yield to m—turity y for the ˜ondD —nd use th—t in estim—ting the ˜ond pri™eF „his is ™—lled Macaulay DurationF pirst one ™—l™ul—tes y D the yield to m—turityD from T fond pri™e = t=1 Ct (1 + y)t —nd then use this y in the dur—tion ™—l™ul—tionX w—™—ul—y dur—tion = tCt t (1+y)t Ct t (1+y)t @QFQA gode QFU implements this ™—l™ul—tionF #include "fin_recipes.

return h/(1+y). ™—sh)ows. const double& ˜ond pri™e){ double y = ˜onds yield to m—turity dis™rete(times.2.3. double h = ˜onds dur—tion dis™rete(times. y). const ve™tor<double>& ™—sh)ows.3 Measuring bond sensitivity to interest rate changes xowD the re—son for why we s—y th—t we ™—n me—sure the sensitivity of — ˜ond pri™e using dur—tionF „o — (rst —pproxim—tionD ∆B0 D the ™h—nge in the ˜ond pri™e for — sm—ll ™h—nge in the interest r—te ∆rD ™—n ˜e ™—l™ul—ted ∆B0 D ≈− ∆r B0 1+r where D is the ˜ond9s dur—tionF por simpli™ity one often ™—l™ul—tes the term in front of the ∆y in the D —˜oveD 1+y dire™tly —nd terms it the ˜ond9s modied durationF wodi(ed hur—tion = D∗ = D 1+r „he sensitivity ™—l™ul—tion is then ∆B0 ≈ −D∗ ∆r B0 „he modi(ed dur—tion is —lso written in term9s of the ˜ond9s yield to m—turity y D —nd is then D∗ = D 1+y gode QFV shows this ™—l™ul—tionF #include <ve™tor> using namespace std. #include "fin_recipes.8: wodi(ed dur—tion epproxim—ting ˜ond pri™e ™h—nges using dur—tion is illustr—ted in the following (gureF T ˜ond pri™e d d d d d d d d d d d hur—tion me—sures '—ngle of t—ngentF yield d E „he modi(ed dur—tion me—sures the —ngle of the t—ngent —t the ™urrent ˜ond yieldF epproxim—ting the ™h—nge in ˜ond pri™e with dur—tion is thus only — (rst order —pproxim—tionF „o improve on this PS . }.h" double ˜onds dur—tion modi(ed dis™rete (const ve™tor<double>& times. ˜ond pri™e). ™—sh)ows. C++ Code 3.

const double& r) { double gx=0. Your portfolio is currently worth 2000. for (int i=0.i++){ gx+= ™—sh)ows[i]*times[i]*(times[i]+1)/(pow((1+r). r). Consider the pricing of a perpetual bond. 2. PT . }. Both bonds have face values of 100. Consider an equally weighted portfolio of two bonds. Determine the rst derivative of the price with respect to the interest rate. Find the number of each bond invested. Find the duration of the bond. const ve™tor<double>& ™—sh)ows. 2. 1.9: fond ™onvexity with — )—t term stru™ture —nd —nnu—l ™ompounding when the interest r—tes ™h—nges you will then ™—l™ul—te ∆B0 1 2 ≈ −D∗ ∆y + Cx (∆y) B0 2 pormul— QFI summ—rizes the —˜ove ™—l™ul—tionsF Exercise 9. Determine the duration of the portfolio. return (gx/(pow(1+r. Perpetual duration [4] ∞ The term structure is at. The current interest rate is 5%.i<times. ™—sh)ows.times[i])). }.2)))/f.h" double ˜onds ™onvexity dis™rete(const ve™tor<double>& times. Determine the convexity of your position. double f=˜onds pri™e dis™rete(times. Exercise 10. 4. Bond A is a zero coupon bond with 1 year to maturity. 3. A and B. C++ Code 3. Let C be the per period cash ow B0 = t=1 C C = t (1 + r) r 1. Determine the bond prices. Bond B is a zero coupon bond with 3 years to maturity.size().—pproxim—tion we —lso need to —™™ount for the ™urv—ture in the rel—tionship ˜etween ˜ond pri™e —nd interest r—teF „o qu—ntify this ™urv—ture we ™—l™ul—te the convexity of — ˜ondF gonvexity = Cx = 1 1 B0 (1 + r)2 T (t + t2 ) t=1 Ct (1 + r)t @QFRA „his ™—l™ul—tion is implemented in ™ode QFWF F „o improve on the estim—te of how the ˜ond pri™e ™h—nge #include <™m—th> #include "fin_recipes.

y : bond yield to maturity. Formula 3. T . . . Bond pays coupon at evenly spaced dates t = 1.fond €ri™e (B0 A T B0 = t=1 Ct (1 + r)t ‰ield to m—turity y solves T B0 = t=1 Ct (1 + y)t hur—tion (D) 1 D= B0 T t=1 tCt (1 + r)t w—™—ul—y dur—tion D= 1 B0 T t=1 tCt (1 + y)t wodi(ed dur—tion D∗ = D 1+y gonvexity (Cx) Cx = 1 1 B0 (1 + r)2 T (t + t2 ) t=1 Ct (1 + r)t epproxim—ting ˜ond pri™e ™h—nges ∆B0 ≈ −D∗ ∆y B0 1 ∆B0 ≈ −D∗ ∆y + × Cx × (∆y)2 B0 2 Ct : Cash ow at time t. . B0 : current bond price. r : interest rate. 2. 3 .1: fond pri™ing formul—s with — )—t term stru™ture —nd dis™reteD —nnu—l ™ompounding PU .

531 1 · 10 2 · 10 3 · 110 + + 1. double r=0. ™)ows.0251 B0 ‡hi™h me—ns the—t the ˜ond pri™e ™h—nges toX B0 + δB0 = 102.01)2 = −0.531 − 0.957 RF g—l™ul—te the ˜ond9s ™onvexity Cx = 1 1 (1 + 0. . ™)ows.09)2 102.push ˜—™k(10). times.push ˜—™k(2).e Q ye—r ˜ond with — f—™e v—lue of 6IHH m—kes —nnu—l ™oupon p—yments of IH7F „he ™urrent interest r—te @with —nnu—l ™ompoundingA is W7F IF hetermine the ™urrent ˜ond pri™eF PF ƒuppose the interest r—te ™h—nges to IH7D determine the new pri™e of the ˜ond ˜y dire™t ™—l™ul—tionF QF snste—d of dire™t ™—l™ul—tionD use dur—tion to estim—te the new pri™e —nd ™omp—re it to the ™orre™t pri™eF RF …se ™onvexity to improve on your estim—tion using dur—tionF ƒolving the —˜ove IF „he ˜ond pri™eX B0 = 10 110 10 + + = 102.09 1.531 1 2 (1 + 0.09) (1 + 0. ™)ows.93(0. double f = ˜onds pri™e dis™rete(times.531 = 99.01 = −0.02465 B0 2 2 …se this to reEestim—te the ˜ond pri™eX B0 + ∆B0 = 102.93 ‚e™—l™ul—ting the ™h—nge in the ˜ond pri™e using ™onvexityX ∆B0 1 1 = −D∗ ∆y + Cx y 2 = −2.push ˜—™k(3). times.51 1+r 1.531 (1 + 1) · 10 (22 + 2) · 10 (3 + 32 ) · 110 + + 1.74 D = = 2.00044 = −0.093 = 2. ve™tor<double> times.02465) = 100.01 + 8.74 wodi(ed dur—tionX D∗ = 2.1)1 (1 + 0.09.093 = 8.0036 wost of the s—me ™—l™ul—tions —re shown ˜elowX g++ progr—mX PV void test ˜onds dur—tion dis™rete(){ ve™tor<double> ™)ows.push ˜—™k(1).531 1 + ∆B0 B0 B0 = 102. times.531 + ∆B0 B0 B0 = 102.0251 + 0.092 1.51 · 0.09 1.0251 · 102.1)2 (1 + 0.push ˜—™k(10).09)3 PF sf the interest r—te in™re—ses to IH7D the ˜ond will ˜e selling —t p—rD equ—l to IHHD whi™h ™—n ˜e ™on(rmed with dire™t ™omput—tionX B0 = 10 10 110 + + = 100 (1 + 0.51 · 0. ™)ows. r).push ˜—™k(110).09) (1 + 0.092 1.1)3 QF g—l™ul—te the ˜ond9s dur—tionX D= 1 102.09 vet us now ™—l™ul—te the ™h—nge in the ˜ond pri™e ∆B0 = −D∗ ∆y = −2.531(1 − 0.

t++) { ™)ow —mounts[t] * exp(−r*™)ow times[t]).2: „r—nsl—ting ˜etween dis™rete —nd ™ontinous ™ompounding 3.size(). r: interest rate with continuous compounding. pormul— QFP summ—rizes some rules for tr—nsl—ting ˜etween ™ontinously ™ompounded —nd dis™retly ™omE pounded interest r—tesF r = n ln 1 + r rn n rn = n e n − 1 puture v—lue = ert €resent v—lue = e−rt Notation: rn : interest rate with discrete compounding. }.1 Present value epplying this to — set of ™—sh )ows —t future d—tes t1 .0. t<™)ow €† += }. t: time to maturity. tn D we get the following present v—lue ™—l™ul—tionX n PV = i=1 e−rti Cti „his ™—l™ul—tion is implemented —s shown in ™ode QFIHF #include <™m—th> #include <ve™tor> using namespace double std. t2 .10: €resent v—lue ™—l™ul—tion with ™ontinously ™ompounded interest sn mu™h of wh—t follows we will work with the ™—se of ™ontinously ™ompounded interestF „here is — num˜er of re—sons whyD ˜ut — prime re—son is —™tu—lly th—t it is e—sier to use ™ontinously ™ompounded interest th—n dis™retely ™ompoundedD ˜e™—use it is e—sier to de—l with uneven time periodsF his™retely ™ompounded interest is e—sy to use with evenly sp—™ed ™—sh )ows @su™h —s —nnu—l ™—sh )owsAD ˜ut h—rder otherwiseF PW . . return €†. const double& r){ times.3. const ve™tor<double>& ™)ow —mounts. . Formula 3. C++ Code 3.3 Continously compounded interest ƒu™h dis™rete ™ompounding —s we h—ve just dis™ussed is not the only —ltern—tive w—y to —pproxim—te the dis™ount f—™torF „he dis™retely ™ompounded ™—se —ssumes th—t interest is —dded —t dis™rete points in time @hen™e the n—meAF roweverD —n —ltern—tive —ssumption is to —ssume th—t interest is —dded ™ontinouslyF sf ™ompounding is ™ontinousD —nd r is the interest r—teD one would ™—l™ul—te the ™urrent pri™e of re™iving one doll—r —t — future d—te t —s Pt = e−rt . const ve™tor<double>& ™)ow times. . n: compounding periods per year. for (int t=0. ™—sh )ow pv( double €†=0. .3.

3: fond pri™ing formul—s with ™ontinously ™ompounded interest —nd — )—t term stru™ture ƒome import—nt di'eren™es is worth pointing outF ‡hen using ™ontinously ™ompounded interestD one does not need the ™on™ept of modied durationF sn the ™ontinously ™ompounded ™—se one uses the ™—l™ul—ted dur—tion dire™tly to —pproxim—t ˜ond ™h—ngesD —s seen in the formul—s des™ri˜ing the —pproxim—tion of ˜ond pri™e ™h—ngesF xote —lso the di'eren™e in the convexity ™—l™ul—tionD one does not divide ˜y (1 + y)2 in the ™ontinously ™ompounded formul—D —s w—s done in the dis™rete ™—seF godes QFIID QFIPD QFIQ —nd QFIR show ™ontinously ™ompounded —n—logs of the e—rlier ™odes for the disE ™retely ™ompounded ™—seF QH . . at times t1 . e: natural exponent. t2 . Formula 3. . .3..2 Bond pricing and analysis ‡e will go over the s—me ™on™epts —s ™overed in the previous se™tion on ˜ond pri™ingF „here —re ™ert—in su˜tle di'eren™es in the ™—l™ul—tionsF pormul— QFQ ™orresponds to the e—rlier summ—ry in formul— QFIF fond €ri™e B0 X B0 = i e−rti ) Cti ‰ield to m—turity y solvesX B0 = i Cti e−yti hur—tion DX D= 1 B0 ti Cti e−rti i w—™—ul—y dur—tion D= 1 B0 ti Cti e−yti i gonvexity CxX Cx = 1 B0 Cti t2 e−rti i i epproxim—ting ˜ond pri™e ™h—nges ∆B0 ≈ −D∆y B0 1 ∆B0 ≈ −D∆y + × Cx × (∆y)2 B0 2 Bond paying cash ows Ct1 . . . . Ct2 .3. Notation: B0 : current bond price.

h" double ˜onds ™onvexity(const ve™tor<double>& times.14: stru™ture fond ™onvexity ™—l™ul—tion with ™ontinously ™ompounded interest —nd — )—t term QI .i++){ g += ™—sh)ows[i] * pow(times[i].i<times.13: g—l™ul—ting the w—™—ul—y dur—tion of — ˜ond with ™ontinously ™ompounded interest —nd — )—t term stru™ture #include <™m—th> #include "fin_recipes. hI += ™—sh)ow times[i] * ™—sh)ows[i] * exp(−r*™—sh)ow times[i]).i<™—sh)ow times.11: fond pri™e ™—l™ul—tion with ™ontinously ™ompounded interest —nd — )—t term stru™ture using namespace double #include <™m—th> #include <ve™tor> std. const double& ˜ond pri™e) { double y = ˜onds yield to m—turity(™—sh)ow times.size(). const ve™tor<double>& ™—sh)ows. }.size(). y).r). }. const ve™tor<double>& ™—sh)ows. C++ Code 3. ™—sh)ows. pri™e(times.size(). ™—sh)ows.h" double ˜onds dur—tion m—™—ul—y(const ve™tor<double>& ™—sh)ow times. return C++ Code 3. const double& r) { double p=0. }. C++ Code 3. ˜onds dur—tion(const ve™tor<double>& ™—sh)ow times. const double& r) { double ƒ=0. for (int i=0.using namespace double #include <™m—th> #include <ve™tor> std. }. double f=˜onds return g/f. ˜onds pri™e(const ve™tor<double>& ™—sh)ow times. const double& r ) { double g=0. ™—sh)ows. // use YTM in duration }. return }. for (int i=0.i<™—sh)ow times. return ˜onds dur—tion(™—sh)ow times.2) * exp(−r*times[i]). }. p. ˜ond pri™e). const ve™tor<double>& ™—sh)ows.i++){ ƒ += ™—sh)ows[i] * exp(−r*™—sh)ow times[i]). const ve™tor<double>& ™—sh)ows. double hI=0. hI / ƒ. for (int i=0.12: stru™ture fond dur—tion ™—l™ul—tion with ™ontinously ™ompounded interest —nd — )—t term #include "fin_recipes.i++) { p += exp(−r*™—sh)ow times[i])*™—sh)ows[i]. C++ Code 3.

3.4 Further readings „he m—teri—l in this ™h—pter is ™overed in most st—nd—rd text˜ooks of ™orpor—te (n—n™e @eFgF fre—ley —nd wyers @PHHPA or ‚ossD ‡ester(eldD —nd t—'e @PHHSAA —nd investments @eFgF fodieD u—neD —nd w—r™us @PHHSAD r—ugen @PHHIA or ?AF ƒhiller @IWWHA is — good referen™e on the term stru™tureF QP .

Chapter 4 The term structure of interest rates and an object lesson sn this ™h—pter we exp—nd on the —n—lysis of the previous ™h—pter ˜y rel—xing the one interest r—te —ssumption used there —nd —llow the spot r—tes to ™h—nge —s you ™h—nge the time you —re dis™ounting overF ‚e™—ll th—t we s—id th—t the present v—lue of — set of ™—sh )ows is ™—l™ul—ted —s N PV = i=1 dti Cti Ct1 0 t1 Ct2 t2 CtN E tN time dt1 Ct1 ' ' dt2 Ct2 dtN CtN ' „o m—ke this —ppli™—˜le to ™—sh )ows re™eived —t —ny future d—te t we potenti—lly need —n in(nite num˜er of dis™ount f—™tors dt F „his is not fe—si˜leD so some lower dimension—l w—y needs to ˜e found to —pproxim—te dt D ˜ut with more )exi˜ility th—n the extremely strong —ssumption th—t there is one (xed interest r—te rD —nd th—t the dis™ount f—™tor for —ny time t is ™—l™ul—ted —s either dt = 1/(1 + r)t @dis™rete ™ompoundingAD or dt = e−rt @™ontinuous ™ompoundingAD whi™h we used in the previous ™h—pterF sn this ™h—pter we (rst show th—t this —pproxim—tion of the dis™ount f—™tors ™—n ˜e done in either terms of dis™ount f—™tors dire™tlyD interest r—tesD or forw—rd r—tesF iither of these —re useful w—ys of formul—ting — term stru™tureD —nd either of them ™—n ˜e usedD sin™e there —re one to one tr—nsform—tions ˜etween either of these threeF ‡e then go on to demonstr—te how — fe—ture of g++D the —˜ility to ™re—te —n —˜str—™t d—t—type —s —n o˜je™tD or ™l—ssD is very useful for the p—rti™ul—r —ppli™—tion of de(ning —nd using — term stru™tureF st is in f—™t this p—rti™ul—r —ppli™—tionD to ™re—te — term stru™ture ™l—ssD whi™h re—lly illustr—tes the power of g++D —nd why you w—nt to use —n o˜je™t oriented l—ngu—ge inste—d of ™l—ssi™—l l—ngues like FORTRAN —nd CD or m—trix l—ngu—ges like Gauss or Matlab for m—ny (n—n™i—l ™—l™ul—tionsF 4. spot interest rates and forward interest rates „he term stru™ture ™—n ˜e spe™i(ed in terms of either dis™ount f—™torsD spot interest r—tes or forw—rd interest r—tesF e dis™ount f—™tor is the ™urrent pri™e for — future @time tA p—yment of one doll—rF „o (nd the ™urrent v—lue P V of — ™—sh )ow Ct D we ™—l™ul—te P V = dt Ct F „his dis™ount f—™tor ™—n —lso ˜e spe™i(ed in terms of interest r—tesD where we let rt ˜e the relev—nt interest r—te @spot r—teA for dis™ounting — tEperiod ™—sh)owF „hen we know th—t the present v—lue P V = e−rt t Ct F ƒin™e these two methods of ™—l™ul—ting the present v—lue must ˜e ™onsistentD P V = dt Ct = e−rt t Ct —nd hen™e dt = e−rt t QQ .1 The interchangeability of discount factors.

xote th—t this equ—tion ™—l™ul—tes dt given rt F ‚e—rr—nging this equ—tion we (nd the spot r—te rt in terms of dis™ount f—™tors rt = − ln(dt ) t en —ltern—tive ™on™ept th—t is very useful is — forw—rd interest r—teD the yield on ˜orrowing —t some future d—te t1 —nd rep—ying it —t — l—ter d—te t2 F vet ft1 .e.t2 (t2 −t1 ) „he present v—lue of this forw—rd v—lue using the time t2 dis™ount f—™tor h—s to equ—l oneX dt2 F V = 1 „hese ™onsider—tions —re enough to ™—l™ul—te the relev—nt tr—nsformsF „he forw—rd r—te for ˜orrowing —t time t1 for delivery —t time t2 is ™—l™ul—ted —s − ln ft1 . ft1 . rt : spot rate applying to cash ows at time t.t2 = rt2 Notation: dt discount factor for payment at time t.t2 = dt2 dt1 ln = dt1 dt2 t2 − t1 t2 − t1 „he forw—rd r—te ™—n —lso ˜e ™—l™ul—ted dire™tly from yields —s ft1 .t2 = dt1 dt2 t2 − t1 t2 t1 − rt1 t2 − t1 t2 − t1 ft1 . the interest rate you would agree on today on the future transactions.t2 = rt2 t1 t2 − rt1 t2 − t1 t2 − t1 dt = e−rt t rt = − ln(dt ) t − ln ft1 . i.t2 ˜e this interest r—teF sf we invest one doll—r tod—yD —t the ™urrent spot r—te spot r—te till period t1 —nd the forw—rd r—te for the period from t1 to t2 @whi™h is wh—t you would h—ve to do to m—ke —n —™tu—l investmentAD you would get the following future v—lue F V = ert1 t1 eft1 . gode RFI shows the implement—tion of these tr—nsform—tionsF QR .t2 forward rate between time t1 and t2 .

1: „erm stru™ture tr—nsform—tions g++ progr—mX void test termstru tr—nsforms(){ double tI=1. double& d tI.tI). double tP=2.951229 a 2 period discount factor of 0. } from dis™ount f—™tor(const double& double& d t.r tP.tP) << " using yields " << endl. double r tP = term stru™ture yield from dis™ount f—™tor(d 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. dis™ount f—™tor from yield(const r. ™out << " a " << tI << " period spot rate of " << r tI << " corresponds to a discount factor of " << d tI << endl. }. term stru™ture forw—rd r—te from dis™ount f—™tors(const (log (d return double }. const double& tP) { C++ Code 4.d tP. tI/d tP))/time.1: „erm stru™ture tr—nsform—tions QS . term stru™ture forw—rd r—te from yields(const r tP*tP/(tP−tI)−r tI*tI/(tP−tI).0553605 using yields Example 4.05. ™out << " and is " << term stru™ture forw—rd r—te from yields(r tI.tP−tI) << " using discount factors " << endl. double term stru™ture yield return (−log(d t)/t). }.#include <™m—th> using namespace std.0553605 using discount factors and is 0.0526803 the forward rate between 1 and 2 is 0. double r tI=0.9.tP). const double& t) t) { double term stru™ture return exp(−r*t).9 corresponds to a spot rate of 0.05 corresponds to a discount factor of 0. double d tP = 0. const double& r const double& tI. const double& const double& time) { tP. const double& { double }. double d tI = term stru™ture dis™ount f—™tor from yield(r tI.tI. yutput from g++ progr—mX a 1 period spot rate of 0. d tP. return double& r tI.

virtual double forw—rd r—te(const double& tI.1 Base class gode RFP shows how we des™ri˜e the generi™ term stru™ture —s — g++ ™l—ssF #ifndef „i‚w ƒ„‚…g„…‚i gveƒƒ r #dene „i‚w ƒ„‚…g„…‚i gveƒƒ r class term stru™ture ™l—ss { public: virtual double yield(const double& t) const.4. #endif C++ Code 4. tP) const. virtual double dis™ount f—™tor(const double& t) const. const double& virtual £term stru™ture ™l—ss().2 The term structure as an object prom the previous we see th—t the term stru™ture ™—n ˜e des™ri˜ed in terms of dis™ount f—™torsD spot r—tes or forw—rd r—tesD ˜ut th—t does not help us in getting round the dimension—lity pro˜lemF sf we think in terms of dis™ount f—™torsD for — ™omplete spe™i(™—tion of the ™urrent term stru™ture one needs —n in(nite num˜er of dis™ount f—™tors {dt }t∈R+ F st is perh—ps e—sier to think —˜out this set of dis™ount f—™tors —s — function d(t)D th—tD given — nonneg—tive time tD returns the dis™ount f—™torF ƒin™e we h—ve est—˜lished th—t there —re three equiv—lent w—ys of de(ning — term stru™tureD dis™ount f—™torsD spot r—tes —nd forw—rd r—tesD we ™—n therefore des™ri˜e — term stru™ture —s — ™olle™tion of three di'erent fun™tions th—t o'er di'erent views of the s—me underlying o˜je™tF e term stru™ture is —n —˜str—™t o˜je™t th—t to the user should provide • dis™ount f—™tors @pri™es of zero ™oupon ˜ondsAF • spot r—tes @yields of zero ™oupon ˜ondsAF • forw—rd r—tesF for —ny future m—turity tF „he user of — term stru™ture will not need to know how the term stru™ture is implementedD —ll th—t is needed is —n interf—™e th—t spe™i(es the —˜ove three fun™tionsF „his is t—ilor m—de for ˜eing implemented —s — g++ classF e ™l—ss in g++ terms is — ™olle™tion of d—t— stru™tures —nd fun™tions th—t oper—te on these d—t— stru™turesF sn the present ™ontext it is — w—y of spe™ifying the three fun™tionsF yield(t) dis™ount•f—™tor(t) forw—rd•r—te(t) 4. }.2.2: re—der (le des™ri˜ing the term_structure ˜—se ™l—ss „he ™ode for these fun™tions uses —lgorithms th—t —re des™ri˜ed e—rlier in this ™h—pter for tr—nsforming ˜etween v—rious views of the term stru™tureF „he term stru™ture ™l—ss merely provide — ™onvenient interf—™e to these —lgorithmsF xote th—t the de(nitions of ™—l™ul—tions —re ™ir™ul—rF eny given specic type of term stru™ture h—s to overEride —t le—st one of the fun™tions yieldD discount_factor or forward_rateF ‡e next ™onsider two ex—mples of specic term stru™turesF QT .

f—™tor(t). C++ Code 4.h" term stru™ture ™l—ssXX£term stru™ture ™l—ss(){}.t). { double term stru™ture ™l—ssXXdis™ount f—™tor(const double& t) const return term stru™ture dis™ount f—™tor from yield(yield(t).dP.tP−tI). }. }.t). const double& double dI = dis™ount f—™tor(tI). double dP = dis™ount f—™tor(tP). double term stru™ture ™l—ssXXforw—rd r—te(const double& tI.3: hef—ult ™ode for tr—nsform—tions ˜etween dis™ount f—™torsD spot r—tes —nd forw—rd r—tes in — term stru™ture ™l—ss QU .#include "fin_recipes. return term stru™ture forw—rd r—te from dis™ount f—™tors(dI. tP) const{ double term stru™ture ™l—ssXXyield(const double& t) const{ return term stru™ture yield from dis™ount f—™tor(dis™ount }.

}. double d2 = discount factor(t2).4: //#include  n recipes.d2.t2-t1). virtual £term stru™ture ™l—ss )—t(). virtual double yield(const double& t) void }.h re—der (le for term stru™ture ™l—ss using — )—t term stru™ture //#include  term structure class at. }.h" #include <iostre—m> #include <™m—th> using namespace std. */ void term stru™ture ™l—ss )—tXXset int r—te(const double& r) { ‚ = r.h #include "fin_recipes.2. return term structure forward rate from discount factors(d1. C++ Code 4. double /* term stru™ture ™l—ss )—tXXyield(const double& „) { if („>=0) return ‚ . „he )—t term stru™ture overrides ˜oth the yield mem˜er fun™tion of the ˜—se ™l—ssF „he only pie™e of d—t— this type of term stru™ture needs is —n interest r—teF #ifndef „i‚w ƒ„‚…g„…‚i gveƒƒ pve„ #dene „i‚w ƒ„‚…g„…‚i gveƒƒ pve„ #include "term_structure_class. double& const r){ ‚ = r. const. #endif C++ Code 4. double term structure class at::forward rate(const double& t1.2 Flat term structure.4. double term structure class at::discount factor(const double& T) const { if (T>=0.0){ return exp(-R *T). // virtual double discount factor(const double& t) const. term stru™ture ™l—ss )—tXXterm stru™ture ™l—ss )—t(const term stru™ture ™l—ss )—tXX£term stru™ture ™l—ss )—t(){}. const double& t2) const{ double d1 = discount factor(t1). }. return 0. }.5: smplementing term stru™ture ™l—ss using — )—t term stru™ture QV . return 0. set int r—te(const double& r).h" class term stru™ture private: double ‚ . public: ™l—ss )—t X public term stru™ture ™l—ss { // interest rate term stru™ture ™l—ss )—t(const double& r). }. }.

tP) << endl.05 forward rate from t1= 1 to t2= 2:0.yield(tI) << endl.yield(tP) << endl.dis™ount f—™tor(tI) << endl.951229 discount factor t2 = 2:0. yutput from g++ progr—mX discount factor t1 = 1:0. ™out << "discount factor t2 = " << tP << ":" << ts.forw—rd r—te(tI. ™out << "forward rate from t1= " << tI << " to t2= " << tP << ":" << ts.g++ progr—mX void test term stru™ture ™l—ss )—t(){ term stru™ture ™l—ss )—t ts(0.05). double tI=1. ™out << "discount factor t1 = " << tI << ":" << ts. ™out << "spot rate t = " << tP << ":" << ts.904837 spot rate t = 1:0.05 spot rate t = 2:0. ™out << "spot rate t = " << tI << ":" << ts. double tP=2.05 QW . }.dis™ount f—™tor(tP) << endl.

4. const const double& time. // later than latest obs int t=1.6: snterpol—ted term stru™ture from spot r—tes RH .1 Linear Interpolation. #include "fin_recipes. if (no o˜s<1) return 0. sf we —re given — set of yields for v—rious m—turitiesD the simplest w—y to ™onstru™t — term stru™ture is ˜y str—ightforw—rd line—r interpol—tion ˜etween the o˜serv—tions we h—ve to (nd —n intermedi—te timeF por m—ny purposes this is good enoughF „his interpol—tion ™—n ˜e on either yieldsD dis™ount f—™tors or forw—rd r—tesD we illustr—te the ™—se of line—r interpol—tion of spot r—tesF Computer algorithm.0−l—m˜d—). }. „o just use tod—ys term stru™tureD we need to t—ke the o˜serv—tions of yields th—t is o˜served in the m—rket —nd use these to gener—te — term stru™tureF „he simplest possi˜le w—y of doing this is to line—rly interpol—te the ™urrently o˜serv—˜le zero ™oupon yieldsF 4. if (time <= t min) return o˜s yields[0]. // earlier than lowest obs.h" double term stru™ture yield line—rly interpol—ted(const // assume the yields are in increasing time to maturity order. ve™tor<double>& o˜s times.3 Using the currently observed term structure. —re ordered in in™re—sing order of time to m—turityF #include <ve™tor> xote th—t the —lgorithm —ssumes the yields using namespace std. double r = return r. linear interpolation of yields.3. double t min = o˜s times[0]. o˜s yields[t−1] * l—m˜d— + o˜s yields[t] * (1. C++ Code 4. time is between t-1.size(). double t m—x = o˜s times[no o˜s−1]. if (time >= t m—x) return o˜s yields[no o˜s−1]. }. // nd which two observations we are between while ( (t<no o˜s) && (time>o˜s times[t])) { ++t.t times[t−1]). ve™tor<double>& o˜s yields) { int no o˜s = o˜s times. double l—m˜d— = (o˜s times[t]−time)/(o˜s times[t]−o˜s // by ordering assumption.

yields.1 t=0.times. times.times. yields.push ˜—™k(5).yields) << endl.1 " << term stru™ture yield line—rly interpol—ted(0. times.5).4).5 0. yields.1). ™out << " t=.push ˜—™k(0.3).5.3 t=3 0. times.push ˜—™k(0.push ˜—™k(0.2).5 " << term stru™ture yield line—rly interpol—ted(0.5 RI .times. }.1 0.times.push ˜—™k(0. yields.yields) << endl.1.1).push ˜—™k(1).g++ progr—mX void test termstru interpol—ted(){ ve™tor<double> times.2 t=1 0.push ˜—™k(0.push ˜—™k(0.push ˜—™k(0.35 t=5 0.5).yields) << endl. yields.4 t=10 0. ™out << " yields at times: " << endl. yutput from g++ progr—mX yields at times: t=. ™out << " t=10 " << term stru™ture yield line—rly interpol—ted(10. times. ™out << " t=3 " << term stru™ture yield line—rly interpol—ted(3. ™out << " t=1 " << term stru™ture yield line—rly interpol—ted(1. times.yields) << endl. ™out << " t=5 " << term stru™ture yield line—rly interpol—ted(5.push ˜—™k(10).yields) << endl. ve™tor<double> yields.times.times.yields) << endl. ™out << " t=0.

„he interpol—ted term stru™ture implemented here uses — set of o˜serv—tions of yields —s — ˜—sisD —nd for o˜serv—tions in ˜etween o˜serv—tions will interpol—te ˜etween the two ™losestF „he following only provides implement—tions of ™—l™ul—tion of the yieldD for the other two rely on the ˜—se ™l—ss ™odeF „here is some more ˜ookEkeeping involved hereD need to h—ve ™ode th—t stores o˜serv—tions of times —nd yieldsF #ifndef „i‚w ƒ„‚…g„…‚i gveƒƒ sx„i‚€yve„ih #dene „i‚w ƒ„‚…g„…‚i gveƒƒ sx„i‚€yve„ih #include "term_structure_class. . #endif r—tes C++ Code 4. // use to keep a list of yields term stru™ture ™l—ss interpol—ted().4. virtual double yield(const double& „) const. term stru™ture ™l—ss interpol—ted operator= (const term stru™ture ™l—ss interpol—ted&). }.size(). term stru™ture ™l—ss interpol—ted(const term stru™ture ™l—ss interpol—ted&). const ve™tor<double>& yields). int no o˜serv—tions() const { return times . term stru™ture ™l—ss interpol—ted(const ve™tor<double>& times.2 Interpolated term structure class.7: re—der (le des™ri˜ing — term stru™ture ™l—ss using line—r interpol—tion ˜etween spot RP . ve™tor<double>& yields). virtual £term stru™ture ™l—ss interpol—ted().3.h" #include <ve™tor> using namespace std. class term private: public: stru™ture ™l—ss interpol—ted X . void set interpol—ted o˜serv—tions(ve™tor<double>& times. public term stru™ture ™l—ss { ve™tor<double> times ve™tor<double> yields void ™le—r(). }.

ve™tor<double>& in yields) ™le—r(). if (in times. if (in times. }.no o˜serv—tions()).size()!=in yields.end()). { 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. for (int i=0. for (int i=0. yields = ve™tor<double> (term. }.size()!=in yields.size().size()). const ve™tor<double>& in yields) ™le—r(). times = ve™tor<double>(in times. term stru™ture ™l—ss interpol—tedXXterm stru™ture ™l—ss interpol—ted(const ve™tor<double>& in times.end()).˜egin(). yields = ve™tor<double>(in yields.˜egin().i<term.no o˜serv—tions(). term stru™ture ™l—ss interpol—tedXX™le—r(){ times .i++){ times [i] = term.er—se(times .size()) return.i<in times.}. times = ve™tor<double>(in times.times [i]. term stru™ture ™l—ss interpol—tedXXterm stru™ture ™l—ss interpol—ted()Xterm stru™ture ™l—ss(){™le—r().yields [i]. }.i++){ = term.size(). 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. { C++ Code 4.er—se(yields .yields [i]. times .#include "fin_recipes. { return (* this). }.no o˜serv—tions(). }.8: „erm stru™ture ™l—ss using line—r interpol—tion ˜etween spot r—tes RQ .size()) return.size()). for (int i=0.i++) { times [i]=in times[i]. }. }.i<in times. yields . { term stru™ture ™l—ss interpol—tedXX£term stru™ture ™l—ss interpol—ted(){ ™le—r(). }. void term stru™ture ™l—ss interpol—tedXXset interpol—ted o˜serv—tions(ve™tor<double>& in times.no o˜serv—tions()).h" void }.times [i].no o˜serv—tions()). yields [i]=in yields[i]. yields [i]=in yields[i].i++) { times [i]=in times[i]. yields = ve™tor<double> (term. yields .size()). yields [i] = term. }. for (int i=0. times [i] yields [i] = term. times . yields ).i<term.size()).no o˜serv—tions()).}. yields = ve™tor<double>(in yields. { double term stru™ture ™l—ss interpol—tedXXyield(const double& „) const return term stru™ture yield line—rly interpol—ted(„.

yield(tI) << endl. times.08).865022 spot rate t = 1:0.spotr—tes.932394 discount factor t2 = 2:0. ™out << "forward rate from t1= " << tI << " to t2= " << tP << ":" << ts. ve™tor<double> spotr—tes.05).push ˜—™k(0.yield(tP) << endl.push ˜—™k(5).0725 forward rate from t1= 1 to t2= 2:0. ™out << "spot rate t = " << tP << ":" << ts.spotr—tes).tP) <<endl.07 spot rate t = 2:0. double tI=1. ™out << "spot rate t = " << tI << ":" << ts.push ˜—™k(0.dis™ount f—™tor(tI) << endl.dis™ount f—™tor(tP) << endl. times. }. times. ™out << "discount factor t2 = " << tP << ":" << ts.forw—rd r—te(tI. yutput from g++ progr—mX discount factor t1 = 1:0. ™out << "discount factor t1 = " << tI << ":" << ts.push ˜—™k(0. spotr—tes.push ˜—™k(0.push ˜—™k(1).07). term stru™ture ™l—ss interpol—ted ts(times.075 RR . double tP=2.g++ progr—mX void test term stru™ture ™l—ss interpol—ted(){ ve™tor<double> times. spotr—tes.1).

. }.dis™ount f—™tor(™—sh)ow times[i])*™—sh)ows[i]. .size(). C++ Code 4. #include "fin_recipes. t2 .9: References €ri™ing — ˜ond with — term stru™ture ™l—ss ƒhiller @IWWHA is — good referen™e on the use of the term stru™tureF RS . for (unsigned i=0. const term stru™ture ™l—ss& d) { double p = 0.i<™—sh)ow times. return p. }.4.i++) { p += d.X B0 = i dti Cti = i e−rti ti Cti hur—tion DX D= 1 B0 1 B0 1 B0 ti dti Cti i D= ti e−rti ti Cti i D= ti e−yti Cti i ‰ield to m—turity y solvesX B0 = i Cti e−yti gonvexity CxX Cx = 1 B0 1 B0 1 B0 t2 dti Cti i i Cx = t2 e−rti ti Cti i i Cx = t2 e−yti Cti i i godes RFW —nd RFIH illustr—tes how one would ™—l™ul—te ˜ond pri™es —nd dur—tion if one h—s — term stru™ture ™l—ssF #include <ve™tor> using namespace double std.h" ˜onds pri™e(const ve™tor<double>& ™—sh)ow times.4 Bond calculations with a general term structure and continous compounding Bond pricing with a continously compounded term structure fond €ri™e B0 X Coupon bond paying coupons at dates t1 . . const ve™tor<double>& ™—sh)ows.

11: g—l™ul—ting — ˜onds ™onvexity with — term stru™ture ™l—ss g++ progr—mX void test term stru™ture ™l—ss ˜ond ™—l™ul—tions(){ ve™tor <double> times. ts)—t) << endl. term stru™ture ™l—ss )—t ts)—t(0. hI += ™—sh)ow times[i] * ™—sh)ow —mounts[i] * d.i++){ f += ™—sh)ow —mounts[i] * d.dis™ount f—™tor(™—sh)ow times[i]). const ve™tor<double>& ™—sh)ow —mounts.size().push ˜—™k(110).72611 RT .1088 duration = 1. double hI=0.i++){ ƒ += ™—sh)ow —mounts[i] * d. times.size().push ˜—™k(2).dis™ount f—™tor(™—sh)ow times[i]). ™—sh)ows.push ˜—™k(1). double gx=0.push ˜—™k(10). ™out << " price = " << ˜onds pri™e (times.h" #include <™m—th> double ˜onds ™onvexity(const ve™tor<double>& ™—sh)ow times. return }.dis™ount f—™tor(™—sh)ow times[i]). times. }. yutput from g++ progr—mX price = 99. ™—sh)ows. ™—sh)ows. ™out << " convexity = " << ˜onds ™onvexity(times.2) * ™—sh)ow —mounts[i] * d. C++ Code 4. const term stru™ture ™l—ss& d ) { double ƒ=0. ™out << " duration = " << ˜onds dur—tion(times. ™—sh)ows. }.#include "fin_recipes. }. const term stru™ture ™l—ss& d ) { double f=0. return C++ Code 4.dis™ount f—™tor(™—sh)ow times[i]).i<™—sh)ow times.1). }.h" double ˜onds dur—tion(const ve™tor<double>& ™—sh)ow times. gx/f.10: g—l™ul—ting — ˜onds dur—tion with — term stru™ture ™l—ss #include "fin_recipes. for (unsigned i=0. hI/ƒ. ts)—t) << endl.9087 convexity = 3.i<™—sh)ow times. for (unsigned i=0. gx += pow(™—sh)ow times[i]. ™—sh)ows. const ve™tor<double>& ™—sh)ow —mounts. ve™tor <double> ™—sh)ows. ts)—t) << endl.

5.r. sn this we dis™uss —lgoritms used in v—luing futures ™ontr—™tsF 5. const double& r.1: g++ progr—mX putures pri™e void test futures pri™e(){ double ƒ=100. ™out << " futures price = " << futures pri™e(ƒ. „he futures pri™e of —n —sset without p—youts is the future v—lue of the ™urrent pri™e of the —sssetF double futures pri™e(const return }. double& ƒ.1: putures pri™e RU . double }. time) << endl.1 Pricing of futures contract.10. ft = er(T −t) St #include <™m—th> using namespace std.127 Example 5. const double& time // current price of underlying asset to m—turity) // risk free interest rate { C++ Code 5. r=0. yutput from g++ progr—mX futures price = 105.Chapter 5 Futures algoritms. double time=0. exp(r*time to m—turity)*ƒ.

K − ST ) „he ™h—llenge of option pri™ing is to determine the option premium C0 —nd P0 F ell pri™ing ™onsiders th—t the ™—sh)ows from the deriv—tive is — dire™t fun™tion of the pri™e of the underlying se™urityF €ri™ing ™—n therefore ˜e done relative to the pri™e of the underlying se™urityF „o pri™e options it is ne™ess—ry to m—ke —ssumptions —˜out the pro˜—˜ility distri˜ution of movements of the underlying se™urityF ‡e st—rt ˜y ™onsidering this in — p—rti™ul—rly simple fr—meworkD the ˜inomi—l —ssumptionF „he pri™e of the underlying is ™urrently S0 F „he pri™e ™—n next period only t—ke on two v—luesD Su —nd Sd F ¨ ¨¨0 S rr rr ¨ ¨¨ B ¨ Su ¨ rr r S j r d sf one ™—n (nd —ll possi˜le future st—tesD —n enumer—tion of —ll possi˜ilitiesD one ™—n v—lue — se™urity ˜y ™onstru™ting —rti(™i—l pro˜—˜ilitiesD ™—lled st—te pri™e pro˜—˜ilitiesD whi™h one use to (nd —n —rti(™i—l expe™ted v—lue of the underlying se™urityD whi™h is then dis™ounted —t the risk free interest r—teF „he ˜inomi—l fr—mework is p—rti™ul—rly simpleD sin™e there —re only two possi˜le st—tesF sf we (nd the pro˜—˜ility q of one st—teD we —lso (nd the pro˜—˜ility of the other —s (1−q)F iqu—tion TFI demonstr—tes this ™—l™ul—tion for the underlying se™urityF S0 = e−r (qSu + (1 − q)Sd ) @TFIA xowD —ny deriv—tive se™urity ˜—sed on this underlying se™urity ™—n ˜e pri™ed using the s—me pro˜—˜ility q F „he ™ontri˜ution of ˜inomi—l option pri™ing is in —™tu—lly ™—l™ul—ting the num˜er q F „o do v—lu—tionD RV . ST − K) PT = m—x(0.Chapter 6 Binomial option pricing yption —nd other deriv—tive pri™ing is one of the prime su™™ess stories of modern (n—n™eF en option is — deriv—tive se™urityD the ™—sh )ows from the se™urity is — fun™tion of the pri™e of some other se™urityD typi™—lly ™—lled the underlying se™urityF e ™—ll option is — rightD ˜ut not o˜lig—tionD to ˜uy — given qu—ntity of the underlying se™urity —t — given pri™eD ™—lled the exer™ise pri™e K D within — ™ert—in time interv—lF e put option is the rightD ˜ut not o˜lig—tionD to sell — given qu—ntity of the underlying se™urity to —n —greed ex™er™ise pri™e within — given time interv—lF sf —n option ™—n only ˜e exer™ised @usedA —t — given d—te @the time interv—l is one d—yAD the option is ™—lled —n iurope—n yptionF sf the option ™—n ˜e used in — whole time period up to — given d—teD the option is ™—lled emeri™—nF en option will only ˜e used if it is v—lu—˜le to the option holderF sn the ™—se of — ™—ll optionD this is when the exer™ise pri™e K is lower th—n the pri™e one —ltern—tively ™ould ˜uy the underlying se™urity forD whi™h is the ™urrent pri™e of the underlying se™urityF ren™eD options h—ve never neg—tive ™—sh )ows —t m—turityF „husD for —ny˜ody to ˜e willing to o'er —n optionD they must h—ve — ™ost when entered intoF „his ™ostD or pri™eD is typi™—lly ™—lled —n option premiumF es not—tionD let C signify the pri™e of — ™—ll optionD P the pri™e of — put option —nd S the pri™e of the underlying se™urityF ell of these pri™es —re indexed ˜y timeF ‡e typi™—lly let 0 ˜e now —nd T the (n—l m—turity d—te of the optionF prom the de(nition of the optionsD it is ™le—r th—t —t their l—st possi˜le exer™ise d—teD the m—turity d—teD they h—ve ™—sh )owsF CT = m—x(0.

C++ Code 6.(u*ƒ−ˆ)). // exercice price const double& r. // standard mathematical library // dening the max() operator double option pri™e ™—ll europe—n ˜inomi—l single period( double p up = (exp(r)−d)/(u−d). double ™ d = m—x(0. r is the (continously compounded) risk free interest rate and K is the call option exercise price.st—rt ˜y introdu™ing ™onst—nts u —nd d impli™itly de(ned ˜y Su = uS0 —nd Sd = dS0 D —nd you get — pro™ess —s illustr—ted in (gure TFIF S0 ¨ r ¨ r ¨ r B uS0 ¨¨ rr j dS0 pigure TFIX finomi—l „ree —nd ™—l™ul—te the —rti(™—l pro˜—˜ility q —s q= er − d u−d „he pri™e of — oneEperiod ™—ll option in — ˜inomi—l fr—mework is shown in formul— TFI —nd implemented in ™ode TFIF Cu = max(0.0−p up. // up movement const double& d){ // down movement u+p down*™ d). Sd − K) C0 = e−r (qCu + (1 − q)Cd ) q= er − d u−d Su = uS0 and Sd = dS0 are the possible values for the underlying security next period. double ™ u = m—x(0. double ™—ll pri™e = exp(−r)*(p up*™ return ™—ll pri™e. // interest rate (per period) const double& u. double p down = 1. // spot price const double& ˆ. const double& ƒ.1: „he single period ˜inom—l ™—ll option pri™e #include <™m—th> #include <—lgorithm> using namespace std. u and d are constants.1: finomi—l iurope—nD one period „he st—te pri™e pro˜—˜ility q is found ˜y —n —ssumption of no —r˜itr—ge opportunitiesF sf one h—s the possi˜ility of tr—ding in the underlying se™urity —nd — risk free ˜ondD it is possi˜le to ™re—te — portfolio of these two —ssets th—t ex—™tly dupli™—tes the future p—yo's of the deriv—tive se™urityF ƒin™e this portfolio h—s the s—me future p—yo' —s the deriv—tiveD the pri™e of the deriv—tive h—s to equ—l the ™ost of the dupli™—ting portfolioF ‡orking out the —lge˜r— of thisD one ™—n (nd the expression for q —s the fun™tion of the up —nd down movements u —nd dF RW . Formula 6.0.(d*ƒ−ˆ)). }. Su − K) Cd = max(0.0.

6. The price of the underlying security follows the binomial process S0 ¨ r ¨ r ¨ r B Su ¨¨ rr j Sd A one period call option has payos C0 ¨ r ¨ r ¨ r B Cu = max(0. 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.Exercise 11. Sd − K) 1.1.1 Multiperiod binomial pricing yf ™ourseD —n —ssumption of only two possi˜le future st—tes next period is somewh—t unre—listi™D ˜ut if we iter—te this —ssumptionD —nd —ssume th—t every d—teD there —re only two possi˜le out™omes next d—teD ˜ut thenD for e—™h of these two out™omesD there is two new out™omesD —s illustr—ted in the next (gureX ¨ ¨¨ ¨S t r rr r ¨ ¨¨ ¨ B r ¨ ruSt ¨¨ rr ¨ B ¨ u(uSt ) = uuSt ¨¨ ¨ rr rr ¨¨ r ¨¨ j r dSt r rr rr r j r d(uS ) = u(dS ) = udS t t t B ¨ ¨¨ ¨ r r d(dS ) = ddS j r t t ster—ting this ide— — few times moreD the num˜er of di'erent terminal st—tes in™re—ses m—rkedlyD —nd we get ™loser to — re—listi™ distri˜ution of future pri™es of the underlying —t the termin—l d—teF xote th—t — ™ru™i—l —ssumption to get — pi™ture like this is th—t the f—™tors u —nd d —re the s—me on e—™h d—teF SH . Use this result to show the one period pricing formula for a call option shown in formula 6. 2. Su − K) ¨¨ rr j Cd = max(0.

Suu − X) ¨¨ ¨ rr rr r ¨¨ j r rr ¨¨ rr r j r C = max(0.¨ ¨ ¨ ¨r ¨ r r ¨ ¨ rr ¨¨ ¨ r ¨ r ¨r r ¨ r ¨¨ rr ¨ r ¨ ¨ rr ¨¨ r ¨ ¨ r¨ r ¨ r ¨ rr ¨¨rr r ¨ r r ¨ ¨ r r ¨ r ¨¨ r¨¨ r ¨ r r ¨¨ rr r ¨ r ¨ r¨ r r r €ri™ing in — setting like this is done ˜y working ˜—™kw—rdsD st—rting —t the termin—l d—teF rere we know —ll the possi˜le v—lues of the underlying se™urityF por e—™h of theseD we ™—l™ul—te the p—yo's from the deriv—tiveD —nd (nd wh—t the set of possi˜le deriv—tive pri™es is one period beforeF qiven theseD we ™—n (nd the option one period ˜efore this —g—inD —nd so onF ‡orking ones w—y down to the root of the treeD the option pri™e is found —s the deriv—tive pri™e in the (rst nodeF por ex—mpleD suppose we h—ve two periodsD —nd pri™e — two period ™—ll option with exer™ise pri™e K F ¨ ¨¨ ¨S 0 r rr rr ¨ ¨¨ ¨ B r ¨ ruS0 ¨¨ rr ¨ B ¨ uuS0 ¨¨ ¨ rr r ¨¨ r ¨dS j r ¨0 r rr rr r j r udS 0 B ¨ ¨¨ ¨ r r ddS j r 0 pirst stepX pind termin—l p—yo's of deriv—tive se™urityX ¨¨ rr ¨¨ rr ¨ ¨¨ B ¨ ¨ rr ¨ ¨¨ rr B ¨ Cuu = max(0. ddS − X) j r dd SI . duS − X) B ¨ du ¨¨ ¨ rr r C − max(0.

More ecient would be to carry out the tree building by doing the multiplication from the previous node. fuilding — ˜inomi—l tree In terms of computational eciency the approcach of code 6.++i){ ve™tor<double> ƒ(i). const double& u. return tree.++j){ ƒ[j] = ƒH*pow(u. ve™tor< ve™tor<double> > ˜inomi—l tree(const ve™tor< ve™tor<double> > tree.2 will not be optimal. double& ƒH. }. Further reading „he deriv—tion of the single period ˜inomi—l is eFgF shown in foss—erts —nd Ødeg——rd @PHHIAF rull @PHHTA —nd w™hon—ld @PHHTA —re st—nd—rd referen™esF SP . 1.push ˜—™k(ƒ). and then one need to add one more node by multiplying the lowest element by d. for example the j 'th vector is the j − 1'th vector times u. Implement such an alternative tree building procedure.2: Exercise 12. const double& d. f—sing the re™ursive ™—l™ul—tion of — deriv—tive pri™e on — tri—ngul—r —rr—y stru™ture —s shown in ™ode TFP is the most n—tur—l —ppro—™hD ˜ut with some ™leverness ˜—sed on underst—nding the stru™ture of the ˜inomi—l treeD we ™—n get —w—y with the more e0™ienent —lgorithm th—t is shown in ™ode TFQF xote th—t here we only use one vector<double>D not — tri—ngul—r —rr—y —s ˜uilt —˜oveF Exercise 13.i−j−1). }. for (int j=0. since it requires a lot of calls to the pow() functional call. for (int i=1.j<i. C++ Code 6.i<=no steps. Implement pricing of single and multi period binomial put options.xext stepX pind the two possi˜le ™—ll pri™es —t time IX Cu = e−r (qCuu + (1 − q)Cud ) Cd = e−r (qCud + (1 − q)Cdd ) B Cu ¨¨ C0 ¨ r ¨ r ¨ r rr j Cd pin—l stepX …sing the two possi˜le p—yo's —t time ID Cu —nd Cd D (nd option v—lue —t time HX C0 = e−r (qCu + (1 − q)Cd ) „husD ˜inomi—l pri™ing re—lly ™on™erns rolling ˜—™kw—rd in — ˜inomi—l treeD —nd progr—mming therefore ™on™erns —n e0™ient w—y of tr—versing su™h — treeF „he o˜vious d—t— stru™ture for des™ri˜ing su™h — tree is shown in ™ode TFPD where the v—lue in e—™h node is ™—l™ul—ted from (nding out the num˜er of up —nd down steps —re used to get to the p—rti™ul—r nodeF #include <ve™tor> #include <™m—th> using namespace std. }. const int& no steps){ tree.j)*pow(d.

u. ™out << " one period european call = " << option pri™e ™—ll europe—n ˜inomi—l single period(ƒ. no periods).u. // ll in the endnodes. }.r.025D u = 1.d. ++i) ™—ll v—lues[i] = m—x(0.no periods) << endl. i<=step. // price of underlying pri™es[0] = ƒ*pow(d. // standard mathematical library // dening the max() operator // STL vector templates double option pri™e ™—ll europe—n ˜inomi—l multi period given ud(const double double double double ‚inv = exp(−r). }.0. ++i) { ™—ll v—lues[i] = (p up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv. double double u = 1. for (int step=no periods−1. double u = 100.0D K = 100. // spot price double& u. // interest rate (per period) double& u. int no periods = 2. C++ Code 6. p up = (exp(r)−d)/(u−d). i<=no periods. }. }.r.#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. // up movement double& d. (pri™es[i]−u)). step>=0.0. ve™tor<double> pri™es(no periods+1). ve™tor<double> ™—ll v—lues(no periods+1).3: finomi—l multiperiod pri™ing of iurope—n ™—ll option vet S = 100.05 —nd d = 1/uF IF €ri™e one —nd two period iurope—n g—ll optionsF g++ progr—mX void test ˜in eur ™—ll ud (){ double ƒ = 100.025.0. i<=no periods. ™out << " two period european call = " << option pri™e ™—ll europe—n ˜inomi—l multi period given ud(ƒ. for (int i=1.05. −−step) { for (int i=0.44255 SQ .64342 5. r = 0. // inverse of interest rate uu = u*u. const const const const const double& ƒ. yutput from g++ progr—mX one period european call = two period european call = 3. ++i) pri™es[i] = uu*pri™es[i−1].0−p up. // value of corresponding call for (int i=0. double d = 1/u. p down = 1.d) << endl.u.0D r = 0. // down movement int& no periods){ // no steps in binomial tree // call payos at maturity return ™—ll v—lues[0].u. // exercice price double& r.

the Black Scholes formula „he pri™ing of options —nd rel—ted instruments h—s ˜een — m—jor ˜re—kthrough for the use of (n—n™i—l theory in pr—™ti™—l —ppli™—tionF ƒin™e the origin—l p—pers of fl—™k —nd ƒ™holes @IWUQA —nd werton @IWUQAD there h—s ˜een — we—lth of pr—™ti™—l —nd theoreti™—l —ppli™—tionsF ‡e will now ™onsider the orgin—l fl—™k ƒ™holes formul— for pri™ing optionsD how it is ™—l™ul—ted —nd usedF por the ˜—si™ intuition —˜out option pri™ing the re—der should (rst re—d the dis™ussion of the ˜inomi—l model in the previous ™h—pterD —s th—t is — mu™h ˜etter environment for underst—nding wh—t is —™tu—lly ™—l™ul—tedF en option is — derivative securityD its v—lue depends on the v—lueD or pri™eD of some other underlying se™urityD ™—lled the underlying se™urityFF vet S denote the v—lueD or pri™eD of this underlying se™urityF ‡e need to keep tr—™k of wh—t time this pri™e is o˜served —tD so let St denote th—t the pri™e is o˜served —t time tF e ™—ll @putA option gives the holder the rightD ˜ut not the o˜lig—tionD to ˜uy @sellA some underlying —sset —t — given pri™e K D ™—lled the exer™ise pri™eD on or ˜efore some given d—te T F sf the option is — so ™—lled European optionD it ™—n only ˜e used @exer™isedA —t the m—turity d—teF sf the option is of the so ™—lled American typeD it ™—n ˜e used @exer™isedA —t —ny d—te up to —nd in™luding the m—turity d—te T F sf exer™ised —t time T D — ™—ll option provides p—yo' CT = max(0. ST − K) —nd — put option provides p—yo' PT = max(0. K − ST ) „he fl—™k ƒ™holes formul—s provides —n—lyti™—l solutions for European put —nd ™—ll optionsD options whi™h ™—n only ˜e exer™ised —t the options m—turity d—teF fl—™k —nd ƒ™holes showed th—t the —ddition—l inform—tion needed to pri™e the option is the @™ontinously ™ompoundedA risk free interest r—te rD the v—ri—˜ility of the underlying —ssetD me—sured ˜y the st—nd—rd devi—tion σ of @logA pri™e ™h—ngesD —nd the time to m—turity (T − t) of the optionD me—sured in ye—rsF „he origin—l formul— w—s derived under the —ssumption th—t there —re no p—youtsD su™h —s sto™k dividendsD ™oming from the underlying se™urity during the life of the optionF ƒu™h p—youts will —'e™tion option v—luesD —s will ˜e™ome —pp—rent l—terF 7.Chapter 7 Basic Option Pricing.1 The formula pormul— UFI gives the ex—™t formul— for — ™—ll optionD —nd the ™—l™ul—tion of the s—me ™—ll option is shown in ™ode UFI SR .

K the exercise price. Formula 7. // spot (underlying) price double& u.1: €ri™e of iurope—n ™—ll option using the fl—™k ƒ™holes formul— SS . // interest rate double& sigm—.time) time sqrt = sqrt(time).1: €ri™e of iurope—n ™—ll option using the fl—™k ƒ™holes formul— function ™ = ˜l—™k s™holes ™—ll(ƒ. double dI = (log(ƒ/u)+r*time)/(sigm—*time double dP = dI−(sigm—*time sqrt).5*sigm—*time sqrt. ™ = ƒ * norm—l ™df (dI) − u * exp(−r*time) * norm—l ™df (dP). dP = dI−(sigm—*time sqrt). σ the standard deviation of the underlying asset.r. // strike (exercise) price. dI = (log(ƒ/u)+r*time)/(sigm—*time sqrt)+0.c = SN (d1 ) − Ke−r(T −t) N (d2 ) where d1 = —nd ln S K + (r + 1 σ 2 )(T − t) √ 2 σ T −t √ d2 = d1 − σ T − t eltern—tively one ™—n ™—l™ul—te d1 —nd d2 —s d1 = ln S K + r(T − t) 1 √ √ + σ T −t 2 σ T −t + r(T − t) 1 √ √ − σ T −t 2 σ T −t d2 = ln S K S is the price of the underlying security.u. double& r. C++ Code 7.1: „he fl—™k ƒ™holes formul— #include <™m—th> #include "normdist. t the current date. endfun™tion MatlabCode 7. r the (continously compounded) risk free interest rate. T the maturity date.h" // mathematical C library // the calculation of the cumularive normal distribution double option pri™e ™—ll ˜l—™k s™holes(const double time sqrt = sqrt(time). return ƒ*x(dI) − u*exp(−r*time)*x(dP). }.sigm—. const const const const double& ƒ.5*sigm—*time sqrt. // volatility double& time) { // time to maturity sqrt)+0. T − t the time to maturity for the option and N (·) the cumulative normal distribution.

50. sigm—=0.u. }. ™out << option pri™e ™—ll ˜l—™k s™holes(ƒ.45325 Matlabprogram: echo #€ƒI = ">> ". time) << endl.1.1: ix—mple using the fl—™k ƒ™holes formul— ST . u .5F g++ progr—mX void test option pri™e ™—ll ˜l—™k s™holes(){ double ƒ = 50.30. double time=0.10D σ = 0.r. = 0. yutput from g++ progr—mX Black Scholes call price = 5. double u = 50. u=100. ™=˜l—™k s™holes ™—ll(ƒ. r=0. sigm—. r. ƒ=100. time=1.sigm—. ™out << " Black Scholes call price = ".time) Output from Matlabprogram: Example 7.ƒto™k in ™omp—ny ˆ‰ is ™urrently tr—ding —t SHF gonsider — ™—ll option on ˆ‰ sto™k with —n exer™ise pri™e of K = 50 —nd time to m—turity of T monthsF „he vol—tility of ˆ‰ sto™k h—s ˜een estim—ted to ˜e σ = 30%F „he ™urrent risk free interest r—te @with ™ontinous ™ompoundingA for six month ˜orrowing is IH7F „o ™—l™ul—te the pri™e of this option we use the fl—™k ƒ™holes formul— with inputs S = 50D K = 50D r = 0. double r double sigm— = 0.1.3 —nd (T − t) = 0.10.

ST − K) w—s shown ˜y fl—™k —nd ƒ™holes to h—ve —n —n—lyti™—l solution of fun™tion—l form shown in the fl—™k ƒ™oles formul— UFIF 7. 1. K the exercise price. 7.2.Exercise 14. Implement this formula. σ the standard deviation of the underlying asset.1 The original Black Scholes analysis „he prim—ry —ssumption underlying the fl—™k ƒ™holes —n—lyis ™on™erns the sto™h—sti™ pro™ess governing the pri™e of the underlying —ssetF „he pri™e of the underlying —ssetD S D is —ssumed to follow — geometri™ frowni—n wotion pro™essD ™onveniently written in either of the shorth—nd forms dS = µSdt + σSdZ or dS = µdt + σdZ S where µ —nd σ —re ™onst—ntsD —nd Z is frowni—n motionF …sing sto9s lemm—D the —ssumption of no —r˜itr—geD —nd the —˜ility to tr—de ™ontinuouslyD fl—™k —nd ƒ™holes showed th—t the pri™e of any ™ontingent ™l—im written on the underlying must solve the partial dierential equation @UFIAF ∂f 1 ∂2f 2 2 ∂f rS + + σ S = rf ∂S ∂t 2 ∂S 2 @UFIA por —ny particular ™ontingent ™l—imD the terms of the ™l—im will give — num˜er of boundary conditions th—t determines the form of the pri™ing formul—F „he pde given in equ—tion @UFIAD with the ˜ound—ry ™ondition cT = max(0. r the (continously compounded) risk free interest rate.2 Understanding the why's of the formula „o get some underst—nding of the fl—™k ƒ™holes formul— —nd why it works will need to delve in some det—il into the m—them—ti™s underlying its deriv—tionF st does not help th—t there —re — num˜er of w—ys to prove the fl—™k ƒ™holes formul—D depending on the setupF es it turns outD two of these w—ys —re import—nt to underst—nd for ™omput—tion—l purposesD the origin—l fl—™k ƒ™holes ™ontinous time w—yD —nd the limit of — ˜inomi—l pro™ess w—y of goxD ‚ossD —nd ‚u˜instein @IWUWAF 7. The Black Scholes price for a put option is: p = Ke−r(T −t) N (−d2 ) − SN (−d1 ) where d1 and d2 are as for the call option: + (r + 1 σ 2 )(T − t) √ 2 σ T −t √ d2 = d1 − σ T − t.2 The limit of a binomial case enother is to use the limit of — ˜inomi—l pro™ess @gox et —lFD IWUWAF „he l—tter is p—rti™ul—rly interestingD —s it —llows us to link the fl—™k ƒ™holes formul— to the ˜inomi—lD —llowing the ˜inomi—l fr—mework to ˜e used —s —n —pproxim—tionF SU . d1 = ln S X S is the price of the underlying secrutity.2. T − t the time to maturity for the option and N (·) the cumulative normal distribution.

2 Other Derivatives g—l™ul—ting the delt— of the fl—™k ƒ™holes ™—ll option pri™e „he rem—ining deriv—tives —re more seldom usedD ˜ut —ll of them —re relev—ntF ell of them —re listed in formul— UFQFPF „he ™—l™ul—tion of —ll of these p—rti—l deriv—tives for — ™—ll option is shown in ™ode UFQ SV .3 Partial derivatives.3 The representative agent framework e (n—l w—y to show the fƒ formul— to —ssume — represent—tive —gent —nd lognorm—lity —s w—s done in ‚u˜instein @IWUTAF 7.1 Delta „he (rst deriv—tive of the option pri™e with respe™t to the pri™e of the underlying se™urity is ™—lled the delta of the option pri™eF st is the deriv—tive most people will run intoD sin™e it is import—nt in hedging of optionsF ∂c = N (d1 ) ∂S gode UFP shows the ™—l™ul—tion of the delt— for — ™—ll optionF #include <™m—th> #include "normdist.2.h" double option pri™e delt— ™—ll ˜l—™k s™holes(const double time sqrt = sqrt(time).3. return delt—. // Strike (exercise) price. double& r.2: 7. sn tr—ding of optionsD — num˜er of p—rti—l deriv—tives of the option pri™e formul— is import—ntF 7.3. }.7. double dI = (log(ƒ/u)+r*time)/(sigm—*time double delt— = x(dI). // spot price double& u. C++ Code 7. // interest rate double& sigm—. const const const const double& ƒ. // volatility double& time){ // time to maturity + 0.5*sigm—*time sqrt) sqrt.

}. q—mm— = n(dI)/(ƒ*sigm—*time sqrt). // partial wrt time double& †eg—. dI = (log(ƒ/u)+r*time)/(sigm—*time sqrt) + 0. „het— =− (ƒ*sigm—*n(dI))/(2*time sqrt) − r*u*exp( −r*time)*x(dP).helt— @∆A ∆= ∂c = N (d1 ) ∂S q—mm— @ΓA n(d1 ) ∂2c √ = 2 ∂S Sσ T − t „het— @ΘA @™—reful —˜out whi™h of these you w—ntA ∂c 1 1 = Sn(d1 ) σ √ + rKe−r(T −t) N (d2 ) ∂(T − t) 2 T −t ∂c 1 1 − rKe−r(T −t) N (d2 ) = −Sn(d1 ) σ √ ∂t 2 T −t †eg— √ ∂c = S T − tn(d1 ) ∂σ ‚ho @ρA ∂c = K(T − t)e−r(T −t) N (d2 ) ∂r S is the price of the underlying security.2: €—rti—l deriv—tives of the fl—™k ƒ™holes ™—ll option formul— #include <™m—th> #include "normdist. // interest rate const double& sigm—. // partial wrt sigma double& ‚ho){ // partial wrt r C++ Code 7. r the (continously compounded) risk free interest rate. t the current date. ‚ho = u*time*exp(−r*time)*x(dP). †eg— = ƒ * time sqrt*n(dI). σ the standard deviation of the underlying asset. // second prt wrt S double& „het—. K the exercise price. // partial wrt S double& q—mm—. double double double const double& ƒ. // spot price const double& u.3: g—l™ul—ting the p—rti—l deriv—tives of — fl—™k ƒ™holes ™—ll option SW . // volatility const double& time. n(·) is “ “ ” Rz 1 2 and N (·) the cumulative normal distribution N (z) = −∞ n(t)dt .h" using namespace std. dP = dI−(sigm—*time sqrt). // time to maturity double& helt—. the normal distribution function n(z) = √1 e− 2 z 2π Formula 7. // Strike (exercise) price. const double& r.”T the maturity date and T − t the time to maturity for the option. void option pri™e p—rti—ls ™—ll ˜l—™k s™holes( time sqrt = sqrt(time).5*sigm—*time sqrt. helt— = x(dI).

}. q—mm—. yutput from g++ progr—mX Black Scholes call partial derivatives Delta = 0. ‚ho). „het—. ™out << " Rho = " << ‚ho << endl. double helt—. †eg—. ™out << " Delta = " << helt— << endl.50.3046 Rho = 13. ™out << " Theta = " << „het— << endl.u.2: ix—mple ™—l™ul—ting p—rti—l deriv—tives using the fl—™k ƒ™holes formul— TH .633737 Gamma = 0. double sigm— = 0.30. „het—.10. time. double u = 50. ™out << " Vega = " << †eg— << endl. double time=0. †eg—.sigm—.61473 Vega = 13. helt—.gonsider the s—me ™—ll option —s in the previous ex—mpleF „he option m—tures T months from nowD —t whi™h time the holder of the option ™—n re™ive one unit of the underlying se™urity ˜y p—ying the exer™ise pri™e of K = 50F „he ™urrent pri™e of the underlying se™urity is S = 50F „he vol—tility of the underlying se™urity is given —s σ = 30%F „he ™urrent risk free interest r—te @with ™ontinous ™ompoundingA for six month ˜orrowing is IH7F „o ™—l™ul—te the p—rti—l deriv—tives we therefore use inputs S = 50D K = 50D r = 0.3 —nd (T − t) = 0. double r = 0.1168 Example 7. q—mm—. ™out << " Gamma = " << q—mm— << endl. double ƒ = 50. option pri™e p—rti—ls ™—ll ˜l—™k s™holes(ƒ.5F g++ progr—mX void test ˜l—™k s™holes p—rti—ls ™—ll(){ ™out << " Black Scholes call partial derivatives " << endl.r. ‚ho.10D σ = 0.0354789 Theta = -6.

C++ Code 7. double sigm— high=0. if (f—˜s(test)<egg…‚eg‰) { return sigm—. // make this smaller for higher accuracy // want to bracket sigma. σ.5.0 * sigm— high. K. }. const const const const double& ƒ. }.time).u.sigm— high.u. { sigm— high = 2. double rsqr †ev…i = 1e10. { // check for arbitrage violations.3.3 Implied Volatility. double test = (pri™e−option pri™e). pri™e = option pri™e ™—ll ˜l—™k s™holes(ƒ. }.r. // keep doubling. for (int i=0. something wrong. sn ™—l™ul—tion of the option pri™ing formul—sD in p—rti™ul—r the fl—™k ƒ™holes formul—D the only unknown is the st—nd—rd devi—tion of the underlying sto™kF e ™ommon pro˜lem in option pri™ing is to (nd the implied vol—tilityD given the o˜served pri™e quoted in the m—rketF por ex—mpleD given c0 D the pri™e of — ™—ll optionD the following equ—tion should ˜e solved for the v—lue of σ c0 = c(S. } else { sigm— high = sigm—. double& r. if (sigm— high>rsqr †ev…i) return i‚‚y‚. if (test < 0. TI .0. double& u. rst nd a maximum sigma by nding a sigma // with a estimated price higher than the actual price.0) { sigm— low = sigm—.7.u.0e−5.r. // panic. T − t) …nfortun—telyD this equ—tion h—s no ™losed form solutionD whi™h me—ns the equ—tion must ˜e numeri™—lly solved to (nd σ F ‡h—t is pro˜—˜ly the —lgorithmi™ simplest w—y to solve this is to use — ˜inomi—l se—r™h —lgorithmD whi™h is implemented in the followingF ‡e st—rt ˜y ˜r—™keting the sigm— ˜y (nding — high sigm— th—t m—kes the fƒ pri™e higher th—n the o˜served pri™eD —nd thenD given the ˜r—™keting interv—lD we se—r™h for the vol—tility in — system—ti™ w—yF gode UFR shows su™h — ™—l™ul—tionF #include <™m—th> #include "fin_recipes. double pri™e = option pri™e while (pri™e < option pri™e) ™—ll ˜l—™k s™holes(ƒ. return i‚‚y‚.h" double option pri™e implied vol—tility ™—ll ˜l—™k s™holes ˜ise™tions(const if }.r.99*(ƒ−u*exp(−time*r))) 0. double& time.time). double i‚‚y‚ = −1e40.sigm— high. pri™e = option pri™e ™—ll ˜l—™k s™holes(ƒ. } }.4: g—l™ul—tion of implied vol—tility of fl—™k ƒ™holes using ˜ise™tions snste—d of this simple ˜r—™ketingD whi™h is —™tu—lly pretty f—stD —nd will @—lmostA —lw—ys (nd the solutionD we ™—n use the xewton!‚—phson formul— for (nding the root of —n equ—tion in — single v—ri—˜leF „he gener—l des™ription of this method st—rts with — fun™tion f () for whi™h we w—nt to (nd — rootF f (x) = 0.i++){ double sigm— = (sigm— low+sigm— high)*0. r.i<weˆ s„i‚e„syxƒ. int weˆ s„i‚e„syxƒ = 100. double& option pri™e){ // Option price is too low if this happens // simple binomial search for the implied volatility.3. (option return pri™e<0. double sigm— low=1e−5. const const const const // relies on the value of the option increasing in volatility double egg…‚eg‰ = 1.time).sigm—.

398*t sqrt). return −99e10.sigm—. const double egg…‚eg‰ = 1. (option return pri™e<0.5*sigm—*t sqrt. { // check for arbitrage violations.0. double& r. double veg— = ƒ * t sqrt * n(dI).„he fun™tion f () needs to ˜e di'erenti—˜leF qiven — (rst guess x0 D iter—te ˜y xi+1 = xi − until f (xi ) f (xi ) |f (xi )| < where is the desired —™™ur—™yF1 sn our ™—se f (x) = cobs − cBS (σ) —ndD e—™h new iter—tion will ™—l™ul—te σi+1 = σi + cobs − cBS (σi ) BS − ∂c∂σ () gode UFS shows the ™—l™ul—tion of implied vol—tility using xewtonE‚—phsonF #include "fin_recipes.5: g—l™ul—tion of implied vol—tility of fl—™k ƒ™holes using xewtonE‚—phson xote th—t to use xewtonE‚—phson we need the deriv—tive of the option pri™eF por the fl—™kEƒ™holes formul— this is knownD —nd we ™—n use thisF fut for pri™ing formul—s like the ˜inomi—lD where the p—rti—l deriv—tives —re not th—t e—sy to ™—l™ul—teD simple ˜ise™tion is the preferred —lgorithmF 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 TP . double sigm— = (option pri™e/ƒ)/(0. // nd initial value for (int i=0.r. double t sqrt = sqrt(time).i<weˆ s„i‚e„syxƒ.time). double& u.99*(ƒ−u*exp(−time*r))) 0. double& option pri™e) { const int weˆ s„i‚e„syxƒ = 100.h" #include "normdist.u.0e−5. double& time.h" #include <™m—th> #include <iostre—m> double option pri™e implied vol—tility ™—ll ˜l—™k s™holes newton(const if }. double di' = option pri™e −pri™e. // something screwy happened. if (f—˜s(di' )<egg…‚eg‰) return sigm—. }.i++){ double pri™e = option pri™e ™—ll ˜l—™k s™holes(ƒ. }. sigm— = sigm— + di' /veg—. double dI = (log(ƒ/u)+r*time)/(sigm—*t sqrt) + 0. should throw exception C++ Code 7. Option price is too low if this happens const const const const double& ƒ.

gonsider the s—me ™—ll option —s in the previous ex—mplesF „he option m—tures T months from nowD —t whi™h time the holder of the option ™—n re™ive one unit of the underlying se™urity ˜y p—ying the exer™ise pri™e of K = 50F „he ™urrent pri™e of the underlying se™urity is S = 50F „he ™urrent risk free interest r—te @with ™ontinous ™ompoundingA for six month ˜orrowing is IH7F „o ™—l™ul—te we therefore use inputs S = 50D K = 50D r = 0.g) << endl.5F g++ progr—mX void test ˜l—™k s™holes implied vol—tility(){ double ƒ = 50.time.50. option pri™e implied vol—tility ™—ll ˜l—™k s™holes newton(ƒ.5. }.r. ™out ™out ™out ™out << << << << r = 0. " Black Scholes implied volatility using bisections = ".r.10 —nd (T − t) = 0.5F „he implied vol—tility is the σ whi™hD input in the fl—™k ƒ™holes formul— with these other inputsD will produ™e —n option pri™e of C = 2.u.time. double time=0. yutput from g++ progr—mX Black Scholes implied volatility using Newton search = 0.10. option pri™e implied vol—tility ™—ll ˜l—™k s™holes ˜ise™tions(ƒ.5F ‡e —re now told th—t the ™urrent option pri™e is C = 2.g) << endl.u.0500427 Black Scholes implied volatility using bisections = 0. " Black Scholes implied volatility using Newton search = ".0500419 Example 7. double u = 50.3: ix—mple (nding implied vol—tility using the fl—™k ƒ™holes formul— TQ . double double g=2.

K. (T − t) . r. r. (T − t) n TR .Chapter 8 Warrants e w—rr—nt is —n optionElike se™urity on equityD ˜ut it is issued ˜y the s—me ™omp—ny whi™h h—s issued the equityD —nd when — w—rr—nt is exer™isedD — new sto™k is issuedF „his new sto™k is issued —t — the w—rr—nt strike pri™eD whi™h is lower th—n the ™urrent sto™k pri™e @sf it w—sn9t the w—rr—nt would not ˜e exer™isedFA ƒin™e the new sto™k is — — fr—™tion—l right to —ll ™—sh)owsD this sto™k issue waters outD or dilutesD the equity in — ™omp—nyF „he degree of dilution is — fun™tion of how m—ny w—rr—nts —re issuedF 8. ˜ut this new —sset v—lue is spre—d over more sh—resD sin™e e—™h exer™ised w—rr—nt is now —n equityF „he —ssets of the (rm is spre—d over —ll sh—resD hen™e e—™h new sh—re is worthX At + mK m+n m—king e—™h exer™ised w—rr—nt worthX n At + mK −K = m+n m+n At −K n sf we knew the ™urrent v—lue of —ssets in the ™omp—nyD we ™ould v—lue the w—rr—nt in two stepsX IF †—lue the option using the fl—™k ƒ™holes formul— —nd PF wultiply the resulting ™—ll pri™e with n m+n F At n —s the ™urrent sto™k pri™eF sf we let Wt ˜e the w—rr—nt v—lueD the —˜ove —rguments —re summ—rized —sX Wt = n CBS n+m A . σ.1 Warrant value in terms of assets vet K ˜e the strike pri™eD n the num˜er of sh—res outst—nding —nd m the num˜er of w—rr—nts issuesF essume e—™h w—rr—nt is for I new sh—reD —nd let At ˜e the ™urrent —sset v—lue of (rmF ƒuppose —ll w—rr—nts —re exer™ised simult—neouslyF „hen the —ssets of the (rm in™re—se ˜y the num˜er of w—rr—nts times the strike pri™e of the w—rr—ntF At + mK. K. σ. n where CBS (·) is the fl—™k ƒ™holes formul—F 8.2 Valuing warrants when observing the stock value roweverD one does not ne™ess—rily o˜serve the —sset v—lue of the (rmF „ypi™—lly one only o˜serves the equity v—lue of the (rmF sf we let St ˜e the ™urrent sto™k pri™eD the —sset v—lue is re—llyX At = nSt + mWt …sing the sto™k pri™eD one would v—lue the w—rr—nt —s Wt = n CBS n+m nSt + mWt .

double time sqrt = sqrt(time). }. // number of warrants outstanding double& n){ // number of shares outstanding return C++ Code 8.u. // strike price double& r.5*sigm—*time sqrt.r.r.time).sigm—. w.h" #include <™m—th> double w—rr—nt pri™e —djusted ˜l—™k s™holes(const const double epsilon=0.r. σ. w=w−g/gprime.h" #include "normdist.3 Readings w™hon—ld @PHHTA —nd rull @PHHTA —re gener—l referen™esF e pro˜lem with w—rr—nts is th—t exer™ise of —ll w—rr—nts simult—neously is not ne™ess—rily optim—lF TS .time). const const const const const const double& ƒ. r. // time to maturity double& m. // current stock price double& u. σ. g = w−(n/(n+m))*option pri™e ™—ll ˜l—™k s™holes(ƒ+(m/n)*w.u.00001. }. double g = w−(n/(n+m))*option pri™e ™—ll ˜l—™k s™holes(ƒ+(m/n)*w. double gprime = 1−(m/n)*x(dI).u. K.1: edjusted fl—™k ƒ™holes v—lue for — ‡—rr—nt 8.or Wt = m n CBS St + Wt . // volatility double& time. (T − t) n+m n ƒt—rting with —n initi—l guess for the w—rr—nt v—lue Wto D the xewtonE‚h—pson method is th—t one iter—tes —s follows Wti = Wti−1 − g(Wti−1 ) . (T − t) n+m n xote th—t this gives the v—lue of Wt —s — fun™tion of Wt F yne need to solve this equ—tion numeri™—lly to (nd Wt F „he numeri™—l solution for Wt is done using the xewtonE‚h—pson methodF vet g(Wt ) = Wt − m n CBS St + Wt . while (f—˜s(g)>epsilon) { double dI = (log((ƒ+(m/n))/u)+r*time)/(sigm—*time sqrt)+0. g (Wti−1 ) where i signi(es iter—tion iD until the ™riterion fun™tion g(Wti−1 ) is ˜elow some given —™™ur—™y F sn this ™—se m g (Wt ) = 1 − N (d1 ) m+n where St + m Wt n K ln d1 = 1 + (r + 2 σ 2 )(T − t) √ σ T −t en o˜vious st—rting v—lue is to set ™—l™ul—te the fl—™k ƒ™holes v—lue using the ™urrent sto™k pri™eD —nd m multiplying it with m+n F gode VFI implements this ™—l™ul—tionF #include "fin_recipes. // interest rate double& sigm—. K.sigm—.sigm—.time). double w = (n/(n+m))*option pri™e ™—ll ˜l—™k s™holes(ƒ. r.

double w = w—rr—nt pri™e —djusted ˜l—™k s™holes(ƒ. double n = 10000. time.1: ix—mple w—rr—nt pri™ing €ress et —lF @IWWPA dis™usses the xewtonE‚h—pson method for root (ndingF TT . }.142 Example 8. double m = 1000.e sto™k is ™urrently pri™ed —t S = 48F gonsider w—rr—nts on the s—me ™omp—ny with exer™ise pri™e K = 40 —nd time to m—turity of six monthsF „he ™omp—ny h—s n = 10000 sh—res outst—ndingD —nd h—s issued m = 1000 w—rr—ntsF „he ™urrent @™ontinously ™ompoundedA risk free interest r—te is V7F hetermine the ™urrent w—rr—nt pri™eF g++ progr—mX void test w—rr—nt pri™e —djusted ˜l—™k s™holes(){ double ƒ = 48. n).sigm—. yutput from g++ progr—mX warrant price = 10.5.r. m. double sigm— = 0.30. double u = 40.u.08. ™out << " warrant price = " << w << endl. double time = 0. double r = 0.

2).1: Exercise 15. S K Formula 9. double dP = dI−(sigm—*time sqrt). const double& ƒ.1: en—lyti™—l pri™es for iurope—n ™—ll option on underlying se™urity h—ving — p—yout of q #include <™m—th> #include "normdist. q the (continous) payout and σ the standard deviation of the underlying asset. const double& r. por options on other (n—n™i—l instruments th—n sto™ksD we h—ve to —llow for the f—™t th—t the underlying m—y h—ve p—youts during the life of the optionF por ex—mpleD in working with ™ommodity optionsD there is often some stor—ge ™osts if one w—nted to hedge the option ˜y ˜uying the underlyingF 9. „he simplest ™—se is when the p—youts —re done ™ontinuouslyF „o v—lue —n iurope—n optionD — simple —djustment to the fl—™k ƒ™holes formul— is —ll th—t is neededF vet q ˜e the continuous payout of the underlying ™ommodityF g—ll —nd put pri™es for iurope—n options —re then given ˜y formul— WFID whi™h —re implemented in ™ode WFIF c = Se−q(T −t) N (d1 ) − Ke−r(T −t) N (d2 ) where + (r − q + 1 σ 2 )(T − t) 2 √ σ T −t √ d2 = d1 − σ T − t d1 = ln S is the price of the underlying secrutity.1.h" using namespace std. double dI = (log(ƒ/ˆ) + (r−q + 0. // mathematical library // this denes the normal distribution double option pri™e europe—n ™—ll p—yout( double sigm— sqr = pow(sigm—. T the maturity date. }. double ™—ll pri™e = ƒ * exp(−q*time)* x(dI) − ˆ * exp(−r*time) * x(dP). // yield on underlying const double& sigm—.5*sigm— sqr)*time)/(sigm—*time sqrt). // interest rate const double& q. yption pri™eD ™ontinous p—yout from underlying The price of a put on an underlying security with a continous payout of q is: p = Ke−r(T −t) N (−d2 ) − Se−q(T −t) N (−d1 ) TU .1 Adjusting for payouts of the underlying. // volatility const double& time) { // time to maturity C++ Code 9. t the current date. // spot price const double& ˆ. double time sqrt = sqrt(time). T − t the time to maturity for the option and N (·) the cumulative normal distribution. return ™—ll pri™e. K the exercise price. // Strike (exercise) price. r the risk free interest rate.1 Continous Payouts from underlying.Chapter 9 Extending the Black Scholes formula 9.

1. Implement this formula.

9.1.2 Dividends.
e spe™i—l ™—se of p—youts from the underlying se™urity is sto™k options when the sto™k p—ys dividendsF ‡hen the sto™k p—ys dividendsD the pri™ing formul— is —djustedD ˜e™—use the dividend ™h—nges the v—lue of the underlyingF „he ™—se of ™ontinuous dividends is e—siest to de—l withF st ™orresponds to the ™ontinuous p—youts we h—ve looked —t previouslyF „he pro˜lem is the f—™t th—t most dividends —re p—id —t dis™rete d—tesF

European Options on dividend-paying stock.
„o —djust the pri™e of —n iurope—n option for known dividendsD we merely su˜tr—™t the present v—lue of the dividends from the ™urrent pri™e of the underlying —sset in ™—l™ul—ting the fl—™k ƒ™holes v—lueF
#include <™m—th> // #include <ve™tor> #include "fin_recipes.h"
mathematical library // dene the black scholes price

double

option pri™e europe—n ™—ll dividends(

double —djusted ƒ = ƒ; for (int i=0;i<dividend times.size();i++) { if (dividend times[i]<=time to m—turity){
—djusted ƒ −= dividend —mounts[i]
* }; }; };

const double& ƒ, const double& u, const double& r, const double& sigm—, const double& time to m—turity, const ve™tor<double>& dividend const ve™tor<double>& dividend
exp(−r*dividend times[i]);

times, —mounts

) {

return

option pri™e ™—ll ˜l—™k s™holes(—djusted ƒ,u,r,sigm—,time to m—turity);

C++ Code 9.2:
g++ progr—mX

iurope—n option pri™eD dividend p—ying sto™k

void test ˜l—™k s™holes with dividends(){ double ƒ = 100.0; double u = 100.0; double r = 0.1; double sigm— = 0.25; double time=1.0; double dividend yield=0.05; ve™tor<double> dividend times; ve™tor<double>

dividend —mounts; dividend times.push ˜—™k(0.25); dividend —mounts.push ˜—™k(2.5); dividend times.push ˜—™k(0.75); dividend —mounts.push ˜—™k(2.5); ™out << " european stock call option with contininous dividend = " << option pri™e europe—n ™—ll p—yout(ƒ,u,r,dividend yield,sigm—,time) << endl; ™out << " european stock call option with discrete dividend = " << option pri™e europe—n ™—ll dividends(ƒ,u,r,sigm—,time,dividend times,dividend —mounts) << endl;

};

yutput from g++ progr—mX

european stock call option with contininous dividend = 11.7344 european stock call option with discrete dividend = 11.8094

TV

9.2

American options.

emeri™—n options —re mu™h h—rder to de—l with th—n iurope—n onesF „he pro˜lem is th—t it m—y ˜e optim—l to use @exer™iseA the option ˜efore the (n—l expiry d—teF „his optim—l exer™ise poli™y will —'e™t the v—lue of the optionD —nd the exer™ise poli™y needs to ˜e known when solving the pdeF „here is therefore no gener—l —n—lyti™—l solutions for emeri™—n ™—ll —nd put optionsF „here is some spe™i—l ™—sesF por emeri™—n ™—ll options on —ssets th—t do not h—ve —ny p—youtsD the emeri™—n ™—ll pri™e is the s—me —s the iurope—n oneD sin™e the optim—l exer™ise poli™y is to not exer™iseF por emeri™—n €ut is this not the ™—seD it m—y p—y to exer™ise them e—rlyF ‡hen the underlying —sset h—s p—youtsD it m—y —lso p—y to exer™ise the option e—rlyF „here is one known known —n—lyti™—l pri™e for emeri™—n ™—ll optionsD whi™h is the ™—se of — ™—ll on — sto™k th—t p—ys — known dividend once during the life of the optionD whi™h is dis™ussed nextF sn —ll other ™—ses the emeri™—n pri™e h—s to ˜e —pproxim—ted using one of the te™hniques dis™ussed in l—ter ™h—ptersX finomi—l —pproxim—tionD numeri™—l solution of the p—rti—l di'erenti—l equ—tionD or —nother numeri™—l —pproxim—tionF

9.2.1 Exact american call formula when stock is paying one dividend.
‡hen — sto™k p—ys dividendD — ™—ll option on the sto™k m—y ˜e optim—lly exer™ised just ˜efore the sto™k goes exEdividendF ‡hile the gener—l dividend pro˜lem is usu—lly —pproxim—ted somehowD for the spe™i—l ™—se of one dividend p—yment during the life of —n option —n —n—lyti™—l solution is —v—il—˜leD due to ‚oll!qeske!‡h—leyF sf we let S ˜e the sto™k pri™eD K the exer™ise pri™eD D1 the —mount of dividend p—idD t1 the time of dividend p—ymentD T the m—turity d—te of optionD we denote the time to dividend p—yment τ1 = T − t1 —nd the time to m—turity τ = T − tF e (rst ™he™k of e—rly exer™ise isX

D1 ≤ K 1 − e−r(T −t1 )
sf this inequ—lity is ful(lledD e—rly exer™ise is not optim—lD —nd the v—lue of the option is

c(S − e−r(t1 −t) D1 , K, r, σ, (T − t))
where c(·) is the regul—r fl—™k ƒ™holes formul—F sf the inequ—lity is not ful(lledD one performs the ™—l™ul—tion shown in formul— WFP —nd implemented in ™ode WFQ

Exercise 16.

The Black approximation to the price of an call option paying a xed dividend is an approximation to the value of the call. Suppose the dividend is paid as some date t1 before the maturity date of the option T . Blacks approximation calculates the value of two European options using the Black Scholes formula. One with expiry date equal to the ex dividend date of the options. Another with expiry date equal to the option expiry, but the current price of the underlying security is adjusted down by the amount of the dividend. 1. Implement Black's approximation.

TW

C = (S − D1 e−r(t1 −t) ) (N (b1 ) + N (a1 , −b1 , ρ)) + Ke−r(T −t)) N (a2 , −b2 , ρ) − (K − D1 )e−r(t1 −t) N (b2 )
where

ρ=− ln a1 =

(t1 − t T −t
S−D1 e−q(τ1 K

σ τ

+ (r + 1 σ 2 )τ 2

√ a2 = a1 − σ T − t ln b1 =
S−D1 e−r(t1 −t) ¯ S

+ (r + 1 σ 2 )(t1 − t) 2 (t1 − t)

σ √

b2 = b1 − σ T − t ¯ —nd S solves ¯ ¯ c(S, t1 ) = S + D1 − K
S is the price of the underlying secrutity, K the exercise price, r the risk free interest rate, D1 is the dividend amount and σ 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. N () with one argument is the univariate normal cumulative distribution. N () with three arguments is the bivariate normal distribution with the correlation between the two normals given as the third arguement.

Formula 9.2:

‚oll!qeske!‡h—ley pri™e of —meri™—n ™—ll option p—ying one (xed dividend

UH

t—u−t—uI).t—u−t—uI). while ( (f—˜s(test)>egg…‚eg‰) && ((ƒ high−ƒ low)>egg…‚eg‰) if (test<0. // rst nd the S bar that solves c=S bar+D1-K double ƒ low=0.sigm—. ƒ ˜—r = 0. test = ™−ƒ ˜—r−hI+u. while ( (test>0. double& t—u. ˜P = ˜I − sigm— * t—uI sqrt.t—u−t—uI). ƒ ˜—r = 0. test = ™−ƒ ˜—r−hI+u.5 * ƒ high. double& hI.−˜I. double ƒ ˜—r = 0. return g.5*sigm— sqr)*t—uI)/(sigm—*t—uI sqrt).r.r. nd BS value option pri™e ™—ll ˜l—™k s™holes(ƒ−hI*exp(−r*t—uI).t—u).0.u.sigm—.rho) − (u−hI)*exp(−r*t—uI)*x(˜P). if (hI < = u* (1.r.t—u−t—uI). C++ Code 9.h" dene the normal distribution functions // the regular black sholes formula double option pri™e —meri™—n ™—ll one dividend(const return option pri™e ™—ll ˜l—™k s™holes(ƒ−exp(−r*t—uI)*hI.3: yption pri™eD ‚oll!qeske!‡h—ley ™—ll formul— for dividend p—ying sto™k UI . }.sigm—. double t—uI sqrt = sqrt(t—uI). // now nd S bar that solves c=S bar-D+K ™ = option pri™e ™—ll ˜l—™k s™holes(ƒ ˜—r.u.r.sigm—. double test = ™−ƒ high−hI+u. —I = (log((ƒ−hI*exp(−r*t—uI))/u) +( r+0.0) && (ƒ high<=1e10) ) { ƒ high *= 2. —P = —I − sigm—*t—u sqrt.u. ™ = option pri™e ™—ll ˜l—™k s™holes(ƒ high.0) { ƒ high = ƒ ˜—r. ˜I = (log((ƒ−hI*exp(−r*t—uI))/ƒ ˜—r)+(r+0. double& r.sigm—.0−exp(−r*(t—u−t—uI)))) // check for no exercise const const const const const const double& ƒ.rho) − (u*exp(−r*t—u))*x(—P. }. double rho = − sqrt(t—uI/t—u). ) { double double double double double }.#include <™m—th> #include "normdist. test = ™−ƒ high−hI+u. double& t—uI){ }. // start by nding a very high S above S bar double ™ = option pri™e ™—ll ˜l—™k s™holes(ƒ high. if (ƒ return high>1e10) { // early exercise never optimal. // the simplest: binomial search double ƒ high=ƒ.5 * (ƒ high + ƒ low). }. double t—u sqrt = sqrt(t—u).−˜P.t—u). const double egg…‚eg‰ = 1e−6.sigm—. g = (ƒ−hI*exp(−r*t—uI)) * x(˜I) + (ƒ−hI*exp(−r*t—uI)) * x(—I. } else { ƒ low = ƒ ˜—r. ™ = option pri™e ™—ll ˜l—™k s™holes(ƒ ˜—r.u.u.r. double& sigm—. // decrease this for more accuracy double sigm— sqr = sigm—*sigm—.r.u.5*sigm— sqr)*t—u) / (sigm—*t—u sqrt). double& u.h" // #include "fin_recipes.

5.r.0.1: ix—mple of pri™ing of option on sto™k p—ying one dividend during the life of the option UP . double t—u = 1.g++ progr—mX void test rgw pri™e —m ™—ll div(){ double ƒ = 100.25.0. t—uI)<< endl.1.hI.sigm—. }. double t—uI = 0.0. yutput from g++ progr—mX american call price with one dividend = 10. ™out << " american call price with one dividend = " << option pri™e —meri™—n ™—ll one dividend(ƒ.t—u. double r = 0. double u = 100.0166 Example 9. double hI = 10. double sigm— = 0.0.u.

0.1 Black's model por —n iurope—n option written on — futures ™ontr—™tD we use —n —djustment of the fl—™k ƒ™holes solutionD whi™h w—s developed in fl—™k @IWUTAF issenti—lly we repl—™e S0 with e−r(T −t)r F in the fl—™k ƒ™holes formul—D —nd get the formul— shown in WFQ —nd implemented in ™ode WFRF c = e−r(T −t) (F N (d1 ) − KN (d2 )) where + 1 σ 2 (T − t) √2 σ T −t √ d2 = d1 − σ T − t d1 = ln F is the futures pri™eD K is the exer™ise pri™eD r the risk free interest r—teD σ the vol—tility of the futures pri™eD —nd T − t is the time to m—turity of the option @in ye—rsAF Formula 9. €ri™ing of putures option using the fl—™k formul— The Black formula for a put option on a futures contract is p = e−r(T −t) (KN (−d2 ) − F N (−d1 )) UQ .u.2: Exercise 17. double time sqrt = sqrt(time). yutput from g++ progr—mX european futures call option = 0. // futures price const double& u.851476 Example 9.sigm—. double dI = (log (p/u) + 0.3 Options on futures 9.h" using namespace std. // exercise price const double& r. C++ Code 9. double u = 45.4: g++ progr—mX €ri™e of iurope—n g—ll option on putures ™ontr—™t void test futures option pri™e ˜l—™k(){ double p = 50. }. }.3: fl—™ks formul— for the pri™e of —n iurope—n g—ll option with — futures ™ontr—™t —s the underlying se™urity #include <™m—th> #include "normdist.9. ™out << " european futures call option = " << futures option pri™e put europe—n ˜l—™k(p.r.08. double r = 0.3.5 * sigm— sqr * time) double dP = dI − sigm— * time sqrt. // interest rate const double& sigm—.time) << endl. return exp(−r*time)*(p * x(dI) − u * x(dP)).5. const double& p.0. // volatility const double& time){ // time to maturity / (sigm— * time sqrt). F K // mathematics library // normal distribution double futures option pri™e ™—ll europe—n ˜l—™k( double sigm— sqr = sigm—*sigm—. double sigm— = 0.2. double time=0.

where the varibles are as dened for the call option. Implement the put option price. 1. UR .

r.9. const double& sigm—. // r domestic. const double& ˆ. C++ Code 9. T − t is the time to maturity for the option. // exercise. double time sqrt = sqrt(time).4: iurope—n ™urren™y ™—ll #include <™m—th> #include "normdist.5*sigm— sqr)) * time)/(sigm—*time double dP = dI − sigm— * time sqrt. double u = 52.time) << endl. // exchange rate.5. const double& r.rf.h" // dene the normal distribution function double ™urren™y option pri™e ™—ll europe—n( double sigm— sqr = sigm—*sigm—. return ƒ * exp(−r f *time) * x(dI) − ˆ * exp(−r*time) * x(dP). const double& r f.3: Exercise 18.4 Foreign Currency Options enother rel—tively simple —djustment of the fl—™k ƒ™holes formul— o™™urs when the underlying se™urity is — ™urren™y ex™h—nge r—te @spot r—teAF sn this ™—se one —djusts the fl—™kEƒ™holes equ—tion for the interestEr—te di'erenti—lF vet S ˜e the spot ex™h—nge r—teD —nd now let r ˜e the domesti™ interest r—te —nd rf the foreign interest r—teF σ is then the vol—tility of ™h—nges in the ex™h—nge r—teF „he ™—l™ul—tion of the pri™e of —n iurope—n ™—ll option is then shown in formul— WFR —nd implented in ™ode WFSF c = Se−rf (T −t) N (d1 ) − Ke−r(T −t) N (d2 ) where + r − rf + 1 σ 2 (T − t) 2 √ σ T −t √ d2 = d1 − σ T − t d1 = ln S is the spot exchange rate and K the exercise price. r is the domestic interest rate and rf the foreign interest rate.0. double time=0.2. const double& time){ // time to maturity sqrt). double dI = (log(ƒ/ˆ) + (r−r f + (0. σ is the volatility of changes in the exchange rate. S K Formula 9. yutput from g++ progr—mX european currency call option = 2.sigm—. }. const double& ƒ. // r foreign. }.22556 Example 9.0. ™out << " european currency call option = " << ™urren™y option pri™e ™—ll europe—n(ƒ.5: g++ progr—mX iurope—n putures g—ll option on ™urren™y void test ™urren™y option europe—n ™—ll(){ double ƒ = 50. // volatility.08.u. double sigm— = 0. €ri™ing — foreign ™urren™y ™—ll option The price for an european put for a currency option is p = Ke−r(T −t) N (−d2 ) − Se−rf (T −t) N (−d1 ) US . double r = 0.05. double rf =0.

Implement this formula.1. UT .

4767 Example 9.hI).0*r/sigm— sqr).2)+2. hI += sqrt(pow(((r−q)/sigm— sqr−0. double r=0.5).r.02.05. double u=40.05. return pri™. yutput from g++ progr—mX perpetual call price = 19.u. ™out << " perpetual call price = " << pri™e << endl. double& q.0.0. double q=0. double& r. hI = 0. ™—ll(ƒ. double sigm—=0. double pri™e = option pri™e —meri™—n perpetu—l }. Formula 9. double& u.q.sigm—). double option pri™e —meri™—n perpetu—l ™—ll(const sigm— sqr=pow(sigm—.0))*pow(((hI−1.2). The price for a perpetual american put is ix—mple of pri™ing of perpetu—l ™—ll Pp = K 1 − h2 h2 − 1 S h2 K h2 1 ƒu™h options would ˜e like the ™l—ssi™—l epril fools presentD — perpetu—l zero ™oupon ˜ondF F F UU . double double const const const const double& ƒ.5− ((r−q)/sigm— sqr). r is the risk free interest rate.9. K is the exercise price. q is the dividend yield and σ is the volatility of the underlying asset.5 Perpetual puts and calls e perpetal option is one with no m—turity d—teD it is ini(nitely livedF yf ™ourseD only emeri™—n perpetu—l options m—ke —ny senseD iurope—n perpetu—l options would pro˜—˜ly ˜e h—rd to sellF1 por ˜oth puts —nd ™—lls —n—lyti™—l formul—s h—s ˜een developedF ‡e ™onsider the pri™e of —n emeri™—n ™—llD —nd dis™uss the put in —n exer™iseF pormul— WFS gives the —n—lyti™—l solutionF Cp = where K h1 − 1 h1 − 1 S h1 K h1 h1 = 1 r−q − + 2 σ2 r−q 1 − σ2 2 2 + 2r σ2 S is the current price of the underlying security.4: Exercise 19.6: g++ progr—mX €ri™e for —n —meri™—n perpetu—l ™—ll option void test option pri™e perpetu—l —meri™—n ™—ll(){ double ƒ=50. double pri™=(u/(hI−1.0)/hI)*(ƒ/u). double& sigm—){ C++ Code 9. }.5: €ri™e for — perpetu—l ™—ll option #include <™m—th> using namespace std.

6 Readings rull @PHHTA —nd w™hon—ld @PHHTA —re gener—l referen™esF e (rst formul—tion of —n —n—lyti™—l ™—ll pri™e with dividends w—s in ‚oll @IWUU˜AF „his h—d some errorsD th—t were p—rti—lly ™orre™ted in qeske @IWUWAD ˜efore ‡h—ley @IWVIA g—ve — (n—lD ™orre™t formul—F ƒee rull @PHHTA for — text˜ook summ—ryF fl—™k @IWUTA is the origin—l development of the futures optionF „he origin—l formul—tions of iurope—n foreign ™urren™y option pri™es —re in ? —nd ?F „he pri™e of — perpetu—l put w—s (rst shown in werton @IWUQAF por — perpetu—l ™—ll see w™hon—ld —nd ƒiegel @IWVTAF „he not—tion for perpetu—l puts —nd ™—lls follows the summ—ry in @w™hon—ldD PHHTD pgF QWQAF UV .where h2 = 1 r−q − − 2 σ2 r−q 1 − σ2 2 2 + 2r σ2 1. 9. Implement the calculation of this formula.

1 Introduction ‡e h—ve shown ˜inomi—l ™—l™ul—tions given —n up —nd down movement in ™h—pter TF roweverD ˜inomi—l option pri™ing ™—n —lso ˜e viewed —s —n approximation to — ™ontinuous time distri˜ution ˜y judi™ious ™hoi™e of the ™onst—nts u —nd dF „o do so one h—s to —skX ss it possi˜le to (nd — p—r—metriz—tion @™hoi™e of u —nd dA of — ˜inomi—l pro™ess ¨S r rr ¨ ¨ ¨ ¨ ¨ B ¨ uS ¨ rr ¨ r ¨ ¨ ¨ ¨ ¨ B ¨ uuS ¨ r r r rr r r ¨dS j r ¨ r rr ¨¨ ¨¨ r j r B ¨ ¨ udS rr r r ddS j r whi™h h—s the s—me time series properties —s — @™ontinous timeA pro™ess with the s—me me—n —nd vol—tilityc „here is —™tu—lly —ny num˜er of w—ys of ™onstru™ting thisD hen™e one uses one degree of freedom on 1 imposing th—t the nodes reconnectD ˜y imposing u = d F „o v—lue —n option using this —ppro—™hD we spe™ify the num˜er n of periods to split the time to m—turity (T − t) intoD —nd then ™—l™ul—te the option using — ˜inomi—l tree with th—t num˜er of stepsF qiven S. X. r. T —nd the num˜er of periods nD ™—l™ul—te ∆t = T −t n √ ∆t √ ∆t u = eσ d = e−σ ‡e —lso rede(ne the risk neutr—l pro˜—˜ilities R = er∆t q= R−d u−d „o (nd the option pri™eD will roll ˜—™kw—rdsX et node tD ™—l™ul—te the ™—ll pri™e —s — fun™tion of the two possi˜le out™omes —t time t + 1F por ex—mpleD if there is one stepD UW .Chapter 10 Option pricing with binomial approximations 10. σ.

¨ ¨ C0 r r r ¨ ¨ ¨ ¨ B ¨ ¨ Cu = max(0.2 Pricing of options in the Black Scholes setting gonsider options on underlying se™urities not p—ying dividendF 10. S − X) d d (nd the ™—ll pri™e —t time H —s C0 = e−r (qCu + (1 − q)Cd ) ‡ith more periods one will roll ˜—™kw—rds —s dis™ussed in ™h—pter T 10.2.2.1 European Options por iurope—n optionsD ˜inomi—l trees —re not th—t mu™h usedD sin™e the fl—™k ƒ™holes model will give the ™orre™t —nswerD ˜ut it is useful to see the ™onstru™tion of the ˜inomi—l tree without the ™he™ks for e—rly exer™iseD whi™h is the emeri™—n ™—seF „he ™omputer —lgorithm for — ˜inomi—l in the following merits some ™ommentsF „here is only one ve™tor of ™—ll pri™esD —nd one m—y think one needs twoD one —t time t —nd —nother —t time t + 1F @„ry to write down the w—y you would solve it ˜efore looking —t the —lgorithm ˜elowFA fut ˜y using the f—™t th—t the ˜r—n™hes re™onne™tD it is possi˜le to get —w—y with the —lgorithm ˜elowD using one less —rr—yF ‰ou m—y w—nt to ™he™k how this worksF st is —lso — useful w—y to m—ke sure one underst—nds ˜inomi—l option pri™ingF 10. Su − X) r r r r j r C = max(0.2 American Options en emeri™—n option di'ers from —n iurope—n option ˜y the exer™ise possi˜ilityF en emeri™—n option ™—n ˜e exer™ised —t —ny time up to the m—turity d—teD unlike the iurope—n optionD whi™h ™—n only ˜e exer™ised —t m—turityF sn gener—lD there is unfortun—tely no —n—lyti™—l solution to the emeri™—n option pro˜lemD ˜ut in some ™—ses it ™—n ˜e foundF por ex—mpleD for —n emeri™—n ™—ll option on nonEdividend p—ying sto™kD the emeri™—n pri™e is the s—me —s the iurope—n ™—llF st is in the ™—se of emeri™—n optionsD —llowing for the possi˜ility of e—rly exer™iseD th—t ˜inomi—l —pproxE im—tions —re usefulF et e—™h node we ™—l™ul—te the v—lue of the option —s — fun™tion of the next periods pri™esD —nd then ™he™k for the v—lue exer™ising of exer™ising the option now gode IHFP illustr—tes the ™—l™ul—tion of the pri™e of —n emeri™—n ™—llF e™tu—llyD for this p—rti™ul—r ™—seD the —meri™—n pri™e will equ—l the europe—nF VH .

++i) ™—ll v—lues[i] = m—x(0.0/‚. steps). // call for (int step=steps−1. }. i<=steps. p down = 1. −−step) { for (int i=0.0/u. // up movement uu = u*u. i<=step. // interest rate const double& sigm—. // standard mathematical library // dening the max() operator // STL vector templates double option pri™e ™—ll europe—n ˜inomi—l( double double double double double double double ‚ = exp(r*(t/steps)). i<=steps. }. ve™tor<double> pri™es(steps+1).#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. // volatility const double& t. for (int i=1. step>=0. // interest rate for each step ‚inv = 1. (pri™es[i]−ˆ)). // ll in the endnodes. d = 1. // time to maturity const int& steps){ // no steps in binomial tree payos at maturity return }. ™—ll v—lues[0]. ++i) pri™es[i] = uu*pri™es[i−1]. // exercice price const double& r.0.0−p up. C++ Code 10. // inverse of interest rate u = exp(sigm—*sqrt(t/steps)).1: yption pri™e for ˜inomi—l europe—n VI . const double& ƒ. // price of underlying pri™es[0] = ƒ*pow(d. // value of corresponding call for (int i=0. ++i) { ™—ll v—lues[i] = (p up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv. // spot price const double& ˆ. ve™tor<double> ™—ll v—lues(steps+1). p up = (‚−d)/(u−d).

0. double time=1.u. ™—ll v—lues[i] = m—x(™—ll v—lues[i].pri™es[i]−ˆ). // price of underlying pri™es[0] = ƒ*pow(d. double uu = u*u. double u = 100. // ‚inv = 1.time. ™out << " american call = " << option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. // time to maturity const int& steps) { // no steps in binomial tree ve™tor<double> pri™es(steps+1). double sigm— = 0. (pri™es[i]−ˆ)). // exercice price const double& r.2: finomi—l option pri™e —meri™—n opstion g++ progr—mX void test ˜inomi—l —pproxim—tions option pri™ing(){ double ƒ = 100.1: yption pri™ing using ˜inomi—l —pproxim—tions VP . d = 1. pri™es[i] = d*pri™es[i+1]. ++i) { { ™—ll v—lues[i] = (p up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv.no steps) << endl.0. // ll in the endnodes.0. for (int i=1.time.0−p up.9505 Example 10. return C++ Code 10. int no steps = 100. ++i) pri™es[i] = uu*pri™es[i−1]. // u = exp(sigm—*sqrt(t/steps)).0/‚.u.no steps) << endl.sigm—. // standard mathematical library // denes the max() operator // STL vector templates double option pri™e ™—ll —meri™—n ˜inomi—l( double double double double double double ‚ = exp(r*(t/steps)). p down = 1. p up = (‚−d)/(u−d). ++i) ™—ll v—lues[i] = m—x(0.25.9505 american call = 14. interest rate for each step inverse of interest rate // up movement const double& ƒ. // check for exercise ™—ll v—lues[0]. ™out << " european call = " << option pri™e ™—ll europe—n ˜inomi—l(ƒ.0. steps). // value of corresponding call for (int i=0. ve™tor<double> ™—ll v—lues(steps+1). // interest rate const double& sigm—. }. // volatility const double& t.r.0/u. double r = 0. // spot price const double& ˆ.1. −−step) for (int i=0. yutput from g++ progr—mX european call = 14.r. i<=step. }.#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. }.sigm—. i<=steps. // call payos at maturity for (int step=steps−1. }. i<=steps. step>=0.

0/‚. (pri™es[i]−ˆ)). no steps). }. for (int i=0. double delt— = return delt—. p…p = (‚−d)/(u−d). i<=gurrƒtep. st is —lw—ys ne™ess—ry to ™—l™ul—te the p—rti—l deriv—tives —s well —s the option pri™eF „he ˜inomi—l methods gives us w—ys to —pproxim—te these —s wellF row to (nd them in the ˜inomi—l ™—se —re des™ri˜ed in rull @PHHTAF „he ™ode ˜elow is for the non!dividend ™—seF Delta D the deriv—tive of the option pri™e with respe™t to the underlyingF #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. ++i) { −−gurrƒtep) pri™es[i] = d*pri™es[i+1]. d = 1. pri™es[i]−ˆ). = ve™tor<double> ™—ll v—lues (no steps+1). for (int i=1. u = exp(sigm—*sqrt(t/no steps)). i<=no steps. gurrƒtep>=1. ++i) ™—ll v—lues[i] m—x(0. for (int i=0. i<=no steps.0/u.3 Estimating partials. phown = 1. pri™es[0] = ƒ*pow(d. v—lues[1]−™—ll v—lues[0])/(ƒ*u−ƒ*d). double option pri™e delt— —meri™—n ™—ll ˜inomi—l(const const const const const const double& ƒ.0. helt— VQ . double& sigm—. double& t.3: Other hedge parameters. int& no steps){ // steps in binomial double double double double double double double ‚ = exp(r*(t/no steps)). uu= u*u. ++i) pri™es[i] = uu*pri™es[i−1]. }. ve™tor<double> pri™es (no steps+1).0 − p…p. ™—ll v—lues[i] = m—x(™—ll v—lues[i]. ‚inv = 1. double& r. { for (int gurrƒtep=no steps−1 .10. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv.2. // check for exercise (™—ll }. double& ˆ. C++ Code 10.

sigm—. double u = exp(sigm—*sqrt(delt— t)). double& ƒ. (pri™es[i]−ˆ)). ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv.0. di' = 0. ++i) pri™es[i] = uu*pri™es[i−1]. double ‚inv = 1. // interest rate const double& sigm—. i<=no steps. // check for exercise fII fIH = = ™—ll v—lues[1].ˆ. tmp pri™es = option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. double double C++ Code 10. ™—ll v—lues[i] = m—x(™—ll v—lues[i].h" void option pri™e p—rti—ls —meri™—n ™—ll ˜inomi—l(const ve™tor<double> pri™es(no steps+1). // check for exercise on rst date double fHH = ™—ll v—lues[0].4: redge p—r—meters VR .#include <™m—th> #include <—lgorithm> #include "fin_recipes. // partial wrt sigma double& rho){ // partial wrt r double fPP = ™—ll v—lues[2]. ++i) { pri™es[i] = d*pri™es[i+1]. // spot price const double& ˆ. double ‚ = exp(r*delt— t). thet— = (fPI−fHH) / (2*delt— t). double tmp sigm— = sigm—+di' . }. for (int i=1. pri™es[i]−ˆ). for (int i=0. for (int i=0. ™—ll v—lues[i] = m—x(™—ll v—lues[i].ˆ. for (int gurrƒtep=no steps−1. const double& r. // partial wrt time double& veg—. −−gurrƒtep) { for (int i=0. // time to maturity const int& no steps.tmp sigm—.no steps). rho = (tmp pri™es−fHH)/di' . // Exercise price. g—mm— = ( (fPP−fPI)/(ƒ*(uu−1)) − (fPI−fPH)/(ƒ*(1−d*d)) ) / h.time. pri™es[i] = d*pri™es[i+1]. // check for exercise }. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv.i++) { }.tmp r.0 − p…p. double tmp pri™es = option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. ve™tor<double> ™—ll v—lues(no steps+1). i<=gurrƒtep. pri™es[0] = d*pri™es[1].time.5 * ƒ * ( uu − d*d).0/‚. ƒ−ˆ). double d = 1. double p…p = (‚−d)/(u−d). ™—ll v—lues[0]. double fPH = ™—ll v—lues[0]. ++i) ™—ll v—lues[i] = m—x(0. double delt— t =(time/no steps). ™—ll v—lues[0] = m—x(™—ll v—lues[0].0/u. double fPI = ™—ll v—lues[1]. // partial wrt S double& g—mm—.no steps). // second prt wrt S double& thet—. double di' = 0.05. // steps in binomial double& delt—. ™—ll v—lues[0] = (phown*™—ll v—lues[0]+p…p*™—ll v—lues[1])*‚inv. delt— = (fII−fIH)/(ƒ*u−ƒ*d).i<=1.r.02. no steps). double uu= u*u. }. i<=no steps. double h = 0. veg— = (tmp pri™es−fHH)/di' . pri™es[i]−ˆ). double phown = 1. pri™es[0] = ƒ*pow(d. // volatility const double& time. double tmp r = r+di' . gurrƒtep>=2.

}. ™out << " delta = " << delt— << endl. delt—. ™out << " Call price partials " << endl.25. g—mm—. yutput from g++ progr—mX Call price partials delta = 0. p—rti—ls(){ double delt—.89067 vega = 34. int no steps = 100.8536 rho = 56.0.0140407 theta = -9.r. double u = 100. thet—. g—mm—.0. double r = 0. rho.0. no steps. ™out << " vega = " << veg— << endl. veg—.699792 gamma = 0. ™out << " rho = " << rho << endl. option pri™e p—rti—ls —meri™—n ™—ll ˜inomi—l(ƒ. sigm—.9652 Example 10. veg—. ™out << " gamma = " << g—mm— << endl. double sigm— = 0.2: yption pri™e p—rti—ls using ˜inomi—l —pproxim—tions VS . rho).g++ progr—mX void test ˜inomi—l —pproxim—tions option pri™e double ƒ = 100. thet—. double time=1.u. ™out << " theta = " << thet— << endl.1. time.

i<=step. ++i) pri™es[i] = uu*pri™es[i−1]. pri™es[i] = d*pri™es[i+1]. }. // exercice price const double& r. // check for exercise ™—ll v—lues[0]. // price of underlying pri™es[0] = ƒ*pow(d. // interest rate for each step ‚inv = 1. steps). // time to maturity const int& steps) { // no steps in binomial tree the endnodes. p down = 1. // inverse of interest rate u = exp(sigm—*sqrt(t/steps)).0/‚. p up = (exp((r−y)*(t/steps))−d)/(u−d). d = 1. ++i) { { ™—ll v—lues[i] = (p up*™—ll v—lues[i+1]+p down*™—ll v—lues[i])*‚inv. // ll in const double& ƒ. −−step) for (int i=0. step>=0. // continous payout const double& sigm—. // interest rate const double& y. // up movement uu = u*u.0−p up. return C++ Code 10. (pri™es[i]−ˆ)).3 Adjusting for payouts for the underlying „he simplest ™—se of — p—yout is the simil—r one to the one we s—w in the fl—™k ƒ™holes ™—seD — ™ontinous p—yout of y F #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. i<=steps. ve™tor<double> pri™es(steps+1).10. i<=steps.0. ve™tor<double> ™—ll v—lues(steps+1). ++i) ™—ll v—lues[i] = m—x(0.pri™es[i]−ˆ). // value of corresponding call for (int i=0.0/u. }. // volatility const double& t. ™—ll v—lues[i] = m—x(™—ll v—lues[i]. // standard mathematical library // denes the max() operator // STL vector templates double option pri™e ™—ll —meri™—n ˜inomi—l( double double double double double double double ‚ = exp(r*(t/steps)). for (int i=1. // call payos at maturity for (int step=steps−1. // spot price const double& ˆ. }.5: finomi—l option pri™e with ™ontinous p—yout VT .

2 Proportional dividends.10. por proportion—l dividendsD we simply multiply with —n —djustment f—™tor the sto™k pri™es —t the ex! dividend d—teD the nodes in the ˜inomi—l tree will link up —g—inD —nd we ™—n use the s—me rolling ˜—™k pro™edureF 10.3 Discrete dividends „he pro˜lem is when the dividends —re ™onst—nt doll—r —mountsF sn th—t ™—se the nodes of the ˜inomi—l tree do not link upD —nd the num˜er of ˜r—n™hes in™re—ses dr—m—ti™—llyD whi™h me—ns th—t the time to do the ™—l™ul—tion is in™re—sedF „he —lgorithm presented here implements this ™—seD with no linkupD ˜y ™onstru™ting — ˜inomi—l tree up to the exEdividend d—teD —nd thenD —t the termin—l nodes of th—t treeD ™—ll itself with one less dividend p—ymentD —nd time to m—turity the time rem—ining —t the exEdividend d—teF hoing th—t ™—l™ul—tes the v—lue of the option —t the exEdividend d—teD whi™h is then ™omp—red to the v—lue of exer™ising just ˜efore the exEdividend d—teF st is — ™ute ex—mple of using re™ursion in simplifying ™—l™ul—tionsD ˜ut —s with most re™ursive solutionsD it h—s — ™ost in ™omputing timeF por l—rge ˜inomi—l trees —nd sever—l dividends this pro™edure will t—ke — long timeF VU .4.1 Checking for early exercise in the binomial model.4. sf the underlying —sset is — sto™k p—ying dividends during the m—turity of the optionD the terms of the option is not —djusted to re)e™t this ™—sh p—ymentD whi™h me—ns th—t the option v—lue will re)e™t the dividend p—ymentsF sn the ˜inomi—l modelD the —djustment for dividends depend on whether the dividends —re dis™rete or proportion—lF 10.4 Pricing options on stocks paying dividends using a binomial approximation 10.4.

i<no dividends. ‚ = exp(r*delt— t). (pri™es[i]−ˆ)). uu= u*u.0/‚. }. ++i) { ™—ll pri™es[i] = (phown*™—ll pri™es[i]+p…p*™—ll pri™es[i+1])*‚inv. ++i) { pri™es[0]*=(1. }.ˆ. ™—ll pri™es[i] = m—x(™—ll pri™es[i]. // check for exercise ™—ll pri™es[0]. pri™es[0] = ƒ*pow(d. double& ˆ. u = exp(sigm—*sqrt(delt— t)). }.0.#include #include #include #include #include <™m—th> <—lgorithm> <ve™tor> "fin_recipes.++i) { // check if (step==dividend steps[i]) { for (int }. phown = 1. i<=no steps. for (int i=1. dividend yields) { int no dividends=dividend times. }. return C++ Code 10. ve™tor<double>& ve™tor<double>& steps). // adjust downward terminal prices by dividends for (int i=0. p…p = (‚−d)/(u−d).0−dividend yields[i]).h" <iostre—m> double option pri™e ™—ll —meri™—n proportion—l dividends ˜inomi—l(const // note that the last dividend date should be before the expiry date const const const const const const const double& ƒ. ‚inv = 1. // price w/o dividends paid ve™tor<double> pri™es(no steps+1).0 − p…p. i<no dividends. i<=no steps.no double double double double double double double double delt— t = time/no steps.j<=(step+1). if (no dividends == 0) { return option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. for (int step=no steps−1. for (int i=0.r.6: finomi—l option pri™e of sto™k option where sto™k p—ys proportion—l dividends VV . double& sigm—. ++i) ™—ll pri™es[i] = m—x(0. pri™es[i]−ˆ).0/(1. ve™tor<int> dividend steps(no dividends). −−step) { for (int i=0.0−dividend yields[i])). whether dividend paid ™out << "step " << step << endl. }. dividend times. }.sigm—.size(). }.i<no dividends.0/u. double& time. ve™tor<double> ™—ll pri™es(no steps+1). ++i) { pri™es[i] = uu*pri™es[i−1]. // when dividends are for (int i=0. step>=0. d = 1. no steps). }. i<=step. }. j=0. pri™es[i] = d*pri™es[i+1]. ++i) { dividend steps[i] = (int)(dividend times[i]/time*no steps).time. for (int i=0. int& no steps. double& r.++j) { pri™es[j]*=(1.

double& r. const double u = exp(sigm—*sqrt(t/steps)).// int steps ˜efore dividend = (int)(dividend times[0]/t*steps). const double ‚ = exp(r*(t/steps)).0/u.++i){ tmp dividend —mounts[i] = dividend —mounts[i+1]. sigm—. pri™es[0] = ƒ*pow(d. return C++ Code 10.7: finomi—l option pri™e of sto™k option where sto™k p—ys dis™rete dividends VW . const const const const const const const double& ƒ. }. ™—ll v—lues[i] = m—x(™—ll v—lues[i]. for (int step=steps ˜efore dividend−1. for (int i=0. pri™es[i]−u). }. if (no dividends==0) return option pri™e ™—ll —meri™—n ˜inomi—l(ƒ.// time after rst dividend steps−steps ˜efore dividend.i<(no dividends−1).0 − p…p. i<=steps ˜efore dividend. for (int i=0. tmp dividend —mounts).size().t. }. tmp dividend times. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv. r. for (int i=1. ++i) { step>=0. ™—ll v—lues[0]. const double d = 1. ™—ll v—lues[i] = m—x(v—lue —live. double& t. }. i<=step. −−step) { pri™es[i] = d*pri™es[i+1].u. t−dividend times[0]. const double ‚inv = 1.(pri™es[i]−u)).r. // one less dividend for (int i=0. double& sigm—. ve™tor<double> tmp dividend times(no dividends−1). ++i){ double v—lue —live = option pri™e ™—ll —meri™—n dis™rete dividends ˜inomi—l(pri™es[i]−dividend —mount.u. double& u.#include <™m—th> #include <ve™tor> #include "fin_recipes. ve™tor<double> ™—ll v—lues(steps ˜efore dividend+1). int& steps.h" #include <iostre—m> double option pri™e ™—ll —meri™—n dis™rete dividends ˜inomi—l(const int no dividends = dividend times.steps). ++i) pri™es[i] = u*u*pri™es[i−1]. ve™tor<double>& ve™tor<double>& dividend times. i<=steps ˜efore dividend. tmp dividend times[i] = dividend times[i+1] − dividend times[0]. // temporaries with ve™tor<double> tmp dividend —mounts(no dividends−1).sigm—. dividend —mounts) { just do regular ve™tor<double> pri™es(steps ˜efore dividend+1). // compare to exercising now }. double dividend —mount = dividend —mounts[0]. const double phown = 1.0/‚. steps ˜efore dividend). const double p…p = (‚−d)/(u−d).

r.u. dividends(){ ™out << " call price with continuous dividend payout = " << option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. ve™tor<double> dividend —mounts.25.0233 Example 10. dividend yields.0.no steps. double u = 100. int no steps = 100. double sigm— = 0.8604 call price with proportial dividend amounts at discrete dates = 12. dividend times. dividend times. double r = 0.10. ™out << " call price with proportial dividend amounts at discrete dates = " << option pri™e ™—ll —meri™—n dis™rete dividends ˜inomi—l(ƒ.push ˜—™k(0.r.sigm—. dividend —mounts.sigm—.no steps) << endl. }. ™out << " call price with proportial dividend yields at discrete dates = " << option pri™e ™—ll —meri™—n proportion—l dividends ˜inomi—l(ƒ.r.u.75).0.no steps.push ˜—™k(2. yutput from g++ progr—mX call price with continuous dividend payout = 13.025).time. dividend yields) << endl.0.time.push ˜—™k(0.push ˜—™k(2.time.25).sigm—.push ˜—™k(0. ve™tor<double> dividend times. ve™tor<double> dividend yields. dividend yields.025).5926 step 75 step 25 call price with proportial dividend yields at discrete dates = 11. dividend times.u.g++ progr—mX void test ˜inomi—l —pproxim—tions option pri™e double ƒ = 100. double time=1.5). dividend —mounts) << endl. dividend —mounts.push ˜—™k(0.5).d. dividend times. double d=0.3: finomi—l pri™ing with dividends WH .02.

0. // exercise price double& r. double u = 45. }.5. double ‚inv = exp(−r*(t delt—)).0 − p…p.0. for (i=1. // volatility double& time. double futures option pri™e ™—ll —meri™—n ˜inomi—l(const ve™tor<double> futures pri™es(no steps+1). for (int step=no steps−1. −−step) { for (i=0.0. yutput from g++ progr—mX european futures call option = 5. // price futures contract double& ˆ. const const const const const double& p. i<=no steps. // note how probability is calculated double phown = 1. i<=step. double t delt—= time/no steps. double sigm— = 0. ++i) futures pri™es[i] = uu*futures pri™es[i−1]. options(){ ™out << " european futures call option = " << futures option pri™e ™—ll —meri™—n ˜inomi—l(p. // check for exercise }.2. }. (futures pri™es[i]−ˆ)). double time=0. no steps). ™—ll v—lues[i] = m—x(™—ll v—lues[i]. double uu= u*u. ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv.08. ++i) { futures pri™es[i] = d*futures pri™es[i+1]. int i. double d = 1.5 Option on futures por emeri™—n optionsD ˜e™—use of the fe—si˜ility of e—rly exer™iseD the ˜inomi—l model is used to —pproxE im—te the option v—lueF #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. C++ Code 10.no steps) << endl. // interest rate double& sigm—.74254 Example 10.sigm—. }. double u = exp(sigm—*sqrt(t delt—)). int no steps=100. ++i) ™—ll v—lues[i] = m—x(0.4: putures option pri™e WI .10. step>=0.8: g++ progr—mX yption on futures void test ˜inomi—l —pproxim—tions futures double p = 50. // terminal for (i=0.r. double r = 0. futures pri™es[i]−ˆ). // time to maturity int& no steps) { // number of steps tree nodes return ™—ll v—lues[0]. ve™tor<double> ™—ll v—lues (no steps+1).time.u. double p…p = (1−d)/(u−d).0/u. i<=no steps. futures pri™es[0] = p*pow(d.

double u = 52.0. step>=0.0.no steps) << endl. double d = 1. double ™urren™y option pri™e ™—ll —meri™—n ˜inomi—l(const ve™tor<double> ex™h—nge r—tes(no steps+1).0 − p…p.0. ve™tor<double> ™—ll v—lues(no steps+1). ™—ll v—lues[i] = (phown*™—ll v—lues[i]+p…p*™—ll v—lues[i+1])*‚inv. return C++ Code 10. no steps). double u = exp(sigm—*sqrt(t delt—)).rate double phown = 1. double t delt—= time/no steps.08.23129 Example 10. double uu= u*u. ++i) ™—ll v—lues[i] = m—x(0. double& sigm—.r.10. // terminal tree nodes } const const const const const const double& ƒ.5. double time=0. ++i) { (ex™h—nge r—tes[i]−u)). int }. ex™h—nge r—tes[i] = d*ex™h—nge r—tes[i+1].6 Foreign Currency options por emeri™—n optionsD the usu—l method is —pproxim—tion using ˜inomi—l treesD ™he™king for e—rly exer™ise due to the interest r—te di'erenti—lF #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. for (int step=no steps−1. double r = 0. yutput from g++ progr—mX european currency option call = 2. −−step) { for (i=0. int& no steps) { for (i=0. double& time. ™—ll v—lues[i] = m—x(™—ll v—lues[i].5: gurren™y option pri™e WP . i<=step. double ‚inv = exp(−r*(t delt—)). i<=no steps. options(){ no steps = 100. // adjust for foreign int. double& r f.rf. double p…p = (exp((r−r f )*t delt—)−d)/(u−d).sigm—.u. }.2. ™out << " european currency option call = " << ™urren™y option pri™e ™—ll —meri™—n ˜inomi—l(ƒ. double rf =0.0/u. exercise }. // check for ™—ll v—lues[0].9: g++ progr—mX finomi—l gurren™y yption void test ˜inomi—l —pproxim—tions ™urren™y double ƒ = 50. }. ex™h—nge r—tes[i]−u). int i. ++i) { ex™h—nge r—tes[i] = uu*ex™h—nge r—tes[i−1]. for (i=1. double sigm— = 0. double& r. double& u.time. i<=no steps. ex™h—nge r—tes[0] = ƒ*pow(d.05.

(T − t) = 1 and r = 0. 3. where S = 100.7 References „he origin—l sour™e for ˜inomi—l option pri™ing w—s the p—per ˜y gox et —lF @IWUWAF qood text˜ook dis™ussions —re in gox —nd ‚u˜instein @IWVSAD foss—erts —nd Ødeg——rd @PHHIA —nd rull @PHHTAF Exercise 20. Discuss what are sources of dierences in the estimated prices. Calculate the price of this option using Black Scholes 2. 1. 100 and 1000 steps in the approximation. σ = 0.2.10. K = 100.1. Calculate the price using a binomial approximation. Consider an European call option on non-dividend paying stock. WQ . using 10.

2 European Options.Chapter 11 Finite Dierences 11.1 Explicit Finite dierences „he method of ™hoi™e for —ny engineer given — di'erenti—l equ—tion to solve is to numeri™—lly —pproxim—te it using — (nite di'eren™e s™hemeD whi™h is to —pproxim—te the ™ontinous di'erenti—l equ—tion with — dis™rete dierence equ—tionD —nd solve this di'eren™e equ—tionF 11. por iurope—n options we do not need to use the (nite di'eren™e s™hemeD ˜ut we show how one would (nd the europe—n pri™e for ™omp—rison purposesF ‡e show the ™—se of —n expli™it (nite di'eren™e s™heme in ™ode IIFIF e pro˜lem with the expli™it version is th—t it m—y not ™onverge for ™ert—in ™om˜in—tions of inputsF WR .

˜[j] = rI*(1. // need M = no S steps to be even: if ((no ƒ steps%2)==1) { w=no ƒ steps+1.++m) { f next[m] = f [m]. ve™tor<double> f next(w+1). }. for (int t=x−1. double& time. double delt— t = time/x. for (unsigned m=1.m<=w. }. for (unsigned }. ve™tor<double> ˜(w).t>=0.#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. f [w] = 0.5*j*(−r+sigm— sqr*j).0. }. } else { w=no double delt— ƒ = 2.−−t) { f [0]=ˆ. double option pri™e put europe—n (nite di' expli™it(const double sigm— sqr = sigm—*sigm—. double rP=delt— t/(1. double& r. return f [w/2].0/(1. }. }. double rI=1. for (unsigned int j=1. double& sigm—. }. const const const const const const double& ƒ. unsigned int w. ™[j] = rP*0. int& no t steps) { ƒ steps.m<=w.j<w. int& no ƒ steps. ƒ. ve™tor<double> —(w).ˆ−ƒ v—lues[m]).++m) { f [m]=—[m]*f next[m−1]+˜[m]*f next[m]+™[m]*f next[m+1].m++) { ƒ v—lues[m] = m*delt— int x=no t steps.0−sigm— sqr*j*j*delt— t). ve™tor<double> ƒ v—lues(w+1).m<=w.m<w. m=0.0+r*delt— t). }. for (unsigned m=0. C++ Code 11.++m) { f next[m]=m—x(0. double& ˆ.1: ixpli™it (nite di'eren™es ™—l™ul—tion of europe—n put option WS .j++){ —[j] = rP*0.0+r*delt— t).0*ƒ/w. ve™tor<double> ™(w).5*j*(r+sigm— sqr*j). double f [w+1]. for (unsigned m=0.

ve™tor<double> f next(w+1). ve™tor<double> ˜(w).m<=w. // need M = no S steps to be even: if ((no ƒ steps%2)==1) { w=no ƒ steps+1.m<=w.0/(1. m=0. f [m] = m—x(f [m].0. int x=no t steps.11. ve™tor<double> ™(w). const int& no t steps) { ƒ steps. for (int m=0. C++ Code 11.m++) { ƒ v—lues[m] = m*delt— ƒ. for (int j=1. const int& no ƒ steps.++m) { f next[m]=m—x(0. double option pri™e put —meri™—n (nite di' expli™it( double sigm— sqr = sigm—*sigm—. }.3 American Options. }.j<w. }. }. int w. const double& time.0+r*delt— t). for (int t=x−1. double rP=delt— t/(1.ˆ−ƒ v—lues[m]). ˜[j] = rI*(1. // check for exercise }. const double& r. double delt— t = time/x. const double& ˆ. return f [w/2].t>=0. ve™tor<double> f (w+1).j++){ —[j] = rP*0. const double& ƒ. }. for (int m=1.5*j*(r+sigm— sqr*j). } else { w=no double delt— ƒ = 2. ve™tor<double> —(w). double rI=1. ™[j] = rP*0.0*ƒ/w.0+r*delt— t).m<=w. f [w] = 0. const double& sigm—.++m) { f next[m] = f [m]. }.−−t) { f [0]=ˆ.m<w.++m) { f [m]=—[m]*f next[m−1]+˜[m]*f next[m]+™[m]*f next[m+1]. ve™tor<double> ƒ v—lues(w+1).ˆ−ƒ v—lues[m]). for (int m=0. ‡e now ™omp—re the emeri™—n versions of the s—me —lgoritmsD the only di'eren™e ˜eing the ™he™k for exer™ise —t e—™h pointF gode IIFP shows the ™ode for —n —meri™—n put optionF #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std.2: Readings ixpli™it (nite di'eren™es ™—l™ul—tion of —meri™—n put option frenn—n —nd ƒ™hw—rtz @IWUVA is one of the (rst (n—n™e —ppli™—tions of (nite di'eren™esF ƒe™tion IRFU of rull @IWWQA h—s — short introdu™tion to (nite di'eren™esF ‡ilmottD hewynneD —nd rowison @IWWRA is —n exh—ustive sour™e on option pri™ing from the perspe™tive of solving p—rti—l di'erenti—l equ—tionsF WT . for (int }.0−sigm— sqr*j*j*delt— t).5*j*(−r+sigm— sqr*j).

g++ progr—mX

void test expli™it (nite di'eren™es(){ double ƒ = 50.0; double u = 50.0; double r = 0.1; double sigm— = 0.4; double time=0.4167; int no ƒ steps=20; int no t steps=11;

™out << " explicit finite differences, european put price = "; ™out << option pri™e put europe—n (nite di' expli™it(ƒ,u,r,sigm—,time,no ƒ steps,no t steps) << endl; ™out << " explicit finite differences, american put price = "; ™out << option pri™e put —meri™—n (nite di' expli™it(ƒ,u,r,sigm—,time,no ƒ steps,no t steps) << endl;

};

yutput from g++ progr—mX

explicit finite differences, european put price = 4.03667 explicit finite differences, american put price = 4.25085

Example 11.1:

ixpli™it (nite di'eren™es

WU

Chapter 12

Option pricing by simulation
‡e now ™onsider using wonte g—rlo methods to estim—te the pri™e of —n iurope—n optionD —nd let us (rst ™onsider the ™—se of the usu—l iurope—n g—llD whi™h is pri™ed ˜y the fl—™k ƒ™holes equ—tionF ƒin™e there is —lre—dy — ™losed form solution for this ™—seD it is not re—lly ne™ess—ry to use simul—tionsD ˜ut we use the ™—se of the st—nd—rd ™—ll for illustr—tive purposesF et m—turityD — ™—ll option is worth

cT = max(0, ST − X)
et —n e—rlier d—te tD the option v—lue will ˜e the expe™ted present v—lue of thisF

ct = E[P V (max(0, ST − X)]
xowD —n import—nt simplifying fe—ture of option pri™ing is the risk neutr—l resultD whi™h implies th—t we ™—n tre—t the @suit—˜ly tr—nsformedA pro˜lem —s the de™ision of — risk neutr—l de™ision m—kerD if we —lso modify the expe™ted return of the underlying —sset su™h th—t this e—rns the risk free r—teF

ct = e−r(T −t) E ∗ [max(0, ST − X)],
where E ∗ [·] is — tr—nsform—tion of the origin—l expe™t—tionF yne w—y to estim—te the v—lue of the ™—ll is to simul—te — l—rge num˜er of s—mple v—lues of ST —™™ording to the —ssumed pri™e pro™essD —nd (nd the estim—ted ™—ll pri™e —s the —ver—ge of the simul—ted v—luesF fy —ppe—ling to — l—w of l—rge num˜ersD this —ver—ge will ™onverge to the —™tu—l ™—ll v—lueD where the r—te of ™onvergen™e will depend on how m—ny simul—tions we performF

12.1

Simulating lognormally distributed random variables

vognorm—l v—ri—˜les —re simul—ted —s followsF vet x ˜e norm—lly distri˜uted with me—n zero —nd v—ri—n™e ˜ oneF sf St follows — lognorm—l distri˜utionD then the oneEperiodEl—ter pri™e St+1 is simul—ted —s
1 2 ˜ St+1 = St e(r− 2 σ )+σx ,

or more gener—llyD if the ™urrent time is t —nd termin—l d—te is T D with — time ˜etween t —nd T of (T − t)D
1 2 ST = St e(r− 2 σ )(T −t)+σ

√ T −t˜ x

ƒimul—tion of lognorm—l r—ndom v—ri—˜les is illustr—ted ˜y ™ode IPFIF

12.2

Pricing of European Call options
ct = e−r(T −t) E[max(0, ST − X)],

por the purposes of doing the wonte g—rlo estim—tion of the pri™e if —n iurope—n ™—ll

note th—t here one merely need to simul—te the termin—l pri™e of the underlyingD ST D the pri™e of the underlying —t —ny time ˜etween t —nd T is not relev—nt for pri™ingF ‡e pro™eed ˜y simul—ting lognorm—lly distri˜uted r—ndom v—ri—˜lesD whi™h gives us — set of o˜serv—tions of the termin—l pri™e ST F sf we let ST,1 , ST,2 , ST,3 , . . . ST,n denote the n simul—ted v—luesD we will estim—te E ∗ [max(0, ST −X)] —s the —ver—ge of option p—yo's —t m—turityD dis™ounted —t the risk free r—teF
n

ct = e ˆ

−r(T −t) i=1

max (0, ST,i − X)

gode IPFP shows the implement—tion of — wonte g—rlo estim—tion of —n iurope—n ™—ll optionF WV

#include <™m—th> using namespace std; #include "normdist.h"

double

simul—te lognorm—l r—ndom v—ri—˜le(const

double ‚ = (r − 0.5 * pow(sigm—,2) )*time; double ƒh = sigm— * sqrt(time); return ƒ * exp(‚ + ƒh * r—ndom norm—l());
};

double& ƒ, // current value of variable const double& r, // interest rate const double& sigm—, // volatitily const double& time) { // time to nal date

C++ Code 12.1:

ƒimul—ting — lognorm—lly distri˜uted r—ndom v—ri—˜le

#include <™m—th> // standard mathematical functions #include <—lgorithm> // dene the max() function using namespace std; #include "normdist.h" // denition of random number

generator

double

option pri™e ™—ll europe—n simul—ted(

double ‚ = (r − 0.5 * pow(sigm—,2))*time; double ƒh = sigm— * sqrt(time); double sum p—yo's = 0.0; for (int n=1; n<=no sims; n++) { double ƒ „ = ƒ* exp(‚ + ƒh * r—ndom
sum p—yo's
+=

const double& ƒ, // price of underlying const double& ˆ, // exercise price const double& r, // risk free interest rate const double& sigm—, // volatility of underlying const double& time, // time to maturity (in years) const int& no sims){ // number of simulations

m—x(0.0, ƒ „−ˆ);
* (sum

norm—l());

}; };

return

exp(−r*time)

p—yo's/double(no sims));

C++ Code 12.2:

iurope—n g—ll option pri™ed ˜y simul—tion

12.3

Hedge parameters

st is of ™ourseD just —s in the st—nd—rd ™—seD desir—˜le to estim—te hedge p—r—meters —s well —s option pri™esF ‡e will show how one ™—n (nd —n estim—te of the option deltaD the (rst deriv—tive of the ™—ll g++ progr—mX

void test simul—tion pri™ing() { double ƒ=100.0; double u=100.0; double double time=1.0; int no sims=5000;

r=0.1;

double

sigm—=0.25;

™out << " call: black scholes price = " << option pri™e ™—ll ˜l—™k s™holes(ƒ,u,r,sigm—,time) << endl; ™out << " simulated price = " << option pri™e ™—ll europe—n simul—ted(ƒ,u,r,sigm—,time,no sims) << endl; ™out << " put: black scholes price = " << option pri™e put ˜l—™k s™holes(ƒ,u,r,sigm—,time) << endl; ™out << " simulated price = " << option pri™e put europe—n simul—ted(ƒ,u,r,sigm—,time, no sims) << endl;

};

yutput from g++ progr—mX

call:

black scholes price = 14.9758 simulated price = 14.8404 put: black scholes price = 5.45954 simulated price = 5.74588
WW

C++ Code 12. n++) { double  = r—ndom norm—l().0. ƒ „ q = (ƒ+q)* exp(‚ + ƒh * ). ƒ „−ˆ).0. double q = ƒ*0. double ƒh = sigm— * sqrt(time). ƒ „ q−ˆ). }.5 * pow(sigm—. }. double sum p—yo's q = 0. double& sigm—. for (int n=1. int& no sims){ sum p—yo's += m—x(0. double sum p—yo's = 0. return (™ q−™)/q. n<=no sims.01.0. double& time. double& r. double ƒ „ = ƒ* exp(‚ + ƒh * ).0.pri™e with respe™t to the underlying se™urityX ∆ = ∂ct F „o underst—nd how one goes —˜out estim—ting ∂S thisD let us re™—ll th—t the (rst deriv—tive of — fun™tion f is de(ned —s the limit f (x) = lim f (x + h) − f (x) h→0 h „hinking of f (S) —s the option pri™e formul— ct = f (S.2))*time. X. σ. double& ˆ. double const const const const const double& ƒ. #include "normdist. r. (T − t))D we see th—t we ™—n ev—lu—te the option pri™e —t two di'erent v—lues of the underlyingD S —nd S + q D where q is — sm—ll qu—ntityD —nd estim—te the option delt— —s ∆= f (S + q) − f (S) q sn the ™—se of wonte g—rlo estim—tionD it is very import—nt th—t this is done ˜y using the s—me sequen™e of r—ndom v—ri—˜les to estim—te the two option pri™es with pri™es of the underlying S —nd S + q F gode IPFQ implements this estim—tion of the option delt—F yne ™—n estim—te other hedge p—r—meters in — simul—r #include <™m—th> // standard mathematical functions #include <—lgorithm> // dene the max() function using namespace std. double ™ = exp(−r*time) * ( sum p—yo's/no sims).3: w—yF istim—te helt— of iurope—n g—ll option pri™ed ˜y wonte g—rlo IHH .h" // denition of random number generator double option pri™e delt— ™—ll europe—n simul—ted(const double ‚ = (r − 0. sum p—yo's q += m—x(0. double ™ q = exp(−r*time) * ( sum p—yo's q/no sims).

sigm—.g++ progr—mX void test simul—tion pri™ing delt—(){ double ƒ=100.r.time.r.time) << " sim delta = " << option pri™e delt— put europe—n simul—ted(ƒ.sigm—.1.u. int no sims=5000.299792 sim delta = 0. yutput from g++ progr—mX call: bs delta = 0.u.sigm—. }.701484 sim delta = -0.no sims) << endl.0. double u=100.307211 IHI . r=0.25.time. ™out << " put: bs delta = " << option pri™e delt— put ˜l—™k s™holes(ƒ.0. double sigm—=0.r. ™out << " call: bs delta = " << option pri™e delt— ™—ll ˜l—™k s™holes(ƒ.0.u.r. double double time=1.700208 put: bs delta = -0.time) << " sim delta = " << option pri™e delt— ™—ll europe—n simul—ted(ƒ.no sims) << endl.sigm—.u.

}. Function prototypes „he —˜ove shows the ™—se for — ™—ll optionF sf we w—nt to pri™e other types of optionsD with di'erent p—yo's we ™ould write simil—r routines for every possi˜le ™—seF fut this would ˜e w—stefulD inste—d — ˜it of thought —llows us to write option v—lu—tions for —ny kind of option whose p—yo' depend on the v—lue of the underlying —t m—turityD onlyF vet us now move tow—rd — generi™ routine for pri™ing deriv—tives with wonte g—rloF „his relies on the —˜ility of g++ to write su˜routines whi™h one ™—ll with function prototypesD iFeF th—t in the ™—ll to to the su˜routineGfun™tion one provides — fun™tion inste—d of — v—ri—˜leF gonsider pri™ing of st—nd—rd iurope—n put —nd ™—ll optionsF et m—turity e—™h option only depend on the v—lue of the underlying ST —nd the exer™ise pri™e X through the rel—tions CT = max(ST − X.5: xote the presen™e of the line qeneri™ simul—tion pri™ing double payoff(const double& price.4 More general payos.4: €—yo' ™—ll —nd put options „he interesting p—rt ™omes when one re—lises one ™—n write — generi™ simul—tion routine to whi™h one provide one of these fun™tionsD or some other fun™tion des™ri˜ing — p—yo' whi™h only depends on the pri™e of the underlying —nd some ™onst—ntF gode IPFS shows how this is doneF #include <™m—th> using namespace std.ˆ).0.time). IHP . // time to maturity double p—yo' (const double& pri™e.pri™e−ˆ). for (int n=0.r. return exp(−r*time) p—yo's/no sims). }.12. 0) gode IPFR shows two g++ fun™tions whi™h ™—l™ul—tes thisF #include <—lgorithm> using namespace std. n<no sims.ˆ−pri™e). // volatility const double& time. 0) PT = max(X − ST . // price of underlying const double& ˆ.0. // risk free interest rate const double& sigm—. #include "fin_recipes. const double& X).h" double deriv—tive pri™e simul—te europe—n option generi™(const double& ƒ. const double& ˆ). const double& ˆ){ double p—yo' put (const double& return m—x(0. }. }. double p—yo' ™—ll(const double& return m—x(0. // used by user provided payo function const double& r. pri™e. C++ Code 12. pri™e. * (sum r—ndom v—ri—˜le(ƒ.sigm—. const double& ˆ) { C++ Code 12. // user provided function double sum p—yo's=0. n++) { double ƒ „ = simul—te lognorm—l sum p—yo's += const int& no sims) { // number of simulations to run p—yo' (ƒ „.

ˆ.0.i ) ct = e−r(T −t) ˆ i=1 max (0.25.5599 es we seeD even with —s m—ny —s SHDHHH simu—tionsD the option pri™es estim—ted using wonte g—rlo still di'ers su˜st—nti—lly from the true v—luesF 12.time) << endl.45954 5. }.i − X) ‡e ™—l™ul—te the fl—™k ƒ™holes v—lue of the ™—ll cbs D —nd ™—l™ul—te pcv D the estim—te of the put pri™e with ˆt t IHQ .sigm—.no sims) << endl.no sims) << endl. double time = 1.time. = 50000.p—yo' ™—ll.5.in the su˜routine ™—llF ‡hen this fun™tion is ™—lledD the ™—lling progr—m will need to provide — fun™tion to put thereD su™h —s the fl—™k ƒ™holes ex—mple —˜oveF „he next ex—mple shows — ™omplete ex—mple of how this is doneF g++ progr—mX void test simul—tion ˜s ™—se using generi™ routine(){ double ƒ = 100. ™out << "Simulated call option price = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ. yne is the method of ™ontrol v—ri—tesF „he ide— is simpleF ‡hen one gener—tes the set of termin—l v—lues of the underlying se™urityD one ™—n v—lue sever—l deriv—tives using the s—me set of termin—l v—luesF ‡h—t if one of the deriv—tives we v—lue using the termin—l v—lues is one whi™h we h—ve —n —n—lyti™—l solution toc por ex—mpleD suppose we ™—l™ul—te the v—lue of —n —t the money iurope—n ™—ll option using ˜oth the @—n—lyti™—lA fl—™k ƒ™holes formul— —nd wonte g—rlo simul—tionF sf it turns out th—t the wonte g—rlo estim—te overv—lues the option pri™eD we think th—t this will —lso ˜e the ™—se for other deriv—tives v—lued using the s—me set of simul—ted termin—l v—luesF ‡e therefore move the estim—te of the pri™e of the deriv—tive of interest downw—rdsF „husD suppose we w—nt to v—lue —n iurope—n put —nd we use the pri™e of —n —t the money iurope—n ™—ll —s the ™ontrol v—ri—teF …sing the s—me set of simul—ted termin—l v—lues ST.sigm—.time) << endl. ™out << "Black Scholes put option price = " << option pri™e put ˜l—™k s™holes(ƒ. double r = 0. double ˆ = 100. double sigm— = 0. int no sims ™out << "Black Scholes call option price = " << option pri™e ™—ll ˜l—™k s™holes(ƒ.sigm—.1. yutput from g++ progr—mX Black Scholes call option price Simulated call option price Black Scholes put option price Simulated put option price = = = = 14.time.r.1 Control variates.sigm—. X − ST. ™out << "Simulated put option price = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.ˆ.5 Improving the eciency in simulation „here —re — num˜er of w—ys of improving the implement—tion of wonte g—rlo estim—tion su™h th—t the estim—te is ™loser to the true v—lueF 12.9758 14.995 5. ST.r.r.r.p—yo' put.ˆ.i D we estim—te the two options using wonte g—rlo —sX n pt = e−r(T −t) ˆ i=1 n max (0.ˆ.

// price double sum p—yo's=0. ™ sim = exp(−r*time) * (sum p—yo's/no sims). const double& time.ƒ). double sum p—yo's ˜s=0.r.time). }. double& ƒ. const double& ˆ.h" double deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(const double ™ ˜s = option pri™e ™—ll ˜l—™k s™holes(ƒ. const double& r.ˆ).5. sum p—yo's ˜s += p—yo' ™—ll(ƒ „. return ™ sim. const int& no sims) { an at the money Black Scholes call // simulate at the money Black Scholes price double double }.— ™ontrol v—ri—te —djustmentD —s follows pcv = pt + (cbs − ct ) ˆt ˆ ˆ t yne ™—n use other deriv—tives th—n the —tEtheEmoney ™—ll —s the ™ontrol v—ri—teD the only limit—tion ˜eing th—t it h—s — tr—™t—˜le —n—lyti™—l solutionF gode IPFT shows the implement—tion of — wonte g—rlo estim—tion using —n —tEtheEmoney iurope—n ™—ll —s the ™ontrol v—ri—teF #include <™m—th> using namespace std.sigm—.2 Antithetic variates.ƒ. const double& ˆ).6: 12. ™ ˜s sim = exp(−r*time) * (sum p—yo's ˜s/no sims). #include "fin_recipes. const double& sigm—. double p—yo' (const double& ƒ. ™ sim += (™ ˜s−™ ˜s sim). C++ Code 12. n<no sims. sum p—yo's += p—yo' (ƒ „. for (int n=0.sigm—. n++) { double ƒ „= simul—te lognorm—l r—ndom v—ri—˜le(ƒ.time). qeneri™ with ™ontrol v—ri—te en —ltern—tive to using ™ontrol v—ri—tes is to ™onsider the method of antithetic v—ri—tesF „he ide— ˜ehind this is th—t wonte g—rlo works ˜est if the simul—ted v—ri—˜les —re spre—d out —s ™losely —s possi˜le to the true distri˜utionF rere we —re simul—ting unit norm—l r—ndom v—ri—˜lesF yne property of the norm—l is th—t it is symmetri™ —round zeroD —nd the medi—n v—lue is zeroF ‡hy don9t we enfor™e this in the simul—ted termin—l v—luesc en e—sy w—y to do this is to (rst simul—te — unit r—ndom norm—l v—ri—˜le Z D —nd then use ˜oth Z —nd −Z to gener—te the lognorm—l r—ndom v—ri—˜lesF gode IPFU shows the implement—tion of this ide—F foyle @IWUUA shows th—t the e0™ien™y g—in with —ntitheti™ v—ri—tes is not p—rti™ul—rly l—rgeF „here —re other w—ys of ensuring th—t the simul—ted v—lues re—lly sp—n the whole s—mple sp—™eD sometimes ™—lled pseudo wonte g—rloF IHR .r.

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

CV Simulated put option price.time) << endl.sigm—.time.r.41861 5.sigm—. AV = = = = = = = = 14.no sims) << endl. ™out << "Black Scholes call option price = " << option pri™e ™—ll ˜l—™k s™holes(ƒ. ™out << "Simulated call option price.no sims) << endl. CV Simulated call option price.sigm—.u. double sigm— = 0.r.sigm—. AV = " << deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(ƒ. double time = 1.time) << endl.42541 5.25.p—yo' put.995 14. ™out << "Simulated put option price.time. AV Black Scholes put option price Simulated put option price Simulated put option price.45954 5.no sims) << endl. }.time. CV = " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ.u.time. p—yo' put.r. double u = 100.5.9758 14.u. double r = 0.u.time.46043 IHT .9758 14.r. ™out << "Black Scholes put option price = " << option pri™e put ˜l—™k s™holes(ƒ.sigm—. int no sims = 50000.sigm—.time. p—yo' ™—ll. ™out << "Simulated put option price = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.3 Example vet us see how these improvements ™h—nge —™tu—l v—luesF ‡e use the s—me num˜ers —s in the previous ex—mpleD ˜ut —dd estim—tion using ™ontrol —nd —ntitheti™ v—ri—tesF g++ progr—mX void test simul—tion ˜s ™—se using generi™ routine improving e0™ien™y(){ double ƒ = 100. p—yo' put. ™out << "Simulated put option price. ™out << "Simulated call option price = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ. AV = " << deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(ƒ.r.no sims) << endl.u.no sims) << endl. yutput from g++ progr—mX Black Scholes call option price Simulated call option price Simulated call option price.no sims) << endl. p—yo' ™—ll.r.u. CV = " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ.12.u. ™out << "Simulated call option price.sigm—.sigm—.1. p—yo' ™—ll.r.u.9919 5.r.

}.6 More exotic options „hese generi™ routines ™—n —lso ˜e used to pri™e other optionsF eny iurope—n option th—t only depends on the termin—l v—lue of the pri™e of the underlying se™urity ™—n ˜e v—luedF gonsider the binary options dis™ussed ˜y eFgF rull @PHHTAF en cash or nothing call p—ys — (xed —mount Q if the pri™e of the —sset is —˜ove the exer™ise pri™e —t m—turityD otherwise nothingF en asset or nothing call p—ys the pri™e of the —sset if the pri™e is —˜ove the exer™ise pri™e —t m—turityD otherwise nothingF foth of these options —re e—sy to implement using the generi™ routines —˜oveD —ll th—t is ne™es—ry is to provide the p—yo' fun™tions —s shown in ™ode IPFVF double p—yo' ™—sh or nothing if (pri™e>=ˆ) return 1. pri™e. Note the dierence in the implementation of the lognormal simulation of terminal values. and the generic formula for pricing with Monte Carlo for European options that only depend on the terminal value of the underlying security. return 0.5.12. foyle @IWUUA is — good e—rly sour™e on the use of the wonte g—rlo te™hnique for pri™ing deriv—tivesF ƒimul—tion is —lso ™overed in rull @PHHTAF Consider the pricing of an European Call option as implemented in code 12. ™—ll(const double& pri™e.8: €—yo' ˜in—ry options xowD m—ny exoti™ options —re not simply fun™tions of the termin—l pri™e of the underlying se™urityD ˜ut depend on the evolution of the pri™e from now till the termin—l d—te of the optionF por ex—mple options th—t depend on the —ver—ge of the pri™e of the underlying @esi—n optionsAF por su™h ™—ses one will h—ve to simul—te the whole p—thF ‡e will return to these ™—ses in the ™h—pter on pri™ing of exoti™ optionsF Further Reading Exercise 21. return 0. const double& ˆ){ C++ Code 12. const double& ˆ){ double p—yo' —sset or nothing ™—ll(const double& if (pri™e>=ˆ) return pri™e. as implemented in code 12. Why can one argue that the rst implementation is more ecient than the other? IHU . }.2.

p—yo' ™—sh or nothing ™—ll.sigm—. ™out << " cash or nothing.u. double double time=1.02552 antithetic_variate 0.549598 asset or nothing: 70.time.2205 IHV .0. p—yo' —sset or nothing ™—ll. p—yo' ™—sh or nothing ™—ll.1. r=0. p—yo' —sset or nothing ™—ll. p—yo' ™—sh or nothing ™—ll.time.time. no sims) << endl.r.u. ™out << " antithetic_variate " << deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(ƒ. double u=100.u.sigm—.sigm—. }. Q=1: " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.r.time.547427 control_variate 1. no sims) << endl.r.0. p—yo' —sset or nothing ™—ll.r.u.g++ progr—mX void test simul—tion ˜in—ry options(){ double ƒ=100.sigm—.r. no sims) << endl.time. ™out << " control_variate " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ. ™out << " control_variate " << deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(ƒ.time. Q=1: 0. int no sims=5000.u.8451 antithetic_variate 70.0.r.25. double sigm—=0.u.sigm—. ™out << " asset or nothing: " << deriv—tive pri™e simul—te europe—n option generi™(ƒ. no sims) << endl. no sims) << endl. ™out << " antithetic_variate " << deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(ƒ.sigm—. no sims) << endl. yutput from g++ progr—mX cash or nothing.5292 control_variate 69.

Chapter 13 Approximations „here h—s ˜een developed some useful approximations to v—rious spe™i(™ optionsF st is of ™ourse emerE i™—n options th—t —re —pproxim—tedF „he p—rti™ul—r ex—mple we will look —tD is — gener—l qu—dr—ti™ —pproxim—tion to emeri™—n ™—ll —nd put pri™esF 13. T ) + εC (S. T ) rere εC is the e—rly exer™ise premiumF „he insight used ˜y fe‡ is th—t εC must also s—tisfy the s—me p—rti—l di'erenti—l equ—tionF „o ™ome up with —n —pproxim—tion fe‡ tr—nsformed equ—tion @IQFIA into one where the terms involving Vt —re negli˜leD removed theseD —nd ended up with — st—nd—rd line—r homeogenous se™ond order equ—tionD whi™h h—s — known solutionF „he fun™tion—l form of the —pproxim—tion is shown in formul— IQFIF sn implementing this formul—D the only pro˜lem is (nding the ™riti™—l v—lue S ∗ F „his is the ™l—ssi™—l pro˜lem of (nding — root of the equ—tion g(S ∗ ) = S ∗ − X − c(S ∗ ) − S∗ 1 − e(b−r)(T −t) N (d1 (S ∗ )) = 0 q2 „his is solved using xewton9s —lgorithm for (nding the rootF ‡e st—rt ˜y (nding — (rst seed v—lue S0 F „he next estim—te of Si is found ˜yX Si+1 = Si − g() g et e—™h step we need to ev—lu—te g() —nd its deriv—tive g ()F g(S) = S − X − c(S) − 1 S 1 − e(b−r)(T −t) N (d1 ) q2 g (S) = (1 − 1 1 1 ) 1 − e(b−r)(T −t) N (d1 ) + (e(b−r)(T −t) n(d1 )) √ q2 q2 σ T −t where c(S) is the fl—™k ƒ™holes v—lue for ™ommoditiesF gode IQFI shows the implement—tion of this formul— for the pri™e of — ™—ll optionF IHW . T ) = c(S.1 A quadratic approximation to American prices due to BaroneAdesi and Whaley. ‡e now dis™uss —n —pproxim—tion to the option pri™e of —n emeri™—n option on — ™ommodityD des™ri˜ed in f—roneEedesi —nd ‡h—ley @IWVUA @fe‡AF1 „he ™ommodity is —ssumed to h—ve — ™ontinuous p—yout bF „he st—rting point for the —pproxim—tion is the @fl—™kEƒ™holesA sto™h—sti™ di'erenti—l equ—tion v—lid for the v—lue of —ny deriv—tive with pri™e V F 1 2 2 σ S VS S + bSVS − rV + Vt = 0 2 @IQFIA rere V is the @unknownA formul— th—t determines the pri™e of the ™ontingent ™l—imF por —n iurope—n option the v—lue of V h—s — known solutionD the —djusted fl—™k ƒ™holes formul—F por emeri™—n optionsD whi™h m—y ˜e exer™ised e—rlyD there is no known —n—lyti™—l solutionF „o do their —pproxim—tionD fe‡ de™omposes the emeri™—n pri™e into the iurope—n pri™e —nd the e—rly exer™ise premium C(S.

T ) + A1 X −S S q1 S ∗∗ if if S > S ∗∗ S ≤ S ∗∗ A1 = − S ∗∗ (1 − e(b−r)(T −t) N (−d1 (S ∗∗ )) q1 One again solves iteratively for S ∗∗ . T ) + Formula 13. K(T ) = 1 − e−r(T −t) σ2 σ S∗ 1 − e(b−r)(T −t) N (d1 (S ∗ )) q2 —nd S ∗ solves S ∗ − X = c (S ∗ . T ) + A2 S−X S q2 S∗ if if S < S∗ S ≥ S∗ q2 = 1 2 −(N − 1) + (N − 1) + 2 4M K A2 = M= S∗ 1 − e(b−r)(T −t) N (d1 (S ∗ )) q2 2b 2r . For a put option the approximation is P (S) = p(S. N = 2 . The Barone-Adesi  Whaley insight can also be used to value a put option. Implement the calculation of the price of an American put option using the BAW approach. by approximating the value of the early exercise premium. for example by Newton's procedure. where now one would use g(S) = X − S − p(S) + S 1 − e(b−r)(T −t) N (−d1 ) q1 g (S) = ( 1 1 1 − 1) 1 − e(b−r)(T −t) N (−d1 ) + e(b−r)(T −t) √ n(−d1 ) q1 q1 σ T −t 1.1: emeri™—n ™—ll „he fun™tion—l form of the f—rone edesi ‡h—ley —pproxim—tion to the v—lue of —n Exercise 22. T ) = where c(S.C(S. 1 „he —pproxim—tion is —lso dis™ussed in rull @PHHTAF IIH .

r.sigm—. const double& r. // know value will never be less than BS value }. nn = 2. g=™+eP*pow((ƒ/ƒ st—r). double ™ = option pri™e europe—n if (ƒ>=ƒ st—r) { g=ƒ−ˆ. while ((f—˜s(g) > egg…‚eg‰) double double && (ƒi>0.0/qP)*ƒi−ˆ−™+(1.0.0−1.0−exp((˜−r)*time)*x(dI)) +(1. // seed value from paper int no iter—tions=0.time). } // did not converge ™—ll p—yout(ƒ. { } }.™). double g=0. u = 1.0)+4. m = 2. }.h" // normal distribution // dene other option pricing formulas const double double egg…‚eg‰=1. m—x(g. return C++ Code 13.0/qP)*ƒi*exp((˜−r)*time)*x(dI).0 − 1.1: f—rone edesi qu—dr—ti™ —pproxim—tion to the pri™e of — ™—ll option III .h" #include "fin_recipes. eP = (1.ˆ.ˆ. const double& ƒ. gprime=( 1. const double& ˆ.˜. const double& ˜. ƒ seed = ˆ + (ƒ st—r inf −ˆ)*(1. else double double dI = (log(ƒ st—r/ˆ)+(˜+0. double g=1.0/qP)*exp((˜−r)*time)*n(dI)*(1.2.sigm—.0*sigm—*time sqrt)*(ˆ/(ƒ st—r inf −ˆ)).0e−6. }.0−exp(−r*time).2.0)) { && ( S to nd S star. #include "normdist. ƒi=ƒi−(g/gprime).0/(sigm—*time sqrt)).5*sigm— sqr)*time)/(sigm—*time sqrt). double gprime=1. ƒ st—r inf = ˆ / (1. const double& time) { qP inf = 0.0)+(4*m/u)))*0.5*sigm— sqr)*time)/(sigm—*time sqrt).0−exp((˜−r)*time)*x(dI))* (ƒ st—r/qP). using Newton steps && (f—˜s(gprime)>egg…‚eg‰ ) // to avoid exploding Newton's no iter—tions++<500) ™ = option pri™e europe—n ™—ll p—yout(ƒi.r.0−1. time sqrt = sqrt(time). if (f—˜s(g)>egg…‚eg‰) { ƒ st—r else { ƒ st—r = ƒi.5.0/qP)*(1. = ƒ seed.0*r/sigm— sqr.˜.0*˜/sigm— sqr.#include <™m—th> #include <—lgorithm> using namespace std.0/qP inf ).5 * ( −(nn−1) + sqrt(pow((nn−1).0−exp(hP)). // iterate on double ƒi=ƒ seed.0*m)).qP). double ƒ st—r = 0.time). const double& sigm—. qP = (−(nn−1)+sqrt(pow((nn−1). hP = −(˜*time+2. g=(1. option pri™e —meri™—n ™—ll —pproxim—ted ˜—w( double double double double double double double double double double sigm— sqr = sigm—*sigm—. dI = (log(ƒi/ˆ)+(˜+0.

˜. double ˜ = −0.time) << endl.25.04. yutput from g++ progr—mX Call price using Barone-Adesi Whaley approximation = 5.20D r = 0.08D b = −0. double r = 0.r.1: ix—mple using the fe‡ —pproxim—tion IIP .gonsider the following set of p—r—metersD used —s —n ex—mple in the f—roneEedesi —nd ‡h—ley @IWVUA p—perX S = 100D X = 100D σ = 0.ˆ.04F €ri™e — ™—ll option with time to m—turity of of Q monthsF g++ progr—mX void test ˜—w —pproxim—tion ™—ll(){ double ƒ = 100.sigm—. ™out << " Call price using Barone-Adesi Whaley approximation = " << option pri™e —meri™—n ™—ll —pproxim—ted ˜—w(ƒ. double sigm— = 0.74339 Example 13. double ˆ = 100. double time = 0.20. }.08.

Chapter 14 Average. lookback and other exotic options ‡e now look —t — type of options th—t h—s re™eived — lot of —ttention in l—ter ye—rsF „he distinguishing f—™tor of these options is th—t they depend on the whole price path of the underlying se™urity ˜etween tod—y —nd the option m—turityF 14.1 Bermudan options e fermud—n option isD —s the n—me impliesD1 — mix of —n iurope—n —nd emeri™—n optionF st is — st—nd—rd put or ™—ll option whi™h ™—n only ˜e exer™ised —t dis™rete d—tes throughout the life of the optionF „he simplest w—y to do the pri™ing of this is —g—in the ˜inomi—l —pproxim—tionD ˜ut nowD inste—d of ™he™king —t every node whether it is optim—l to exer™ise e—rlyD only ™he™k —t the nodes ™orresponding to the potenti—l exer™ise timesF gode IRFI shows the ™—l™ul—tion of the fermud—n pri™e using ˜inomi—l —pproxim—tionsF „he times —s whi™h exer™ise ™—n h—ppen is p—ssed —s — ve™tor —rgument to the routineD —nd in the ˜inomi—l — list of whi™h nodes exer™ise ™—n h—ppen is ™—l™ul—ted —nd ™he™ked —t every stepF 1 ƒin™e fermud— is somewhere ˜etween emeri™— —nd iuropeFFF IIQ .

d = 1. ve™tor<double> pri™es(steps+1).i<potenti—l exer™ise times.0−p up. // volatility const double& time. // put payos for (int step=steps−1. at maturity for (int i=0.++i){ double t = potenti—l exer™ise times[i].0. }. // spot price const double& ˆ. p up = (exp((r−q)*delt— t)−d)/(u−d).#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. for (int i=1. i<=step. if ( (t>0. (ˆ−pri™es[i])).ˆ−pri™es[i]). if (™he™k exer™ise this step) put v—lues[i] = m—x(put v—lues[i]. }. }. // standard C mathematical library // denes the max() operator // STL vector templates double option pri™e put ˜ermud—n ˜inomi—l( double double double double double double double double delt— t=time/steps. const int& steps) { // no steps in binomial tree put ve™tor<int> potenti—l exer™ise steps. −−step) { bool ™he™k exer™ise this step=false. // value of corresponding const double& ƒ. // create list of for (int i=0. }.++j){ if (step==potenti—l exer™ise steps[j]) { ™he™k exer™ise this step=true.0/u. ++i) pri™es[i] = uu*pri™es[i−1]. pri™es[i] = d*pri™es[i+1].size(). return C++ Code 14. i<=steps.0/‚. pri™es[0] = ƒ*pow(d. }. steps). // inverse of interest rate u = exp(sigm—*sqrt(delt— t)).push ˜—™k(int(t/delt— }. }.j<potenti—l exer™ise steps. steps at which exercise may happen t)). // interest rate for each step ‚inv = 1. i<=steps. step>=0. for (int j=0. // continous payout const double& sigm—. // interest rate const double& q. ++i) put v—lues[i] = m—x(0. ‚ = exp(r*delt— t). // exercice price const double& r. put v—lues[0]. // time to maturity const ve™tor<double>& potenti—l exer™ise times. p down = 1.1: finomi—l —pproxim—tion to fermud—n put option IIR . // price of underlying ve™tor<double> put v—lues(steps+1).size(). // up movement uu = u*u. // ll in the endnodes. ++i) { put v—lues[i] = (p up*put v—lues[i+1]+p down*put v—lues[i])*‚inv. for (int i=0.0)&&(t<time) ) { potenti—l exer™ise steps.

potenti—l exer™ise times.g++ progr—mX void test ˜ermud—n option(){ double ƒ=80.time.sigm—.75).25.potenti—l exer™ise times.r.5). potenti—l exer™ise times.push ˜—™k(0. double q=0. double time = 1. }. potenti—l exer™ise times. ve™tor<double> potenti—l exer™ise times.u. double r = 0.20. double sigm— = 0.0.steps) << endl. ™out << " Bermudan put price = " << option pri™e put ˜ermud—n ˜inomi—l(ƒ.push ˜—™k(0.25).q. int steps = 500. yutput from g++ progr—mX Bermudan put price = 15. double u=100.push ˜—™k(0.0.9079 IIS .

sigm—.0.q. const const const const const double& ƒ. ST − S) ¯ „here —re di'erent types of esi—ns depending on how the —ver—ge S is ™—l™ul—tedF por the ™—se of S ˜eing ¯ ˜eing — geometri™ —ver—geD there is —n —n—lyti™ formul— due to uemn— —nd lognorm—l —nd the —ver—ge S †orst @IWWHAF rull @PHHTA —lso dis™usses this ™—seF st turns out √ th—t one ™—n ™—l™ul—te this option using the regul—r fl—™k ƒ™holes formul— —djusting the vol—tility to σ/ 3 —nd the dividend yield to 1 2 1 r + q + σ2 6 in the ™—se of ™ontinous s—mpling of the underlying pri™e distri˜utionF gode IRFP shows the ™—l™ul—tion of the —n—lyti™—l pri™e of —n esi—n geometri™ —ver—ge pri™e ™—llF #include <™m—th> using namespace std. C++ Code 14. double& ˆ. double —dj sigm—=sigm—/sqrt(3. double& q. double —dj sigm— sqr = pow(—dj sigm—. „he p—yo' depends on the —ver—ge of the underlying pri™eF en ¯ where S is the —ver—ge of the underlying in the period ˜etween t —nd T F enother esi—n is the average strike call ¯ CT = max(0. double time sqrt = sqrt(time). }.25. double —dj div yield=0.2).14. return ™—ll pri™e. ™out << " Analytical geometric average = " << option pri™e —si—n geometri™ —ver—ge pri™e ™—ll(ƒ.r.time) << endl.3562 IIT .2 Asian options average price call h—s p—yo' ¯ CT = max(0. double sigm—=0. S − X). double r=0.0).u.h" // normal distribution denitions double option pri™e —si—n geometri™ —ver—ge pri™e ™—ll(const double sigm— sqr = pow(sigm—. }. double& sigm—.5*(r+q+sigm— sqr).06. yutput from g++ progr—mX Analytical geometric average = 5. #include "normdist.5*—dj sigm— sqr)*time)/(—dj sigm—*time double dP = dI−(—dj sigm—*time sqrt). double dI = (log(ƒ/ˆ) + (r−—dj div yield + 0. double q=0. double ™—ll pri™e = ƒ * exp(−—dj div yield*time)* x(dI) − ˆ * exp(−r*time) * x(dP). double& time){ sqrt).2: g++ progr—mX en—lyti™—l pri™e of —n esi—n geometri™ —ver—ge pri™e ™—ll void test —n—lyti™—l geometri™ —ver—ge(){ double ƒ=100. double& r. double time=1. double u=100.2).

double ‰I = 2. ST − min Sτ ) τ ∈[t. double& q. }. double sigm— sqr=sigm—*sigm—.1: #include <™m—th> using namespace std. double& time){ exp(−r*time)*(x(—P)−(sigm— sqr/(2*(r−q)))*exp(‰I)*x(−—Q)).h" en—lyti™—l formul— for — look˜—™k ™—ll double option pri™e europe—n look˜—™k ™—ll(const if (r==q) return 0. C++ Code 14. double —P = —I−sigm—*time sqrt.0)*time)/(sigm—*time sqrt).0*(r−q)))*x(−—I) − ƒmin * const const const const const double& ƒ.3: €ri™e of look˜—™k ™—ll option IIU .0 * (r−q−sigm— sqr/2. #include "normdist. double& r.T ] por this p—rti™ul—r option —n —n—lyti™—l solution h—s ˜een foundD due to qoldm—nD ƒosinD —nd q—tto @IWUWAD whi™h is shown in formul— IRFI —nd implemented in ™ode IRFQ C = Se−q(T −t) N (a1 ) − Se−q(T −t) ln a1 = S Smin σ2 σ2 N (−a1 ) − Smin e−r(T −t) N (a2 ) − eY1 N (−a3) 2(r − q) 2(r − q) + (r − q + 1 σ 2 )(T − t) 2 √ σ T −t √ a2 = a1 − σ T − t ln a3 = S Smin 1 + −r + q + 2 σ 2 (T − t) √ σ T −t S Smin Y1 = 2 r − q − 1 σ 2 ln 2 σ2 Formula 14. double& ƒmin.0)*log(ƒ/ƒmin)/sigm— sqr. double time sqrt = sqrt(time).3 Lookback options „he p—yo' from look˜—™k options depend on the m—ximum or minimum of the underlying —™hieved through the periodF „he p—yo' from the look˜—™k ™—ll is the termin—l pri™e of the undelying less the minimum v—lue CT = max(0.0)*time)/(sigm—*time sqrt).14. return ƒ * exp(−q*time)*x(—I)− ƒ*exp(−q*time)*(sigm— sqr/(2. double —I = (log(ƒ/ƒmin) + (r−q+sigm— sqr/2. double& sigm—. double —Q = (log(ƒ/ƒmin) + (−r+q+sigm— sqr/2.

sigm—. double q = double sigm— = 0.time) << endl.g++ progr—mX void test exoti™s look˜—™k(){ double ƒ=100. yutput from g++ progr—mX Lookback call price = 27.q. double ƒmin=ƒ. double r = 0.0.0713 IIV .ƒmin. }. 0.06.r. ™out << " Lookback call price = " << option pri™e europe—n look˜—™k ™—ll(ƒ.346. double time = 1.

return C++ Code 14. double ‚ = (r−0. // interest rate double& sigm—. double ƒ t = ƒ.4: ƒimul—ting — sequen™e of lognorm—lly distri˜uted v—ri—˜les „his ™ode is then used in the generi™ routine to do ™—l™ul—tionsD —s shown in ™ode IRFSF IIW . i<no steps.4 Monte Carlo Pricing of options whose payo depend on the whole price path wonte g—rlo simul—tion ™—n ˜e used to pri™e — lot of di'erent optionsF „he limit—tion is th—t the options should ˜e iurope—nF emeri™—n options ™—n not ˜e pri™ed ˜y simul—tion methodsF sn ™h—pter IP we looked —t — gener—l simul—tion ™—se where we wrote — generi™ routine whi™h we p—ssed — p—yo' fun™tion toD —nd the p—yo' fun™tion w—s —ll th—t w—s ne™ess—ry to de(ne —n option v—lueF „he p—yo' fun™tion in th—t ™—se w—s — fun™tion of the terminal pri™e of the underlying se™urityF „he only di'eren™e to the previous ™—se is th—t we now h—ve to gener—te — pri™e sequence —nd write the termin—l p—yo' of the deriv—tive in terms of th—tD inste—d of just gener—ting the termin—l v—lue of the underlying se™urity from the lognorm—l —ssumptionF 14. // current value of underlying double& r.2))*delt— t.4.14.h" ve™tor<double> simul—te lognorm—lly distri˜uted sequen™e(const ve™tor<double> pri™es(no steps). // time to nal date int& no steps){ // number of steps at current price ƒh * r—ndom norm—l()). }. double delt— t = time/no steps.5*pow(sigm—. pri™es. // volatitily double& time.1 Generating a series of lognormally distributed variables ‚e™—ll th—t one will gener—te lognorm—lly distri˜uted v—ri—˜les —s 1 2 ST = St e(r− 2 σ )(T −t)+σ √ T −t˜ x where the ™urrent time is t —nd termin—l d—te is T F „o simul—te — pri™e sequen™e one splits this period into s—y N periodsD e—™h of length ∆t = T −t N E „ime t t + ∆t t + 2∆t t + 3∆t · · · T i—™h step in the simul—ted pri™e sequen™e is 1 2 St+∆t = St e(r− 2 σ )∆+σ √ ∆t˜ x gode IRFR shows how one would simul—te — sequen™e of lognorm—lly distri˜uted v—ri—˜lesF #include <™m—th> #include <ve™tor> using namespace std. }. ++i) { ƒ t = ƒ t * exp(‚ pri™es[i]=ƒ t. // initialize for (int i=0. #include "normdist. double ƒh = sigm— * sqrt(delt— t). + const const const const double& ƒ.

—vg−ˆ). for (int n=0. return exp(−r*time) p—yo's/no sims). // price of underlying const double& ˆ. n++) { ve™tor<double>pri™es = simul—te sum p—yo's += no steps.—vg−ˆ).end().˜egin(). }. for (unsigned i=1. // used by user provided payo const double& r.0.0.time.no steps).5: #include <™m—th> #include <numeri™> #include <ve™tor> using namespace std.r.0).#include <™m—th> using namespace std. n<no sims. // number of steps in generated price no sims) { // number of simulations to run sequence p—yo' (pri™es. double —vg = exp(logsum/pri™es.++i){ logsum+=log(pri™es[i]).size(). }.sigm—. qeneri™ routine for pri™ing iurope—n options whi™h double p—yo' —rithmetri™ —ver—ge ™—ll(const ve™tor<double>& double sum=—™™umul—te(pri™es. return m—x(0. ˆ) { C++ Code 14.size(). pri™es. * (sum lognorm—lly distri˜uted sequen™e(ƒ. }.ˆ). #include "fin_recipes. pri™es. const double& ˆ) { double p—yo' geometri™ —ver—ge ™—ll(const ve™tor<double>& pri™es. }.0. // time to maturity double p—yo' (const ve™tor<double>& pri™es. const int& const int& // user provided function function double sum p—yo's=0. // volatility const double& time. // risk free interest rate const double& sigm—. }. const double& ˆ).h" double deriv—tive pri™e simul—te europe—n option generi™(const double& ƒ. double —vg = sum/pri™es. C++ Code 14.6: €—yo' fun™tion for esi—n ™—ll option „o pri™e —n option we —re then only in need of — de(nition of — p—yo' fun™tionF ‡e ™onsider — ™ouple of ex—mplesF yne is the ™—se of —n esi—n optionD shown in ™ode IRFTF enother is the p—yo' for — look˜—™kD shown in ™ode IRFU IPH .size()).i<pri™es. const double& double logsum=log(pri™es[0]). return m—x(0.

// max is always larger or equal.7: €—yo' fun™tion for look˜—™k option IPI . }.#include <ve™tor> #include <—lgorithm> using namespace std.pri™es. const double& double m = *min element(pri™es. // always positive or zero }.˜egin().˜—™k().end()).end()). return m−pri™es. unused v—ri—˜le) { C++ Code 14.˜egin().pri™es. unused v—ri—˜le) { double p—yo' look˜—™k put(const ve™tor<double>& pri™es. return pri™es.˜—™k()−m. double p—yo' look˜—™k ™—ll(const ve™tor<double>& pri™es. const double& double m = *m—x element(pri™es.

sigm—. C++ Code 14. ™ ˜s sim = exp(−r*time) * (sum p—yo's ˜s/no sims).14. n<no sims.r. const double& ˆ. for (int n=0.time).ƒ.r. n++) { ve™tor<double> pri™es = simul—te lognorm—lly distri˜uted sequen™e(ƒ. double p—yo' (const ve™tor<double>& const double& ˆ). const double& time.sigm—. return ™ sim. double ƒI= pri™es. const double& r. const int& no steps. const double& sigm—.ƒ). ™ sim = exp(−r*time) * (sum p—yo's/no sims). call double double }.h" #include <™m—th> using namespace std.// price an at the money Black Scholes double sum p—yo's=0.˜—™k(). // simulate at the money Black Scholes price }.time. sum p—yo's ˜s += p—yo' ™—ll(ƒI. double deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(const double ™ ˜s = option pri™e ™—ll ˜l—™k s™holes(ƒ. no steps). double sum p—yo's ˜s=0. ™ sim += (™ ˜s−™ ˜s sim).8: References gontrol †—ri—te ixoti™ options —re ™overed in rull @PHHTAF ‚u˜instein @IWWQA h—s —n extensive dis™ussion of —n—lyti™—l solutions to v—rious exoti™ optionsF IPP . sum p—yo's += p—yo' (pri™es. double& ƒ.5 Control variate es dis™ussed in ™h—pter IPD — ™ontrol v—ri—te is — pri™e whi™h we ˜oth h—ve —n —n—lyti™—l solution of —nd (nd the wonte g—rlo pri™e ofF „he di'eren™es ˜etween these two pri™es is — me—sure of the ˜i—s in the wonte g—rlo estim—teD —nd is used to —djust the wonte g—rlo estim—te of other deriv—tives pri™ed using the s—me r—ndom sequen™eF gode IRFV shows the fl—™k ƒ™holes pri™e used —s — ™ontrol v—ri—teF en —ltern—tive ™ould h—ve ˜een the —n—lyti™—l look˜—™k pri™eD or the —n—lyti™—l solution for — geometri™ —ver—ge pri™e ™—ll shown e—rlierF #include "fin_recipes.ˆ). const int& no sims) { pri™es.

10.25.0685 IPQ . ™out << " analytical lookback call = " << option pri™e europe—n look˜—™k ™—ll(ƒ. p—yo' look˜—™k put. p—yo' look˜—™k ™—ll. p—yo' look˜—™k ™—ll.9846 analytical lookback call = 22. 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(ƒ.r. = 250. no steps.no sims) << endl.sigm—.no sims) << endl.ƒ.time. p—yo' —rithmetri™ —ver—ge ™—ll.time.1 price=1.0. int no steps double q=0.u. double ƒ=100.time.8089 simulated lookback call = 21.0.no sims) << endl.2665 simulated lookback put = 14.r.49696 simulated geometric average = 1. int no sims = 10000. no steps.sigm—. ™out << " analytical lookback put = " << option pri™e europe—n look˜—™k put(ƒ.38017 analytical lookback put = 16.u.sigm—. double r = 0.no sims) << endl. ™out << " simulated arithmetric average " << " S= " << ƒ << " r= " << r << " price=" << deriv—tive pri™e simul—te europe—n option generi™(ƒ. no steps.time) << endl.0. no steps.r. ™out << " simulated lookback call = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.r.time. double sigm— = 0.r.time.g++ progr—mX void test simul—te gener—l europe—n(){ ™out << "Testing general simulation of European options " << endl. }.no sims) << endl.q.sigm—. ™out << " simulated lookback put = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ. ™out << " simulated geometric average = " << deriv—tive pri™e simul—te europe—n option generi™(ƒ.9336 simulated lookback call using control variates = 22.q. double u=120. yutput from g++ progr—mX Testing general simulation of European options simulated arithmetric average S= 100 r= 0.ƒ.time) << endl.r. p—yo' geometri™ —ver—ge ™—ll.sigm—. no steps.sigm—.r.sigm—.0.

Chapter 15

Alternatives to the Black Scholes type option formula
e l—rge num˜er of —ltern—tive formul—tions to the fl—™k ƒ™holes —n—lysis h—s ˜een proposedF †ery few of them h—ve seen —ny widespre—d useD ˜ut we will look —t some of these —ltern—tivesF

15.1

Merton's Jump diusion model.

werton h—s proposed — model where in —ddition to — frowni—n wotion termD the pri™e pro™ess of the underlying is —llowed to h—ve jumpsF „he risk of these jumps is —ssumed to not ˜e pri™edF sn the following we look —t —n implement—tion of — spe™i—l ™—se of werton9s modelD des™ri˜ed in @rullD IWWQD pg RSRAD where the size of the jump h—s — norm—l distri˜utionF λ —nd κ —re p—r—meters of the jump distri˜utionF „he pri™e of —n iurope—n ™—ll option is

c=
where

eλ τ (λ τ )n 2 CBS (S, X, rn , σn , T − t) n! n=0

τ =T −t λ = λ(1 + κ) CBS (·) is the fl—™k ƒ™holes formul—D —nd
2 σn = σ 2 +

nδ 2 τ n ln(1 + κ) τ

rn = r − λκ +

sn implementing this formul—D we need to termin—te the in(nite sum —t some pointF fut sin™e the f—™tori—l fun™tion is growing —t — mu™h higher r—te th—n —ny otherD th—t is no pro˜lemD termin—ting —t —˜out n = 50 should ˜e on the ™onserv—tive sideF „o —void numeri™—l di0™ultiesD use the following method for ™—l™ul—tion of

eλ τ (λ τ )n = exp ln n!

eλ τ (λ τ )n n!

n

= exp −λ τ + n ln(λ τ ) −
i=1

ln i

IPR

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

double

option pri™e ™—ll merton jump di'usion(

const int weˆx=50; double t—u=time to m—turity; double sigm— sqr = sigm—*sigm—; double delt— sqr = delt—*delt—; double l—m˜d—prime = l—m˜d— * (1+k—pp—); double g—mm— = log(1+k—pp—); double ™ = exp(−l—m˜d—prime*t—u)*option pri™e ™—ll ˜l—™k double log n = 0; for (int n=1;n<=weˆx; ++n) { log n += log(double(n)); double sigm— n = sqrt( sigm— sqr+n*delt— sqr/t—u ); double r n = r−l—m˜d—*k—pp—+n*g—mm—/t—u;
™
+= }; };

const double& ƒ, const double& ˆ, const double& r, const double& sigm—, const double& time to m—turity, const double& l—m˜d—, const double& k—pp—, const double& delt—) {

s™holes(ƒ,ˆ,r−l—m˜d—*k—pp—,sigm—,t—u);

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(ƒ,ˆ,r n,sigm— n,t—u); ™;

return

C++ Code 15.1:

wertons jump di'usion formul—

g++ progr—mX
#include <™m—th>

void test merton jump di' ™—ll(){ double ƒ=100; double u=100; double r=0.05; double sigm—=0.3; double time to m—turity=1; double l—m˜d—=0.5; double k—pp—=0.5; double delt—=0.5;

™out << " Merton Jump diffusion call = " << option pri™e ™—ll merton jump di'usion(ƒ,u,r,sigm—,time to m—turity,l—m˜d—,k—pp—,delt—) << endl;

};

yutput from g++ progr—mX

Merton Jump diffusion call = 23.2074

Example 15.1:

wertons tump di'usion formul—

IPS

Chapter 16

Using a library for matrix algebra
‡h—t re—lly distinguishes g++ from st—nd—rd C is the —˜ility to extend the l—ngu—ge ˜y ™re—ting ™l—sses —nd ™olle™ting these ™l—sses into li˜r—riesF e li˜r—ry is — ™olle™tion of ™l—sses —nd routines for one p—rti™ul—r purposeF ‡e h—ve —lre—dy seen this ide— when ™re—ting the date —nd term_structure ™l—ssesF roweverD one should not ne™ess—rily —lw—ys go —he—d —nd ™re—te su™h ™l—sses from s™r—t™hF st is just —s well to use some˜ody else9s ™l—ssD —s long —s it is ™orre™t —nd well do™umented —nd ful(lls — p—rti™ul—r purposeF

16.1

An example matrix class

…se Newmat —s —n ex—mple m—trix ™l—ssF

16.2

Finite Dierences

‡e use the ™—se of impli™it (nite di'eren™e ™—l™ul—tions to illustr—te m—trix ™—l™ul—tions in —™tionF „he method of ™hoi™e for —ny engineer given — di'erenti—l equ—tion to solve is to numeri™—lly —pproxim—te it using — (nite di'eren™e s™hemeD whi™h is to —pproxim—te the ™ontinous di'erenti—l equ—tion with — dis™rete dierence equ—tionD —nd solve this di'eren™e equ—tionF sn the following we implement the implicit nite dierencesF ixpli™it (nite di'eren™es w—s dis™ussed e—rlierD we postponed the impli™it ™—se to now ˜e™—use it is mu™h simpli(ed ˜y — m—trix li˜r—ryF

16.3

European Options

por iurope—n options we do not need to use the (nite di'eren™e s™hemeD ˜ut we show how one would (nd the europe—n pri™e for ™omp—rison purposesF

IPT

w)=1. double& u.0 + delt— t*(r+sigm— sqr*j*j).j+1) = 0.element(j. double& sigm—.m<=w.++m){ f.element(0. // c[j].1. if ((no ƒ steps%2)==1) { w=no ƒ steps+1. #include <ve™tor> // standard #include <—lgorithm> using namespace std.++j) { e.i()*f. int w. e=0. e. for newmat matrix library STL vector template double option pri™e put europe—n (nite di' impli™it(const double sigm— sqr = sigm—*sigm—.i()*f. // need no S steps to be even: f—ndw—trix e(w+1.0.0.m<=w. } else { double delt— ƒ = 2.element(j.element(m) golumn†e™tor p=e. e. golumn†e™tor f(w+1). double delt— t = time/x.u−ƒ v—lues[m]). const const const const const const double& ƒ.j−1) = 0. return p. }. }.1). }. // b[j]. p = e.j<w.0) = 1.element(w/2).t>0. }. C++ Code 16.0*ƒ/w. for (int m=0.1: g—l™ul—tion of pri™e of iurope—n put using impli™it (nite di'eren™es IPU .0. for (int j=1. double& r. = m—x(0.5*j*delt— t*(r−sigm— sqr*j).element(w. // a[j] e. }. ve™tor<double> ƒ v—lues(w+1).h" // denitions using namespace xi‡we„.0. double& time.#include <™m—th> #include "newmat.m++) { ƒ v—lues[m] = m*delt— ƒ. e. }.5*j*delt— t*(−r−sigm— sqr*j). for (int m=0.j) = 1. int x=no t steps. int& no t steps) { w=no ƒ steps.−−t) { f = p. int& no ƒ steps.element(j. for(int t=x−1.

element(j. }.2: g—l™ul—tion of pri™e of emeri™—n put using impli™it (nite di'eren™es IPV . e. int& no t steps) { ƒ steps. int w.u−ƒ v—lues[m]). }.j) = 1. double& sigm—. e=0. } else { w=no double delt— ƒ = 2. for (int m=0. golumn†e™tor p=e. e. double ƒ v—lues[w+1].element(m) = m—x(p.0 + delt— t*(r+sigm— sqr*j*j).m<=w.element(w. for newmat matrix library double option pri™e put —meri™—n (nite di' impli™it(const double sigm— sqr = sigm—*sigm—. double delt— t = time/x. f—ndw—trix e(w+1.−−t) { f = p. int x=no t steps. }. return p. // need no S steps to be even: if ((no ƒ steps%2)==1) { w=no ƒ steps+1.i()*f.4 American Options ‡e now ™omp—re the emeri™—n versions of the s—me —lgoritmsD the only di'eren™e ˜eing the ™he™k for exer™ise —t e—™h pointF #include <™m—th> #include "newmat.m<w.16.i()*f. e. C++ Code 16.h" // denitions using namespace xi‡we„.m++) { ƒ v—lues[m] = m*delt— ƒ.t>0. for(int t=x−1. const const const const const const double& ƒ. }.0.m<=w.element(j.element(j.0*ƒ/w. double& u. golumn†e™tor f(w+1).5*j*delt— t*(r−sigm— sqr*j).0.element(w/2). // a[j] e.1. double& r.j<w. }. int& no ƒ steps.++m){ f. for (int m=0.0.5*j*delt— t*(−r−sigm— sqr*j).1).w)=1.0) = 1.j+1) = 0.0.++m) { // now check for exercise p.++j) { e.element(m) = m—x(0. u−ƒ v—lues[m]). }. for (int m=1. // c[j].element(m). }.j−1) = 0. // b[j]. for (int j=1. p = e.element(0. double& time. #include <ve™tor> #include <—lgorithm> using namespace std.

0. int no ƒ steps=200. double r = 0. double time=0. int no t steps=200. ™out ™out ™out ™out ™out << << << << << " black scholes put price = " << option pri™e put ˜l—™k s™holes(ƒ.34731 implicit American put price = 4.60064 IPW .sigm—.u.r. double sigm— = 0.sigm—.4.time)<< endl.35166 implicit Euro put price = 4.r.no ƒ steps. " implicit Euro put price = ". option pri™e put europe—n (nite di' impli™it(ƒ. double u = 50.r. " implicit American put price = ".time.u.sigm—.0. }.u.no t steps) << endl. option pri™e put —meri™—n (nite di' impli™it(ƒ.1.no t steps) << endl.g++ progr—mX void test impli™it (nite di'eren™es(){ double ƒ = 50.5.no ƒ steps. yutput from g++ progr—mX black scholes put price = 4.time.

r1 ) σ(r1 . σ(rp ))D with utility in™re—sing in expe™ted return (∂u/∂E[rp ] > 0) —nd de™re—sing in v—ri—n™e (∂u/∂ v—r(rp ) < 0)F sn this p—rt we ™onsider the represent—tion of the portfolio opportunity set of su™h de™ision m—kersF „here —re — num˜er of useful properties of this opportunity set whi™h follows purely from the m—them—ti™—l formul—tion of the optimiz—tion pro˜lemF st is these properties we fo™us on hereF 17.1 Setup ‡e —ssume there exists n ≥ 2 risky se™uritiesD with expe™ted returns e   E[r1 ]  E[r2 ]    e=  F F   F E[rn ] —nd ™ov—ri—n™e m—trix VX  σ(r1 . . r1 ) „he ™ov—ri—n™e m—trix V is —ssumed to ˜e inverti˜leF e portfolio p is de(ned ˜y — set of weights w invested in the risky —ssetsF   ω1  ω2    w =  F .. σ(rn . r2 )  σ(r2 ... r1 ) σ(r2 . rn )      σ(rn . ..  F  F ωn where wi is the fr—™tion of the investors we—lth invested in —sset iF xote th—t the weights sum to oneF „he expe™ted return on — portfolio is ™—l™ul—ted —s E[rp ] = w e —nd the v—ri—n™e of the portfolio is σ 2 (rp ) = w Vw gode IUFI implements these ™—l™ul—tionsF IQH .Chapter 17 The Mean Variance Frontier ‡e now (n—lly en™ounter — ™l—ssi™—l topi™ in (n—n™eD me—n v—ri—n™e —n—lysisF „his h—s h—d to w—it ˜e™—use we needed the tool of — line—r —lge˜r— ™l—ss ˜efore de—ling with thisF we—n v—ri—n™e —n—lysis ™on™erns investors ™hoi™es ˜etween portfolios of risky —ssetsD —nd how —n investor ™hooses portfolio weightsF vet rp ˜e — portfolio returnF ‡e —ssume th—t investors preferen™es over portfolios p s—tisfy — me—n v—ri—n™e utility represent—tionD u(p) = u(E[rp ]... r2 )  V= F F  F .

w—trix tmp = e. ™out << " stdev " << mv ™—l™ul—te st dev(†.0)=0.0.element(0. double }.0).#include "newmat.element(1. w—trix e(2.5.707107 17.element(0.element(1. w.2). †.0)=0. const w—trix& w){ double }. w.h" #include "mv_calc. using namespace xi‡we„.t()*†*w. w—trix tmp = w.5 stdev 0. const double v—r = mv ™—l™ul—te v—ri—n™e(†.0.05.0.0)=0.element(1.1: g++ progr—mX we—n v—ri—n™e ™—l™ul—tions #include "newmat. mv ™—l™ul—te me—n(const w—trix& e.h" #include <™m—th> using namespace std.element(0. mv ™—l™ul—te v—ri—n™e(const w—trix& †.0).1). †.0.1.h" void test me—n v—ri—n™e ™—l™ul—tions(){ ™out << "Simple example of mean variance calculations " << endl. return tmp.1)=1.t()*w. yutput from g++ progr—mX Simple example of mean variance calculations mean 0.element(0. e.075 variance 0.element(0. e. w—trix& w){ C++ Code 17.2 The minimum variance frontier e portfolio is — frontier portfolio if it minimizes the v—ri—n™e for — given expe™ted returnD th—t isD — frontier portfolio p solves 1 wp = arg min w Vw 2 w su˜je™t toX w e = E[˜p ] r w1=1 „he set of —ll frontier portfolios is ™—lled the minimum variance frontierF IQI .1). w—trix w(2.element(0. }.1)=0.w) << endl. ™out << " mean " << mv ™—l™ul—te me—n(e. †.w). return tmp.0)=1.0)=0. const w—trix& w){ double mv ™—l™ul—te st dev(const w—trix& †. return sqrt(v—r). w—trix †(2. }. †.element(1.w) << endl.5.w) << endl. ™out << " variance " << mv ™—l™ul—te v—ri—n™e(†.0)=0.

w = λe V −1 − γ1 V−1 r w e = E[˜p ] w1=1 (17.1) (17. the weights wp for a frontier portfolio p with mean E[˜p ] can be found as r wp = g + hE[rp ] where g= h= 1 (B1 − Ae ) V−1 D 1 (Ce − A1 ) V−1 D A = 1 V−1 e B = e V−1 e C = 1 V−1 1 A= B A A C D = BC − A2 = |A| Proof Any minimum variance portfolio solves the program 1 wp = arg min w Vw 2 w subject to w e = E[˜p ] r w1=1 Set up the Lagrangian corresponding to this problem L(w. λ. V) = ` ´ 1 w Vw − λ E[˜p ] − w e − γ(1 − w 1) r 2 Dierentiate ∂L = w V − λe − γ1 = 0 ∂w ∂L = E[rp ] − w e = 0 ∂λ ∂L =1−w 1=0 ∂γ Rewrite conditions above as (note that this requires the invertibility of V. γ|e.17. and there are no restrictions on shortsales.3 Calculation of frontier portfolios Proposition 1 If the matrix V is full rank.2) (17.3) IQP .

const w—trix& †.i<no —ssets.element(0. w—trix w = g + h*r. this becomes the following system of equations  E[rp ] 1 = = λB + γA λA + γC ff Solving for λ and γ . = 1. for (int i=0.0/d). double ˜ = f.i().element(0. double — = e. }.t()*†inv*ones.0). w—trix †inve=†inv*e. w. w—trix h = f*g − e*e.element(i.t()*†inv*e.0). w—trix g = (†invI*˜ − †inve*—)*(1. C++ Code 17.0/d). w—trix ones = w—trix(no —ssets.Post-multiply the rst equation with e and recognise the expression for E[rp ] in the second equation w e = E[rp ] = λe V−1 e + γ1 V−1 e Similarly post-multiply the rst equation with 1 and recognise the expression for 1 in the second equation w 1 = 1 = λe V−1 1 + γ1 V−1 1 With the denitions of A.element(0.‚ele—se().1).xrows().0).2: g—l™ul—ting the un™onstr—ined frontier portfolio given —n expe™ted return 17.1) above. B .0) w—trix †inv = †. double ™ = g.h" using namespace xi‡we„.element(0. w—trix f = e. C and D above. // inverse of V w—trix e = (ones. get γ= B − AE[rp ] D CE[rp ] − A D λ= Plug in expressions for λ and γ into equation (17.++i){ ones.0).4 The global minimum variance portfolio portfolioF vet mvp ˜e the glo˜—l minimum v—ri—n™e portfolioF IQQ „he portfolio th—t minimizes v—ri—n™e reg—rdless of expe™ted return is ™—lled the global minimum variance . ‚eturnw—trix mv ™—l™ul—te portfolio given me—n un™onstr—ined(const w—trix& e.t()*†inv*e). w—trix h = (†inve*™ − †invI*—)*(1. return w. double d = h. }. w—trix †invI=†inv*ones. and get w = ´ ´ 1 ` 1 ` B1 − Ae V−1 + Ce − A1 V−1 E[rp ] = g + hE[rp ] D D xote th—t the portfolio de(ned ˜y weights g is — portfolio with expe™ted return HD —nd th—t the portfolio de(ned ˜y weights (g + h) is — portfolio with expe™ted return IF xote —lso the useful property th—t g1 = 1D —nd h1 = 0F gode IUFP does this ™—l™ul—tionF #include "newmat. const double& r){ int no —ssets=e. w—trix g = ones.

w—trix †(2.2). yutput from g++ progr—mX Testing portfolio calculation suggested portfolio: w1 = 0.r).element(0.1. w—trix e(2.0) << " w2 = " << w.5 w2 = 0.0. double r=0. C expected return E[rmvp ] = E[r] T A C 1 and variance var(rmvp ) = C . E q 1 C σ(r) 17.1)=0.0)=0. †.0.0)=0.075.1)=1.0.0)=0.0) << endl.5 Proposition 2 (Global Minimum Variance Portfolio) The global minimum variance portfolio has weights wmvp = 1 V−1 1 −1 1 V−1 = A C 1 1 V−1 . ™out << " suggested portfolio: ".h" void test me—n v—ri—n™e portfolio ™—l™ul—tion(){ ™out << "Testing portfolio calculation " << endl.element(1.element(1.element(1.element(0.5 Ecient portfolios €ortfolios on the minimum v—ri—n™e frontier with expe™ted returns higher th—n or equ—l to E[rmvp ] —re ™—lled ecient portfoliosF E[r] T E[rmvp ] E σ(rmvp ) σ(r) IQR . w—trix w = mv ™—l™ul—te portfolio given me—n un™onstr—ined(e.g++ progr—mX #include "mv_calc. †.†. e.element(1. †. }.1).element(0. e.element(0.0. ™out << " w1 = " << w.05.0)=1. †.

ƒuppose h—ve N risky —ssets with weights w —nd one riskless —ssets with return rf F sntuitivelyD the return on — portfolio with — mix of risky —nd risky —ssets ™—n ˜e written —s E[rp ] = weight in risky × return risky + weight riskless × rf whi™h in ve™tor form isX E[rp ] = w e + (1 − w 1)rf Proposition 4 An ecient portfolio in the presence of a riskless asset has the weights wp = V−1 (e − 1rf ) E[rp ] − rf H where H = (e − 1rf ) V−1 (e − 1rf ) IQS .17. rp ) = 0.7 Allowing for a riskless asset. The zero beta portfolio zb(p) has return E[rzc(p) ] = D A C2 − C E[rp ] − A C T s mvp E[rzc(p) ] s p s zc(p) E xote th—t if p is —n e0™ient portfolio on the me—n v—ri—n™e frontier then zc(p) is ine0™ientF gonverselyD if p is ine0™ient zc(p) is e0™ientF E[r] T     sp       s mvp     s zc(p) E σ(r) 17. Proposition 3 For any portfolio p on the frontier.6 The zero beta portfolio cov(rzc(p) . there is a frontier portfolio zc(p) satisfying This portfolio is called the zero beta portfolio relative to p.

The variance of the ecient portfolio is σ 2 (rp ) = (E[rp ] − rf )2 H xote th—t st—nd—rd devi—tion is — line—r fun™tion of E[rp ]F „he e0™ient set is — line in me—nEst—nd—rd devi—tion sp—™eF 17. A CF ƒuppose rf < risky —ssetsF E[r] „hen the e0™ient set is the line from (0. rf )F   T         rf A C   d d d s mvp d d s de q A CD 1 C E σ(r) sf rf = the weight in the risk free —sset is oneF „he risky portfolio is —n zero investment portfolioF „he e0™ient set ™onsists of two —symptotes tow—rd the e0™ient set of risky —ssetsF E[r] T           A C   d d d d s mvp d d q 1 C E σ(r) IQT . rf ) through t—ngen™y on the e0™ient set of T se         s mvp     d d d d qd 1 C A C rf E d σ(r) A CF ƒuppose rf > E[r] „hen the e0™ient set is the two h—lfElines st—rting from (0.8 Ecient sets with risk free assets.

17.10 Short-sale constraints ƒo f—r the —n—lysis h—s put no restri™tions on the set of weights wp th—t de(nes the minimum v—ri—n™e frontierF por pr—™ti™—l —ppli™—tionsD existen™e of neg—tive weights is pro˜lem—ti™D sin™e this involves selling se™urities shortF „his h—s led to the investig—tion of restricted me—n v—ri—n™e frontiersD where the weights —re ™onstr—ined to ˜e nonEneg—tiveF Denition 1 A short sale resctricted minimum variance portfolio p solves 1 wp = arg min w Vw 2 w subject to w e = E[˜p ] r w1=1 w ≥0 ƒu™h short s—le res™tri™ted minimum v—ri—n™e portfolio portfolios —re mu™h h—rder to de—l with —n—E lyti™—llyD sin™e they do not —dmit — gener—l solutionD one r—ther h—s to investig—te the uuhnE„u™ker ™onditions for ™orner solutions et™F „o de—l with this pro˜lem in pr—™ti™e one will use — su˜routine for solving ™onstr—ined optimiz—tion pro˜lemsF Readings and Sources „he ™l—ssi™—l sour™es for this m—teri—l —re werton @IWUPA —nd ‚oll @IWUU—AF @ru—ng —nd vitzen˜ergerD IWVVD gh QA h—s — good text˜ook dis™ussion of itF IQU .9 The Sharpe Ratio „he ƒh—rpe r—tio of — given portfolio p is de(ned —s Sp = E[rp ] − rf σ(rp ) „he ƒh—rpe r—tio Sp of — portfolio p is the slope of the line in me—nEst—nd—rd devi—tions sp—™e from the risk free r—te through pF xote th—t in the ™—se with — risk free —ssetD the t—ngen™y portfolio h—s the m—xim—l ƒh—rpe ‚—tio on the e0™ient frontierF 17.

h" double ˜ond option pri™e put zero ˜l—™k s™holes(const double time sqrt = sqrt(time). double& sigm—.Chapter 18 Pricing of bond options.1: fl—™k s™holes pri™e for iurope—n ™—ll option on zero ™oupon ˜ond IQV . double& ˆ. const const const const double& f. C++ Code 18. double& r. double p = ˆ * exp(−r*time) * x(−dP) − f * x(−dI).1 Black Scholes bond option pricing qiven the —ssumed frowni—n wotion pro™essD pri™es of iurope—n fond yptions ™—n ˜e found using the usu—l fl—™k ƒ™holes formul—D —s shown in ™ode IVFI for — zero ™oupon ˜ond —nd ™ode IVFP for the ™—se of —n option on — ™oupon ˜ondF #include <™m—th> #include "normdist. return p. double dI = (log(f/ˆ)+r*time)/(sigm—*time sqrt) + 0.5*sigm—*time double dP = dI−(sigm—*time sqrt). double& time){ sqrt. }. basic models „he —re— of (xed in™ome se™urities is one where — lot of work is ˜eing done in ™re—ting —dv—n™ed m—thE em—ti™—l models for pri™ing of (n—n™i—l se™uritiesD in p—rti™ul—r (xed in™ome deriv—tivesF „he fo™us of the modelling in this —re— is on modelling the term stru™ture of interest r—tes —nd its evolution over timeD whi™h is then used to pri™e ˜oth ˜onds —nd (xed in™ome deriv—tivesF roweverD in some ™—ses one does not need the m—™hinery of term stru™ture modelling whi™h we9ll look —t in l—ter ™h—ptersD —nd pri™e deriv—tives ˜y modelling the evolution of the ˜ond pri™e dire™tlyF ƒpe™i(™—llyD suppose th—t the pri™e of — fond follows — qeometri™ frowni—n wotion pro™essD just like the ™—se we h—ve studied ˜eforeF „his is not — p—rti™ul—rly re—listi™ —ssumption for the long term ˜eh—viour of ˜ond pri™esD sin™e —ny ˜ond pri™e ™onverges to the ˜ond f—™e v—lue —t the m—turity of the ˜ondF „he qeometri™ frowni—n motion m—y ˜e yu for the ™—se of short term options on long term ˜ondsF 18.

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

++i) { f*pow(d. i<=step.(u−pri™es[i])).0−p up. // up movement uu = u*u. }. // check for exercise put v—lues[0]. put v—lues[i] = m—x(put v—lues[i]. // price of underlying ve™tor<double> put v—lues(steps+1). }.0.0/u. −−step) { for (int i=0. steps). // time to maturity const int& steps){ // no steps in binomial tree put for (int i=1. // Bond price const double& u. // interest rate const double& sigm—. pri™es[i] = d*pri™es[i+1].2 Binomial bond option pricing ƒin™e we —re in the ™—se of geometri™ frowni—n motionD the usu—l ˜inomi—l —pproxim—tion ™—n ˜e used to pri™e emeri™—n optionsD where the ˜ond is the underlying se™urityF gode IVFQ shows the ™—l™ul—tion of — put pri™e #include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. return C++ Code 18. // standard mathematical library // dening the max() operator // STL vector templates double ˜ond option pri™e put —meri™—n ˜inomi—l( ‚ = exp(r*(t/steps)).0/‚. // ll in the endnodes.18. }. for (int i=0. // interest rate for each step ‚inv = 1. i<=steps. p up = (‚−d)/(u−d). ve™tor<double> pri™es(steps+1). step>=0. // inverse of interest rate u = exp(sigm—*sqrt(t/steps)).3: finomi—l —pproxim—tion to —meri™—n ˜ond option pri™e IRH . // value of corresponding pri™es[0] = double double double double double double double const double& f. // volatility const double& t. (u−pri™es[i])). p down = 1. i<=steps. ++i) pri™es[i] = uu*pri™es[i−1]. d = 1. // exercise price const double& r. ++i) put v—lues[i] = m—x(0. // put payos at maturity put v—lues[i] = (p up*put v—lues[i+1]+p down*put v—lues[i])*‚inv. for (int step=steps−1.

r.sigm—. steps=100.r.92791 coupon bond put option price = 2. ™out << endl.05.sigm—.g++ progr—mX void test ˜ond option g˜m double f=100.43282 IRI . ™out << " zero coupon american put option price.push ˜—™k(1). ™oupons. ™oupon times.u.™oupon times. double r=0.u.u. double u=100. binomial = " << ˜ond option pri™e put —meri™—n ˜inomi—l(f.push ˜—™k(0. binomial = 2.5).time.sigm—.r.steps) << endl. int }. pri™ing(){ ™out << " zero coupon put option price = " << ˜ond option pri™e put zero ˜l—™k s™holes(f.time.™oupons). yutput from g++ progr—mX zero coupon put option price = 1.22852 zero coupon american put option price. ve™tor<double> ™oupon times. ™out << " coupon bond put option price = " << ˜ond option pri™e put ™oupon ˜ond ˜l—™k s™holes(f. double sigm—=0. ve™tor<double> ™oupons. double time=1.1.time) << endl.

1 The Merton Model „his ˜uilds on the fl—™k —nd ƒ™holes @IWUQA —nd werton @IWUQA fr—mework to (nd the v—lue of the de˜t issued ˜y the (rmF „he ide—s were —lre—dy in fl—™k —nd ƒ™holesD who dis™ussed the view of the (rm —s — ™—ll optionF essume de˜t stru™tureX „here is — single de˜t issueF he˜t is issued —s — zero ™oupon ˜ondF „he ˜ond is due on — given d—te T F essuming the (rm v—lue V follows the usu—l frowni—n motion pro™esD de˜t is found —s — ™losed form solutionD simil—r in stru™ture to the fl—™k ƒ™holes equ—tion for — ™—ll optionF i—siest seen from the interpret—tion of (rm de˜t —s the pri™e of risk free de˜tD minus the v—lue of — put optionF €ri™e de˜t ˜y the pri™e B of risk free de˜tD —nd then su˜tr—™t the pri™e of the putD using the fl—™k ƒ™holes formul—F „he fl—™k ƒ™holes formul— for — ™—ll option is c = S · N (d1 ) − K · e−r(T −t) N (d2 ) where d1 = ln S K + (r + 1 σ)(T − t) √ 2 σ T −t √ d2 = d1 − σ T − t N (·) = „he ™umul—tive norm—l distri˜ution p = Ke−r(T −t) N (−d2 ) − SN (−d1 ) sn the ™ontext hereD reinterpret S —s V D (rm v—lueF „he put is pri™ed —s p = Ke−r(T −t) N (−d2 ) − Vt N (−d1 ) where d1 = ln Vt K + (r + 1 σ)(T − t) √ 2 σ T −t xote on interpret—tionX „he spre—d ˜etween risky —nd risk free de˜t determined solely ˜y the pri™e of the put optionF 19.2 Issues in implementation • pirm v—lue —nd (rm vol—tility is uno˜serv—˜leF • „he model —ssumes — simple de˜t stru™tureD most de˜t stru™tures tend to ˜e more ™omplexF IRP .Chapter 19 Credit risk yption pri™ing h—s o˜vious —ppli™—tions to the pri™ing of risky ˜ondsF 19.

double „=1. double sigm—=0. double r=0.„he ™urrent v—lue of the (rm V = 100F „he (rm h—s issued one ˜ond with f—™e v—lue WHD whi™h is due to ˜e p—id one ye—r from nowF „he risk free interest r—te is S7 —nd the vol—tility of the (rms v—lue is PS7F hetermine the v—lue of the de˜tF g++ progr—mX #include "fin_recipes. ™out << " Debt value = " << exp(−r*„)*p − p << endl.p.sigm—.„). double †=100. double p=90. yutput from g++ progr—mX Credit Risk Calculation Debt value = 81.25. }.h" #include <™m—th> void test ™redit risk(){ ™out << " Credit Risk Calculation " << endl.05.8592 IRQ . double p = option pri™e put ˜l—™k s™holes(†.r.

1 The Nelson Siegel term structure approximation 1 − e− λ t λ t €roposed ˜y xelson —nd ƒiegel @IWVUAF r(t) = β0 + (β1 + β2 ) + β2 e− λ t „he implement—tion of this ™—l™ul—tion is shown in PHFI „his is wr—pped in — term stru™ture class —s shown in ™odes PHFP —nd PHFQF 20.Chapter 20 Term Structure Models ‡e now exp—nd on the —n—lysis of the term stru™ture in ™h—pter RF es shown thereD the term stru™ture is ˜est viewed —s —n —˜str—™t ™l—ss providingD —s fun™tions of term to m—turityD the pri™es of zero ™oupon ˜onds @dis™ount f—™torsAD yield on zero ™oupon ˜onds @spot r—tesA or forw—rd r—tesF sn the e—rlier ™—se we ™onsidered two p—rti™ul—r implement—tions of the term stru™tureX e )—t term stru™ture or — term stru™ture estim—ted ˜y line—r interpol—tions of spot r—tesF ‡e now ™onsider — num˜er of —ltern—tive term stru™ture modelsF „he fo™us of this ™h—pter is empiri™—lD we ™onsider w—ys in whi™h on one ™—n spe™ify — term stru™ture in — lower dimension—l w—yF issenti—lly we —re looking —t w—ys of doing ™urveE(ttingD of estim—ting — nonline—r rel—tionship ˜etween time —nd dis™ount f—™torsD or ˜etween time —nd spot r—tesF ƒin™e the rel—tionship is nonline—rD this is — nontrivi—l pro˜lemF yne h—s to ™hoose — fun™tion—l form to estim—teD whi™h —llows enough )exi˜ility to (t the term stru™tureD ˜ut not so )exi˜le th—t it viol—tes the e™onomi™ restri™tions on the term stru™tureF rere —re some ™onsider—tionsF • his™ount f—™tors must ˜e positiveF @dt > 0AF „his is ˜e™—use they —re pri™esD neg—tive pri™es —llow for —˜ritr—geF • his™ount f—™tors must ˜e — nonin™re—sing fun™tion of timeF @dt ≥ dt+k ∀ k > 0AF eg—inD this is to —void —r˜itr—geF • xomin—l interest r—tes ™—n not ˜e neg—tiveF @rt ≥ 0 ∀ t) „his is —nother impli™—tion of the —˜sen™e of —r˜itr—ge opportunitiesF • foth dis™ount f—™tors —nd interest r—tes must ˜e smooth fun™tions of timeF • „he v—lue of — p—yment tod—y is the p—yment tod—yF d0 = 1F e num˜er of —ltern—tive w—ys of estim—ting the term stru™ture h—s ˜een ™onsideredF ƒome —re purely used —s interpol—tion fun™tionsD while others —re fully spe™i(edD dyn—mi™ term stru™ture modelsF yf the models th—t followD the —pproxim—ting fun™tion proposed in xelson —nd ƒiegel @IWVUA —nd the ™u˜i™ spline used ˜y eFgF w™gullo™h @IWUIA —re ex—mples of the (rst kindD —nd the term stru™ture models of goxD sngersollD —nd ‚oss @IWVSA —nd †—si™ek @IWUUA —re ex—mples of the se™ond kindF ‡h—t is the typi™—l use of the fun™tions we ™onsider herec yne st—rts with — set of (xed in™ome se™uritiesD typi™—lly — set of tre—sury ˜ondsF y˜serving the pri™es of these ˜ondsD one —sksX ‡h—t set of dis™ount f—™tors is most likely to h—ve gener—ted the o˜served pri™esF yrX ‡h—t term stru™ture —pproxim—tions provides the ˜est (t to this set of o˜served ˜ond pri™esF 20.2 Bliss 1 − e− λ1 t λ1 t sn fliss @IWVWA — further development of xelson —nd ƒiegel @IWVUA w—s proposedF r(t) = γ0 + γ1 + γ2 1 − e− λ2 t λ2 t − e− λ2 t IRR .

}. γ2 . const double& ˜P. term stru™ture ™l—ss { l—m˜d— double& ˜et—H. λ1 . class term stru™ture ™l—ss nelson private: double ˜et—H . γ1 . const double& ˜et—I.h" term stru™ture ™l—ss nelson siegelXXterm stru™ture ™l—ss nelson siegel( ˜et—H }.#include <™m—th> using namespace std. double& ˜et—H.1: g—l™ul—tion of the xelson —nd ƒiegel @IWVUA term stru™ture model siegel X . double& ˜et—P. C++ Code 20. virtual double yield(const double& „) const. double r = ˜et—H + (˜et—I+˜et—P) return r. ˜et—I =˜I. const double& ˜et—P. return term stru™ture yield nelson siegel(t.0) return ˜et—H. λ2 }F #include "fin_recipes. ˜et—I . const const const const double& t. }.˜et—I . const double& l) { term stru™ture ™l—ss nelson siegelXX£term stru™ture ™l—ss nelson siegel(){}. double term stru™ture ™l—ss nelson siegelXXyield(const double& t) const { if (t<=0.l—m˜d— ). re—der (le de(ning — term stru™ture ™l—ss wr—pper for the xelson ƒiegel —pproxim—tion term stru™ture ™l—ss nelson siegel(const }. double term stru™ture yield nelson siegel(const if (t==0. l—m˜d— =l. double tl = t/l—m˜d—.3: he(ning — term stru™ture ™l—ss wr—pper for the xelson ƒiegel —pproxim—tion IRS . C++ Code 20. ˜et—P public: public . double& ˜et—I.2: „his h—s S p—r—meters to estim—teX {γ0 . =˜H.˜et—H .0) return ˜et—H . const double& ˜I. const double& ˜H. const double& l—m˜d—). C++ Code 20.˜et—P . ˜et—P =˜P. double& l—m˜d—) ˜et—P { * ((1−exp(−tl))/tl) + * exp(−tl).

yield = 0. double ˜et—P=0. ™out << " direct calculation.0.0363142 discount factor (t=1) = 0.˜et—I.yield(t) << endl.0300602 IRT .964337 forward rate (t1=1. siegel(){ ˜et—I=0.˜et—H. t2=2) = 0.01.01. ™out << " forward rate (t1=1.0. }.g++ progr—mX void test term stru™ture nelson double ˜et—H=0.0363142 using a term structure class yield (t=1) = 0.˜et—P.01. ™out << "Example calculations using the Nelson Siegel term structure approximation" << endl.2) << endl. ™out << " using a term structure class" << endl. yutput from g++ progr—mX Example calculations using the Nelson Siegel term structure approximation direct calculation.dis™ount f—™tor(t) << endl. t2=2) = " << ns.l—m˜d—). ™out << " yield (t=1) = " << ns. term stru™ture ™l—ss nelson siegel ns(˜et—H. double double t=1.˜et—P.l—m˜d—) << endl. ™out << " discount factor (t=1) = " << ns.˜et—I. double l—m˜d—=5. yield = " << term stru™ture yield nelson siegel(t.forw—rd r—te(1.

· · · . }. C++ Code 20.i++) { if (t >= knots[i]) { d += f [i] * (pow((t−knots[i]). virtual £term stru™ture ™l—ss ™u˜i™ spline(). const ve™tor<double>& const ve™tor<double>& } f. knots){ return d. FK } sf the spline knots —re knownD this is — simple line—r regressionF gode ?? shows the ™—l™ul—tion using this —pproxim—tionF #include <™m—th> #include <ve™tor> using namespace double std. }. ve™tor<double> f .3 Cubic spline. }.20. const double& dI. F1 .5: „erm stru™ture ™l—ss wr—pping the ™u˜i™ spline —pproxim—tion IRU .size(). }. const double& ˜I. const double& ™I.0 + ˜I*t + ™I*(pow(t. gu˜i™ splines —re well known for their good interpol—tion ˜eh—viourF „he ™u˜i™ spline p—r—meteriz—tion w—s (rst used ˜y w™gullo™h @IWUIA to estim—te the nomin—l term stru™tureF re l—ter —dded t—xes in w™gullo™h @IWUSAF „he ™u˜i™ spline w—s —lso used ˜y vitzen˜erger —nd ‚olfo @IWVRAF sn this ™—se the qu˜i™ spline is used to —pproxim—te the discount factorD not the yieldsF K d(t) = 1 + b1 t + c1 t2 + d1 t3 + j=1 Fj (t − tj )3 1{t<tj } rere 1{A} is the indi™—tor fun™tion for —n event AD —nd we h—ve K „o estim—te this we need to (nd the 3 + K p—r—metersX knots F {b1 . d1 . const ve™tor<double>& f. double d .3)). C++ Code 20. public: term stru™ture ™l—ss ™u˜i™ spline(const double& ˜. for (int i=0. c1 . double ™ . const double& ™. term stru™ture dis™ount f—™tor ™u˜i™ spline(const double d = 1.2)) + dI*(pow(t.h" #include <ve™tor> using namespace std. double& t.4: epproxim—ting — dis™ount fun™tion using — ™u˜i™ spline godes PHFS —nd PHFT wr—ps this ™—l™ul—tions into — term stru™ture ™l—ssF #include "fin_recipes. const ve™tor<double> & knots). const double& d.i<knots.3)). else { break. ve™tor<double> knots . virtual double dis™ount f—™tor(const double& „) const. class term stru™ture ™l—ss ™u˜i™ spline X public term stru™ture ™l—ss { private: double ˜ .

f. ™ = ™. if (f. f.™le—r().01). }.1 Using a term structure class yield (t=1) = -0.™. t2=2) = 0. term stru™ture ™l—ss ™u˜i™ spline ™s(˜. double ™=0.size()){ return. const { C++ Code 20.#include "fin_recipes.i<f.size()!=knots. ve™tor<double> knots.0953102 discount factor (t=1) = 1.forw—rd r—te(1.6: „erm stru™ture ™l—ss wr—pping the ™u˜i™ spline —pproxim—tion g++ progr—mX void test term stru™ture ™u˜i™ spline(){ ™out << "Example term structure calculations using a cubic spline " << endl.˜. ve™tor<double> f .1 forward (t1=1.knots ).knots) << endl. double ˜=0.push ˜—™k(−0.push ˜—™k(0.f . const ve™tor<double>& f.push ˜—™k(knots[i]). const double& ˜. knots.push ˜—™k(7).f.push ˜—™k(f [i]).™le—r(). }. knots. f . knots. ™out << " Using a term structure class " << endl.2) << endl. ™out << " yield (t=1) = " << ™s.size().yield(1) << endl.d . }. }.318454 IRV .push ˜—™k(2).h" term stru™ture ™l—ss ™u˜i™ splineXX term stru™ture ™l—ss ™u˜i™ spline ( ˜ = ˜.push ˜—™k(12).1.01). discount factor (t=1) 1. f.knots).push ˜—™k(0. yutput from g++ progr—mX Example term structure calculations using a cubic spline direct calculation. double d=−0. knots . double term stru™ture ™l—ss ™u˜i™ return term stru™ture dis™ount }. }. ™out << " forward (t1=1. knots . discount factor (t=1) " << term stru™ture dis™ount f—™tor ™u˜i™ spline(1. d = d.™.d. { term stru™ture ™l—ss ™u˜i™ splineXX£term stru™ture ™l—ss ™u˜i™ spline(){ f .™le—r().™ . splineXXdis™ount f—™tor(const double& „) f—™tor ™u˜i™ spline(„.1.dis™ount f—™tor(1) << endl. const ve™tor<double>& knots) knots . ™out << " discount factor (t=1) = " << ™s.d. const double& ™. for (int i=0.01).f.1.++i) { f .™le—r(). ™out << " direct calculation. t2=2) = " << ™s. const double& d.˜ .

T ) = 2eγ(T −t) − 1 (γ + κ + λ)(eλ(T −t) − 1) + 2γ pive p—r—metersX rD the short term interest r—teD κD the me—n reversion p—r—meterD λD the m—rket risk p—r—meterD θ the long!run me—n of the pro™ess —nd σ D the v—ri—n™e r—te of the pro™essF #include <™m—th> using namespace std. double& l—m˜d—. double enumI= 2*g—mm—*exp(0. double& k—pp—.7: g—l™ul—tion of the dis™ount f—™tor using the gox et —lF @IWVSA model IRW . double f = (2*(exp(g—mm—*t)−1))/denum.p). }. „he gox et —lF @IWVSA model is the most well!known ex—mple of — ™ontinous timeD gener—l equili˜rium model of the term stru™tureF „he term stru™ture model des™ri˜ed in gox et —lF @IWVSA is one of the most ™ommonly used in —™—demi™ workD ˜e™—use it is — gener—l equili˜rium model th—t still is simple enough to let us (nd ™losed form expressions for deriv—tive se™uritiesF „he short interest r—teF dr(t) = κ(θ − r(t))dt + σ r(t)dW „he dis™ount f—™tor for — p—yment —t time „F d(t. return df—™t.4 Cox Ingersoll Ross.5*(k—pp—+l—m˜d—+g—mm—)*t).2). double df—™t=e*exp(−f*r).0*sigm— sqr). const const const const const double& t. double p=2*k—pp—*thet—/sigm— sqr. T ) = (γ + κ + λ)(eλ(T −t) − 1) + 2γ —nd B(t.20. double term stru™ture dis™ount f—™tor ™ir(const double sigm— sqr=pow(sigm—. double& sigm—){ C++ Code 20. double denum = (g—mm—+k—pp—+l—m˜d—)*(exp(g—mm—*t)−1)+2*g—mm—. double g—mm— = sqrt(pow((k—pp—+l—m˜d—). double e = pow((enumI/denum). T ) = A(t.T )r(t) where γ= (κ + λ)2 + 2σ 2 1 2κθ σ2 2γe 2 (κ+λ+γ)(T −t) A(t.2)+2. T )e−B(t. double& thet—. double& r.

™out << " using a class " << endl.0498756 ISH . r.k—pp— .2) << endl. l—m˜d— =l. double l—m˜d—=0. C++ Code 20.08. l. double sigm—=0. thet— =th.05. =r. t2=2) = " << ™ir. const double& k. double thet—=0.1. public: ™ir X public term stru™ture ™l—ss { // interest rate // mean reversion parameter // risk aversion // long run mean // volatility £term stru™ture ™l—ss ™ir().l—m˜d—.9: gl—ss de(nitionD gox et —lF @IWVSA model g++ progr—mX void test term stru™ture ™ir(){ ™out << "Example calculations using the Cox Ingersoll Ross term structure model " << endl.h" term stru™ture ™l—ss ™irXX£term stru™ture ™l—ss ™ir(){.thet— .sigm— }. }. double sigm— . t2=2) = 0. ™out << " yield (t=1) = " << ™ir. virtual double dis™ount f—™tor(const double& „) const. }. double l—m˜d— . ™out << " forward (t1=1. double k—pp— . C++ Code 20.l—m˜d— .h" class term stru™ture ™l—ss private: double r . const double& sigm—) { =sigm—. ™out << " discount factor (t=1) = " << ™ir.951166 using a class yield (t=1) = 0.k—pp—.951166 forward (t1=1. double r = 0. const double& const double& th.01. term stru™ture ™l—ss ™ir ™ir(r. const double& sigm—). l.forw—rd r—te(1.#include "fin_recipes. ™out << " direct calculation. sigm— double& r. const double& const double& th.}. yutput from g++ progr—mX Example calculations using the Cox Ingersoll Ross term structure model direct calculation. sigm—) << endl.r . k—pp— =k. double k—pp—=0. discount factor (t=1): " << term stru™ture dis™ount f—™tor ™ir(1.dis™ount f—™tor(1) << endl. k—pp—. term stru™ture ™l—ss ™ir(const double& r.0. discount factor (t=1): 0.thet—.sigm—). ). double thet— . l—m˜d—. thet—. term stru™ture ™l—ss ™irXXterm stru™ture ™l—ss ™ir(const r }.yield(1) << endl.8: gl—ss de(nitionD gox et —lF @IWVSA modelD he—der (le #include "fin_recipes.0500668 discount factor (t=1) = 0. double term stru™ture ™l—ss ™irXXdis™ount f—™tor(const double& „) const{ return term stru™ture dis™ount f—™tor ™ir(„. const double& k.

time.}. C++ Code 20. double& ˜. double& —. }.3))/6. C++ Code 20. − exp(−—*time))/—.12: gl—ss de(nitionD †—si™ek @IWUUA model ISI . const double& sigm—). if (—==0. const double& —.0){ f e { = = } const const const const double& time. =r. double — .r . double& r.5*sigm— sqr))/—— −((sigm— sqr*f*f)/(4*—))). double& sigm—){ sigm—*sigm—. }. sigm— =sigm—.— . — =—. const double& ˜. ˜ =˜. term stru™ture ™l—ss v—si™ekXXterm stru™ture ™l—ss v—si™ek(const r }.0 = exp( double df—™t = return df—™t.0. const double& virtual double dis™ount f—™tor(const double& „) const. exp(sigm— sqr*pow(time.h" gl—ss de(nitionD †—si™ek @IWUUA model term stru™ture ™l—ss v—si™ekXX£term stru™ture ™l—ss v—si™ek(){. —.h" g—l™ul—ting — dis™ount f—™tor using the †—si™ek fun™tion—l form class term stru™ture ™l—ss v—si™ek X public term stru™ture ™l—ss { private: double r .11: #include "fin_recipes. double term stru™ture dis™ount f—™tor v—si™ek(const double e. C++ Code 20. } e*exp(−f*r). f e = (1.20. double& r. const double& ˜.10: #include "fin_recipes.5 Vasicek #include <™m—th> using namespace std. ((f−time)*(——*˜−0.sigm— ). else }.˜ . double ˜ . public: term stru™ture ™l—ss v—si™ek(const double& r. double sigm— .f. const double& sigm—) { double term stru™ture ™l—ss v—si™ekXXdis™ount f—™tor(const double& „) const{ return term stru™ture dis™ount f—™tor v—si™ek(„. double sigm— sqr = double —— = —*—.

double sigm—=0. term stru™ture ™l—ss v—si™ek v™(r.955408 forward rate (t1=1.—.dis™ount f—™tor(1) << endl. ™out << " yield (t=1) = " << v™.1. r. double —=−0. double r=0. } yutput from g++ progr—mX Example term structure calculation using the Vasicek term structure model direct calculation.g++ progr—mX void test term stru™ture v—si™ek() { ™out << "Example term structure calculation using the Vasicek term structure model" << endl. sigm—) << endl. discount factor (t=1): " << term stru™ture dis™ount f—™tor v—si™ek(1. ™out << " direct calculation.2) << endl.1. double ˜=0.yield(1) << endl.05. ™out << " forward rate (t1=1.forw—rd r—te(1. ˜.1.955408 using a term structure class yield (t=1) = 0. discount factor (t=1): 0.˜.0456168 discount factor (t=1) = 0. t2=2) = " << v™.0281476 ISP . ™out << " discount factor (t=1) = " << v™. ™out << " using a term structure class " << endl.sigm—). t2=2) = 0. —.

„he methods in this ™h—pter s (rst studied in my dissert—tion —t g—rnegie wellon …niversity in IWWPD whi™h w—s pu˜lished in qreen —nd Ødeg——rd @IWWUAF ISQ .

1 The Rendleman and Bartter model „he ‚endlem—n —nd f—rtter —ppro—™h to v—lu—tion of interest r—te ™ontingent ™l—ims @see ‚endlem—n —nd f—rtter @IWUWA —nd ‚endlem—n —nd f—rtter @IWVHAA is — p—rti™ul—r simple oneF issenti—llyD it is to —pply the s—me ˜inomi—l —ppro—™h th—t is used to —pproxim—te options in the fl—™k ƒ™holes worldD ˜ut the r—ndom v—ri—˜le is now the interest r—teF „his h—s impli™—tions for multiperiod dis™ountingX „—king the present v—lue is now — m—tter of ™hoosing the ™orre™t sequen™e of spot r—tesD —nd it m—y ˜e ne™ess—ry to keep tr—™k of the whole tree of interest r—tesF „he gener—l ide— is to ™onstru™t — tree —s shown in (gure PIFIF ¨ ¨r0 r rr ¨¨ ¨¨ = ur0 B r ¨ rru ¨¨ rr ¨ rr ¨¨ rr ¨ ¨¨ ¨ B ¨ ruu = uur0 ¨¨ ¨ r j r B ¨ ¨ rud = udr0 ¨ r r ¨r = dr j r 0 rd rr rr r r r = ddr j r dd 0 The gure illustrates the building of an interest rate tree of one period spot rates by assuming that for any given period t the next period interest rate can only take on two values. where u and d are constants. pigure PIFIX snterest r—te tree gode PIFI shows how one ™—n ™onstru™t su™h —n interest r—te treeF ƒu™h — tree ™—n then ˜e used to pri™e v—rious (xed in™ome se™uritiesF ‡e will do this in — l—ter version of this m—nus™riptD ˜ut for now we just show — dire™t implement—tion of the origin—l modelF gode PIFP implements the origin—l —lgorithm for — ™—ll option on — @long m—turityA zero ™oupon ˜ondF 21. rt+1 = urt or rt+1 = drt .2 Readings qener—l referen™es in™lude ƒund—res—n @PHHIAF ‚endlem—n —nd f—rtter @IWUWA —nd ‚endlem—n —nd f—rtter @IWVHA —re the origin—l referen™es for ˜uilding st—nd—rd ˜inomi—l interest r—te treesF ISR .Chapter 21 Binomial Term Structure models €ri™ing ˜ond options with the fl—™k ƒ™holes modelD or its ˜inomi—l —pproxim—tionD —s done in ™h—pter IVD does not —lw—ys get it rightF por ex—mpleD it ignores the f—™t th—t —t the m—turity of the ˜ondD the ˜ond vol—tility is zeroF „he ˜ond vol—tility de™re—ses —s one gets ™loser to the ˜ond m—turityF „his ˜eh—viour is not ™—ptured ˜y the —ssumptions underlying the fl—™k ƒ™holes —ssumptionF ‡e therefore look —t more ™ompli™—ted term stru™ture modelsD the unifying theme of whi™h is th—t they —re ˜uilt ˜y ˜uilding trees of the interest r—teF 21. r0 is the initial spot rate.

C++ Code 21.1: fuilding —n interest r—te tree ISS .j<i.++j){ r[j] = rH*pow(u. }.i−j−1). const double& u. const int& n){ tree. double& rH. }. return tree. ve™tor< ve™tor<double> > ˜uild interest r—te tree rendlem—n ˜—rtter(const for (int ve™tor< ve™tor<double> > tree. i=1.i<=n. }.++i){ ve™tor<double> r(i).push ˜—™k(r). const double& d.using namespace #include <ve™tor> #include <™m—th> std.j)*pow(d. for (int j=0.

ve™tor<double> r(no steps+1). int no ™—ll steps=int(no steps*option m—turity/˜ond m—turity).i<=no steps. double ˜ond m—turity int no steps=100. ˜ond m—turity p—yment. p up = (exp(w*delt— t)−d)/(u−d). double ˜ond m—turity=5. return g[0].i++) { r[i] = r[i]*u. // term structure paramters double& interest. w. option m—turity.2: g++ progr—mX ‚f ˜inomi—l model for iurope—n ™—ll on zero ™oupon ˜ond void test rendlem—n ˜—rtter zero ™oupon ™—ll() { double u=950.10.00713661 IST .™urr step>no ™—ll steps. }. for (int i=0. for (int i=1. double ƒ=0.i<=no ™—ll steps. €[i] = exp(−r[i]*delt— t)*(p down*€[i]+p up*€[i+1]). const const const const const const const double& ˆ. exp(−r[i]*delt— t)*(p up*g[i+1]+p down*g[i])).i<=no steps. double w=0.i<™urr step. ™out << " Rendleman Bartter price of option on zero coupon bond: ".05.−−™urr step) { for (int i=0. int& no steps) { underlying bon u=exp(ƒ*sqrt(delt— t)).0−p up. p down = 1.no steps). double ˜ond option pri™e ™—ll zero —meri™—n rendlem—n ˜—rtter(const double double double double double delt— t = ˜ond m—turity/no steps. interest. double option m—turity=4. }. ƒ. // current short interest rate double& ˜ond m—turity. // time to maturity for double& m—turity p—yment. C++ Code 21.€[i]−ˆ). ˜ond m—turity.i<™urr step. for (int i=0. no steps).0. p—yment=1000. g[i]=m—x(€[i]−ˆ.++i){ g[i]=m—x(0.++i){ €[i] = m—turity p—yment.i++) { r[i] = r[i]*u. double uu=u*u. ve™tor<double> €(no steps+1). yutput from g++ progr—mX Rendleman Bartter price of option on zero coupon bond: c = 0. double& ƒ. }. €[i] = exp(−r[i]*delt— t)*(p down*€[i]+p up*€[i+1]). for (int ™urr step=no steps.™urr step>=0. double& w.15. for (int ™urr step=no ™—ll steps. d=1/u. r[0]=interest*pow(d. }. double ™ = ˜ond option pri™e ™—ll zero —meri™—n rendlem—n ˜—rtter( u.}. ™out << " c = " << ™ << endl. }. double interest=0.++i){ r[i]=r[i−1]*uu. { ve™tor<double> g(no ™—ll steps+1).#include <™m—th> #include <—lgorithm> #include <ve™tor> using namespace std. }. }. }.−−™urr step) for (int i=0. double& option m—turity.

s)N (h) − XP (t. T )B(T. T ) = σ T − t √ σP = σ(s − T ) T − t ISU . T )2 = sn the ™—se of a = 0D √ v(t. s) ˜e the time t pri™e of — zero ™oupon ˜ond with — p—yment of 6I —t time s @the dis™ount f—™torAF „he pri™e —t time t of — iurope—n ™—ll option m—turing —t time T on on — dis™ount ˜ond m—turing —t time s is @ƒee t—mshid—n @IWVWA —nd rull @IWWQAA P (t.1 Vasicek bond option pricing sf the term stru™ture model is †—si™ek9s model there is — solution for the pri™e of —n option on — zero ™oupon ˜ondD due to t—mshid—n @IWVWAF …nder †—™isek9s model the pro™ess for the short r—te is —ssumed to followF dr = a(b − r)dt + σdZ where aD b —nd σ —re ™onst—ntsF ‡e h—ve seen e—rlier how to ™—l™ul—te the dis™ount f—™tor in this ™—seF ‡e now w—nt to ™onsider —n iurope—n g—ll option in this settingF vet P (t. T )X 2 σP = v(t. T ) = 1 − e−a(T −t) a σ 2 (1 − e−a(T −t) ) 2a v(t. s) B(t. T )N (h − σP ) where h= 1 P (t.Chapter 22 Term Structure Derivatives 22. s) 1 ln + σP σP P (t.

sigm—)/ stru™ture dis™ount f—™tor v—si™ek(„ t. f „ s = (1−exp(−—*„ s))/—.1.0/sigm— }. double& —. double „ s = s t−„ t. yutput from g++ progr—mX Vasicek call option price 0. sigm— € = v t „*f „ s.˜. double r = 0. // exercise price double& r. ™out << " Vasicek call option price " << ˜ond option pri™e ™—ll zero v—si™ek(ˆ.#include "normdist. (term = (1. double ˆ=0. v t „ { = } const const const const const const double& ˆ. double ™ = term stru™ture dis™ount f—™tor v—si™ek(s t. sigm— € = sigm—*„ s*sqrt(„ t).˜. if (—==0.5. double }. return ™. double s t = ˜ond time to m—turity.˜.sigm—)*x(h−sigm— €). double& ˜ond time to m—turity. double h }.05.—.˜.9. double& sigm—){ else sqrt (sigm—*sigm—*(1−exp(−2*—*„ t))/(2*—)).0) { v t „ = sigm— * sqrt ( „ t ) .sigm—) << endl. double sigm— €.sigm—)*ˆ) ) + sigm— €/2. sigm— = 0.1.r. C++ Code 22. // parameters double& ˜. double €) * log (term stru™ture dis™ount f—™tor v—si™ek(s t.000226833 ISV .˜.1.h" #include "fin_recipes.—. double v t „.r.—.02.sigm—)*x(h) −ˆ*term stru™ture dis™ount f—™tor v—si™ek(„ t.—.r.—.r. // current interest rate double& option time to m—turity.r.0.1: fond option pri™ing using the †—si™ek model g++ progr—mX void test v—si™ek option pri™ing(){ double — = 0. double ˜ond option pri™e ™—ll zero v—si™ek(const double „ t = option time to m—turity.h" #include <™m—th> using namespace std. double ˜ = 0.

0*€s))*exp(−0. // which is part of the standard #ifndef €s #dene €s #endif namespace // most C compilers dene PI.141592653589793238462643 double n(const double& z) { // normal distribution return (1.1 The normal distribution function n(x) = e− x2 2 „he nurm—l distri˜ution fun™tion is ™—l™ul—ted —s #include <™m—th> // c library of math functions using namespace std. }.1: „he norm—l distri˜ution fun™tion A.5*z*z).0/sqrt(2. ‡e will in gener—l not go into det—il —˜out more st—nd—rd numeri™—l pro˜lems not ™onne™ted to (n—n™eD there —re — num˜er of well known sour™es for su™hD ˜ut we show the ex—mple of ™—l™ul—tions involving the norm—l distri˜utionF A.2 The cumulative normal distribution „he solution of — l—rge num˜er of option pri™ing formul—s —re written in terms of the ™umul—tive norm—l distri˜utionF por — r—ndom v—ri—˜le x the ™umul—tive pro˜—˜ility is the pro˜—˜ility th—t the out™ome is lower th—n — given v—lue z F „o ™—l™ul—te the pro˜—˜ility th—t — norm—lly distu˜uted r—ndom v—ri—˜le with me—n 0 —nd unit v—ri—n™e is less th—n z D N (z)D one h—ve to ev—lu—te the integr—l z z Prob(x ≤ z) = N (z) = −∞ n(x)dx = −∞ e− x2 2 dx „here is no expli™it ™losed form solution for ™—l™ul—tion of this integr—lD ˜ut — l—rge num˜er of well known —pproxim—tions existsF e˜r—mowiz —nd ƒtegun @IWTRA is — good sour™e for these —pproxim—tionsF „he following is pro˜—˜ly the most used su™h —pproxim—tionD it ˜eing pretty —™™ur—te —nd rel—tively f—stF „he —rguments to the fun™tion —re —ssumed norm—lized to — @HDI A distri˜utionF A.Appendix A Normal Distribution approximations. function C++ Code A. but just in case it doesn't 3.3 Multivariate normal vector of „he norm—l distri˜ution is —lso de(ned for sever—l r—ndom v—ri—˜lesF ‡e then ™h—r—™terise the r—ndom v—ri—˜les   x1  x2    X= F   F  F xn ISW .

356563782.3989423. ˜ = ™P*exp((−z)*(z/2. double x(const double& z) { if (z > 6. ™P = 0. }. C++ Code A. p = 0.0 − n. // if (z < −6.330274429. 1]F „he ™umul—tive pro˜—˜ility distri˜ution P (x < a.2316419.0) { return 0. y < b) = N (a. ˜S = 1.0−˜*n.0/(1.0+—*p). ˜Q = 1. this guards against overow —=f—˜s(z).2: „he ™umul—tive norm—l e pro˜—˜ility st—tement —˜out this ve™tor is — joint st—tement —˜out —ll elements of the ve™torF A.781477937.0. double double double double double double double double double double double ˜I = 0. }. b. ˜P = −0.0) { return 1. t = 1.821255978. functions.4 Calculating cumulative bivariate normal probabilities „he most used multiv—ri—te norm—l ™—l™ul—tion is the ˜iv—ri—te ™—seD where we let x —nd y ˜e ˜iv—ri—te norm—lly distri˜utedD e—™h with me—n H —nd v—ri—n™e ID —nd —ssume the two v—ri—˜les h—ve ™orrel—tion of ρF fy the de(nition of ™orrel—tion ρ ∈ [−1.0.0 ) n = 1.#include <™m—th> // math using namespace std. return n. if ( z < 0. n = 1.31938153. }.0)). n = ((((˜S*t+˜R)*t+˜Q)*t+˜P)*t+˜I)*t. ρ) a b −∞ = −∞ 1 2π 1 − ρ2 exp − 1 x2 − 2ρxy + y 2 2 1 − ρ2 dxdy „here —re sever—l —pproxim—tions to this integr—lF ‡e pi™k one su™hD dis™ussed in @rullD IWWQD gh IHAD shown in ™ode eFQ sf one h—s more th—n two ™orrel—ted v—ri—˜lesD the ™—l™ul—tion of ™umul—tive pro˜—˜ilites is — nontrivi—l pro˜lemF yne ™ommon method involves wonte g—rlo estim—tion of the de(nite integr—lF ‡e will ™onsider thisD ˜ut then it is ne™ess—ry to (rst ™onsider simul—tion of r—ndom norm—l v—ri—˜lesF ITH . ˜R = −1.

( sqrt(1.0) && (rho<=0. double f[4]={0. }.3253030.rhoI) + x(˜.4211071. −rho). return x(—. double rhoI = ((rho * — − ˜) * sgn(—))/denum.9.0−rho*rho)/€s).#include <™m—th> // include the standard library mathematics using namespace std.0*(1.0.rho).i++) { for (int j=0. return −1.i<4. const double& ˜prime. }. 0. }.0*(1.3425378. double sum = 0. return } sum = sum * sum.f[j]. // which are in the standard namespace functions double x(const double&).0 ) { if ( ( —<=0. const double& rho) if ( (—<=0. −˜.0) && (˜<=0. for (int i=0.0−sgn(—)*sgn(˜))/4. double e[4]={0. }.0) ) { else if ( (—>=0.2626645 }.0.0) ) { double —prime = —/sqrt(2. } { else if ( — * ˜ * rho >= 0.1337764.141592653589793238462643. else if ( — * ˜ * rho <= 0.6243247.0) ) return x(—) + x(˜) − 1. alternatively throw exception C++ Code A.0. }. }.006374323}.rhoP) − delt—. inline double f (const double& x. double ˜prime = ˜/sqrt(2. } (rho>=0. −rho). 0.—prime. double rhoP = ((rho * ˜ − —) * sgn(˜))/denum. −˜.0) ) { else if ( (—>=0. j<4.0) && (˜>=0.0 ) && ( ˜>=0. const double& rho) { double r = —prime*(2*x−—prime) + ˜prime*(2*y−˜prime) + return exp(r). }. rho). } (rho>=0. 1.0.0) && (˜<=0.0) && return x(˜) − x(−—.0. 2*rho*(x−—prime)*(y−˜prime). inline double sgn(const double& if (x>=0.1334425. const double& ˜.3: epproxim—tion to the ™umul—tive ˜iv—ri—te norm—l ITI . 0.0. const double& —prime. j++) { sum += { e[i]*e[j]* f (f[i]. 2. // dene the univariate cumulative normal distribution as a separate function #ifndef €s const double #endif €s=3.0 ) && return x(—) − x(—.˜prime.0) && (rho<=0.0 + x(−—. double delt—=(1.0−rho*rho)).0) return 1. const double& y.0. 0. ˜. return −99.0 ) { double denum = sqrt(—*— − 2*rho*—*˜ + ˜*˜).0−rho*rho)). x) { // sign function double x(const double& —. // should never get here.

5 N(0.0) << endl.0. ™out << " N(0. test ™umul—tive norm—l() { ™out << " N(0) = " << x(0) << endl.25 ITP .0) = " << x(0.h" void }.0.0.g++ progr—mX #include "normdist. yutput from g++ progr—mX N(0) = 0.0) = 0.

€seudor—ndom num˜ers from —n uniform [0. 1) distri˜ution A.7 References „ong @IWWHA dis™usses the multiv—ri—te norm—l distri˜utionD —nd is — good referen™eF ITQ .0.5 Simulating random normal numbers qener—tion of r—ndom num˜ers is — l—rge topi™ —nd is tre—ted —t length in su™h sour™es —s unuth @IWWUAF „he gener—ted num˜ers ™—n never ˜e truly r—ndomD only pseudoEr—ndomD they will ˜e gener—ted —™E ™ording to some reprodu™i˜le —lgorithm —nd —fter — @l—rgeA num˜er of r—ndom num˜er gener—tions the sequen™e will st—rt repe—ting itselfF „he num˜er of iter—tions ˜efore repli™—tion st—rts is — me—sure of the qu—lity of — r—ndom num˜er gener—torF por —ny˜ody requiring highEqu—lity r—ndom num˜er gener—tors the rand() fun™tion provided ˜y the st—nd—rd g++ li˜r—ry should ˜e —voidedD ˜ut for not getting into involved dis™ussion of r—ndom num˜er gener—tions we use this fun™tion —s — ˜—sis for the gener—tion of uniformly distri˜uted num˜ers in the interv—l [0. }.0*log(ƒ))/ƒ). C++ Code A. C++ Code A. †I = 2. …P = r—ndom uniform H I(). „hese uniformly distri˜uted distri˜uted r—ndom v—ri—tes —re used —s — ˜—sis for the pol—r method for norm—l densities dis™ussed in unuth @IWWUA —nd inplemented —s shown in ™ode eFS #include <™m—th> #include <™stdli˜> //using namespace std. …P. return ˆI. †P = 2. while (ƒ>=1) { …I = r—ndom uniform H I(). †I.6 Cumulative probabilities for general multivariate distributions ‡hen moving ˜eyond the ˜iv—ri—te ™—se ™—l™ul—tion of pro˜—˜ility integr—ls ˜e™ome more of —n exer™ise in gener—l numeri™—l integr—tionF e typi™—l tool is wonte g—rlo integr—tionD ˜ut th—t is not the only possi˜ilityF A.2). }. weˆ).5: €seudor—ndom num˜ers from — norm—l (0. ƒ = pow(†I. †P. double r—ndom norm—l(void){ double …I. // this uses the C library random number generator. double ˆI=†I*sqrt((−2.0. double r—ndom uniform H I(void).0*…P−1. 1)D —s shown in ™ode eFRF #include <™stdli˜> double r—ndom uniform H I(void){ return double(r—nd())/double(‚exh }. 1) distri˜ution Replace the random_uniform function here by an alternative of higher quality. by looking into what numerical libraries is available on your computing platform. double ƒ=2.A.2)+pow(†P.4: Exercise 23. or by downloading a high quality random number generator from such places as mathlib or statlib.0*…I−1.

07224 0.++i){ ™out << " " << r—ndom uniform H I().36918 0.h" void test r—ndom norm—l(){ ™out << " 5 random uniform numbers between 0 and 1: ".1) numbers: ". ™out << endl.79844 0.840188 0. ™out << endl.783099 0.0187313 ITR .911647 5 random normal(0.g++ progr—mX #include "normdist.394383 0. }. yutput from g++ progr—mX 5 random uniform numbers between 0 and 1: 0.70202 1. }. for (int i=0. ™out << " 5 random normal(0.925946 2.1) numbers: -1.i<5.i<5. for (int i=0.++i){ ™out << " " << r—ndom norm—l(). }.

Appendix B C++ concepts „his ™h—pter ™ont—ins — listing of v—rious CGg++ ™on™epts —nd some notes on e—™h of themF bool foole—n v—ri—˜leD t—king on the two v—lues true —nd falseF por histori™—l re—sons one ™—n —lso use the v—lues zero —nd one for false —nd trueF class @g++ keywordAF const @qu—lifyer to v—ri—˜le in g++ fun™tion ™—llAF double @˜—si™ typeAF e )o—ting point num˜er with high —™™ur—™yF exp(x) @g fun™tionAF he(ned in <™m—th>F ‚eturns the n—tur—l exponent e to the given power xD ex F fabs float @˜—si™ typeAF e )o—ting point num˜er with limited —™™ur—™yF for voop header file if Indexation @in ve™tors —nd m—tri™esAF „o —™™ess element num˜er i in —n —rr—y AD use A[i-1]F ‡ell known tr—p for people ™oming to C from other l—ngu—gesF €resent in C for histori™—l e0™ien™y re—sonsF err—ys in C were implemented using pointersF sndexing w—s done ˜y (nding the (rst element of the —rr—yD —nd then —dding pointers to (nd the indexed elementF „he (rst element is of ™ourse found ˜y —dding nothing to the (rst elmentD hen™e the (rst element w—s indexed ˜y zeroF include inline @qu—lifyer to g++ fun™tion n—meAF rint to the optimizer th—t this fun™tion is most e0™iently implemented ˜y inlining itD or putting the full ™ode of the fun™tion into e—™h inst—n™e of its ™—llingF r—s the side e'e™t of m—king the fun™tion lo™—l to the (le in whi™h it is de(nedF int @˜—si™ typeAF en integer with — limited num˜er of signi(™—nt digitsF log(x) @g fun™tionAF he(ned in <™m—th>F g—l™ul—tes the n—tur—l log—rithm ln(x) of its —rgumentF long @˜—si™ typeAF en integer th—t ™—n ™ont—in — l—rge num˜erF namespace return standard namespace string using vector @gCC ™ont—iner ™l—ssAF he(ned in <ve™tor> while ITS .

h // author: Bernt Arne Oedegaard // denes all routines in the nancial numerical recipes  book #ifndef psx ‚igs€iƒ r #dene psx ‚igs€iƒ r #include <ve™tor> using namespace std. const double& ˜ond pri™e). const ve™tor<double>& prin™ip—l times. bool ™—sh )ow unique irr(const ve™tor<double>& ™)ow times. const double& t). const ve™tor<double>& ™—sh)ows. double ™—sh )ow pv dis™rete ( ///////////////////////////////// // continous compounding. const double& y ). const double& r). ITT . annual compounding const ve™tor<double>& ™)ow times. const ve™tor<double>& prin™ip—l —mounts. const double& r). double ˜onds dur—tion dis™rete(const ve™tor<double>& times.const ve™tor<double>& ™)ow —mounts. const ve™tor<double>& ™—sh)ows. ///////// present value //////////////////////////////////// // discrete coumpounding ///////////////////////////////// // discrete. ˜onds dur—tion m—™—ul—y(const ve™tor<double>& ™—sh)ow times. const ve™tor<double>& ™)ow —mounts.const double& r). ™—sh )ow irr(const ve™tor<double>& ™)ow times. const double& ˜ond pri™e). const ve™tor<double>& ™)ow —mounts. const double& r). /// term structure basics double double double term stru™ture yield from dis™ount f—™tor(const double& df—™t. const double& d tP. const ve™tor<double>& ™)ow —mounts). const ve™tor<double>& ™)ow —mounts). const ve™tor<double>& —mounts. const double& ˜ondpri™e). double ˜onds yield to m—turity dis™rete(const ve™tor<double>& times. double ™—sh )ow irr dis™rete(const ve™tor<double>& ™)ow times. double double double double double double double double ™—sh )ow pv(const ve™tor<double>& ™)ow times. const double& t). const ve™tor<double>& ™)ow —mounts). double ˜onds dur—tion m—™—ul—y dis™rete(const ve™tor<double>& ™—sh)ow times. const ve™tor<double>& ™—sh)ow —mounts. const double& r). double ˜onds dur—tion modi(ed dis™rete (const ve™tor<double>& times. const ve™tor<double>& ™oupon —mounts. const ve™tor<double>& ™—sh)ows. const double& r). ˜onds pri™e(const ve™tor<double>& ™oupon times. ˜onds dur—tion(const ve™tor<double>& ™—sh)ow times. const double& r). ˜onds pri™e(const ve™tor<double>& ™—sh)ow times. double ˜onds pri™e dis™rete(const ve™tor<double>& ™—sh)ow times. ˜onds ™onvexity(const ve™tor<double>& ™—sh)ow times. const ve™tor<double>& ™—sh)ows. const ve™tor<double>& ™—sh)ows. const ve™tor<double>& ™—sh)ows. term stru™ture dis™ount f—™tor from yield(const double& r. ˜onds yield to m—turity(const ve™tor<double>& ™—sh)ow times. const ve™tor<double>& —mounts. const double& r). const double& ˜ond pri™e).Appendix C Summarizing routine names sn m—ny of the —lgorithms use is m—de of other routinesF „o simplify the m—tter —ll routines —re sumE m—rised in one he—der (leD fin_recipes.hF „his —ppendix shows this (leF // le: n recipes. const double& ˜ondpri™e). term stru™ture forw—rd r—te from dis™ount f—™tors(const double& d tI.const ve™tor<double>& ™—sh)ow —mounts. double ˜onds ™onvexity dis™rete(const ve™tor<double>& ™)ow times.

}. virtual double forw—rd r—te(const double& tI. // using the term structure classes double double double ˜onds pri™e(const ve™tor<double>& ™—sh)ow times. // // virtual double discount factor(const double& t) const. double option pri™e ™—ll europe—n ˜inomi—l multi period given ud( const double& ˆ. const double& ƒ. class term stru™ture private: double ‚ . futures pri™e(const //// Futures pricing double double& ƒ. r. const double& r. const ve™tor<double>& ™—sh)ow —mounts. const ve™tor<double>& ™—sh)ows. virtual double yield(const double& „) const. interpol—ted(const double& time. term stru™ture ™l—ss interpol—ted(const ve™tor<double>& times. const double& time to m—turity). int no o˜serv—tions() const { return times . /// Binomial option pricing // one periode binomial double option pri™e ™—ll europe—n ˜inomi—l single period( // multiple periode binomial const double& ƒ. . virtual £term stru™ture ™l—ss interpol—ted(). class term private: public: stru™ture ™l—ss interpol—ted X . void set interpol—ted o˜serv—tions(ve™tor<double>& times. const double& tP). }. virtual £term stru™ture ™l—ss )—t(). const ve™tor<double>& ™—sh)ow —mounts. virtual double dis™ount f—™tor(const double& t) const. public: ™l—ss )—t X public term stru™ture ™l—ss { // interest rate term stru™ture ™l—ss )—t(const double& r). term stru™ture ™l—ss interpol—ted operator= (const term stru™ture ™l—ss interpol—ted&). tP. const double& d). const term stru™ture ™l—ss& d). class term stru™ture ™l—ss { public: virtual £term stru™ture ™l—ss(). virtual double term structure class at::forward rate(const double& t1. ITU . virtual double yield(const double& t) const. const ve™tor<double>& yields). const double& r. tP) const. // use to keep a list of yields term stru™ture ™l—ss interpol—ted(). set int r—te(const double& r).double double term stru™ture forw—rd r—te from yields(const term stru™ture yield line—rly // a term structure class const double& time). const double& u. const ve™tor<double>& o˜s times. const double& const double& u.size(). const ve™tor<double>& o˜s yields). const term stru™ture ™l—ss& d). const term stru™ture ™l—ss& d). ve™tor<double>& yields). double& r tI. ˜onds ™onvexity(const ve™tor<double>& ™—sh)ow times. const double& t2) const. ˜onds dur—tion(const ve™tor<double>& ™—sh)ow times. virtual double yield(const double& t) const. term stru™ture ™l—ss interpol—ted(const term stru™ture ™l—ss interpol—ted&). public term stru™ture ™l—ss { ve™tor<double> times ve™tor<double> yields void ™le—r(). const double& r const double& tI. const double& }. void }.

ve™tor< ve™tor<double> > ˜inomi—l tree(const double& ƒH. const double& sigm—. const double& u. const double& time). const double& t—uI). const double& time). double option pri™e delt— put ˜l—™k s™holes (const double& ƒ. const double& u. const double& r. const double& time). const double& u. option pri™e europe—n ™—ll dividends(const double& ƒ. const double& r. option pri™e —meri™—n ™—ll one dividend(const double& ƒ. const int& no periods). const double& u. futures option pri™e ™—ll europe—n ˜l—™k(const double& p. const double& r. const double& u. const double& sigm—. option pri™e europe—n put dividends( const double& ƒ. const double& r. s™holes (const double& ƒ. const double& u. double& helt—. const double& sigm—. const double& r. const double& ˜. ITV option pri™e europe—n ™—ll p—yout(const . double& r. const double& option pri™e). double& ‚ho). double& sigm—. double& no sh—res outst—nding). const double& r. double& no sh—res outst—nding). double& no w—rr—nts outst—nding. const double& time). double& ‚ho). const double& r. const double& u. const double& u.const double& const int& no steps). const ve™tor<double>& dividend —mounts ). const double& time). double& ƒ. const double& sigm—. const double& time) . const double& r. const double& time). const double& time. double& „het—. void option pri™e p—rti—ls ™—ll ˜l—™k s™holes(const double& ƒ. double& „het—. const double& time. const double& q. option pri™e europe—n put p—yout (const double& ƒ. const double& r. const double& time. const double& u. const double& sigm—. const double& sigm—. futures option pri™e put europe—n ˜l—™k(const double& p. const double& r. double w—rr—nt pri™e —djusted ˜l—™k s™holes(const const const const const /// Extensions of the Black Scholes model ////////////// double double double double double double double double double& ƒ. const double& option pri™e). const double& u. const double& r. const ve™tor<double>& dividend times. const double& sigm—. const double& r. const double& d. const double& r. double& q—mm—. const double& time. const double& time. double& r. const double& u. const double& r. const double& u. const double& time). const double& u. const double& u. double option pri™e delt— ™—ll ˜l—™k s™holes(const double& ƒ. const double& u. double& †eg—. double& no w—rr—nts outst—nding. const double& u. const double& r. const double& ƒ. const double& sigm—. const double& t—u. const double& ˜. const ve™tor<double>& dividend times. const double& sigm—. const double& time) . const double& u.const double& // multiple periode binomial u. ™urren™y option pri™e ™—ll europe—n(const double& ƒ. option pri™e implied vol—tility ™—ll ˜l—™k s™holes ˜ise™tions( /// warrant price double w—rr—nt pri™e —djusted ˜l—™k s™holes(const const const const const double& ƒ. const double& r. option pri™e implied vol—tility ™—ll ˜l—™k s™holes newton( double const double& ƒ. void option pri™e p—rti—ls put ˜l—™k s™holes(const double& ƒ.const double& time. const double& sigm—. d. const double& hI. const double& u. const double& sigm—. const ve™tor<double>& dividend —mounts). /// Black Scholes formula ////////////////////////////////////////// double double double option pri™e ™—ll ˜l—™k s™holes(const option pri™e put ˜l—™k double& ƒ. const double& sigm—. const double& sigm—. double& time. const double& u. const double& sigm—. double& helt—. double& †eg—. const double& r f. const double& sigm—. const double& time. double& q—mm—.

const double& time. const ve™tor<double>& dividend yields). double& veg—. double& p. const int& steps). // binomial option approximation //////////////// double double double double double double double option pri™e ™—ll europe—n ˜inomi—l(const option pri™e put europe—n option pri™e ™—ll —meri™—n option pri™e put —meri™—n option pri™e ™—ll —meri™—n option pri™e put —meri™—n double& ƒ. const double& ƒ. const double& const double& time. const double& sigm—. const int& no steps). const double& u. double& ƒ. const ve™tor<double>& dividend times. double option pri™e ™—ll —meri™—n proportion—l dividends ˜inomi—l(const double option pri™e put —meri™—n proportion—l dividends ˜inomi—l( double& ƒ. const double& time. ™—ll(const double& ƒ. const double& r. const double& r. const int& no const ve™tor<double>& dividend times. const int& steps. const int& no double& delt—. const double& sigm—). const steps). const double& t. double& rho). const double& u. const double& u. const int& no steps). const double& sigm—. const double& u. const ve™tor<double>& dividend —mounts). steps. const double& t. const double& sigm—. r. double& delt—. double& rho). const int& steps. double& g—mm—. const double& sigm—). const int& no steps. const double& r. const double& u. const double& y. void option pri™e p—rti—ls —meri™—n ™—ll ˜inomi—l(const double& ƒ. double& g—mm—. void option pri™e p—rti—ls —meri™—n put ˜inomi—l(const double option pri™e delt— —meri™—n ™—ll ˜inomi—l(const double& ƒ. const double& r. const double& sigm—. const double& sigm—. const double& time. const double& u. const int& no u. const double& u. const double& sigm—. const double& u. const int& steps). const double& . const double& time. ˜inomi—l (const double& ƒ. const double& ƒ. ˜inomi—l(const double& ƒ. const int& no steps. const ve™tor<double>& dividend —mounts). ˜inomi—l(const double& ƒ. const double& sigm—. const double& sigm—. const double& sigm—. sigm—. const double& r f. r f. ˜inomi—l (const double& ƒ. const double& q. double& thet—. const double& r. const double& u. const double& t. const double& t. const int& no steps). const double& sigm—. const double& u. const double& sigm—. const double& sigm—. const ve™tor<double>& dividend yields). const double& ITW ƒ.double double double ™urren™y option pri™e put europe—n(const option pri™e —meri™—n perpetu—l option pri™e —meri™—n perpetu—l double& ƒ. const double& r. double double double futures option pri™e ™—ll —meri™—n ˜inomi—l(const futures option pri™e put —meri™—n ˜inomi—l( double& r. const double& r. const double& u. const double& r. const double& const double& time. const double& t. const double& r. const double& u. const ve™tor<double>& dividend times. const int& steps). const double& t. const double& r. const double& sigm—. const double& u. const double& u. const double& r. put(const double& ƒ. const double& t. const double& u. const double& r. const double& r. const int& steps). double& thet—. const double& t. double option pri™e delt— —meri™—n put ˜inomi—l(const double& ƒ. const double& t. const double& y. option pri™e ™—ll —meri™—n dis™rete dividends ˜inomi—l( double option pri™e put —meri™—n dis™rete dividends ˜inomi—l(const double& ƒ. ˜inomi—l (const double& ƒ. const double& t. const int& steps). steps. const ve™tor<double>& dividend times. const double& r. const double& ™urren™y option pri™e ™—ll —meri™—n ˜inomi—l( const double& u. const double& r. const double& u. const double& p. const double& sigm—. const double& sigm—. const double& u. const int& steps). const double& time). const double& q. const double& sigm—. const double& r. double& veg—. const double& r. const double& r. const double& u.

option pri™e delt— ™—ll europe—n simul—ted(const double& ƒ. const int& no ƒ steps. const double& time. const double& ƒ. option pri™e ™—ll europe—n simul—ted(const deriv—tive pri™e simul—te europe—n option generi™( u). const double& time. const double& sigm—. const double& time. const double& const double& sigm—. const int& no ƒ steps. const int& no sims). const double& time. const int& no t steps). IUH . const double& u. const double& u. const int& no ƒ steps. const double& r f. const int& no sims). option pri™e ™—ll europe—n (nite di' impli™it( r. const double& u. const int& n). const double& u). double p—yo' (const double& pri™e. r. double deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(const double& ƒ. const double& ƒ. const double& time. const double& u. const double& t. const double& r. const double& ƒ. const double& r. const double& const int& no sims). const double& time. const double& u. option pri™e put europe—n simul—ted(const double& ƒ. const double& const double& sigm—. const double& sigm—. option pri™e ™—ll —meri™—n (nite di' impli™it( r. const int& no t steps). const double& u. const double& u. const double& r. const int& no t steps). const int& no t steps). const double& u. const double& u. const double& ƒ. const double& ƒ. const int& n). const double& const double& sigm—. option pri™e put —meri™—n (nite di' impli™it( r. //////////////////// nite dierences ////////////////// double double double double double double double double option pri™e ™—ll —meri™—n (nite di' expli™it( r. const double& r. const int& no sims). const int& no ƒ steps. const double& sigm—. const int& no t steps). const double& time to m—turity. const double& time. const double& time to m—turity. const double& const double& sigm—. const double& sigm—. const double& u. const int& no ƒ steps. const int& no sims). option pri™e put europe—n (nite di' expli™it( r. const double& ƒ. const double& const double& sigm—. const double& const double& sigm—. simul—te lognorm—l r—ndom v—ri—˜le(const double& ƒ. const double& sigm—. const double& u. const double& t. const double& ƒ. const double& ƒ. const double& u. double p—yo' (const double& pri™e. const int& no ƒ steps. const double& time). const double& time to m—turity. const double& const double& sigm—. const double& sigm—. const double& time to m—turity. const double& u. option pri™e delt— put europe—n simul—ted(const double& ƒ. const double& u. const double& r. const double& time. const double& const double& sigm—. const int& no ƒ steps. option pri™e put europe—n (nite di' impli™it( r. const double& u. option pri™e ™—ll europe—n (nite di' expli™it( r. const int& no ƒ steps.const double& sigm—. const double& time. const double& time. const int& no t steps).const double& double ™urren™y option pri™e put —meri™—n ˜inomi—l( sigm—. const double& r. const int& no t steps). const double& r. const double& ƒ. const double& ƒ. option pri™e put —meri™—n (nite di' expli™it( r. const double& const double& sigm—. const int& no sims). const int& no t steps). ///////////////////////// simulated option prices ////////////////////////////////////// // Payo only function of terminal price double double double double double double double& ƒ.

const double& u). const int& no sims). const double& time). const double& time. const double& sigm—. const double& time). const double& r. const double& ƒmin. const double& ˜. // payos of various options. const double& time. const double& r. const double& u). const double& r. const double& r. const double& u. const double& sigm—. const double& u. /////////// approximated option prices //////////////////////// option pri™e —meri™—n ™—ll —pproxim—ted ˜—w(const option pri™e —meri™—n put —pproxim—ted double& ƒ. const int& r.double deriv—tive pri™e simul—te europe—n option generi™ with —ntitheti™ v—ri—te(const ///////////////////////////// double& ƒ. double option pri™e put ˜ermud—n ˜inomi—l( const double& ƒ. const int& no sims). double p—yo' (const double&pri™e. double& ƒ. const double& r. const double& u). const double& q. const double& r. const double& r. const double& sigm—. const double& u). const int& nosteps. const double& option pri™e —si—n geometri™ —ver—ge pri™e ™—ll(const time). ˜—w(const double& ƒ. const double& ˜. to be used as function arguments in above simulations double double double double double double p—yo' p—yo' p—yo' p—yo' ™—ll(const double& pri™e. to be used as function arguments in above simulations IUI . const double& q. double deriv—tive pri™e simul—te europe—n option generi™ with ™ontrol v—ri—te(const double& ƒ. const double& sigm—. deriv—tive pri™e simul—te europe—n option generi™( const double& ƒ. const int& nosims). no steps). const double& time). const int& steps). const double& time. const double& sigm—. const double& sigm—. double p—yo' (const ve™tor<double>& pri™e. const double& ƒmin. double double double option pri™e europe—n look˜—™k ™—ll(const option pri™e europe—n look˜—™k put(const double& ƒ. const double& u). const ve™tor<double>& potenti—l exer™ise times. const double& u). double& ƒ. const double& r. const double& time. const double& time). ™—sh or nothing ™—ll(const double& pri™e. const double& sigm—. const double& q. —sset or nothing ™—ll(const double& pri™e. const double& r. const double& sigm—. const double& u. double p—yo' (const ve™tor<double>& pri™e. const double& q. const double& r. ve™tor<double> simul—te lognorm—lly distri˜uted sequen™e(const double double& ƒ. const int& steps). const double& sigm—. const double& q. const double& u). const double& ˆ. const double& u. const double& time. const double& sigm—. const ve™tor<double>& potenti—l exer™ise times. const double& ˆ. const double& time. put (const double& pri™e. const int& no steps. const double& u. ///////////////////////////// // payos of various options. const double& u. const double& const double& sigm—. ////////////// path dependent and other exotic options //////////////////////////////// double option pri™e ™—ll ˜ermud—n ˜inomi—l(const double& ƒ.

r. double& t. const int& steps). —meri™—n ˜inomi—l( const double& f. ˜et—P public: virtual £term stru™ture ™l—ss siegel X . stru™ture ™l—ss ™u˜i™ spline X }. const double& r. const double& u). const double& u. double& thet—. knots). —meri™—n ˜inomi—l( const double& f. const double& r. const double& r. const double& sigm—. const double& sigm—. const double& sigm—.double double double double double p—yo' p—yo' p—yo' p—yo' —rithmetri™ —ver—ge ™—ll(const ve™tor<double>& pri™es. const double& t. const double& u. const double& ˜I. const double& u. const double& dI. const double& time). const double& const double& sigm—. class term private: public term stru™ture ™l—ss { IUP . const double& sigm—. zero ˜l—™k s™holes(const double& f. const ve™tor<double> ™oupon —mounts). const double& delt—). double term stru™ture dis™ount f—™tor ™ir(const const const const const double& t. double term stru™ture dis™ount f—™tor ™u˜i™ spline(const f. const ve™tor<double> ™oupon times. const double& ™I. const double& u). const double& u. const double& —. /////////////////// alternative stochastic processes //////////////// option pri™e ™—ll merton jump di'usion( const double& ƒ. geometri™ —ver—ge ™—ll(const ve™tor<double>& pri™es. public . const ve™tor<double> ™oupon —mounts). const double& u. const double& ˜et—P. const double& ˜et—P. const double& u. double& sigm—).const double& term stru™ture ™l—ss ˜. const double& const double& l—m˜d— ). const ve™tor<double>& const ve™tor<double>& ˜et—I. double term stru™ture dis™ount f—™tor v—si™ek(const double& time. /// dening classes wrapping the above term structure approximations class term stru™ture ™l—ss nelson private: double ˜et—H . const double& l—m˜d—. const double& sigm—. term stru™ture ™l—ss nelson siegel(const double& ˜et—H. ˜et—I . look˜—™k put(const ve™tor<double>& pri™es. const double& t. const double& k—pp—. const double& l—m˜d—). const int& steps). r. const double& time to m—turity. const double& ˜et—H. look˜—™k ™—ll(const ve™tor<double>& pri™es. const double& u. const double& r. const double& sigm—). r. // xed income derivatives. { l—m˜d— nelson siegel(). const double& r. const double& double& k—pp—. ™oupon ˜ond ˜l—™k s™holes(const double& f. const double& const double& sigm—. const double& time). const double& unused v—ri—˜le). const double& r. const double& time. GBM assumption on bond price double double double double double double ˜ond option pri™e ™—ll zero ˜l—™k s™holes(const ˜ond option pri™e put ˜ond option pri™e ™—ll ˜ond option pri™e put ˜ond option pri™e ™—ll ˜ond option pri™e put double& f. double& l—m˜d—. //////////////////////////////////////////////////////////////////////////////// // term structure models /// formulas for calculation double term stru™ture yield nelson siegel(const double& t. virtual double yield(const double& t) const. const double& time. const double& unused v—ri—˜le). ™oupon ˜ond ˜l—™k s™holes(const double& f. const double& ˜et—I. const ve™tor<double> ™oupon times.

const double& sigm—). const double& ™. const double& ˜. virtual double dis™ount f—™tor(const double& t) const. double thet— . class term stru™ture ™l—ss v—si™ek X public term stru™ture ™l—ss { private: double r . m—turity. const double& d. double& interest. const double& —. const double& r. }. const double& option time to m—turity. double& m—turity p—yment. const double& virtual £term stru™ture ™l—ss v—si™ek(). const double& k. }. ///////////////// /// binomial term structure models /// bond option. const double& const double& th. l. ///////////////////////////////// // term structure derivatives. double k—pp— . rendlemann bartter (binomial) double ˜ond option pri™e ™—ll zero —meri™—n rendlem—n ˜—rtter(const const const const const const double& u. double d . double sigm— . const double& ˜ond time to m—turity. double l—m˜d— . const double& ˜ond time to m—turity. const double& —. const double& option time to m—turity. public: term stru™ture ™l—ss v—si™ek(const double& r. double — . virtual double dis™ount f—™tor(const double& „) const. const ve™tor<double> & knots). const double& w. t) const. const double& r. ve™tor<double> f . int& no steps). virtual £term stru™ture ™l—ss ™ir(). double ™ . virtual double dis™ount f—™tor(const double& }. double sigm— . IUQ .double public: ˜ . —. double& ˜ond m—turity. term stru™ture ™l—ss ™u˜i™ spline(const virtual £term stru™ture ™l—ss ™u˜i™ spline(). const double& ˜. const double& sigm—).const double& sigm—). v—si™ek(const double& ˆ. ve™tor<double>& f. analytical solutions double double #endif ˜ond option pri™e ™—ll zero v—si™ek(const ˜ond option pri™e put zero double& ˆ. double ˜ . class term stru™ture ™l—ss ™ir X public term stru™ture ™l—ss { private: double r . public: term stru™ture ™l—ss ™ir(const double& r. const double& sigm—). const double& ˜. ve™tor<double> knots . const double& ˜. const double& option double& ƒ.

Appendix D Installation „he routines dis™ussed in the ˜ook —re —v—il—˜le for downlo—dF D.1 Source availability „he —lgorithms —re —v—il—˜le from my home p—ge —s — s€ (le ™ont—ining the sour™e ™odeF „hese h—ve ˜een tested with the l—test version of the qx… gCC ™ompilerF es the —lgorithms in pl—™es uses ™ode from the ƒt—nd—rd „empl—te vi˜r—ryD other ™ompilers m—y not ˜e —˜le to ™ompile —ll the (les dire™tlyF sf your ™ompiler ™ompl—ins —˜out missing he—der (les you m—y w—nt to ™he™k if the ƒ„v he—der (les h—ve di'erent n—mes on your systemF „he —lgorithm (les will tr—™k the new exƒs st—nd—rd for gCC li˜r—ries —s it is ˜eing settled onF sf the ™ompiler is more th—n — ™ouple of ye—rs oldD it will not h—ve ƒ„vF eltern—tivelyD the qx… ™ompiler gcc is —v—il—˜le for free on the internetD for most ™urrent oper—ting systemsF IUR .

List of C++ Codes e ™omplete progr—m F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F he(ning — date ™l—ss F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F f—si™ oper—tions for the d—te ™l—ss F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F gomp—rison oper—tors for the d—te ™l—ss F F F F F F F F F F F F F F F F F F F F F F F F F F F F ster—tive oper—tors for the d—te ™l—ss F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F €resent v—lue with dis™rete ™ompounding F F F F F F F F F F F F F F F F F F F F F F F F F F F istim—tion of the intern—l r—te of return F F F F F F F F F F F F F F F F F F F F F F F F F F F F „est for uniqueness of s‚‚ F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F fond pri™e ™—l™ul—tion with dis™reteD —nnu—l ™ompoundingF F F F F F F F F F F F F F F F F F fond yield ™—l™ul—tion with dis™reteD —nnu—l ™ompounding F F F F F F F F F F F F F F F F F F fond dur—tion using dis™reteD —nnu—l ™ompounding —nd — )—t term stru™ture F F F F F F F g—l™ul—ting the w—™—ul—y dur—tion of — ˜ond F F F F F F F F F F F F F F F F F F F F F F F F F wodi(ed dur—tion F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F fond ™onvexity with — )—t term stru™ture —nd —nnu—l ™ompounding F F F F F F F F F F F F €resent v—lue ™—l™ul—tion with ™ontinously ™ompounded interest F F F F F F F F F F F F F F F fond pri™e ™—l™ul—tion with ™ontinously ™ompounded interest —nd — )—t term stru™ture F F fond dur—tion ™—l™ul—tion with ™ontinously ™ompounded interest —nd — )—t term stru™ture g—l™ul—ting the w—™—ul—y dur—tion of — ˜ond with ™ontinously ™ompounded interest —nd — )—t term stru™ture F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F QFIR fond ™onvexity ™—l™ul—tion with ™ontinously ™ompounded interest —nd — )—t term stru™ture RFI „erm stru™ture tr—nsform—tions F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F RFP re—der (le des™ri˜ing the term_structure ˜—se ™l—ss F F F F F F F F F F F F F F F F F F F F F RFQ hef—ult ™ode for tr—nsform—tions ˜etween dis™ount f—™torsD spot r—tes —nd forw—rd r—tes in — term stru™ture ™l—ss F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F RFR re—der (le for term stru™ture ™l—ss using — )—t term stru™ture F F F F F F F F F F F F F F F F RFS smplementing term stru™ture ™l—ss using — )—t term stru™ture F F F F F F F F F F F F F F F F RFT snterpol—ted term stru™ture from spot r—tes F F F F F F F F F F F F F F F F F F F F F F F F F F RFU re—der (le des™ri˜ing — term stru™ture ™l—ss using line—r interpol—tion ˜etween spot r—tes RFV „erm stru™ture ™l—ss using line—r interpol—tion ˜etween spot r—tes F F F F F F F F F F F F F F RFW €ri™ing — ˜ond with — term stru™ture ™l—ss F F F F F F F F F F F F F F F F F F F F F F F F F F F RFIH g—l™ul—ting — ˜onds dur—tion with — term stru™ture ™l—ss F F F F F F F F F F F F F F F F F F F RFII g—l™ul—ting — ˜onds ™onvexity with — term stru™ture ™l—ss F F F F F F F F F F F F F F F F F F SFI putures pri™e F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F TFI finomi—l iurope—nD one period F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F TFP fuilding — ˜inomi—l tree F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F TFQ finomi—l multiperiod pri™ing of iurope—n ™—ll option F F F F F F F F F F F F F F F F F F F F F UFI €ri™e of iurope—n ™—ll option using the fl—™k ƒ™holes formul— F F F F F F F F F F F F F F F F iurope—n ™—ll option using the fl—™k ƒ™holes formul—SS g—l™ul—ting the delt— of the fl—™k ƒ™holes ™—ll option pri™e F F F F F F F F g—l™ul—ting the p—rti—l deriv—tives of — fl—™k ƒ™holes ™—ll option F F F F F g—l™ul—tion of implied vol—tility of fl—™k ƒ™holes using ˜ise™tions F F F F g—l™ul—tion of implied vol—tility of fl—™k ƒ™holes using xewtonE‚—phson edjusted fl—™k ƒ™holes v—lue for — ‡—rr—nt F F F F F F F F F F F F F F F F yption pri™eD ™ontinous p—yout from underlying F F F F F F F F F F F F F F iurope—n option pri™eD dividend p—ying sto™k F F F F F F F F F F F F F F F yption pri™eD ‚oll!qeske!‡h—ley ™—ll formul— for dividend p—ying sto™k €ri™e of iurope—n g—ll option on putures ™ontr—™t F F F F F F F F F F F F iurope—n putures g—ll option on ™urren™y F F F F F F F F F F F F F F F F F €ri™e for —n —meri™—n perpetu—l ™—ll option F F F F F F F F F F F F F F F F yption pri™e for ˜inomi—l europe—n F F F F F F F F F F F F F F F F F F F F F finomi—l option pri™e —meri™—n opstion F F F F F F F F F F F F F F F F F F IUS F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IFI IFP IFQ IFR IFS QFI QFP QFQ QFR QFS QFT QFU QFV QFW QFIH QFII QFIP QFIQ U W IH II IP IU IW PI PP PQ PR PR PS PT PW QI QI QI QI QS QT QU QV QV RH RP RQ RS RT RT RU RW SP SQ SS SV SW TI TP TS TU TV UI UQ US UU VI VP UFI €ri™e of UFP UFQ UFR UFS VFI WFI WFP WFQ WFR WFS WFT IHFI IHFP .

1) distri˜ution F F F F F F F F F F F F F F F F eFS €seudor—ndom num˜ers from — norm—l (0.IHFQ helt— F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IHFR redge p—r—meters F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IHFS finomi—l option pri™e with ™ontinous p—yout F F F F F F F F F F F F F F F F F F F F F F F F IHFT finomi—l option pri™e of sto™k option where sto™k p—ys proportion—l dividends F F F F F IHFU finomi—l option pri™e of sto™k option where sto™k p—ys dis™rete dividends F F F F F F F F IHFV yption on futures F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IHFW finomi—l gurren™y yption F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IIFI ixpli™it (nite di'eren™es ™—l™ul—tion of europe—n put option F F F F F F F F F F F F F F F F IIFP ixpli™it (nite di'eren™es ™—l™ul—tion of —meri™—n put option F F F F F F F F F F F F F F F F IPFI ƒimul—ting — lognorm—lly distri˜uted r—ndom v—ri—˜le F F F F F F F F F F F F F F F F F F F IPFP iurope—n g—ll option pri™ed ˜y simul—tion F F F F F F F F F F F F F F F F F F F F F F F F F F IPFQ istim—te helt— of iurope—n g—ll option pri™ed ˜y wonte g—rlo F F F F F F F F F F F F F F IPFR €—yo' ™—ll —nd put options F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IPFS qeneri™ simul—tion pri™ing F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IPFT qeneri™ with ™ontrol v—ri—te F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IPFU qeneri™ with —ntitheti™ v—ri—tes F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IPFV €—yo' ˜in—ry options F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IQFI f—rone edesi qu—dr—ti™ —pproxim—tion to the pri™e of — ™—ll option F F F F F F F F F F F F IRFI finomi—l —pproxim—tion to fermud—n put option F F F F F F F F F F F F F F F F F F F F F F IRFP en—lyti™—l pri™e of —n esi—n geometri™ —ver—ge pri™e ™—ll F F F F F F F F F F F F F F F F F F IRFQ €ri™e of look˜—™k ™—ll option F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IRFR ƒimul—ting — sequen™e of lognorm—lly distri˜uted v—ri—˜les F F F F F F F F F F F F F F F F F IRFS qeneri™ routine for pri™ing iurope—n options whi™h F F F F F F F F F F F F F F F F F F F F IRFT €—yo' fun™tion for esi—n ™—ll option F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IRFU €—yo' fun™tion for look˜—™k option F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IRFV gontrol †—ri—te F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F ISFI wertons jump di'usion formul— F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F ITFI g—l™ul—tion of pri™e of iurope—n put using impli™it (nite di'eren™es F F F F F F F F F F F ITFP g—l™ul—tion of pri™e of emeri™—n put using impli™it (nite di'eren™es F F F F F F F F F F F IUFI we—n v—ri—n™e ™—l™ul—tions F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F IUFP g—l™ul—ting the un™onstr—ined frontier portfolio given —n expe™ted return F F F F F F F F IVFI fl—™k s™holes pri™e for iurope—n ™—ll option on zero ™oupon ˜ond F F F F F F F F F F F F F IVFP fl—™k s™holes pri™e for iurope—n ™—ll option on ™oupon ˜ond F F F F F F F F F F F F F F F IVFQ finomi—l —pproxim—tion to —meri™—n ˜ond option pri™e F F F F F F F F F F F F F F F F F F F PHFI g—l™ul—tion of the xelson —nd ƒiegel @IWVUA term stru™ture model F F F F F F F F F F F F F PHFP re—der (le de(ning — term stru™ture ™l—ss wr—pper for the xelson ƒiegel —pproxim—tion PHFQ he(ning — term stru™ture ™l—ss wr—pper for the xelson ƒiegel —pproxim—tion F F F F F F F PHFR epproxim—ting — dis™ount fun™tion using — ™u˜i™ spline F F F F F F F F F F F F F F F F F F PHFS „erm stru™ture ™l—ss wr—pping the ™u˜i™ spline —pproxim—tion F F F F F F F F F F F F F F F PHFT „erm stru™ture ™l—ss wr—pping the ™u˜i™ spline —pproxim—tion F F F F F F F F F F F F F F F PHFU g—l™ul—tion of the dis™ount f—™tor using the gox et —lF @IWVSA model F F F F F F F F F F F PHFV gl—ss de(nitionD gox et —lF @IWVSA modelD he—der (le F F F F F F F F F F F F F F F F F F F F PHFW gl—ss de(nitionD gox et —lF @IWVSA model F F F F F F F F F F F F F F F F F F F F F F F F F F F PHFIHg—l™ul—ting — dis™ount f—™tor using the †—si™ek fun™tion—l form F F F F F F F F F F F F F F PHFIIgl—ss de(nitionD †—si™ek @IWUUA model F F F F F F F F F F F F F F F F F F F F F F F F F F F F PHFIPgl—ss de(nitionD †—si™ek @IWUUA model F F F F F F F F F F F F F F F F F F F F F F F F F F F F PIFI fuilding —n interest r—te tree F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F PIFP ‚f ˜inomi—l model for iurope—n ™—ll on zero ™oupon ˜ond F F F F F F F F F F F F F F F F PPFI fond option pri™ing using the †—si™ek model F F F F F F F F F F F F F F F F F F F F F F F F eFI „he norm—l distri˜ution fun™tion F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F eFP „he ™umul—tive norm—l F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F eFQ epproxim—tion to the ™umul—tive ˜iv—ri—te norm—l F F F F F F F F F F F F F F F F F F F F F eFR €seudor—ndom num˜ers from —n uniform [0. 1) distri˜ution F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F VQ VR VT VV VW WI WP WS WT WW WW IHH IHP IHP IHR IHS IHU III IIR IIT IIU IIW IPH IPH IPI IPP IPS IPU IPV IQI IQQ IQV IQW IRH IRS IRS IRS IRU IRU IRV IRW ISH ISH ISI ISI ISI ISS IST ISV ISW ITH ITI ITQ ITQ IUT .

List of Matlab Codes IUU .

Appendix E Acknowledgements. efter this p—per w—s put up on the netD s9ve h—d quite — few em—ils —˜out themF ƒome of them h—s pointed out ˜ugs —nd other in—™™ur—™iesF emong the ones s w—nt to s—y th—nks to for m—king improving suggestions —nd pointing out ˜ugs —re eriel elmed—l ƒteve fell—ntoni te—nE€—ul fever—ggi v—rs qregori h—niel rerlemont vorenzo ssell— tens v—rsson q—rri™k v—u ƒteven ve—d˜e—ter wi™h—el v vo™her votti vu™—D wil—noD st—ly „u—n xguyen wi™h—el ‚ ‡—yne IUV .

Index γ D SV ρD SV θD SV —ntitheti™ v—ri—tesD IHR —ntitheti™ v—ri—tesD IHR —sset or nothing ™—llD IHU f—rone!edesi —nd ‡h—leyD IHW ˜in—ry optionD IHU ˜inomi—l option pri™eD RVD UW ˜inomi—l term stru™ture modelsD ISR ˜inomi—l•treeD SP d—teXXd—teD IH fl—™k d—teXXd—yD IH futures optionD UQ d—teXXmonthD IH fl—™k ƒ™holes option pri™ing formul—D SR d—teXXv—lidD IH ˜ondD PI d—teXXye—rD IH dur—tionD PQ delt—D SV pri™eD PP ˜inomi—lD VQ yield to m—turityD PP fl—™k ƒ™holesD SV ˜ond ™onvexityD PT deriv—tive•pri™e•simul—te•europe—n•option•generi™D ˜ond option IHPD IPH ˜—si™ ˜inomi—lD IRH deriv—tive•pri™e•simul—te•europe—n•option•generi™•with•—ntith fl—™k ƒ™holesD IQV IHS †—si™ekD ISU deriv—tive•pri™e•simul—te•europe—n•option•generi™•with•™ontr ˜ond•option•pri™e•™—ll•zero•—meri™—n•rendlem—n•˜—rtterD IHRD IPP ISTD IUQ dis™ount f—™torD IT ˜ond•option•pri™e•™—ll•zero•v—si™ekD ISV dis™ount•f—™torD ISID IUQ ˜ond•option•pri™e•put•—meri™—n•˜inomi—lD IRH dou˜le @g++ typeAD R ˜ond•option•pri™e•put•™oupon•˜ond•˜l—™k•s™holesD dur—tionD PQ IQW w—™—ul—yD PR ˜ond•option•pri™e•put•zero•˜l—™k•s™holesD IQV modi(edD PS ˜onds•™onvexityD QID RT e—rly exer™ise premiumD IHW ˜onds•™onvexity•dis™reteD PT exp@A @C++ statementAD S ˜onds•dur—tionD QID RT expli™it (nite di'eren™esD WR ˜onds•dur—tion•dis™reteD PR ˜onds•dur—tion•m—™—ul—yD QI fD ITI ˜onds•dur—tion•m—™—ul—y•dis™reteD PR (nite di'eren™esD WRD IPT ˜onds•dur—tion•modi(ed•dis™reteD PS expli™itD WR ˜onds•pri™eD QID RSD ITU for @C++ statementAD T ˜onds•pri™e•dis™reteD PP fun™tion prototypes @g++ ™on™eptAD IHP ˜onds•yield•to•m—turity•dis™reteD PQ futures ++ typeAD R ˜ool @g optionD UQ ˜uild•interest•r—te•tree•rendlem—n•˜—rtterD ISS futures•option•pri™e•™—ll•—meri™—n•˜inomi—lD WI futures•option•pri™e•™—ll•europe—n•˜l—™kD UQ ™—ll optionD RV futures•pri™eD RU ™—sh )owD IT ™—sh or nothing ™—llD IHU g—mm—D SV ™—sh•)ow•irr•dis™reteD IW geometri™ frowni—n motionD SU ™—sh•)ow•pvD PW ™—sh•)ow•pv•dis™reteD IUD ITT hedging p—r—meters ™—sh•)ow•unique•irrD PI fl—™k ƒ™holesD SV ™l—ssD V ™m—thD S ifD II IUW ™ontrol v—ri—tesD IHQ ™onvexity of ˜ondD PT gox sngersoll ‚oss term stru™ture modelD IRW ™urren™y optionD US ™urren™y option emeri™—nD WP iurope—nD US ™urren™y•option•pri™e•™—ll•—meri™—n•˜inomi—lD WP ™urren™y•option•pri™e•™—ll•europe—nD US .

option•pri™e•™—ll•—meri™—n•proportion—l•dividends•˜inomi—lD VV option•pri™e•™—ll•˜l—™k•s™holesD SS option•pri™e•™—ll•europe—n•˜inomi—lD VI option•pri™e•™—ll•europe—n•˜inomi—l•multi•period•given•udD SQ option•pri™e•™—ll•europe—n•˜inomi—l•single•periodD RW option•pri™e•™—ll•europe—n•simul—tedD WW tump hi'usionD IPR option•pri™e•™—ll•merton•jump•di'usionD IPS option•pri™e•delt—•—meri™—n•™—ll•˜inomi—lD VQ long @g++ typeAD R option•pri™e•delt—•™—ll•˜l—™k•s™holesD SV look˜—™k optionD IIU option•pri™e•delt—•™—ll•europe—n•simul—tedD IHH option•pri™e•europe—n•™—ll•dividendsD TV m—inD U option•pri™e•europe—n•™—ll•p—youtD TU werton option•pri™e•europe—n•look˜—™k•™—llD IIU tump hi'usionD IPR option•pri™e•implied•vol—tility•™—ll•˜l—™k•s™holes•˜ise™tionsD modi(ed dur—tionD PS TI wonte g—rlo option•pri™e•implied•vol—tility•™—ll•˜l—™k•s™holes•newtonD —ntitheti™ v—ri—tesD IHR TP monte ™—rlo option•pri™e•p—rti—ls•—meri™—n•™—ll•˜inomi—lD VR ™ontrol v—ri—tesD IHQ option•pri™e•p—rti—ls•™—ll•˜l—™k•s™holesD SW mv•™—l™ul—te•me—nD IQI option•pri™e•put•—meri™—n•(nite•di'•expli™itD WT mv•™—l™ul—te•portfolio•given•me—n•un™onstr—inedD option•pri™e•put•—meri™—n•(nite•di'•impli™itD IQQ IPV mv•™—l™ul—te•st•devD IQI option•pri™e•put•˜ermud—n•˜inomi—lD IIR mv•™—l™ul—te•v—ri—n™eD IQI option•pri™e•put•europe—n•(nite•di'•expli™itD WS option•pri™e•put•europe—n•(nite•di'•impli™itD xD ITHD ITI IPU nD ISW next•d—teD IP no•o˜serv—tionsD RPD ITU norm—l distri˜ution —pproxim—tionsD ISW simul—tionD ITQ p—rti—l deriv—tives ˜inomi—lD VQ fl—™k ƒ™holesD SV p—rti—ls fl—™k ƒ™holesD SV p—yo'•—rithmetri™•—ver—ge•™—llD IPH option p—yo'•—sset•or•nothing•™—llD IHU ™—llD RV p—yo'•™—llD IHP ™urren™yD US p—yo'•™—sh•or•nothing•™—llD IHU futuresD UQ p—yo'•geometri™•—ver—ge•™—llD IPH look˜—™kD IIU p—yo'•look˜—™k•™—llD IPI putD RV p—yo'•look˜—™k•putD IPI yption pri™e p—yo'•putD IHP fl—™k ƒ™holesD SR pow@A @C++ statementAD S option pri™e powerD U ˜inomi—lD UW present v—lueD IT simul—tedD WV option•pri™e•—meri™—n•™—ll•—pproxim—ted•˜—wD previous•d—teD IP pri™ing III rel—tiveD RV option•pri™e•—meri™—n•™—ll•one•dividendD UI put optionD RV option•pri™e•—meri™—n•perpetu—l•™—llD UU option•pri™e•—si—n•geometri™•—ver—ge•pri™e•™—llD qu—dr—ti™ —pproxim—tionD IHW IIT option•pri™e•™—ll•—meri™—n•˜inomi—lD VPD VT r—ndom•norm—lD ITQ option•pri™e•™—ll•—meri™—n•dis™rete•dividends•˜inomi—lD r—ndom•uniform•H•ID ITQ VW rel—tive pri™ingD RV IVH implied vol—tility ™—l™ul—tionD TI in™lude @C++ statementAD S int @g++ typeAD R intern—l r—te of returnD IV irrD IV iter—tion oper—tor de(nition of @g++ ™on™eptAD IP .

test•˜in•eur•™—ll•udD SQ test•˜inomi—l•—pproxim—tions•™urren™y•optionsD WP test•˜inomi—l•—pproxim—tions•futures•optionsD WI test•˜inomi—l•—pproxim—tions•option•pri™e•dividendsD sgnD ITI WH ƒh—rpe ‚—tioD IQU test•˜inomi—l•—pproxim—tions•option•pri™e•p—rti—lsD simul—te•lognorm—l•r—ndom•v—ri—˜leD WW VS simul—te•lognorm—lly•distri˜uted•sequen™eD IIW test•˜inomi—l•—pproxim—tions•option•pri™ingD VP simul—tionD WV test•˜l—™k•s™holes•implied•vol—tilityD TQ string @g++ typeAD R test•˜l—™k•s™holes•p—rti—ls•™—llD TH test•˜l—™k•s™holes•with•dividendsD TV term stru™ture deriv—tivesD ISU test•˜ond•option•g˜m•pri™ingD IRI term stru™ture model test•˜onds•dur—tion•dis™reteD PV gox sngersoll ‚ossD IRW test•˜onds•pri™e•dis™reteD PQ term stru™ture models test•™redit•riskD IRQ ˜inomi—lD ISR test•™umul—tive•norm—lD ITP term•stru™ture•™l—ssXXdis™ount•f—™torD QU test•™urren™y•option•europe—n•™—llD US term•stru™ture•™l—ssXXforw—rd•r—teD QU test•exoti™s•look˜—™kD IIV term•stru™ture•™l—ssXXyieldD QU test•expli™it•(nite•di'eren™esD WU term•stru™ture•™l—ss•™irD ISHD IUQ test•futures•option•pri™e•˜l—™kD UQ term•stru™ture•™l—ss•™irXXdis™ount•f—™torD ISH test•futures•pri™eD RU term•stru™ture•™l—ss•™irXXterm•stru™ture•™l—ss•™irD test•impli™it•(nite•di'eren™esD IPW ISH test•me—n•v—ri—n™e•™—l™ul—tionsD IQI term•stru™ture•™l—ss•™u˜i™•splineD IRUD IRVD IUQ test•me—n•v—ri—n™e•portfolio•™—l™ul—tionD IQR term•stru™ture•™l—ss•™u˜i™•splineXX£term•stru™ture•™l—ss•™u˜i™•splineD test•merton•jump•di'•™—llD IPS IRV test•option•pri™e•™—ll•˜l—™k•s™holesD ST term•stru™ture•™l—ss•™u˜i™•splineXXdis™ount•f—™torD test•option•pri™e•perpetu—l•—meri™—n•™—llD UU IRV test•present•v—lueD PH term•stru™ture•™l—ss•)—tXXyieldD QV test•r—ndom•norm—lD ITR term•stru™ture•™l—ss•interpol—tedXX™le—rD RQ test•rendlem—n•˜—rtter•zero•™oupon•™—llD IST term•stru™ture•™l—ss•interpol—tedXXset•interpol—ted•o˜serv—tionsD test•rgw•pri™e•—m•™—ll•divD UP RQ test•simul—te•gener—l•europe—nD IPQ term•stru™ture•™l—ss•interpol—tedXXterm•stru™ture•™l—ss•interpol—tedD test•simul—tion•˜in—ry•optionsD IHV RQ test•simul—tion•˜s•™—se•using•generi™•routineD term•stru™ture•™l—ss•interpol—tedXXyieldD RQ IHQ term•stru™ture•™l—ss•nelson•siegelD IRS test•simul—tion•˜s•™—se•using•generi™•routine•improving•e0™ term•stru™ture•™l—ss•nelson•siegelXXterm•stru™ture•™l—ss•nelson•siegelD IHT IRS test•simul—tion•pri™ingD WW term•stru™ture•™l—ss•nelson•siegelXXyieldD IRS test•simul—tion•pri™ing•delt—D IHI term•stru™ture•™l—ss•v—si™ekXXdis™ount•f—™torD ISI test•term•stru™ture•™irD ISH term•stru™ture•™l—ss•v—si™ekXXterm•stru™ture•™l—ss•v—si™ekD test•term•stru™ture•™l—ss•˜ond•™—l™ul—tionsD RT ISI test•term•stru™ture•™l—ss•)—tD QW term•stru™ture•dis™ount•f—™tor•™irD IRW test•term•stru™ture•™l—ss•interpol—tedD RR term•stru™ture•dis™ount•f—™tor•™u˜i™•splineD IRU test•term•stru™ture•™u˜i™•splineD IRV term•stru™ture•dis™ount•f—™tor•from•yieldD QS test•term•stru™ture•nelson•siegelD IRT term•stru™ture•dis™ount•f—™tor•v—si™ekD ISI test•term•stru™ture•v—si™ekD ISP term•stru™ture•forw—rd•r—te•from•dis™ount•f—™torsD test•termstru•interpol—tedD RI QS test•termstru•tr—nsformsD QS term•stru™ture•forw—rd•r—te•from•yieldsD QS test•v—si™ek•option•pri™ingD ISV term•stru™ture•yield•from•dis™ount•f—™torD QS test•w—rr—nt•pri™e•—djusted•˜l—™k•s™holesD TT term•stru™ture•yield•line—rly•interpol—tedD RH thet—D SV term•stru™ture•yield•nelson•siegelD IRS time test•—n—lyti™—l•geometri™•—ver—geD IIT v—lue ofD IT test•˜—w•—pproxim—tion•™—llD IIP test•˜ermud—n•optionD IIS underlying se™urityD SR ‚endlem—n —nd f—rtter modelD ISR return intern—l r—te ofD IV rhoD SV IVI .

v—lidD W †—si™ekD ISI veg—D SV vol—tility impliedD TI w—rr—nt•pri™e•—djusted•˜l—™k•s™holesD TS yieldD QTD QVD RPD ITU IVP .

Futures and €renti™e!r—llD sixth editionD PHHTF other DerivativesF tohn rullF Options. Futures and other Derivative SecuritiesF €renti™e!r—llD se™ond editionD IWWQF IVQ .p t—mshid—nF en ex—™t ˜ond option pri™ing formul—F nal of FinanceD RRXPHS!WD w—r™h IWVWF Jour- Bibliography wilton e˜r—mowiz —nd srene e ƒtegunF Handbook of Mathematical FunctionsF x—tion—l fure—u of ƒt—nd—rdsD IWTRF qiov—nni f—roneEedesi —nd ‚o˜ert i ‡h—leyF i0™ient —nE —lyti™ —pproxim—tion of emeri™—n option v—luesF Journal of FinanceD RP@PAXQHI!PHD tune IWVUF pisher fl—™kF „he pri™ing of ™ommodity ™ontr—™tsF of Financial EconomicsD QXITU!UWD IWUTF Journal e uemn— —nd e †orstF e pri™ing method for options ˜—sed on —ver—ge —sset v—luesF Journal of Banking and FinanceD IRXIIQ!PWD w—r™h IWWHF hon—ld i unuthF editionD IWWUF ume 2. Seminumerical AlgotithmsF The Art of Computer Programming Vol- eddison!‡esleyD third C++ primerF ƒt—nley f vippm—n —nd tos9ee v—joieF eddison!‡esleyD third editionD IWWVF pisher fl—™k —nd wyron ƒ ƒ™holesF „he pri™ing of options —nd ™orpor—te li—˜ilitiesF Journal of Political EconomyD UXTQU!SRD IWUQF ‚o˜ert ‚ flissF pitting term stru™tures to ˜ond pri™esF ‡orking p—perD …niversity of ghi™—goD t—nu—ry IWVWF vi fodieD elex u—neD —nd el—n t w—r™usF w™qr—w rillD T editionD PHHSF InvestmentsF ‚o˜ert r vitzen˜erger —nd t—ques ‚olfoF en intern—tion—l study of t—x e'e™ts on government ˜ondsF Journal of FinanceD QWXI!PPD IWVRF r—rry w—rkowitzF €ortfolio sele™tionF UXUU!WID IWSPF Journal of FinanceD t rouston w™gullo™hF we—suring the term stru™ture of inE terest r—tesF Journal of BusinessD RRXIW!QID IWUIF t rouston w™gullo™hF „he t—x —djusted yield ™urveF Journal of FinanceD QHXVII!VPWD IWUSF ‚o˜ert w™hon—ld —nd h—niel ƒiegelF „he v—lue of w—iting to investF Quarterly Journal of EconomicsD p—ges UHU!UPUD xovem˜er IWVTF ‚o˜ert v w™hon—ldF editionD PHHTF Derivatives MarketsF €eter v foss—erts —nd fernt erne Ødeg——rdF Lectures on Corporate FinanceF ‡orld ƒ™ienti(™ €ressD ƒing—poreD PHHIF €helim € foyleF yptionsX e wonte g—rlo —ppro—™hF of Financial EconomicsD RXQPQ!QVD IWUUF Journal €e—rsonD se™ond ‚i™h—rd e fre—ley —nd ƒtew—rt g wyersF Principles of Corporate FinanceF 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 Journal of Financial and Quantitative AnalysisD IQXRTI!URD IWUVF tohn gox —nd w—rk ‚u˜insteinF r—llD IWVSF Options marketsF ‚o˜ert g wertonF en —n—lyti™ deriv—tion of the e0™ient portfolio frontierF Journal of Financial and Quantitative AnalysisD UXIVSI!UPD ƒeptem˜er IWUPF ‚o˜ert g wertonF „he theory of r—tion—l option pri™ingF Bell JournalD RXIRI!IVQD IWUQF pr—n™o wodigli—ni —nd werton w willerF „he ™ost of ™—pit—lD ™orpor—tion (n—n™e —nd the theory of investmentF American Economic ReviewD RVXPTI!WUD IWSVF gh—rles ‚ xelson —nd endrew p ƒiegelF €—rsimonious modE elling of yield ™urvesF Journal of BusinessD TH@RAXRUQ!VWD IWVUF g—rl t xorstromF e su0™ient ™onditions for — unique nonE neg—tive intern—l r—te of returnF Journal of Financial and Quantitative AnalysisD U@QAXIVQS!QWD IWUPF ‡illi—m €ressD ƒ—ul e „eukolskyD ‡illi—m „ †etterlingD —nd fri—n € pl—nneryF Numerical Recipes in CF 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 Journal of FinanceD 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 Journal of Financial and Quantitative AnalysisD 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 Journal of Financial EconomicsD 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 Journal of Financial EconomicsD SXPSI!SVD IWUU˜F ƒtephen e ‚ossD ‚—ndolph ‡ester(eldD —nd te'rey p t—'eF Corporate FinanceF w™qr—sErillD seventh editionD PHHSF €renti™e! tohn g goxD ƒtephen e ‚ossD —nd w—rk ‚u˜insteinF ypE tion pri™ingX e simpli(ed —ppro—™hF Journal of Financial EconomicsD UXPPW!PTQD IWUWF tohn g goxD ton—th—n i sngersollD —nd ƒtephen e ‚ossF e theory of the term stru™ture of interest r—tesF EconometricaD SQXQVS!RHVD IWVSF ‚o˜ert qeskeF „he v—lu—tion of ™ompound optionsF of Financial EconomicsD UXTQ!VID w—r™h IWUWF Journal 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 Journal of FinanceD QRD he™em˜er IWUWF ‚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 Journal of FinanceD SPXTHW!TQQD tune IWWUF ‚o˜ert e r—ugenF Modern r—llD (fth editionD PHHIF Investment TheoryF €renti™e! for ghiEfu ru—ng —nd ‚o˜ert r vitzen˜ergerF Foundations nancial economicsF xorth!roll—ndD IWVVF tohn rullF Options.

Mathematical models and computationF yxford pin—n™i—l €ressD IWWRF sƒfx H WSPPHVP HPF ƒuresh ƒund—res—nF Fixed Income Markets and their DerivativesF ƒouthE‡esternD P editionD PHHIF IVR .w—rk ‚u˜insteinF „he v—lu—tion of un™ert—in in™ome stre—ms —nd the v—lu—tion of optionsF Bell JournalD UXRHU!PSD IWUTF w—rk ‚u˜insteinF ixoti™ optionsF …niversity of g—liforni—D ferkeleyD working p—perD IWWQF ‚o˜ert tF ƒhillerF „he term stru™ture of interest r—tesF sn f w priedm—n —nd p r r—hnD editorsD Handbook of Monetary EconomicsD volume PD ™h—pter IQD p—ges TPU!UPPF ilsevierD IWWHF fj—rne ƒtroustrupF The C++ Programming eddison!‡esleyD third editionD IWWUF languageF ‰ v „ongF IWWHF The Multivariate Normal DistributionF ƒpringerD y †—si™ekF en equili˜rium ™h—r—™teriz—tion of the term stru™tureF Journal of Financial EconomicsD SXIUU!VVD IWUUF ‚o˜ert i ‡h—leyF yn the v—lu—tion of emeri™—n ™—ll options on sto™ks with known dividendsF Journal of Financial EconomicsD WXPHU!ID IWVIF €—ul ‡ilmottD te' hewynneD —nd ƒ—m rowisonF Option Pricing.

Sign up to vote on this title
UsefulNot useful