Search for the number that zeroes the error
A bond price is easy to compute from a yield; the yield from a price is not. You solve f(y)=P(y)-market price=0 by searching. Newton's method follows the tangent: from a guess y it jumps to y-f(y)/f'(y), and near the answer the number of correct digits roughly doubles each step, so a handful of iterations is enough, but it needs the derivative and can wander off from a bad start. Bisection needs only a bracket [lo,hi] where f changes sign: it halves the bracket again and again, so it cannot fail, but it gains only one binary digit per step, 40 steps to shrink a bracket of width 65 below 10⁻¹⁰. Brent's method, scipy.optimize.brentq, keeps the safety of a bracket and adds interpolation steps, usually needing about as many function calls as a few bisections. With full_output=True it also returns a record whose function_calls field says how many times it evaluated your function.
The same tool inverts the Black–Scholes formula. The price of a call grows with volatility, so for each quoted price you ask brentq for the σ in [10⁻⁴,5] that reproduces it. That only works when the price is strictly between the intrinsic value max(S-Ke^(-rT),0) and the stock price S; outside, no volatility exists and the right answer is NaN, not an exception, so one bad quote does not stop a whole smile. On 9 October 2026 the 10-year Treasury yield is 5.24%, so a 5% annual 10-year bond costs 97.121. Newton recovers the yield in 4 iterations, Brent in 10 function calls and bisection in 40. The implied volatilities of 10%, 20%, 40% and 80% come back to better than 10⁻⁶. Knowing what each method costs and when it can fail is what lets you pick the right one for a whole curve of bonds or an option chain.
- Newton is fast but needs a derivative and a decent start: it took 4 steps here.
- Bisection cannot fail but is slow: 40 steps for a bracket of width 65.
- Use
brentqand handle the impossible cases: a bracket plus interpolation, and NaN when no solution exists.
Lab · what's graded
- A bond price10 pts
- Newton by hand20 pts
- Bisection by hand15 pts
- Brent with scipy15 pts
- Three solvers side by side10 pts
- Implied volatilities15 pts
- The real-data study15 pts