TVM solve for interest rate, revisited
|
06-13-2022, 11:56 PM
(This post was last modified: 06-17-2022 10:11 PM by Albert Chan.)
Post: #11
|
|||
|
|||
RE: TVM solve for interest rate, revisited
Testing for f = 0 (or changed sign), with *guaranteed* root, is good to have.
However, it is possible eps too small to change iterated rate. This cause f unable to improve (toward 0), giving false negative result. lua> find_rate(300,-1000,0,10002) -- ??? nil lua> g = iter_i(300,-1000,0,10002) -- to see what's under the hood lua> for i=1,9 do print(g()) end Code: 0.005469683722009796 0.005469683722009796 30.006666666666668 (i + eps) rounding errors caused iteration not to advance, f unable to change sign. For above example, relative to i, 1/2 ULP = 0x1p-61 ≈ 4.337e-19 ≈ 1.25 eps (that's in a perfect world; i uncertainty is likely > 1/2 ULP) It is not a guarantee, but if rate converged, we should also consider solution found. Revised find_rate Code: function find_rate(n,pv,pmt,fv,BEGIN,i0) Code assumed about 15 digits matched "converged". Last iteration, with |f| not improving, throw away. lua> find_rate(300,-1000,0,10002) -- revised version 0.007705485872366127 true |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)