Post Reply 
(10C) Mortgage Loan Interest Rate
11-03-2018, 06:11 PM
Post: #10
RE: (10C) Mortgage Loan Interest Rate
(11-03-2018 01:51 PM)Albert Chan Wrote:  Tried using Newton's method. It is not as fast, unless f(i) is inlined.
Also, if eps is set too small, i will not converge.

The TVM solvers that I have programmed over the years (well, decades ;-)) all use the Newton method, and usually it converges within a few iterations. In this regard Newton's and the secant method / regula falsi are quite similar. But Newton's method only requires one initial guess instead of two that preferably bracket the solution. How can you realiably ensure this?

If you want to try a secant method I'd recommend implementing a modified algorithm, for instance the Illinois method. This avoids some problems and improves a reasonably fast convergence.

(11-03-2018 01:51 PM)Albert Chan Wrote:  Although √f(i) version does 1 less iteration, it is more accurate (-26 ULP vs +45 ULP)

I think you cannot judge the different methods based on such minor differences. The whole calculation is not that accurate: you can't get 16 valid digits with 16 digit precision. And the implementation already loses several digits when 1+i is calculated, so the last two digits are more or less random. For example, for i=1/30 and n=36 the expression (1+i)n evaluated with 16 digits will cause an error of 38 ULP. Just for this single calculation, even when evaluated without any additional errors. That's why better implementations of the TVM formula use special functions like ex–1 and ln(1+x) to avoid such problems, or at least reduce them significantly.

You also mentioned the problem that successive iterations may oscillate in the last digits so that there is no convergence to a unique 16 digit result. The essential reason for this is that neither f(x) nor f'(x) are evaluated absolutely accurate (see above). Since Newton's method and (approximately) the secant method both converge nearly quadratically close to the true root, I would recommend something like this: in each iteration step check the relative error (!), and then compare this not with 1E–15 but 1E–8. Or maybe 1E–11 for a more conservative approach. If the last relative correction term is below this threshold the next iteration should reach an accuracy level close to machine precision, plus or minus some random deviation in the last few digits that cannot be realiably avoided. You may now exit the iteration or, just to be sure, set a flag and do one more final iteration.

Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
(10C) Mortgage Loan Interest Rate - Gamo - 10-31-2018, 04:49 AM
RE: (10C) Mortgage Loan Interest Rate - Dieter - 11-03-2018 06:11 PM

User(s) browsing this thread: 1 Guest(s)