# Why Yield cannot be calculated for short dated Bonds using Quantlib

I am trying to calculate a yield from a clean price using Quantlib for Bond. I play a lot with the Quantlib samples (Bonds.java) and succeed but when I change to set today close to maturity, Quantlib throws an Exception telling:

unable to bracket root in 100 function evaluations (last bracket attempt: f[-2.2124e+274,5.75224e+274] -> [-nan(ind),105.58])

It seems to happen exactly when today is exactly one month minus one day. I don't know why and can't find a clean explanation about this. Can somebody help me or point me to right explanation, please?

• Please provide the values of all the parameters, so the problem can be reproduced. – noob2 Oct 7 '20 at 12:22

It sounds like you're passing the (clean) prices of 105.58 for a bond that pays 100 (+ some accrued interest) in one month. The simple yield would be somewhere around -50 to -100, pretty nonsensical.

I've seen two philosophical approaches to this situation in libraries. If the program returns a large number that makes no economic sense, then it will be mostly numerical noise. (This is the approach mostly taken by Bloomberg.) Then some users of the library will question why one library computes -100 and some other library computes -110. Conversely, if program throws, then (the same) users will ask why this library throws, while, e.g. Bloomberg terminal displays some huge number that makes no economic sense. Should a library developer try to perform all the arithmetic in exactly the same (undocumented) sequence as Bloomberg in order to match some nonsensical numerical noise?

Edited: the approach that I would try if I were writing yet another library might be along these lines:

• Model Validation sets the minimum yield (and maximum, and valid ranges for other such things)

• the library calcuates the yield, which could be as low as -inf.

• the ibrary looks at the validated range (ideally - dynamically at run rime)

• depending on user-specified setting, the library either throws, or returns the best estimate "tagged" with a warning that this number is outside the vaidated range.

• if a downstream/caller encounters a number tainted by such a tag, then depending on user-specified setting, the caller either throws, or tags other tainted numbers, or footnotes reports, etc.

• – noob2 Oct 7 '20 at 13:23