# Fastest way to calculate YTM from bond price

I would like to calculate YTM for every top of the book update on the 10-year note traded on Brokertec. There is no closed form solution so have to use a root finding method like Newton-Rhapson. It will obviously need to be fast. Is NR method the fastest? Are there any other better methods?

• (1) Since you are continuously updating YTM, a good trick is to use the last value as the starting point for the next iteration. (2) NR should be fine. For the absolutely fastest speed you might use table lookup (into a table prepared at the beginning of the day). Aug 30, 2019 at 18:28

I faced this problem trying to price bund yields from Bloomberg ticks. I found the fastest method was to price three static yields from three static prices and determine a quadratic function for those datapoints. Then any yield could be determined from that function. Although not exactly correct the error is so minimal it is practically un-noticeable, but the speed is effectively instantaneous.

Edit

As an Approximator

To give a bit of context to this, if you do not have access to a bond library in Excel the bloomberg "BDP" function can be used to determine the "YAS_BOND_YLD" parameter from a given price and settlement. But, that function appears to work very slowly, or is server based meaning the round trip is slow. With live ticking prices the function can exist in a permanent state of calculation if a tick change forces a restart of the calculation.

Thus the idea of deriving a quadratic price/yield function is done in the following way.

1. Pick 3 sensibly spaced prices, $$P_1, P_2, P_3$$ and determine their yields, $$y_1, y_2, y_3$$

2. Assert that each yield is a result of a quadratic equation: $$y = x_0 P^2 + x_1 P + x_2$$ and the coefficients are then the solution of the linear system:

$$\begin{bmatrix} P_1^2 & P_1 & 1 \\\\ P_2^2 & P_2 & 1 \\\\ P_3^2 & P_3 & 1 \end{bmatrix} \begin{bmatrix} x_0 \\\\ x_1 \\\\ x_2 \end{bmatrix} = \begin{bmatrix} y_1 \\\\ y_2 \\\\ y_3 \end{bmatrix}$$

This is reasonably easy to code in VBA for use in an excel cell (and is faster if you cache the quadratic coefficients and dont re-derive them each time)

Function BondYieldInterp(known_prices, known_yields, price)
Dim p_arr As Variant: p_arr = known_prices
Dim y_arr As Variant: y_arr = known_yields
Dim m_inv As Variant: ReDim m_inv(3, 3)
Dim m As Variant: ReDim m(3, 3)
Dim i, j As Integer
For i = 1 To 3
m(i, 1) = p_arr(1, i) ^ 2
m(i, 2) = p_arr(1, i)
m(i, 3) = 1
Next i
m_inv = Application.WorksheetFunction.MInverse(m)
Dim beta As Variant
beta = Application.WorksheetFunction.MMult(m_inv, Application.WorksheetFunction.Transpose(known_yields))
BondYieldInterp = price ^ 2 * beta(1, 1) + price * beta(2, 1) + beta(3, 1)
End Function


As a Converger

In Python I have implemented both scipy.optimise.brentq and my own Python brents method to iterate a yield-to-maturity. Since the scipy version is coded in C it is faster. However, these optimisers are designed for arbitrary continuous functions. The signature of a bond price from yield or vice versa is close to a shallow quadratic curve. It is possible to use the above method in reverse to define a convergence routine based on this quadratic interpolator. The basic iterator I have coded in pure python is close to the performance of scipy brentq.

• Interesting and elegant approach. Do you have a comment on how to select the three pillar points (intraday, specific time points etc)? And why a quadratic approach?
– SI7
May 1 at 9:49
• If the current 10y bund price is 120.0. I am currently using say 122.0, 120.0 and 118.0, which is roughly 15bp in either direction of mid, which generally captures intraday movements. A linear function (1st order) is accurate for small moves, and already market-makers use this approach for updating electronic price quotes. For larger movements the impact of gamma/convexity becomes non-neglible so a quadratic (2nd order) function is preferable and effectively no more difficult to implement.
– Attack68
May 1 at 11:33

In my old pricing library I used NR to calculate YTM. That was the fastest that I could find.

But, "Alex C" is correct, you can pre-cache. Remember, BT quotes in 64's, so you can easily build up a cacheahead of time. You don't need to worry about non-standard prices.

Brent's method may converge a little faster than NR for price-yield.

Before electronic computers, a "yield book" was a massive paper book where one could find nearest dirty price, days to maturity, and coupon, and then interpolate. Some caching might help you if you keep varying only the price, and look at the same bonds and settlement date.