This is a equation I want to implement as a function in Python.
r, t, T, a, and b are all specific figures. φ is defined as φR +φi*i where φR is set to 0.5 and φi is used for the integration. erf() is the standard complex error function.
First I defined:
def A(phii, tau):
A = (2*mu*lam)/(2*mu*kk-sigv**2)*np.log(1+((sigv**2-2*mu*kk)*(phir+phii*i))/(2*kk*(1-mu* (phir+phii*i)))*(np.exp(-kk*tau)-1))
return A
def B(phii, tau):
B = (-2*kk*theta)/(sigv**2)*np.log(1+(sigv**2*(phir+phii*i))/(2*kk)*(np.exp(-kk*tau)-1))
return B
def D(phii, tau):
D = (2*kk*(phir+phii*i))/(sigv**2*(phir+phii*i)+(2*kk-sigv**2*(phir+phii*i))*np.exp(kk*tau))
return D
def funct(phii, tau, V):
funct = np.exp(B(phii,tau)+D(phii,tau)*V+A(phii,tau))
return funct
Where funct() is f() in the picture above.
All the variables besides φi are set to a specific figure.
def RE(phii, tau, X, K):
feh = erf(K*np.sqrt((phir+phii*1j)/a)) # error function
feh = feh.real
RE = np.exp(((phir+phii*1j)*b)/a)*funct(phii, tau, ((X**2)-b)/a)*(1-feh)/((np.sqrt((phir+phii*1j)/a))**3)
REreal = RE.real
return REreal
phii_val = np.linspace(0,2000)
tau = 1
X = 0.13
K = 0.13
trap = integrate.trapezoid(RE(phii_val,tau,X,K),phii_val)
tratqu = scipy.integrate.quad(lambda phii: RE(phii,tau,X,K),0,np.inf)[0]
tratres = (np.exp(-r*tau))/(2*a*np.sqrt(np.pi))*trap
tratresu = (np.exp(-r*tau))/(2*a*np.sqrt(np.pi))*tratqu
I tried to use quad and trapezoid for my integration but not only do they differ a lot in results (which I guess is not that uncommon) but also both do not give me the right result. Now I was wondering if I have any mistakes in my integration or if I have done other mistakes?