title: Invalid value encountered in true_divide
body: <p>I am trying to compute implied volatility of black scholes formula using python. however, I have problem with my code. I keep getting this error message when I running the code:</p>
  
  <pre><code>RuntimeWarning: divide by zero encountered in true_divide
  v = sigmaOld - bs_option_call(v, s, k, r, t, call_price1)/fprime(sigmaOld, s, k, r, t)e here
  </code></pre>
  
  <p>and here is my code:</p>
  
  <pre><code>while True:
  for (v, k, s, t, call_price1) in zip(sigma, K, S, Ta, call_price_list):
      sigmaOld = v
      v = sigmaOld - bs_option_call(v, s, k, r, t, call_price1) / fprime(sigmaOld, s, k, r, t)
      if scipy.absolute( v - sigmaOld ) &lt; epsilon:
          break
  print(sigma)
  </code></pre>
  
  <p>where <code>fprime</code> is </p>
  
  <pre><code>def fprime(sigma, S, K, r, T):
      logSoverK = log(S / K)
      numerd1 = logSoverK + (r + sigma**2 / 2) * T
      d1 = numerd1 / (sigma*sqrt(T))
      return S * sqrt(T) * norm.pdf(d1) * exp(-r * T) 
  </code></pre>
  
  <p>and K, Ta, S, sigma, call_price_list are lists and r is just a number.</p>
  
  <p>I tried to use </p>
  
  <pre><code>import numpy as np
  np.seterr(divide='ignore', invalid='ignore')
  </code></pre>
  
  <p>but it was not useful for me for some reason!</p>
  
  <p>can anyone please have a look at my code and tell me what is my mistake!
  Many thanks in advance</p>