HIMIPref™ Bug Fix: curveYield Calculation

As noted on October 22

I’ll explain in another post, because it’s kind of funny, but basically there’s a little loop used in the process of curve approximation that calculates a yield; in the case of YLD.PR.B, quoted at 1.60 with a stated annual dividend of $1.05 (currently suspended) until maturity 2012-2-1 at $15 [dubious], the little loop ran ’round 5,709,833 times [in the run where the problem was unequivocally isolated] before the WebService timed out and blew up the whole programme.

The function at fault (yieldApproximatorTypeCalc::getSemiAnnualYieldFromTable) calculates the yield to maturity of a set of cash flows defined in a table (the input is set up in much the same way as Excel’s XIRR() function) by successive approximations to the yield using the Newton Method.

Unfortunately, this procedure can be unstable near a horizontal asymptote or a local extremum.

When calculating the curveYield for YLD.PR.B on October 21, the function did not converge; instead, it oscillated between two highly incorrect numbers.

The function has been adjusted such that:

  • After 500 iterations, a successively smaller damping factor is applied to the yield change, and
  • After 1,000 iterations, status information is written to the errorOutput.txt file after each iteration, and
  • After 1,010 iterations the process aborts and returns ANALYTICAL_DOUBLE_NO_SOLUTION

The function now converges for YLD.PR.B on October 21; other tests (prior to application of the damping factor) confirm that the ‘no solution’ result is handled properly by the rest of the programme.

It’s not often I find a crippling bug in HMIPref™ any more! That’s the only lack of convergence in this function in almost 15 years of daily data!

Leave a Reply

You must be logged in to post a comment.