Source code for naginterfaces.library.examples.specfun.opt_bsm_price_ex
#!/usr/bin/env python3
"``naginterfaces.library.specfun.opt_bsm_price`` Python Example."
# NAG Copyright 2018-2019.
# pylint: disable=invalid-name
from naginterfaces.library import specfun
[docs]def main():
"""
Example for :func:`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
"""
print(
'naginterfaces.library.specfun.opt_bsm_price Python Example Results.'
)
print('Prices for six European call options.')
# Strike prices:
x = [58., 60., 62.]
# Price of the underlying asset:
s = 55.
# Times to expiry:
t = [0.7, 0.8]
# Volatility:
sigma = 0.3
# Risk-free interest rate:
r = 0.1
# Continuous yield rate:
q = 0.
p = specfun.opt_bsm_price('c', x, s, t, sigma, r, q)
print(' Strike Expiry Price')
for s_i, strike in enumerate(x):
for t_i, time in enumerate(t):
print(' '.join(['{:9.4f}']*3).format(strike, time, p[s_i, t_i]))
if __name__ == '__main__':
import doctest
import sys
sys.exit(
doctest.testmod(
None, verbose=True, report=False,
optionflags=doctest.REPORT_NDIFF,
).failed
)