This chapter is concerned with the provision of some commonly occurring physical and mathematical functions.
Syntax
C# 

public static class S 
Visual Basic 

Public NotInheritable Class S 
Visual C++ 

public ref class S abstract sealed 
F# 

[<AbstractClassAttribute>] [<SealedAttribute>] type S = class end 
Background to the Problems
The majority of the methods in this chapter approximate realvalued functions of a single real argument, and the techniques involved are described in [Functions of a Single Real Argument]. In addition the chapter contains methods for elliptic integrals (see [Approximations to Elliptic Integrals]), Bessel and Airy functions of a complex argument (see [Bessel and Airy Functions of a Complex Argument]), complementary error function of a complex argument, hypergeometric functions and various option pricing methods for use in financial applications.
Functions of a Single Real Argument
Most of the methods provided for functions of a single real argument have been based on truncated Chebyshev expansions. This method of approximation was adopted as a compromise between the conflicting requirements of efficiency and ease of implementation on many different machine ranges. For details of the reasons behind this choice and the production and testing procedures followed in constructing this chapter see Schonfelder (1976).
Basically, if the function to be approximated is $f\left(x\right)$, then for $x\in \left[a,b\right]$ an approximation of the form
is used (${\sum}^{\prime}$ denotes, according to the usual convention, a summation in which the first term is halved), where $g\left(x\right)$ is some suitable auxiliary function which extracts any singularities, asymptotes and, if possible, zeros of the function in the range in question and $t=t\left(x\right)$ is a mapping of the general range $\left[a,b\right]$ to the specific range [$1,+1$] required by the Chebyshev polynomials, ${T}_{r}\left(t\right)$. For a detailed description of the properties of the Chebyshev polynomials see Clenshaw (1962) and Fox and Parker (1968).
$$f\left(x\right)=g\left(x\right)\underset{r=0}{{\sum}^{\prime}}\phantom{\rule{0.25em}{0ex}}{C}_{r}{T}_{r}\left(t\right)$$ 
The essential property of these polynomials for the purposes of function approximation is that ${T}_{n}\left(t\right)$ oscillates between $\pm 1$ and it takes its extreme values $n+1$ times in the interval [$1,+1$]. Therefore, provided the coefficients ${C}_{r}$ decrease in magnitude sufficiently rapidly the error made by truncating the Chebyshev expansion after $n$ terms is approximately given by
That is, the error oscillates between $\pm {C}_{n}$ and takes its extreme value $n+1$ times in the interval in question. Now this is just the condition that the approximation be a minimax representation, one which minimizes the maximum error. By suitable choice of the interval, [$a,b$], the auxiliary function, $g\left(x\right)$, and the mapping of the independent variable, $t\left(x\right)$, it is almost always possible to obtain a Chebyshev expansion with rapid convergence and hence truncations that provide near minimax polynomial approximations to the required function. The difference between the true minimax polynomial and the truncated Chebyshev expansion is seldom sufficiently great enough to be of significance.
$$E\left(t\right)\simeq {C}_{n}{T}_{n}\left(t\right)\text{.}$$ 
The evaluation of the Chebyshev expansions follows one of two methods. The first and most efficient, and hence the most commonly used, works with the equivalent simple polynomial. The second method, which is used on the few occasions when the first method proves to be unstable, is based directly on the truncated Chebyshev series, and uses backward recursion to evaluate the sum. For the first method, a suitably truncated Chebyshev expansion (truncation is chosen so that the error is less than the machine precision) is converted to the equivalent simple polynomial. That is, we evaluate the set of coefficients ${b}_{r}$ such that
The polynomial can then be evaluated by the efficient Horner's method of nested multiplications,
This method of evaluation results in efficient methods but for some expansions there is considerable loss of accuracy due to cancellation effects. In these cases the second method is used. It is well known that if
then
and this is always stable. This method is most efficiently implemented by using three variables cyclically and explicitly constructing the recursion.
$$y\left(t\right)=\sum _{r=0}^{n1}{b}_{r}{t}^{r}=\underset{r=0}{\overset{n1}{{\sum}^{\prime}}}{C}_{r}{T}_{r}\left(t\right)\text{.}$$ 
$$y\left(t\right)=\left({b}_{0}+t\left({b}_{1}+t\left({b}_{2}+\dots t\left({b}_{n2}+t{b}_{n1}\right)\right)\right)\dots \right)\text{.}$$ 
$$\begin{array}{c}{b}_{n1}={C}_{n1}\\ {b}_{n2}=2t{b}_{n1}+{C}_{n2}\\ {b}_{j\phantom{}\phantom{0}}=2t{b}_{j+1}{b}_{j+2}+{C}_{j}\text{, \hspace{1em}}j=n3,n4,\dots ,0\end{array}$$ 
$$\underset{r=0}{{\sum}^{\prime}}\phantom{\rule{0.25em}{0ex}}{C}_{r}{T}_{r}\left(t\right)=\frac{1}{2}\left({b}_{0}{b}_{2}\right)$$ 
That is,
The auxiliary functions used are normally functions compounded of simple polynomial (usually linear) factors extracting zeros, and the primary compilerprovided functions, sin, cos, ln, exp, sqrt, which extract singularities and/or asymptotes or in some cases basic oscillatory behaviour, leaving a smooth wellbehaved function to be approximated by the Chebyshev expansion which can therefore be rapidly convergent.
$$\begin{array}{rll}\alpha & =& {C}_{n1}\\ \beta & =& 2t\alpha +{C}_{n2}\\ \gamma & =& 2t\beta \alpha +{C}_{n3}\\ \alpha & =& 2t\gamma \beta +{C}_{n4}\\ \beta & =& 2t\alpha \gamma +{C}_{n5}\\ & \vdots & \\ \text{say}\alpha & =& 2t\gamma \beta +{C}_{2}\\ \beta & =& 2t\alpha \gamma +{C}_{1}\\ y\left(t\right)& =& t\beta \alpha +\frac{1}{2}{C}_{0}\end{array}$$ 
The mappings of [$a,b$] to [$1,+1$] used range from simple linear mappings to the case when $b$ is infinite, and considerable improvement in convergence can be obtained by use of a bilinear form of mapping. Another common form of mapping is used when the function is even; that is, it involves only even powers in its expansion. In this case an approximation over the whole interval [$a,a$] can be provided using a mapping $t=2{\left(x/a\right)}^{2}1$. This embodies the evenness property but the expansion in $t$ involves all powers and hence removes the necessity of working with an expansion with half its coefficients zero.
For many of the methods an analysis of the error in principle is given, namely, if $E$ and $\nabla $ are the absolute errors in function and argument and $\epsilon $ and $\delta $ are the corresponding relative errors, then
If we ignore errors that arise in the argument of the function by propagation of data errors, etc., and consider only those errors that result from the fact that a real number is being represented in the computer in floatingpoint form with finite precision, then $\delta $ is bounded and this bound is independent of the magnitude of $x$. For example, on an $11$digit machine
(This of course implies that the absolute error $\nabla =x\delta $ is also bounded but the bound is now dependent on $x$.) However, because of this the last two relations above are probably of more interest. If possible the relative error propagation is discussed; that is, the behaviour of the error amplification factor $\leftx{f}^{\prime}\left(x\right)/f\left(x\right)\right$ is described, but in some cases, such as near zeros of the function which cannot be extracted explicitly, absolute error in the result is the quantity of significance and here the factor $\leftx{f}^{\prime}\left(x\right)\right$ is described. In general, testing of the functions has shown that their error behaviour follows fairly well these theoretical error behaviours. In regions where the error amplification factors are less than or of the order of one, the errors are slightly larger than the above predictions. The errors are here limited largely by the finite precision of arithmetic in the machine, but $\epsilon $ is normally no more than a few times greater than the bound on $\delta $. In regions where the amplification factors are large, of order ten or greater, the theoretical analysis gives a good measure of the accuracy obtainable.
$$\begin{array}{lll}E& \simeq & \left{f}^{\prime}\left(x\right)\right\nabla \\ & & \\ E& \simeq & \leftx{f}^{\prime}\left(x\right)\right\delta \\ & & \\ \epsilon & \simeq & \left\frac{x{f}^{\prime}\left(x\right)}{f\left(x\right)}\right\delta \text{.}\end{array}$$ 
$$\left\delta \right\le {10}^{11}\text{.}$$ 
It should be noted that the definitions and notations used for the functions in this chapter are all taken from Abramowitz and Stegun (1972). You are strongly recommended to consult this book for details before using the methods in this chapter.
Approximations to Elliptic Integrals
Four functions provided here are symmetrised variants of the classical (Legendre) elliptic integrals. These alternative definitions have been suggested by Carlson (1965), Carlson (1977b) and Carlson (1977a) and he also developed the basic algorithms used in this chapter.
The symmetrised elliptic integral of the first kind is represented by
where $x,y,z\ge 0$ and at most one may be equal to zero.
$${R}_{F}\left(x,y,z\right)=\frac{1}{2}\underset{0}{\overset{\infty}{\int}}\frac{dt}{\sqrt{\left(t+x\right)\left(t+y\right)\left(t+z\right)}}\text{,}$$ 
The normalization factor, $\frac{1}{2}$, is chosen so as to make
If any two of the variables are equal, ${R}_{F}$ degenerates into the second function
where the argument restrictions are now $x\ge 0$ and $y\ne 0$.
$${R}_{F}\left(x,x,x\right)=1/\sqrt{x}\text{.}$$ 
$${R}_{C}\left(x,y\right)={R}_{F}\left(x,y,y\right)=\frac{1}{2}\underset{0}{\overset{\infty}{\int}}\frac{dt}{\left(t+y\right).\sqrt{t+x}}\text{,}$$ 
This function is related to the logarithm or inverse hyperbolic functions if $0<y<x$, and to the inverse circular functions if $0\le x\le y$.
The symmetrised elliptic integral of the second kind is defined by
with $z>0$, $x\ge 0$ and $y\ge 0$, but only one of $x$ or $y$ may be zero.
$${R}_{D}\left(x,y,z\right)=\frac{3}{2}\underset{0}{\overset{\infty}{\int}}\frac{dt}{\sqrt{\left(t+x\right)\left(t+y\right){\left(t+z\right)}^{3}}}$$ 
The function is a degenerate special case of the symmetrised elliptic integral of the third kind
with $\rho \ne 0$ and $x,y,z\ge 0$ with at most one equality holding. Thus ${R}_{D}\left(x,y,z\right)={R}_{J}\left(x,y,z,z\right)$. The normalization of both these functions is chosen so that
The algorithms used for all these functions are based on duplication theorems. These allow a recursion system to be established which constructs a new set of arguments from the old using a combination of arithmetic and geometric means. The value of the function at the original arguments can then be simply related to the value at the new arguments. These recursive reductions are used until the arguments differ from the mean by an amount small enough for a Taylor series about the mean to give sufficient accuracy when retaining terms of order less than six. Each step of the recurrences reduces the difference from the mean by a factor of four, and as the truncation error is of order six, the truncation error goes like ${\left(4096\right)}^{n}$, where $n$ is the number of iterations.
$${R}_{J}\left(x,y,z,\rho \right)=\frac{3}{2}\underset{0}{\overset{\infty}{\int}}\frac{dt}{\sqrt{\left(t+x\right)\left(t+y\right)\left(t+z\right)}\left(t+\rho \right)}$$ 
$${R}_{D}\left(x,x,x\right)={R}_{J}\left(x,x,x,x\right)=1/\left(x\sqrt{x}\right)\text{.}$$ 
The above forms can be related to the more traditional canonical forms (see Section 17.2 of Abramowitz and Stegun (1972)), as follows.
If we write $q={\mathrm{cos}}^{2}\u200a\varphi ,r=1m\hspace{0.17em}{\mathrm{sin}}^{2}\u200a\varphi ,s=1n\hspace{0.17em}{\mathrm{sin}}^{2}\u200a\varphi $, where $0\le \varphi \le \frac{1}{2}\pi $, we have
the classical elliptic integral of the first kind:
the classical elliptic integral of the second kind:
the classical elliptic integral of the third kind:
Also the classical complete elliptic integral of the first kind:
the classical complete elliptic integral of the second kind:
$$F\left(\varphi \mid m\right)=\underset{0}{\overset{\varphi}{\int}}{\left(1m\hspace{0.17em}{\mathrm{sin}}^{2}\u200a\theta \right)}^{\frac{1}{2}}d\theta =\mathrm{sin}\u200a\varphi \hspace{0.17em}{R}_{F}\left(q,r,1\right)\text{;}$$ 
$$\begin{array}{ll}E\left(\varphi \mid m\right)& =\underset{0}{\overset{\varphi}{\int}}{\left(1m\hspace{0.17em}{\mathrm{sin}}^{2}\u200a\theta \right)}^{\frac{1}{2}}d\theta \\ & \\ & =\mathrm{sin}\u200a\varphi \hspace{0.17em}{R}_{F}\left(q,r,1\right)\frac{1}{3}m\hspace{0.17em}{\mathrm{sin}}^{3}\varphi \hspace{0.17em}{R}_{D}\left(q,r,1\right)\end{array}$$ 
$$\begin{array}{ll}\Pi \left(n\text{;}\varphi \mid m\right)& =\underset{0}{\overset{\varphi}{\int}}{\left(1n\hspace{0.17em}{\mathrm{sin}}^{2}\u200a\theta \right)}^{1}{\left(1m\hspace{0.17em}{\mathrm{sin}}^{2}\u200a\theta \right)}^{\frac{1}{2}}d\theta \\ & \\ & =\mathrm{sin}\u200a\varphi \hspace{0.17em}{R}_{F}\left(q,r,1\right)+\frac{1}{3}n\hspace{0.17em}{\mathrm{sin}}^{3}\varphi \hspace{0.17em}{R}_{J}\left(q,r,1,s\right)\text{.}\end{array}$$ 
$$K\left(m\right)=\underset{0}{\overset{\frac{\pi}{2}}{\int}}{\left(1m\hspace{0.17em}{\mathrm{sin}}^{2}\u200a\theta \right)}^{\frac{1}{2}}d\theta ={R}_{F}\left(0,1m,1\right)\text{;}$$ 
$$E\left(m\right)=\underset{0}{\overset{\frac{\pi}{2}}{\int}}{\left(1m\hspace{0.17em}{\mathrm{sin}}^{2}\theta \right)}^{\frac{1}{2}}d\theta ={R}_{F}\left(0,1m,1\right)\frac{1}{3}m\hspace{0.17em}{R}_{D}\left(0,1m,1\right)\text{.}$$ 
For convenience, (S not in this release) contains methods to evaluate classical and symmetrised elliptic integrals.
Bessel and Airy Functions of a Complex Argument
The methods for Bessel and Airy functions of a real argument are based on Chebyshev expansions, as described in [Functions of a Single Real Argument]. The methods provided for functions of a complex argument, however, use different methods. These methods relate all functions to the modified Bessel functions ${I}_{\nu}\left(z\right)$ and ${K}_{\nu}\left(z\right)$ computed in the righthalf complex plane, including their analytic continuations. ${I}_{\nu}$ and ${K}_{\nu}$ are computed by different methods according to the values of $z$ and $\nu $. The methods include power series, asymptotic expansions and Wronskian evaluations. The relations between functions are based on well known formulae (see Abramowitz and Stegun (1972)).
Option Pricing Methods
The option pricing methods evaluate the closed form solutions or approximations to the equations that define mathematical models for the prices of selected financial option contracts. These solutions can be viewed as special functions determined by the underlying equations. The terminology associated with these methods arises from their setting in financial markets and is briefly outlined below. See Joshi (2003) for a comprehensive introduction to this subject. An option is a contract which gives the holder the right, but not the obligation, to buy (if it is a call) or sell (if it is a put) a particular asset, $S$. A European option can be exercised only at the specified expiry time, $T$, while an American option can be exercised at any time up to $T$. For Asian options the average underlying price over a preset time period determines the payoff.
The asset is bought (if a call) or sold (if a put) at a prespecified strike price $X$. Thus, an option contract has a payoff to the holder of $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{\left({S}_{T}X\right),0\right\}$ for a call or $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{\left(X{S}_{T}\right),0\right\}$, for a put, which depends on whether the asset price at the time of exercise is above (call) or below (put) the strike, $X$. If at any moment in time a contract is currently showing a theoretical profit then it is deemed ‘inthemoney’; otherwise it is deemed ‘outofthemoney’.
The option contract itself therefore has a value and, in many cases, can be traded in markets. Mathematical models (e.g., Black–Scholes, Merton, Vasicek, Hull–White, Heston, CEV, SABR, …) give theoretical prices for particular option contracts using a number of assumptions about the behaviour of financial markets. Typically the price ${S}_{t}$ of the underlying asset at time $t$ is modelled as the solution of a stochastic differential equation (SDE). Depending on the complexity of this equation, the model may admit closed form formulae for the prices of various options. The options described in this chapter introduction are detailed below. We let $\mathbb{E}$ denote expectation with respect to the risk neutral measure and we define ${\mathbb{I}}_{A}$ to be $1$ on the set $A$ and $0$ otherwise.
–  The price of a standard European call option is $\mathbb{E}\left({e}^{rT}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{{S}_{T}X,0\right\}\right)$ and the price of a standard European put option is $\mathbb{E}\left({e}^{rT}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{X{S}_{T},0\right\}\right)$.  
–  For continuously averaged geometric Asian options define


–  For a binary assetornothing option the price of a call is $\mathbb{E}\left({e}^{rT}{S}_{T}{\mathbb{I}}_{\left\{{S}_{T}>X\right\}}\right)$ and the price of a put is $\mathbb{E}\left({e}^{rT}{S}_{T}{\mathbb{I}}_{\left\{{S}_{T}<X\right\}}\right)$.  
–  For a binary cashornothing option the price of a call is $\mathbb{E}\left({e}^{rT}X{\mathbb{I}}_{\left\{{S}_{T}>X\right\}}\right)$ and the price of a put is $\mathbb{E}\left({e}^{rT}X{\mathbb{I}}_{\left\{{S}_{T}<X\right\}}\right)$.  
–  For a floatingstrike lookback option the price of a call is $\mathbb{E}\left({e}^{rT}\left({S}_{T}{\mathrm{min}}_{0\le t\le T}{S}_{t}\right)\right)$ and the price of a put is $\mathbb{E}\left({e}^{rT}\left({\mathrm{max}}_{0\le t\le T}{S}_{t}{S}_{T}\right)\right)$.  
–  For an upandin barrier option with barrier level $H$ and cash rebate $K$, set $A=\left\{{\mathrm{max}}_{0\le t\le T}{S}_{t}>H\right\}$. Then the price of a call is


–  For a downandin barrier option with barrier level $H$ and cash rebate $K$, set $A=\left\{{\mathrm{min}}_{0\le t\le T}{S}_{t}<H\right\}$. Then the price of a call is


–  For an upandout barrier option with barrier level $H$ and cash rebate $K$, set $A=\left\{{\mathrm{max}}_{0\le t\le T}{S}_{t}>H\right\}$. Then the price of a call is


–  For a downandout barrier option with barrier level $H$ and cash rebate $K$, set $A=\left\{{\mathrm{min}}_{0\le t\le T}{S}_{t}<H\right\}$. Then the price of a call is


–  The price of an American call option is $\mathrm{ess}{\mathrm{sup}}_{0\le \tau \le T}\mathbb{E}\left({e}^{r\tau}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{{S}_{\tau}X,0\right\}\right)$ and the price of an American put option is $\mathrm{ess}{\mathrm{sup}}_{0\le \tau \le T}\mathbb{E}\left({e}^{r\tau}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left\{X{S}_{\tau},0\right\}\right)$. Here $\mathrm{ess}{\mathrm{sup}}_{0\le \tau \le T}$ denotes the essential supremum over all stopping times $\tau $ for the process $S$ which take values in $\left[0,T\right]$. If $S$ is a Markov process, then the essential supremum may be replaced with the normal supremum. Note that if the asset $S$ pays no dividends then the price of an American call option is the same as a European call option. 
The Black–Scholes Model
The best known model of asset behaviour is the Black–Scholes model. Under the riskneutral measure, the asset is governed by the SDE
where $r$ is the continuously compounded riskfree interest rate, $q$ is the continuously compounded dividend yield, $\sigma $ is the volatility of logasset returns (i.e., $\mathrm{log}\left({S}_{t+dt}/{S}_{t}\right)$) and $W={\left({W}_{t}\right)}_{t\ge 0}$ is a standard Brownian motion. Under this model, the price of any option $P$ must solve the Black–Scholes PDE
at all times before the option is exercised. This PDE admits a closed form solution for a number of different options.
$$\frac{d{S}_{t}}{{S}_{t}}=\left(rq\right)dt+\sigma {dW}_{t}$$ 
$$\frac{\partial P}{\partial t}+\frac{\partial P}{\partial S}\left(rq\right)S+\frac{1}{2}\frac{{\partial}^{2}P}{\partial {S}^{2}}{\sigma}^{2}{S}^{2}rP=0$$ 
The Black–Scholes Model with Term Structure
The simplest extension of the Black–Scholes model is to allow $r$, $q$ and $\sigma $ to be deterministic functions of time so that
$$\frac{d{S}_{t}}{{S}_{t}}=\left({r}_{t}{q}_{t}\right)dt+{\sigma}_{t}{dW}_{t}\text{.}$$ 
In this case one can still obtain closed form solutions for some options, e.g., European calls and puts.
The Heston Model
Heston (1993) proposed a stochastic volatility model with the following form
where ${W}^{\left(1\right)}$ and ${W}^{\left(2\right)}$ are two Brownian motions with quadratic covariation given by $d{\u2329{W}^{\left(1\right)},{W}^{\left(2\right)}\u232a}_{t}=\rho dt$. In this model $r$ and $q$ are the continuously compounded risk free interest rate and dividend rate respectively, $v={\left({v}_{t}\right)}_{t\ge 0}$ is the stochastic volatility process, $\eta $ is the long term mean of volatility, $\kappa $ is the rate of mean reversion, and $\sigma $ is the volatility of volatility. The prices of European call and put options in the Heston model are available in closed form up to the evaluation of an integral transform (see Lewis (2000)).
$$\begin{array}{ccc}\frac{d{S}_{t}}{{S}_{t}}& =& \left(rq\right)dt+\sqrt{{v}_{t}}d{W}_{t}^{\left(1\right)}\\ d{v}_{t}& =& \kappa \left(\eta {v}_{t}\right)dt+\sigma \sqrt{{v}_{t}}d{W}_{t}^{\left(2\right)}\end{array}$$ 
The Heston Model with Term Structure
The Heston model can be extended by allowing the coefficients to become deterministic functions of time:
where ${W}^{\left(1\right)}$ and ${W}^{\left(2\right)}$ are two Brownian motions with quadratic covariation given by $d{\u2329{W}^{\left(1\right)},{W}^{\left(2\right)}\u232a}_{t}={\rho}_{t}dt$. When the coefficients are restricted to being piecewise constant functions of time, the prices of European call and put options can be calculated as described in Elices (2008) and Mikhailov and Nögel (2003).
$$\begin{array}{ccc}\frac{d{S}_{t}}{{S}_{t}}& =& \left({r}_{t}{q}_{t}\right)dt+\sqrt{{v}_{t}}d{W}_{t}^{\left(1\right)}\\ d{v}_{t}& =& {\kappa}_{t}\left({\eta}_{t}{v}_{t}\right)dt+{\sigma}_{t}\sqrt{{v}_{t}}d{W}_{t}^{\left(2\right)}\end{array}$$ 
Hypergeometric Functions
The confluent hypergeometric function $M\left(a,b,x\right)$ (or ${}_{1}F_{1}\left(a;b;x\right)$) requires a number of techniques to approximate it over the whole parameter $\left(a,b\right)$ space and for all argument $\left(x\right)$ values. For $x$ well within the unit circle $\leftx\right\le \rho <1$ (where $\rho =0.8$ say), and for relatively small parameter values, the function can be well approximated by Taylor expansions, continued fractions or through the solution of the related ordinary differential equation by an explicit, adaptive integrator. For values of $\leftx\right>\rho $, one of several transformations can be performed (depending on the value of $x$) to reformulate the problem in terms of a new argument ${x}^{\prime}$ such that $\left{x}^{\prime}\right\le \rho $. If one or more of the parameters is relatively large (e.g., $\lefta\right>30$) then recurrence relations can be used in combination to reformulate the problem in terms of parameter values of small size (e.g., $\lefta\right<1$).
Approximations to the hypergeometric functions can therefore require all of the above techniques in sequence: a transformation to get an argument well inside the unit circle, a combination of recurrence relations to reduce the parameter sizes, and the approximation of the resulting hypergeometric function by one of a set of approximation techniques. Similar complications arise in the computation of the Gaussian Hypergeometric Function ${}_{2}F_{1}$.
All the techniques described above are based on those described in Pearson (2009).
Recommendations on Choice and Use of Available Methods
Vectorized Method Variants
Many methods in (S not in this release) which compute functions of a single real argument have variants which operate on vectors of arguments. For example, s18ae computes the value of the ${I}_{0}$ Bessel function for a single argument, and (S18ASF not in this release) computes the same function for multiple arguments. In general it should be more efficient to use vectorized methods where possible, though to some extent this will depend on the environment from which you call the methods. See [] for a complete list of vectorized methods.
Elliptic Integrals
IMPORTANT ADVICE: users who encounter elliptic integrals in the course of their work are strongly recommended to look at transforming their analysis directly to one of the Carlson forms, rather than to the traditional canonical Legendre forms. In general, the extra symmetry of the Carlson forms is likely to simplify the analysis, and these symmetric forms are much more stable to calculate.
The method s21ba for ${R}_{C}$ is largely included as an auxiliary to the other methods for elliptic integrals. This integral essentially calculates elementary functions, e.g.,
$$\begin{array}{ll}\mathrm{ln}\u200ax& =\left(x1\right)\hspace{0.17em}{R}_{C}\left({\left(\frac{1+x}{2}\right)}^{2},x\right)\text{, \hspace{1em}}x>0\text{;}\\ \\ \mathrm{arcsin}\u200ax& =x\hspace{0.17em}{R}_{C}\left(1{x}^{2},1\right),\leftx\right\le 1\text{;}\\ \\ \mathrm{arcsinh}\u200ax& =x\hspace{0.17em}{R}_{C}\left(1+{x}^{2},1\right),\text{etc.}\end{array}$$ 
In general this method of calculating these elementary functions is not recommended as there are usually much more efficient specific methods available in the Library. However, s21ba may be used, for example, to compute $\mathrm{ln}\u200ax/\left(x1\right)$ when $x$ is close to $1$, without the loss of significant figures that occurs when $\mathrm{ln}\u200ax$ and $x1$ are computed separately.
Bessel and Airy Functions
For computing the Bessel functions ${J}_{\nu}\left(x\right)$, ${Y}_{\nu}\left(x\right)$, ${I}_{\nu}\left(x\right)$ and ${K}_{\nu}\left(x\right)$ where $x$ is real and $\nu =0\text{ or}1$, special methods are provided, which are much faster than the more general methods that allow a complex argument and arbitrary real $\nu \ge 0$. Similarly, special methods are provided for computing the Airy functions and their derivatives $\mathrm{Ai}\left(x\right)$, $\mathrm{Bi}\left(x\right)$, ${\mathrm{Ai}}^{\prime}\left(x\right)$, ${\mathrm{Bi}}^{\prime}\left(x\right)$ for a real argument which are much faster than the methods for complex arguments.
Option Pricing Functions
For the Black–Scholes model, functions are provided to compute prices and derivatives (Greeks) of all the European options listed in [Option Pricing Methods]. Prices for American call and put options can be obtained by calling (S30QCF not in this release) which uses the Bjerksund and Stensland (2002) approximation to the theoretical value. For the Black–Scholes model with term structure, prices for European call and put options can be obtained by calling (D03NDF not in this release). The prices of European call and put options in the standard Heston model can be obtained by calling (S30NAF not in this release), while (S30NCF not in this release) returns the same prices in the Heston model with term structure.
Hypergeometric Functions
Two methods are provided for the confluent hypergeometric function ${}_{1}F_{1}$. Both return values for ${}_{1}F_{1}\left(a;b;x\right)$ where parameters $a$ and $b$, and argument $x$, are all real, but one variant works in a scaled form designed to avoid unnecessary loss of precision. The unscaled method (S22BAF not in this release) is easier to use and should be chosen in the first instance, changing to the scaled method (S22BBF not in this release) only if problems are encountered. Similar considerations apply to the Gaussian hypergeometric function methods (S22BEF not in this release) (S22BFF not in this release).
References
Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Bjerksund P and Stensland G (2002) Closed form valuation of American options Discussion Paper 2002/09 NHH Bergen Norway http://www.nhh.no/
Carlson B C (1965) On computing elliptic integrals and functions J. Math. Phys. 44 36–51
Carlson B C (1977a) Special Functions of Applied Mathematics Academic Press
Carlson B C (1977b) Elliptic integrals of the first kind SIAM J. Math. Anal. 8 231–242
Clenshaw C W (1962) Chebyshev Series for Mathematical Functions Mathematical tables HMSO
Elices A (2008) Models with timedependent parameters using transform methods: application to Heston’s model arXiv:0708.2020v2
Fox L and Parker I B (1968) Chebyshev Polynomials in Numerical Analysis Oxford University Press
Haug E G (2007) The Complete Guide to Option Pricing Formulas (2nd Edition) McGrawHill
Heston S (1993) A closedform solution for options with stochastic volatility with applications to bond and currency options Review of Financial Studies 6 327–343
Joshi M S (2003) The Concepts and Practice of Mathematical Finance Cambridge University Press
Lewis A L (2000) Option valuation under stochastic volatility Finance Press, USA
Mikhailov S and Nögel U (2003) Heston’s Stochastic Volatility Model Implementation, Calibration and Some Extensions Wilmott Magazine July/August 74–79
Pearson J (2009) Computation of hypergeometric functions MSc Dissertation, Mathematical Institute, University of Oxford
Schonfelder J L (1976) The production of special function routines for a multimachine library Softw. Pract. Exper. 6(1)