Post Reply 
(10C) Mortgage Loan Interest Rate
11-03-2018, 11:34 PM (This post was last modified: 11-05-2018 12:06 AM by Albert Chan.)
Post: #11
RE: (10C) Mortgage Loan Interest Rate
(11-03-2018 06:11 PM)Dieter Wrote:  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?

I started the code from plot of the f(i) vs i. It is relatively straight.
(unlike post 4 formula, which did the flipped version, with i in the denominator)

With my f setup, f(0+) = 1/n ~ 0, f(1) = 1/(1-2^-n) ~ 1. So, for 0 < i <= 1, f'(i) ~ 1
In other words, (r - f(i)) gap is about the same size as i correction.

Since true i is closer to 0% than 100%, I expect flatter f(i).
I wanted i1 closer to true i than i0, so scaled the gap by 1.5 (to compensate)
For small n, that is not quite enough, but big n have slight over-correction.

Quote: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.

My mistake. The last iteration reached limit of IEEE double precision.
I should compare both version with first iteration, not the last.

Relative error (vs true i), f(i) version = 3.44e-6, √f(i) version = 4.70e-9.
So, starting from the same guess, √f(i) version is 732 times closer after 1 iteration.

Quote: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

Your really pick a good example, same issue if done with binary math.

float(31/30) = exact(31/30) + 0.467 ULP, almost a half-way case.

lua> (31/30)^36 -- over-estimated 26 ULP
3.255785675929093
lua> 31^36 / 30^36 -- only off 1 ULP, last 82 should be 815
3.255785675929082

26 ULP sounded bad, but not really: 26 ULP = 26/2^51 ~ 1.15e-14
For 16 decimals setup, 38 ULP = 38/10^15 = 3.8e-14, or 3.3 times worse.

Edit: based on above issue, eps is not recommended to set below 1e-12
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 - Albert Chan - 11-03-2018 11:34 PM



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