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.
nag_pde_bs_1d_means (d03nec) computes the quantities
from a given set of values phid of a continuous time-dependent function at a set of discrete points td, where is the current time and 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 , the continuous dividend , 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.
On entry: the current time .
On entry: the maturity time .
On entry: the number of discrete times at which is given.
– const doubleInput
On entry: the discrete times at which is specified.
– const doubleInput
On entry: must contain the value of at time , for .
On exit: contains the value of interpolated to , contains the first-order average and contains the second-order average , where:
– NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).
6 Error Indicators and Warnings
Dynamic memory allocation failed.
See Section 18.104.22.168 in How to Use the NAG Library and its Documentation for further information.
On entry, argument had an illegal value.
On entry, .
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.
An unexpected error has been triggered by this function. Please contact NAG.
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.
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.
Suppose you wish to evaluate the analytic solution of the Black–Scholes equation in the case when the risk-free interest rate 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 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 is handled by interpolating at that point.
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 -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.