vp.finance.heston_cos
Heston prices of European options on one stock for an array of strikes, with N cosine terms and the truncation half-width L standard deviations. The put comes from the series (its payoff is bounded) and the call from put-call parity, as Fang and Oosterlee recommend. is_call: 1 call, 0 put.
Part of the distribution vipyr; it runs from a checkout of the
repository. Planned on PyPI as pip install vipyr.
Signature
vp.finance.heston_cos(S, K, T, r, q, v0, kappa, theta, eta, rho, N, L, is_call) Parameters
- S : float, required
- K : ndarray[float64], required
- T : float, required
- r : float, required
- q : float, required
- v0 : float, required
- kappa : float, required
- theta : float, required
- eta : float, required
- rho : float, required
- N : int, required
- L : float, required
- is_call : ndarray[float64], required
Returns
A frozen HestonCosResult. Iterating it gives the fields below in order; it also has
params, tests, log and check().
- prices : ndarray[float64]
- One price per strike.
Raises
- TypeError
- An argument of the wrong type, or an unknown keyword.
- vipyr.VivBuildError
- An ImportError: no C compiler, or the program's C does not build.
Examples
import numpy as np
import vipyr as vp
r = vp.finance.heston_cos(S=100.0, K=np.array([100.0]), T=1.0, r=0.0, q=0.0, v0=0.0175,
kappa=1.5768, theta=0.0398, eta=0.5751, rho=-0.5711,
N=1024, L=32.0, is_call=np.array([1.0]))
print(r.prices) # Fang-Oosterlee: 5.785155450
assert r.check() # the program's own test, at this N and L [5.78515543]Each example ran as written when these pages were generated, and the output shown is what it printed.
Checked against
- Reference
- Fang and Oosterlee (2008): 5.785155450 at T = 1 (error 1.6 × 10−8, tolerance 2 × 10−8); SciPy quad of the Gil-Pelaez integrals on 21 options, within 2.0 × 10−13 (tolerance 10−9).
Source
- Viv: examples/options/heston.viv
- The defs it reaches and the calls between them: map of the code