LINEBURG


<< . .

 19
( 20)



. . >>

const double& r, const double& sigma,
const double& time to maturity, const int& no sims);
double option price delta call european simulated(const double& S, const double& K,
const double& r, const double& sigma,
const double& time to maturity, const int& no sims);
double option price delta put european simulated(const double& S, const double& K,
const double& r, const double& sigma,
const double& time to maturity, const int& no sims);
double simulate lognormal random variable(const double& S, const double& r, const double& sigma,
const double& time);

double
derivative price simulate european option generic( const double& S, const double& K,
const double& r, const double& sigma,
const double& time,
double payo¬(const double& price, const double& K),
const int& no sims);
double
derivative price simulate european option generic with control variate(const double& S, const double& K,
const double& r,const double& sigma,
const double& time,
double payo¬(const double& price,
const double& K),
const int& no sims);

double
derivative price simulate european option generic with antithetic variate(const double& S, const double& K,
const double& r,
const double& sigma,
const double& time,
double payo¬(const double&price,
const double& K),
const int& no sims);
/////////////////////////////
// payo¬s of various options, to be used as function arguments in above simulations
double payo¬ call(const double& price, const double& K);
double payo¬ put (const double& price, const double& K);
double payo¬ cash or nothing call(const double& price, const double& K);
double payo¬ asset or nothing call(const double& price, const double& K);

/////////// approximated option prices ////////////////////////

double option price american call approximated baw(const double& S, const double& K,
const double& r, const double& b,
const double& sigma, const double& time);
double option price american put approximated baw(const double& S, const double& K,
const double& r, const double& b,
const double& sigma, const double& time);


////////////// path dependent and other exotic options ////////////////////////////////

double option price call bermudan binomial(const double& S, const double& X, const double& r,
const double& q, const double& sigma, const double& time,
const vector<double>& potential exercise times,
const int& steps);




139
double option price put bermudan binomial( const double& S, const double& X, const double& r,
const double& q, const double& sigma, const double& time,
const vector<double>& potential exercise times,
const int& steps);

double option price european lookback call(const double& S, const double& Smin, const double& r,
const double& q, const double& sigma, const double& time);

double option price european lookback put(const double& S, const double& Smin, const double& r,
const double& q, const double& sigma, const double& time);


double
option price asian geometric average price call(const double& S, const double& K, const double& r,
const double& q, const double& sigma, const double& time);

vector<double> simulate lognormally distributed sequence(const double& S, const double& r,
const double& sigma, const double& time, const int& no steps);
double
derivative price simulate european option generic( const double& S, const double& K, const double& r,
const double& sigma, const double& time,
double payo¬(const vector<double>& price,
const double& K),
const int& no steps, const int& no sims);


double
derivative price simulate european option generic with control variate(const double& S, const double& K,
const double& r, const double& sigma,
const double& time,
double payo¬(const vector<double>& price,
const double& K),
const int& nosteps, const int& nosims);


/////////////////////////////
// payo¬s of various options, to be used as function arguments in above simulations

double payo¬ arithmetric average call(const vector<double>& prices, const double& K);
double payo¬ geometric average call(const vector<double>& prices, const double& K);
double payo¬ lookback call(const vector<double>& prices, const double& unused variable);
double payo¬ lookback put(const vector<double>& prices, const double& unused variable);

/////////////////// alternative stochastic processes ////////////////

double option price call merton jump di¬usion( const double& S, const double& K, const double& r,
const double& sigma, const double& time to maturity,
const double& lambda, const double& kappa, const double& delta);

// ¬xed income derivatives, GBM assumption on bond price

double bond option price call zero black scholes(const double& B, const double& K, const double& r,
const double& sigma, const double& time);
double bond option price put zero black scholes(const double& B, const double& K, const double& r,
const double& sigma, const double& time);
double bond option price call coupon bond black scholes(const double& B, const double& K, const double& r,
const double& sigma, const double& time,
const vector<double> coupon times,
const vector<double> coupon amounts);
double bond option price put coupon bond black scholes(const double& B, const double& K, const double& r,
const double& sigma, const double& time,
const vector<double> coupon times,
const vector<double> coupon amounts);
double bond option price call american binomial( const double& B, const double& K, const double& r,
const double& sigma, const double& t, const int& steps);
double bond option price put american binomial( const double& B, const double& K, const double& r,
const double& sigma, const double& t, const int& steps);



140
////////////////////////////////////////////////////////////////////////////////
// term structure models

double term structure yield nelson siegel(const double& t,
const double& beta0, const double& beta1, const double& beta2,
const double& lambda );


double term structure discount factor cubic spline(const double& t,
const double& b1,
const double& c1,
const double& d1,
const vector<double>& f,
const vector<double>& knots);

double term structure discount factor cir(const double& t, const double& r,
const double& kappa,
const double& lambda,
const double& theta,
const double& sigma);

double term structure discount factor vasicek(const double& time,
const double& r,
const double& a,const double& b, const double& sigma);



/////////////////
/// binomial term structure models
/// bond option, rendlemann bartter (binomial)

double
bond option price call zero american rendleman bartter(const double& K, const double& option maturity,
const double& S, const double& M,
const double& interest,
const double& bond maturity,
const double& maturity payment,
const int& no steps);




141
Appendix D

Installation
The routines discussed in the book are available for download.


D.1 Source availability

The algorithms are available from my home page as a ZIP ¬le containing the source code. These have been
tested with the latest version of the GNU C++ compiler. As the algorithms in places uses code from the
Standard Template Library, other compilers may not be able to compile all the ¬les directly. If your compiler
complains about missing header ¬les you may want to check if the STL header ¬les have di¬erent names on
your system. The algorithm ¬les will track the new ANSI standard for C++ libraries as it is being settled
on. If the compiler is more than a couple of years old, it will not have STL. Alternatively, the GNU compiler
gcc is available for free on the internet, for most current operating systems.




142
List of Codes
1.1 A complete program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 De¬ning a date class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1 Present value with discrete compounding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2 Present value calculation with continously compounded interest . . . . . . . . . . . . . . . . . 13
2.3 Estimation of the internal rate of return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.4 Test for uniqueness of IRR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.5 Bond price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.6 Bond price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.7 Bond price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.8 Bond yield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.9 Bond duration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.10 Calculating the Macaulay duration of a bond . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.11 Modi¬ed duration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.12 Bond convexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.1 Term structure transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2 Interpolated term structure from spot rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3 ......................................... . . . . . . . . . . . . 23
3.4 ......................................... . . . . . . . . . . . . 24
3.5 ......................................... . . . . . . . . . . . . 25
3.6 ......................................... . . . . . . . . . . . . 25
3.7 ......................................... . . . . . . . . . . . . 26
3.8 ......................................... . . . . . . . . . . . . 27
3.9 Pricing a bond with a term structure class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.10 Calculating a bonds duration with a term structure class . . . . . . . . . . . . . . . . . . . . . 28
4.1 Futures price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.1 Binomial European, one period . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2 Building a binomial tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.3 Binomial multiperiod pricing of European call option . . . . . . . . . . . . . . . . . . . . . . . 35
6.1 Price of European call option using the Black Scholes formula . . . . . . . . . . . . . . . . . . 38
6.2 Calculating the delta of the Black Scholes call option price . . . . . . . . . . . . . . . . . . . . 41
6.3 Calculating the partial derivatives of a Black Scholes call option . . . . . . . . . . . . . . . . . 42
6.4 Calculation of implied volatility of Black Scholes using bisections . . . . . . . . . . . . . . . . 44
6.5 Calculation of implied volatility of Black Scholes using Newton-Raphson . . . . . . . . . . . . 45
7.1 Adjusted Black Scholes value for a Warrant . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
8.1 Option price, continous payout from underlying . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.2 European option price, dividend paying stock . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.3 Option price, Roll“Geske“Whaley call formula for dividend paying stock . . . . . . . . . . . . 54
8.4 Price of European Call option on Futures contract . . . . . . . . . . . . . . . . . . . . . . . . 56
8.5 European Futures Call option on currency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.6 Price for an american perpetual call option . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60


143
9.1 Option price for binomial european . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 64
9.2 Binomial option price american opstion . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 65
9.3 Delta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 66
9.4 Hedge parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 67
9.5 Binomial option price with continous payout . . . . . . . . . . . . . . . . . . . . . . . . ... 69
9.6 Binomial option price of stock option where stock pays proportional dividends . . . . . ... 71
9.7 Binomial option price of stock option where stock pays discrete dividends . . . . . . . . ... 72
9.8 Option on futures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 74
9.9 Binomial Currency Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 75
10.1 Explicit ¬nite di¬erences calculation of european put option . . . . . . . . . . . . . . . . ... 78
10.2 Explicit ¬nite di¬erences calculation of american put option . . . . . . . . . . . . . . . . ... 79
11.1 Simulating a lognormally distributed random variable . . . . . . . . . . . . . . . . . . . ... 82
11.2 European Call option priced by simulation . . . . . . . . . . . . . . . . . . . . . . . . . . ... 82
11.3 Estimate Delta of European Call option priced by Monte Carlo . . . . . . . . . . . . . . ... 83
11.4 Payo¬ call and put options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 84
11.5 Generic simulation pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 84
11.6 Simulating Black Scholes values using the generic routine . . . . . . . . . . . . . . . . . ... 85
11.7 Generic with control variate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 86
11.8 Generic with antithetic variates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 87
11.9 Simulating Black Scholes values using the generic Monte Carlo routines, with e¬ciency im-
provents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 88
11.10Payo¬ binary options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 90
12.1 Barone Adesi quadratic approximation to the price of a call option . . . . . . . . . . . . ... 93
13.1 Binomial approximation to Bermudan put option . . . . . . . . . . . . . . . . . . . . . . ... 96
13.2 Analytical price of an Asian geometric average price call . . . . . . . . . . . . . . . . . . ... 98
13.3 Price of lookback call option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 99
13.4 Simulating a sequence of lognormally distributed variables . . . . . . . . . . . . . . . . . ... 100
13.5 Generic routine for pricing European options which . . . . . . . . . . . . . . . . . . . . ... 101
13.6 Payo¬ function for Asian call option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 101
13.7 Payo¬ function for lookback option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 102
13.8 Control Variate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 103
14.1 Mertons jump di¬usion formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 105
15.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 107
15.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 108
16.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 110
16.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 110
17.1 Black scholes price for European call option on zero coupon bond . . . . . . . . . . . . . ... 112
17.2 Black scholes price for European call option on coupon bond . . . . . . . . . . . . . . . ... 113
17.3 Binomial approximation to american bond option price . . . . . . . . . . . . . . . . . . . ... 114
19.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 117
19.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 118
19.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 118
19.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... 118



144
19.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
19.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
19.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
19.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
19.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
19.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
19.11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
19.12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
20.1 Building an interest rate tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
20.2 RB binomial model for European call on zero coupon bond . . . . . . . . . . . . . . . . . . . 126
21.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
A.1 The normal distribution function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
A.2 The cumulative normal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
A.3 Approximation to the cumulative bivariate normal . . . . . . . . . . . . . . . . . . . . . . . . 131
A.4 Pseudorandom numbers from an uniform [0, 1) distribution . . . . . . . . . . . . . . . . . . . 132
A.5 Pseudorandom numbers from a normal (0, 1) distribution . . . . . . . . . . . . . . . . . . . . 132




145
Appendix E

Acknowledgements.
After this paper was put up on the net, I™ve had quite a few emails about them. Some of them has pointed
out bugs etc.
Among the ones I want to say thanks to for making improving suggestions and pointing out bugs are
EARAUJO@pactual.com.br
Jens Larsson <d96-jla@d.kth.se>
Michael L Locher
Lars Gregori
Steve Bellantoni <scj@cs.toronto.edu>
Steven Leadbeater <steven.leadbeater@edfman.com>
Ariel Almedal
Lotti Luca, Milano, Italy
jean-paul.beveraggi@gadz.org




146
Index
γ, 41 option, 58
ρ, 41 currency option
θ, 41 American, 75
European, 58
antithetic variates, 86 currency option price call american binomial, 75
antithetic variates, 86 currency option price call european, 58
asset or nothing call, 90
day, 9
Barone“Adesi and Whaley, 91 delta, 41
binary option, 90 binomial, 66
binomial option price, 30, 62 Black Scholes, 41
binomial term structure models, 124 derivative price simulate european option generic,
binomial tree, 35 84, 101
Black derivative price simulate european option generic with antithe
futures option, 56 87
Black Scholes option pricing formula, 37 derivative price simulate european option generic with control
bond, 16 86, 103
price, 16 discount factor, 12
yield, 17 double (C++ type), 4
bond option duration, 19
basic binomial, 114 Macaulay, 19
Black Scholes, 112 modi¬ed, 19
Vasicek, 127
early exercise premium, 91
bond option price call zero american rendleman bartter,
exp() (C++ statement), 5
126
explicit ¬nite di¬erences, 77
bond option price call zero vasicek, 128
bond option price put american binomial, 114
f, 131
bond option price put coupon bond black scholes,
¬nite di¬erences, 77, 106
113
explicit, 77
bond option price put zero black scholes, 112
for (C++ statement), 6
bonds convexity, 20
function prototypes (C++ concept), 84
bonds duration, 19, 28
futures
bonds duration macaulay, 20
option, 56
bonds duration modi¬ed, 20
futures option price call american binomial, 74
bonds price, 16, 17, 28
futures option price call european black, 56
bonds price discrete, 17, 135
futures price, 29
bonds yield to maturity, 18
bool (C++ type), 4
gamma, 41
build interest rate tree rendleman bartter, 125
geometric Brownian motion, 40
call option, 30
hedging parameters
cash ¬‚ow, 11
Black Scholes, 41
cash or nothing call, 90
cash ¬‚ow irr, 14 implied volatility
cash ¬‚ow pv, 13 calculation, 44
cash ¬‚ow pv discrete, 12 include (C++ statement), 5
cash ¬‚ow unique irr, 15 int (C++ type), 4
class, 8 internal rate of return, 12
cmath, 5 irr, 12
control variates, 85 unique, 15
Cox Ingersoll Ross term structure model, 120
currency Jump Di¬usion, 104

147
long (C++ type), 4 option price implied volatility call black scholes bisections,
lookback option, 99 44

<< . .

 19
( 20)



. . >>

Copyright Design by: Sunlight webdesign