cantaro86 / Financial-Models-Numerical-Methods

Collection of notebooks about quantitative finance, with interactive python code.
GNU Affero General Public License v3.0
5.6k stars 1.01k forks source link

Heston pricing model confusion #11

Closed eatonlin98 closed 1 year ago

eatonlin98 commented 1 year ago

def cf_Heston(u, t, v0, mu, kappa, theta, sigma, rho): """ Heston characteristic function as proposed in the original paper of Heston (1993) """ xi = kappa - sigma rho u 1j d = np.sqrt(xi2 + sigma2 (u*2 + 1j u)) g1 = (xi + d) / (xi - d) cf = np.exp( 1j u mu * t

limit_max = 1000 # right limit in the integration call = S0 Q1(k, cf_H_b_good, limit_max) - K np.exp(-r T) Q2(k, cf_H_b_good, limit_max) print("Heston Fourier inversion call price: ", call)

when call 'call' function, I need to use Q1 and Q2. but in Q1, cf function only has one input like 'u - 1j'. But here it should be cf_Heston function with 7 inputs. Not sure how did you run out with just one input?

Also the cf formula in cf_Heston, wouldn't it be:

1j u mu t => 1j u * log(K), K is strike price.


def Q1(k, cf, right_lim): """ P(X<k) - Probability to be in the money under the stock numeraire. cf: characteristic function right_lim: right limit of integration """

def integrand(u):
    return np.real((np.exp(-u * k * 1j) / (u * 1j)) * cf(u - 1j) / cf(-1.0000000000001j))

return 1 / 2 + 1 / np.pi * quad(integrand, 1e-15, right_lim, limit=2000)[0]
cantaro86 commented 1 year ago

Please, create issues only if there are errors, or if something is wrong in the math or in the code.
An issue should be short, easy to read, and should indicate the error message.

In this case there are no errors. The Heston price seems to be correct.
The answers to your questions are: