Semi-Closed-Form of Pricing Formula
import numpy as np
import scipy.integrate as spi
def Heston_Call_Value_Int(kappa, theta, sigma, rho, v0, r, T, s0, K):
a = s0*Heston_P_Value(kappa, theta, sigma, rho, v0, r, T, s0, K, 1)
b = K*np.exp(-r*T)*Heston_P_Value(kappa, theta, sigma, rho, v0, r, T, s0, K, 2)
#print (a,b)
return a-b
def Heston_P_Value(kappa, theta, sigma, rho, v0, r, T, s0, K, type):
ifun = lambda phi: Int_Function_1(phi, kappa, theta, sigma, rho, v0, r, T, s0, K, type)
return 0.5 + (1/np.pi)*spi.quad(ifun, 0, 100)[0]
def Int_Function_1(phi, kappa, theta, sigma, rho, v0, r, T, s0, K, type):
temp = (np.exp(-1*1j*phi*np.log(K))*Int_Function_2(phi, kappa, theta, sigma, rho, v0, r, T, s0, K, type))
return temp
def Int_Function_2(phi, kappa, theta, sigma, rho, v0, r, T, s0, K, type):
if type==1:
u = 0.5
b = kappa