hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_pde_1d_blackscholes_closed (d03nd)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_pde_1d_blackscholes_closed (d03nd) computes an analytic solution to the Black–Scholes equation for a certain set of option types.

Syntax

[f, theta, delta, gamma, lambda, rho, ifail] = d03nd(kopt, x, s, t, tmat, tdpar, r, q, sigma)
[f, theta, delta, gamma, lambda, rho, ifail] = nag_pde_1d_blackscholes_closed(kopt, x, s, t, tmat, tdpar, r, q, sigma)

Description

nag_pde_1d_blackscholes_closed (d03nd) computes an analytic solution to the Black–Scholes equation (see Hull (1989) and Wilmott et al. (1995))
f t + r-q S f S + σ2 S2 2 2f S2 =rf (1)
Smin< S<Smax,   tmin<t< tmax, (2)
for the value f of a European put or call option, or an American call option with zero dividend q. In equation (1) t is time, S is the stock price, X is the exercise price, r is the risk free interest rate, q is the continuous dividend, and σ is the stock volatility. The parameter r, q and σ may be either constant, or functions of time. In the latter case their average instantaneous values over the remaining life of the option should be provided to nag_pde_1d_blackscholes_closed (d03nd). An auxiliary function nag_pde_1d_blackscholes_means (d03ne) is available to compute such averages from values at a set of discrete times. Equation (1) is subject to different boundary conditions depending on the type of option. For a call option the boundary condition is
f S, t = tmat = max 0,S-X  
where tmat is the maturity time of the option. For a put option the equation (1) is subject to
f S, t = tmat = max 0,X-S .  
nag_pde_1d_blackscholes_closed (d03nd) also returns values of the Greeks
Θ= f t ,   Δ= f x ,   Γ= 2f x2 ,   Λ= f σ ,   ρ= f r .  
nag_specfun_opt_bsm_greeks (s30ab) also computes the European option price given by the Black–Scholes–Merton formula together with a more comprehensive set of sensitivities (Greeks).
Further details of the analytic solution returned are given in Algorithmic Details.

References

Hull J (1989) Options, Futures and Other Derivative Securities Prentice–Hall
Wilmott P, Howison S and Dewynne J (1995) The Mathematics of Financial Derivatives Cambridge University Press

Parameters

Compulsory Input Parameters

1:     kopt int64int32nag_int scalar
Specifies the kind of option to be valued:
kopt=1
A European call option.
kopt=2
An American call option.
kopt=3
A European put option.
Constraints:
  • kopt=1, 2 or 3;
  • if q0, kopt2.
2:     x – double scalar
The exercise price X.
Constraint: x0.0.
3:     s – double scalar
The stock price at which the option value and the Greeks should be evaluated.
Constraint: s0.0.
4:     t – double scalar
The time at which the option value and the Greeks should be evaluated.
Constraint: t0.0.
5:     tmat – double scalar
The maturity time of the option.
Constraint: tmatt.
6:     tdpar3 – logical array
Specifies whether or not various arguments are time-dependent. More precisely, r is time-dependent if tdpar1=true and constant otherwise. Similarly, tdpar2 specifies whether q is time-dependent and tdpar3 specifies whether σ is time-dependent.
7:     r: – double array
The dimension of the array r must be at least 3 if tdpar1=true, and at least 1 otherwise
If tdpar1=false then r1 must contain the constant value of r. The remaining elements need not be set.
If tdpar1=true then r1 must contain the value of r at time t and r2 must contain its average instantaneous value over the remaining life of the option:
r^=ttmatrζdζ.  
The auxiliary function nag_pde_1d_blackscholes_means (d03ne) may be used to construct r from a set of values of r at discrete times.
8:     q: – double array
The dimension of the array q must be at least 3 if tdpar2=true, and at least 1 otherwise
If tdpar2=false then q1 must contain the constant value of q. The remaining elements need not be set.
If tdpar2=true then q1 must contain the constant value of q and q2 must contain its average instantaneous value over the remaining life of the option:
q^=ttmatqζdζ.  
The auxiliary function nag_pde_1d_blackscholes_means (d03ne) may be used to construct q from a set of values of q at discrete times.
9:     sigma: – double array
The dimension of the array sigma must be at least 3 if tdpar3=true, and at least 1 otherwise
If tdpar3=false then sigma1 must contain the constant value of σ. The remaining elements need not be set.
If tdpar3=true then sigma1 must contain the value of σ at time t, sigma2 the average instantaneous value σ^, and sigma3 the second-order average σ-, where:
σ^=ttmatσζdζ,  
σ-= ttmat σ2 ζ dζ 1/2 .  
The auxiliary function nag_pde_1d_blackscholes_means (d03ne) may be used to compute sigma from a set of values at discrete times.
Constraints:
  • if tdpar3=false, sigma1>0.0;
  • if tdpar3=true, sigmai>0.0, for i=1,2,3.

Optional Input Parameters

None.

Output Parameters

1:     f – double scalar
The value f of the option at the stock price s and time t.
2:     theta – double scalar
3:     delta – double scalar
4:     gamma – double scalar
5:     lambda – double scalar
6:     rho – double scalar
The values of various Greeks at the stock price s and time t, as follows:
theta=Θ= f t , delta=Δ= f s , gamma=Γ= 2f s2 , lambda=Λ= f σ , rho=ρ= f r .  
7:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
On entry,kopt<1,
orkopt>3,
orkopt=2 when q0,
orx<0.0,
ors<0.0,
ort<0.0,
ortmat<t,
orsigma10.0, with tdpar3=false,
orsigmai0.0, with tdpar3=true, for some i=1, 2 or 3.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Given accurate values of r, q and sigma no further approximations are made in the evaluation of the Black–Scholes analytic formulae, and the results should therefore be within machine accuracy. The values of r, q and sigma returned from nag_pde_1d_blackscholes_means (d03ne) are exact for polynomials of degree up to 3.

Further Comments

Algorithmic Details

The Black–Scholes analytic formulae are used to compute the solution. For a European call option these are as follows:
f= S e -q^ T-t N d1- X e -r^ T-t Nd2  
where
d1 = logS/X+r^-q^+σ-2/2T-t σ-T-t , d2 = logS/X+r^-q^-σ-2/2T-t σ-T-t =d1-σ-T-t,  
Nx is the cumulative Normal distribution function and Nx is its derivative
Nx = 12π -x e-ζ2/2dζ, Nx = 12π e-x2/2.  
The functions q^, r^, σ^ and σ- are average values of q, r and σ over the time to maturity:
q^ = 1T-t tT qζdζ, r^ = 1T-t tT rζdζ, σ^ = 1T-t tT σζdζ, σ- = 1T-t tT σ2ζdζ 1/2 .  
The Greeks are then calculated as follows:
Δ = f S =e-q^T-t Nd1+ Se-q^T-t Nd1-Xe-r^T-t Nd2 σ-ST-t , Γ = 2 f S2 = Se-q^T-t Nd1+Xe-r^T-t Nd2 σ-S2T-t + Se-q^T-t Nd1-Xe-r^T-t Nd2 σ-2S2T-t , Θ = f t =rf+q-r SΔ- σ2 S22Γ, Λ = f σ = X d1 e-r^T-t Nd2-S d2 e-q^T-t Nd1 σ-2 σ^, ρ = f r =XT-t e-r^T-t Nd2+ Se-q^T-t Nd1-Xe-r^T-t Nd2 T-tσ-.  
Note: that Θ is obtained from substitution of other Greeks in the Black–Scholes partial differential equation, rather than differentiation of f. The values of q, r and σ appearing in its definition are the instantaneous values, not the averages. Note also that both the first-order average σ^ and the second-order average σ- appear in the expression for Λ. This results from the fact that Λ is the derivative of f with respect to σ, not σ^.
For a European put option the equivalent equations are:
f = Xe-r^T-t N-d2-Se-q^T-t N-d1, Δ = f S =-e-q^T-t N-d1+ Se-q^T-t N-d1-Xe-r^T-t N-d2 σ-ST-t , Γ = 2f S2 = Xe-r^T-t N-d2+Se-q^T-t N-d1 σ-S2T-t + Xe-r^T-t N-d2-Se-q^T-t N-d1 σ-2S2T-t , Θ = f t =rf+q-rSΔ- σ2S22Γ, Λ = f σ = Xd1 e-r^T-t N-d2-S d2 e-q^T-t N-d1 σ-2 σ^, ρ = f r =-XT-t e-r^T-t N-d2+ Se-q^T-t N-d1-Xe-r^T-t N-d2 T-tσ^.  
The analytic solution for an American call option with q=0 is identical to that for a European call, since early exercise is never optimal in this case. For all other cases no analytic solution is known.

Example

This example solves the Black–Scholes equation for valuation of a 5-month American call option on a non-dividend-paying stock with an exercise price of $50. The risk-free interest rate is 10% per annum, and the stock volatility is 40% per annum.
The option is valued at a range of times and stock prices.
function d03nd_example


fprintf('d03nd example results\n\n');

% American 5-month call option, exercise price 50

kopt = int64(2);
x = 50;
ns    = 21;  nt    = 4;
s_beg = 0;   t_beg = 0;
s_end = 100; t_end = 0.125;
tmat  = 0.4166667;
tdpar = [false; false; false];
r     = [0.1];
q     = [0];
sigma = [0.4];

% Discretize s and t
ds = (s_end-s_beg)/(ns-1);
dt = (t_end-t_beg)/(nt-1);
s = [s_beg:ds:s_end];
t = [t_beg:dt:t_end];

f = zeros(ns,nt);
theta = f; delta = f; gamma = f; lambda = f; rho = f;

% Loop over times and prices
for j = 1:nt
  for i = 1:ns
    [f(i,j),theta(i,j),delta(i,j),gamma(i,j),lambda(i,j),rho(i,j),ifail] = ...
    d03nd( ...
           kopt, x, s(i), t(j), tmat, tdpar, r, q, sigma);
  end
end

% Tabulate option values only
print_greek(ns,nt,tmat,s,t,'Option Values',f);
% print_greek(ns,nt,tmat,s,t,'Theta',theta);
% print_greek(ns,nt,tmat,s,t,'Delta',delta);
% print_greek(ns,nt,tmat,s,t,'Gamma',gamma);
% print_greek(ns,nt,tmat,s,t,'Lambda',lambda);
% print_greek(ns,nt,tmat,s,t,'Rho',rho);

% plot initial and final option values and greeks 
fig1 = figure;
plot(s,f(:,1),s,theta(:,1),s,delta(:,1),s,gamma(:,1),s,lambda(:,1),s,rho(:,1));
legend('value','theta','delta','gamma','lambda','rho','Location','NorthWest');
title('Option values and greeks at 5 months to maturity');
xlabel('stock price');
ylabel('values and derivatives');
fig2 = figure;
plot(s,f(:,4),s,theta(:,4),s,delta(:,4),s,gamma(:,4),s,lambda(:,4),s,rho(:,4));
legend('value','theta','delta','gamma','lambda','rho','Location','NorthWest');
title('Option values and greeks at 3.5 months to maturity');
xlabel('stock price');
ylabel('values and derivatives');



function print_greek(ns,nt,tmat,s,t,grname,greek)

  fprintf('\n%s\n\n',grname);
  fprintf('  Stock Price  |   Time to Maturity (months)\n');
  fprintf('%16s %12.4e%12.4e%12.4e%12.4e\n', '|', 12*(tmat-t));
  fprintf('%15s+%48s\n', '---------------', ...
          '-------------------------------------------------');
  for i = 1:ns
    fprintf('%12.4e%4s %12.4e%12.4e%12.4e%12.4e\n', s(i), '|', greek(i,:));
  end
d03nd example results


Option Values

  Stock Price  |   Time to Maturity (months)
               |   5.0000e+00  4.5000e+00  4.0000e+00  3.5000e+00
---------------+-------------------------------------------------
  0.0000e+00   |   0.0000e+00  0.0000e+00  0.0000e+00  0.0000e+00
  5.0000e+00   |   4.4491e-19  4.5989e-21  1.5461e-23  1.0478e-26
  1.0000e+01   |   5.5566e-10  5.5129e-11  3.1298e-12  8.0281e-14
  1.5000e+01   |   4.7337e-06  1.2187e-06  2.2774e-07  2.7003e-08
  2.0000e+01   |   7.2236e-04  3.1054e-04  1.1005e-04  2.9678e-05
  2.5000e+01   |   1.6557e-02  9.6610e-03  5.0099e-03  2.2012e-03
  3.0000e+01   |   1.3307e-01  9.4037e-02  6.1869e-02  3.6848e-02
  3.5000e+01   |   5.6631e-01  4.5257e-01  3.4667e-01  2.5053e-01
  4.0000e+01   |   1.6004e+00  1.3850e+00  1.1699e+00  9.5640e-01
  4.5000e+01   |   3.4384e+00  3.1328e+00  2.8168e+00  2.4891e+00
  5.0000e+01   |   6.1165e+00  5.7600e+00  5.3874e+00  4.9960e+00
  5.5000e+01   |   9.5300e+00  9.1645e+00  8.7846e+00  8.3882e+00
  6.0000e+01   |   1.3509e+01  1.3163e+01  1.2808e+01  1.2445e+01
  6.5000e+01   |   1.7883e+01  1.7568e+01  1.7251e+01  1.6932e+01
  7.0000e+01   |   2.2513e+01  2.2230e+01  2.1949e+01  2.1671e+01
  7.5000e+01   |   2.7301e+01  2.7045e+01  2.6792e+01  2.6544e+01
  8.0000e+01   |   3.2182e+01  3.1946e+01  3.1713e+01  3.1485e+01
  8.5000e+01   |   3.7117e+01  3.6894e+01  3.6674e+01  3.6458e+01
  9.0000e+01   |   4.2081e+01  4.1868e+01  4.1656e+01  4.1446e+01
  9.5000e+01   |   4.7062e+01  4.6854e+01  4.6647e+01  4.6441e+01
  1.0000e+02   |   5.2052e+01  5.1847e+01  5.1643e+01  5.1439e+01
d03nd_fig1.png
d03nd_fig2.png

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015