Source code for naginterfaces.library.examples.specfun.opt_heston_more_greeks_ex
#!/usr/bin/env python3
"``naginterfaces.library.specfun.opt_heston_more_greeks`` Python Example."
# NAG Copyright 2022.
# pylint: disable=invalid-name,too-many-locals
from naginterfaces.library import specfun
[docs]def main():
"""
Example for :func:`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()
naginterfaces.library.specfun.opt_heston_more_greeks
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
"""
print('naginterfaces.library.specfun.opt_heston_more_greeks')
print(' Python Example Results.')
print('Prices for four European call options.')
# Call or put:
calput = 'C'
# Strike prices:
x = [100.]
# Price of the underlying asset:
s = 100.
# Times to expiry:
t = [1.,1.,1.,1.]
# Volatility of the volatility:
sigmav = 0.5751
# Long term mean reversion rate of the volatility
kappa = 1.5768
# Correlation coefficient
corr = -0.5711
# Initial value of the variance of the asset price.
var0 = 0.0175
# Long term variance of asset price:
eta = 0.0398
# Greek risk
grisk = 1.0
# Risk-free interest rate:
r = [0.025, 0.025, -0.025, -0.025]
# Continuous yield rate:
q = [0.01, -0.01, 0.01, -0.01]
res = specfun.opt_heston_more_greeks(
calput=calput, x=x, s=s, t=t,
sigmav=sigmav, kappa=kappa, corr=corr,
var0=var0, eta=eta, grisk=grisk, r=r, q=q,
)
print(' q r Price dp_dsigmav')
for s_i in range(len(x)):
for t_i, r_i in enumerate(r):
print(
' '.join(['{:9.4f}']*4).format(
r_i, q[t_i], res.p[s_i, t_i], res.dp_dsigmav[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
)