title: ValueError: f(a) and f(b) must have different sign
body: <p>I have a dataframe with columns Date, cash, rate, name. When I try to groupby by name then I am able to find the value of XIRR but when I try to groupby by rate then the error comes as </p>
  
  <blockquote>
    <p>File
    "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\zeros.py",
    line 519, in brentq
            r = _zeros._brentq(f,a,b,xtol,rtol,maxiter,args,full_output,disp)</p>
  
  <pre><code>ValueError: f(a) and f(b) must have different signs"
  </code></pre>
  </blockquote>
  
  <pre><code>def xnpv(rate, values, dates):    
      if rate &lt;= -1.0:
          return float('inf')
      d0 = dates.min()   # or min(dates)
      return sum([ vi / (1.0 + rate)**((di - d0).days / 365.0) for vi, di in zip(values, dates)])
  def xirr(values, dates):  
      try:
          return scipy.optimize.newton(lambda r: xnpv(r, values, dates), 0.0)
      except RuntimeError:    # Failed to converge?
          return scipy.optimize.brentq(lambda r: xnpv(r, values, dates), -1.0, 1e10) 
  
  def f(x):
  
      x["XNPV"] = xnpv(0.1, x["Cash"], x['Date'])
      x["XIRR"] = xirr( x["Cash"], x['Date'])
      return x
  
  f2 = f1.groupby('RATE').apply(f)
  </code></pre>