library.specfun Submodule

Module Summary

Interfaces for the NAG Mark 29.3 specfun Chapter.

specfun - Approximations of Special Functions

This module is concerned with the provision of some commonly occurring physical and mathematical functions.

See Also

naginterfaces.library.examples.specfun :

This subpackage contains examples for the specfun module. See also the Examples subsection.

Functionality Index

Airy function

, real argument

, real argument

, real argument

or , complex argument, optionally scaled: airy_ai_complex()

, real argument

or , complex argument, optionally scaled: airy_bi_complex()


inverse circular cosine: arccos()


inverse hyperbolic cosine: arccosh()


inverse circular sine: arcsin()


inverse hyperbolic sine: arcsinh()


inverse hyperbolic tangent: arctanh()

Bessel function

, complex argument, optionally scaled: bessel_i_complex()

, real argument

, real argument

, complex argument: bessel_j_seq_complex()

, complex argument, optionally scaled: bessel_j_complex()

, real argument

, real argument

, complex argument, optionally scaled: bessel_k_complex()

, real argument

, real argument

, complex argument, optionally scaled: bessel_y_complex()

, real argument

, real argument

beta function

regularized incomplete

Complement of the Cumulative Normal distribution

Complement of the Error function

complex argument, scaled

real argument

scalar: erfc_real()

vectorized: erfc_real_vector()

real argument, scaled

scalar: erfcx_real()

vectorized: erfcx_real_vector()


hyperbolic: cosh()

Cosine Integral: integral_cos()

Cumulative Normal distribution function

scalar: cdf_normal()

vectorized: cdf_normal_vector()

Dawson’s Integral

scalar: dawson()

vectorized: dawson_vector()

Digamma function, scaled: polygamma_deriv()

Elliptic functions, Jacobian, sn, cn, dn

complex argument: jacellip_complex()

real argument: jacellip_real()

Elliptic integral


of 2nd kind, : ellipint_general_2()

Legendre form

complete of 1st kind, : ellipint_complete_1()

complete of 2nd kind, : ellipint_complete_2()

of 1st kind, : ellipint_legendre_1()

of 2nd kind, : ellipint_legendre_2()

of 3rd kind, : ellipint_legendre_3()


degenerate of 1st kind, : ellipint_symm_1_degen()

of 1st kind, : ellipint_symm_1()

of 2nd kind, : ellipint_symm_2()

of 3rd kind, : ellipint_symm_3()


real argument

scalar: erf_real()

vectorized: erf_real_vector()


complex argument, scaled

real argument

scalar: erfc_real()

vectorized: erfc_real_vector()


real argument

scalar: erfcx_real()

vectorized: erfcx_real_vector()


complex: exp_complex()

Exponential Integral: integral_exp()

Fresnel integral

scalar: fresnel_c()

vectorized: fresnel_c_vector()

scalar: fresnel_s()

vectorized: fresnel_s_vector()

Gamma function


scalar: gamma()

vectorized: gamma_vector()

Generalized factorial function

scalar: gamma()

vectorized: gamma_vector()

Hankel function or

complex argument, optionally scaled: hankel_complex()

Hypergeometric functions

, confluent, real argument: hyperg_confl_real()

, confluent, real argument, scaled form: hyperg_confl_real_scaled()

, Gauss, real argument: hyperg_gauss_real()

, Gauss, real argument, scaled form: hyperg_gauss_real_scaled()

Jacobian theta functions

real argument: jactheta_real()

Kelvin function

scalar: kelvin_bei()

vectorized: kelvin_bei_vector()

scalar: kelvin_ber()

vectorized: kelvin_ber_vector()

scalar: kelvin_kei()

vectorized: kelvin_kei_vector()

scalar: kelvin_ker()

vectorized: kelvin_ker_vector()

Legendre functions of 1st kind , : legendre_p()

Logarithm of : log_shifted()

Logarithm of beta function


Logarithm of gamma function

Mathieu function (angular)

periodic, real

Modified Struve function

, real argument

, real argument

, real argument

scalar: struve_l0()

, real argument

scalar: struve_l1()

Option Pricing

American option, Bjerksund and Stensland option price: opt_amer_bs_price()

Asian option, geometric continuous average rate price: opt_asian_geom_price()

Asian option, geometric continuous average rate price with Greeks: opt_asian_geom_greeks()

binary asset-or-nothing option price: opt_binary_aon_price()

binary asset-or-nothing option price with Greeks: opt_binary_aon_greeks()

binary cash-or-nothing option price: opt_binary_con_price()

binary cash-or-nothing option price with Greeks: opt_binary_con_greeks()

Black–Scholes implied volatility: opt_imp_vol()

Black–Scholes–Merton option price: opt_bsm_price()

Black–Scholes–Merton option price with Greeks: opt_bsm_greeks()

European option, option prices, using Merton jump-diffusion model: opt_jumpdiff_merton_price()

European option, option price with Greeks, using Merton jump-diffusion model: opt_jumpdiff_merton_greeks()

floating-strike lookback option price: opt_lookback_fls_price()

floating-strike lookback option price with Greeks: opt_lookback_fls_greeks()

Heston’s model option price: opt_heston_price()

Heston’s model option price with Greeks: opt_heston_greeks()

Heston’s model with term structure: opt_heston_term()

standard barrier option price: opt_barrier_std_price()

Polygamma function

, real : psi_deriv_real()

, complex : psi_deriv_complex()

psi function: polygamma()

psi function derivatives, scaled: polygamma_deriv()

Scaled modified Bessel function(s)

, real argument

, real argument

, real argument

, real argument


hyperbolic: sinh()

Sine Integral: integral_sin()

Struve function

, real argument

scalar: struve_h0()

, real argument

scalar: struve_h1()


circular: tan()

hyperbolic: tanh()

Trigamma function, scaled: polygamma_deriv()

Zeros of Bessel functions , , ,

For full information please refer to the NAG Library document



Example for naginterfaces.library.specfun.opt_bsm_price().

Computes the European option price given by the Black–Scholes–Merton formula.

>>> main()
naginterfaces.library.specfun.opt_bsm_price Python Example Results.
Prices for six European call options.
  Strike     Expiry    Price
  58.0000    0.7000    5.9198
  58.0000    0.8000    6.5506
  60.0000    0.7000    5.0809
  60.0000    0.8000    5.6992
  62.0000    0.7000    4.3389
  62.0000    0.8000    4.9379

Example for naginterfaces.library.specfun.opt_heston_more_greeks().

Computes the European option price given by the Heston model, provides greeks and derivatives with respect to model parameters.

>>> main()
  Python Example Results.
Prices for four European call options.
   q         r         Price     dp_dsigmav
   0.0250    0.0100    6.5961   -1.9804
   0.0250   -0.0100    7.9845   -1.7047
  -0.0250    0.0100    3.9303   -2.4431
  -0.0250   -0.0100    5.0138   -2.3868