i am trying to get root of a function using Newton's algorithm on python. I have a runtime error even if i change the precision level. can you kindly help me understand how can i improve it?
Best,GB
Below my 'simple' code and the root finding part:
from scipy.stats import normimport numpy as np import matplotlib.pyplot as plt import scipy.optimize as optdef vega_callspread(r,S,T,d,sigma,q,K1,K2): d1 = (np.log(S/K1)+(r+sigma*sigma/2)*T)/(sigma*np.sqrt(T)) d2 = (np.log(S/K2)+(r+sigma*sigma/2)*T)/(sigma*np.sqrt(T)) u1 = S*np.exp(-q*T)*norm.pdf(d1,0,1) u2 = S*np.exp(-q*T)*norm.pdf(d2,0,1) return u1-u2;x0=112r=0T=1d=0sigma=0.2q=0K1=110K2=130res2= opt.newton(vega_callspread, x0, args=(r,T,d,sigma,q,K1,K2,),tol=10**(-1),maxiter=1000000)the error i get is: res2= opt.zeros.newton(vega_callspread, x0, args=(r,T,d,sigma,q,K1,K2,),tol=10**(-1),maxiter=1000000)/Users/anaconda/lib/python3.5/site-packages/scipy/optimize/zeros.py:173: RuntimeWarning: Tolerance of 0.011300000000005639 reached warnings.warn(msg, RuntimeWarning)