LINEBURG


<< . .

 15
( 20)



. . >>

#include "newmat.h" // de¬nitions for newmat matrix library
using namespace NEWMAT;

#include <vector> // standard STL vector template
#include <algorithm>
using namespace std;

double option price put european ¬nite di¬ implicit(double S,
double X,
double r,
double sigma,
double time,
int no S steps,
int no t steps) {
double sigma sqr = sigma*sigma;
// need no S steps to be even:
int M; if ((no S steps%2)==1) { M=no S steps+1; } else { M=no S steps; };
double delta S = 2.0*S/M;
vector<double> S values(M+1);
for (int m=0;m<=M;m++) { S values[m] = m*delta S; };
int N=no t steps;
double delta t = time/N;

BandMatrix A(M+1,1,1); A=0.0;
A.element(0,0) = 1.0;
for (int j=1;j<M;++j) {
A.element(j,j’1) = 0.5*j*delta t*(r’sigma sqr*j); // a[j]
A.element(j,j) = 1.0 + delta t*(r+sigma sqr*j*j); // b[j];
A.element(j,j+1) = 0.5*j*delta t*(’r’sigma sqr*j); // c[j];
};
A.element(M,M)=1.0;
ColumnVector B(M+1);
for (int m=0;m<=M;++m){ B.element(m) = max(0.0,X’S values[m]); };
ColumnVector F=A.i()*B;
for(int t=N’1;t>0;’’t) {
B = F;
F = A.i()*B;
};
return F.element(M/2);
};


Code 15.1:




107
#include <cmath>
#include "newmat.h" // de¬nitions for newmat matrix library
using namespace NEWMAT;

#include <vector>
#include <algorithm>
using namespace std;

double option price put american ¬nite di¬ implicit( double S, double X,
double r, double sigma, double time,
int no S steps, int no t steps) {
double sigma sqr = sigma*sigma;
int M; // need no S steps to be even:
if ((no S steps%2)==1) { M=no S steps+1; } else { M=no S steps; };
double delta S = 2.0*S/M;
double S values[M+1];
for (int m=0;m<=M;m++) { S values[m] = m*delta S; };
int N=no t steps;
double delta t = time/N;

BandMatrix A(M+1,1,1); A=0.0;
A.element(0,0) = 1.0;
for (int j=1;j<M;++j) {
A.element(j,j’1) = 0.5*j*delta t*(r’sigma sqr*j); // a[j]
A.element(j,j) = 1.0 + delta t*(r+sigma sqr*j*j); // b[j];
A.element(j,j+1) = 0.5*j*delta t*(’r’sigma sqr*j); // c[j];
};
A.element(M,M)=1.0;
ColumnVector B(M+1);
for (int m=0;m<=M;++m){ B.element(m) = max(0.0,X’S values[m]); };
ColumnVector F=A.i()*B;
for(int t=N’1;t>0;’’t) {
B = F;
F = A.i()*B;
for (int m=1;m<M;++m) { // now check for exercise
F.element(m) = max(F.element(m), X’S values[m]);
};
};
return F.element(M/2);
};


Code 15.2:




108
Chapter 16

Mean Variance Analysis.
Contents
16.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
16.2 Mean variance portfolios. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
16.3 Short sales constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

We now ¬nally encounter a classical topic in ¬nance, mean variance analysis. This has had to wait because
we needed the tool of a linear algebra class before dealing with this.


16.1 Introduction.

The mean variance choice is one of the oldest ¬nance areas, dating back to work of Markowitz. The basic
assumption is that risk is measured by variance, and that the decision criterion should be to minimize
variance given expected return, or to maximize expected return for a given variance.
Mean variance analysis is very simple when expressed in vector format.
Let
® 
r1
e=E° . »
.
.
rn

be the expected return for the n assets, and
® 
σ11 ... σ1n
.
.
V=°
 
. »
σn1 ... σnn

be the covariance matrix.

σij = cov(ri , rj )

A portfolio of assets is expressed as
® 
ω1
ω=° . »
.
.
ωn

To ¬nd the expected return of a portfolio:

E[rp ] = ω e

and the variance of a portfolio:

σp = ω Vω



109
#include "newmat.h"
#include <cmath>
using namespace std;
using namespace NEWMAT;

double mv calculate mean(const Matrix& e, const Matrix& w){
Matrix tmp = e.t()*w;
return tmp.element(0,0);
};

double mv calculate variance(const Matrix& V, const Matrix& w){
Matrix tmp = w.t()*V*w;
return tmp.element(0,0);
};

double mv calculate st dev(const Matrix& V, const Matrix& w){
double var = mv calculate variance(V,w);
return sqrt(var);
};


Code 16.1:

16.2 Mean variance portfolios.

In the case where there are no short sales constraints, the minimum variance portfolio for any given expected
return has an analytical solution and is therefore easy to generate.
The portfolio given the expected return E[rp ] is found as

ωp = g + hE[rp ]

For the mathematics of generating the unconstrained MV frontier, see chapter 3 of Huang and Litzenberger
[1988].

// ¬le mv calc port unconstrained.cc
// author: Bernt A Oedegaard

#include "newmat.h"
using namespace NEWMAT;

ReturnMatrix mv calculate portfolio given mean unconstrained(const Matrix& e,
const Matrix& V,
const double& r){
int no assets=e.Nrows();
Matrix ones = Matrix(no assets,1); for (int i=0;i<no assets;++i){ ones.element(i,0) = 1; };
Matrix Vinv = V.i(); // inverse of V
Matrix A = (ones.t()*Vinv*e); double a = A.element(0,0);
Matrix B = e.t()*Vinv*e; double b = B.element(0,0);
Matrix C = ones.t()*Vinv*ones; double c = C.element(0,0);
Matrix D = B*C ’ A*A; double d = D.element(0,0);
Matrix Vinv1=Vinv*ones;
Matrix Vinve=Vinv*e;
Matrix g = (Vinv1*b ’ Vinve*a)*(1.0/d);
Matrix h = (Vinve*c ’ Vinv1*a)*(1.0/d);
Matrix w = g + h*r;
w.Release();
return w;
};


Code 16.2:



110
16.3 Short sales constraints

In real applications, it is often not possible to sell assets short. In that case we need to add a constraint that
all portfolio weights shall be zero or above.
When constraining the short sales, we need to solve a quadratic program.

min ω Vω

subject to

ω1=1

ω e = E[rp ]

ωi ∈ [0, 1] ∀ i




111
Chapter 17

Pricing of bond options, basic models
Contents
17.1 Black Scholes bond option pricing . . . . . . . . . . . . . . . . . . . . . . . . . . 112
17.2 Binomial bond option pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114


The area of ¬xed income securities is one where a lot of work is being done in creating advanced mathematical
models for pricing of ¬nancial securities, in particular ¬xed income derivatives. The focus of the modelling in
this area is on modelling the term structure of interest rates and its evolution over time, which is then used
to price both bonds and ¬xed income derivatives. However, in some cases one does not need the machinery
of term structure modelling which we™ll look at in later chapters, and price derivatives by modelling the
evolution of the bond price directly.
Speci¬cally, suppose that the price of a Bond follows a Geometric Brownian Motion process, just like the
case we have studied before. This is not a particularly realistic assumption for the long term behaviour
of bond prices, since any bond price converges to the bond face value at the maturity of the bond. The
Geometric Brownian motion may be OK for the case of short term options on long term bonds.


17.1 Black Scholes bond option pricing

Given the assumed Brownian Motion process, prices of European Bond Options can be found using the usual
Black Scholes formula, as shown in code 17.1 for a zero coupon bond and code 17.2 for the case of an option
on a coupon bond.

#include <cmath>
#include "normdist.h"

double bond option price put zero black scholes(const double& B,
const double& X,
const double& r,
const double& sigma,
const double& time){
double time sqrt = sqrt(time);
double d1 = (log(B/X)+r*time)/(sigma*time sqrt) + 0.5*sigma*time sqrt;
double d2 = d1’(sigma*time sqrt);
double p = X * exp(’r*time) * N(’d2) ’ B * N(’d1);
return p;
};


Code 17.1: Black scholes price for European call option on zero coupon bond




112
#include <cmath>
#include <vector>
using namespace std;
#include "normdist.h"
#include "fin_recipes.h"

double bond option price put coupon bond black scholes( const double& B,
const double& X,
const double& r,
const double& sigma,
const double& time,
const vector<double> coupon times,
const vector<double> coupon amounts){
double adjusted B=B;
for (unsigned int i=0;i<coupon times.size();i++) {
if (coupon times[i]<=time) {
adjusted B ’= coupon amounts[i] * exp(’r*coupon times[i]);
};
};
return bond option price put zero black scholes(adjusted B,X,r,sigma,time);
};


Code 17.2: Black scholes price for European call option on coupon bond




113
17.2 Binomial bond option pricing

Since we are in the case of geometric Brownian motion, the usual binomial approximation can be used to
price American options, where the bond is the underlying security. Code 17.3 shows the calculation of a put
price

#include <cmath> // standard mathematical library
#include <algorithm> // de¬ning the max() operator
#include <vector> // STL vector templates
using namespace std;

double bond option price put american binomial( const double& B, // Bond price
const double& K, // exercise price
const double& r, // interest rate
const double& sigma, // volatility
const double& t, // time to maturity
const int& steps){ // no steps in binomial tree
double R = exp(r*(t/steps)); // interest rate for each step
double Rinv = 1.0/R; // inverse of interest rate
double u = exp(sigma*sqrt(t/steps)); // up movement
double uu = u*u;
double d = 1.0/u;
double p up = (R’d)/(u’d);
double p down = 1.0’p up;
vector<double> prices(steps+1); // price of underlying
vector<double> put values(steps+1); // value of corresponding put

prices[0] = B*pow(d, steps); // ¬ll in the endnodes.
for (int i=1; i<=steps; ++i) prices[i] = uu*prices[i’1];
for (int i=0; i<=steps; ++i) put values[i] = max(0.0, (K’prices[i])); // put payo¬s at maturity
for (int step=steps’1; step>=0; ’’step) {
for (int i=0; i<=step; ++i) {
put values[i] = (p up*put values[i+1]+p down*put values[i])*Rinv;
prices[i] = d*prices[i+1];
put values[i] = max(put values[i],(K’prices[i])); // check for exercise
};
};
return put values[0];
};


Code 17.3: Binomial approximation to american bond option price




114
The program

void test bond option gbm pricing(){
double B=100;
double K=100;
double r=0.05;
double sigma=0.1;
double time=1;
cout << " zero coupon put option price = "
<< bond option price put zero black scholes(B,K,r,sigma,time) << endl;

vector<double> coupon times; coupon times.push back(0.5);
vector<double> coupons; coupons.push back(1);
cout << " coupon bond put option price = "
<< bond option price put coupon bond black scholes(B,K,r,sigma,time,coupon times,coupons);
cout << endl;

int steps=100;
cout << " zero coupon american put option price, binomial = "
<< bond option price put american binomial(B,K,r,sigma,time,steps) << endl;
};


provides the output
zero coupon put option price = 1.92791
coupon bond put option price = 2.22852
zero coupon american put option price, binomial = 2.43282




115
Chapter 18

Credit risk
18.1 The Merton Model

<< . .

 15
( 20)



. . >>

Copyright Design by: Sunlight webdesign