numpy/numpy — pull request #4210 by peliot (2014-01-18 00:50:48+00:00)
Title: BUG: IRR does not return valid solutions in range (-1,0)

The existing imlementation of numpy.irr finds the real roots of NPV(rate) and returns a root if there is a positive real root, and returns nan otherwise. The weakness in this implementation is that it does not find valid solutions when the solution is negative (as is the case when an investment loses money).
The corrected implementation makes two changes. First, it allows all real roots, not just the positive roots. Second, it returns only the minimum of those real roots. In cases where the IRR is negative, there can be multiple roots. By convention, the largest of the rates (which is the smallest of the roots, since the root is 1/(1+rate)) is treated as the correct answer. For example, IRR([-100,0,0,-7]) has roots at both -69% and -8%, and the function returns -8%. The original implementation avoided this by eliminating all negative roots, but in doing so eliminated valid solutions as well.
This new implementation returns the same value as the original when the solution is positive, but returns valid answers in the range (-1,0) for which the original implementation returned nan.
Illustrative doctests were added in the docstring as well.