Student's corner : ac bond yield calculator - pro Newton–Raphson method
ac bond yield calculator- pro
© alarius consulting 2019

Change any value in the white boxes below.
yield calculator inputs:
date format:
value date:
maturity date:
clean price (%):
coupon rate (%):
coupon basis:
coupon frequency:
first coupon type:
first accrual date:
first coupon date:
redemption (%):
FIND YIELD
yield calculator outputs:
yield:
dirty price:
clean price:
time to maturity:
accrued interest:
accrued days:
variation (risk):
mod duration:
duration:
convexity:
raw convexity:
Principle: ( Newton -Raphson method )

Let CP the actual clean price, and Y the yield we are looking for.
c coupon rate, n maturity and r redemption price.
CP = f ( Y , c ,r , n )
PV01 = f ' ( Y , c ,r , n ) - first derivative of f -

❶ We chose a guess yield and calculate the clean price of the bond and it's PV01 (variation) with this guess.
New clean price =f ( guess )
delta price= CP - f ( guess )
PV01 = f ' ( Y )

since f(x+y) ≃ f(y) + x * f '(y) our second guess will be:
❷ guess= guess + delta price / f' (guess)

See our bond sensitivities page / formulas for details.

❸ We then calculate f (guess), f' (guess) and delta price until delta price gets as close to zero as specified.
To avoid endless loops it's a good practice to define a threshold which is not exactly zero (e.g ABS(delta)<0.0001) AND to define a maximum number of iterations so that the loop ends if one of the two conditions is met

See wiki Newton-Raphson for more details.

This method will be all the more efficient that the initial guess is close to the true yield.
For the bond price function a simple initial guess can be made with the following formula:
Calculate "zero price" (a price with yield=0) as zero price = r + n * c
then guess = (zero price-CP) / n

The iterations chart shows the number of iterations and the convergence speed to delta price=0.