NAG Library Function Document

nag_pde_bs_1d_means (d03nec)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

nag_pde_bs_1d_means (d03nec) computes average values of a continuous function of time over the remaining life of an option. It is used together with nag_pde_bs_1d_analytic (d03ndc) to value options with time-dependent arguments.

2
Specification

#include <nag.h>
#include <nagd03.h>
void  nag_pde_bs_1d_means (double t0, double tmat, Integer ntd, const double td[], const double phid[], double phiav[], NagError *fail)

3
Description

nag_pde_bs_1d_means (d03nec) computes the quantities
ϕt0,   ϕ^=1T-t0 t0Tϕζdζ,   ϕ-= 1T-t0 t0Tϕ2ζdζ 1/2  
from a given set of values phid of a continuous time-dependent function ϕt at a set of discrete points td, where t0 is the current time and T is the maturity time. Thus ϕ^ and ϕ- are first and second order averages of ϕ over the remaining life of an option.
The function may be used in conjunction with nag_pde_bs_1d_analytic (d03ndc) in order to value an option in the case where the risk-free interest rate r, the continuous dividend q, or the stock volatility σ is time-dependent and is described by values at a set of discrete times (see Section 9.2). This is illustrated in Section 10.

4
References

None.

5
Arguments

1:     t0 doubleInput
On entry: the current time t0.
Constraint: td[0]t0td[ntd-1].
2:     tmat doubleInput
On entry: the maturity time T.
Constraint: td[0]tmattd[ntd-1].
3:     ntd IntegerInput
On entry: the number of discrete times at which ϕ is given.
Constraint: ntd2.
4:     td[ntd] const doubleInput
On entry: the discrete times at which ϕ is specified.
Constraint: td[0]<td[1]<<td[ntd-1].
5:     phid[ntd] const doubleInput
On entry: phid[i-1] must contain the value of ϕ at time td[i-1], for i=1,2,,ntd.
6:     phiav[3] doubleOutput
On exit: phiav[0] contains the value of ϕ interpolated to t0, phiav[1] contains the first-order average ϕ^ and phiav[2] contains the second-order average ϕ-, where:
ϕ^=1T-t0 t0Tϕζdζ ,   ϕ-= 1T-t0 t0Tϕ2ζdζ 1/2 .  
7:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, ntd=value.
Constraint: ntd2.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Unexpected failure in internal call to spline function.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_NOT_STRICTLY_INCREASING
On entry, td[I]td[I-1], for I=value.
NE_REAL_3
On entry, t0 lies outside the range td[0],td[ntd-1]: t0=value, td[0]=value and td[ntd-1]=value.
On entry, tmat lies outside the range td[0],td[ntd-1]: tmat=value, td[0]=value and td[ntd-1]=value.

7
Accuracy

If ϕC4t0,T then the error in the approximation of ϕt0 and ϕ^ is OH4, where H=maxiTi+1-Ti, for i=1,2,,ntd-1. The approximation is exact for polynomials of degree up to 3.
The third quantity ϕ- is OH2, and exact for linear functions.

8
Parallelism and Performance

nag_pde_bs_1d_means (d03nec) is not threaded in any implementation.

9
Further Comments

9.1
Timing

The time taken is proportional to ntd.

9.2
Use with nag_pde_bs_1d_analytic (d03ndc)

Suppose you wish to evaluate the analytic solution of the Black–Scholes equation in the case when the risk-free interest rate r is a known function of time, and is represented as a set of values at discrete times. A call to nag_pde_bs_1d_means (d03nec) providing these values in phid produces an output array phiav suitable for use as the argument r in a subsequent call to nag_pde_bs_1d_analytic (d03ndc).
Time-dependent values of the continuous dividend Q and the volatility σ may be handled in the same way.

9.3
Algorithmic Details

The ntd data points are fitted with a cubic B-spline using the function nag_1d_spline_interpolant (e01bac). Evaluation is then performed using nag_1d_spline_evaluate (e02bbc), and the definite integrals are computed using direct integration of the cubic splines in each interval. The special case of T=to is handled by interpolating ϕ at that point.

10
Example

This example demonstrates the use of the function in conjunction with nag_pde_bs_1d_analytic (d03ndc) to solve 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 varies linearly with time and the stock volatility has a quadratic variation. Since these functions are integrated exactly by nag_pde_bs_1d_means (d03nec) the solution of the Black–Scholes equation by nag_pde_bs_1d_analytic (d03ndc) is also exact.
The option is valued at a range of times and stock prices.

10.1
Program Text

Program Text (d03nece.c)

10.2
Program Data

Program Data (d03nece.d)

10.3
Program Results

Program Results (d03nece.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −30 −20 −10 0 10 20 30 40 50 0 20 40 60 80 100 −10 −5 0 5 10 15 20 Option Values Derivatives Stock Price Example Program 1 Option Values and Derivatives at 5 Months to Maturity option values θ δ γ λ ρ gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3 gnuplot_plot_4 gnuplot_plot_5 gnuplot_plot_6
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −30 −20 −10 0 10 20 30 40 50 0 20 40 60 80 100 −10 −5 0 5 10 15 20 Option Values Derivatives Stock Price Example Program 2 Option Values and Derivatives at 3.5 Months to Maturity option values θ δ γ λ ρ gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3 gnuplot_plot_4 gnuplot_plot_5 gnuplot_plot_6
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017