TVM solve for interest rate, revisited
|
06-09-2024, 04:07 PM
(This post was last modified: 06-25-2024 05:12 PM by Albert Chan.)
Post: #31
|
|||
|
|||
RE: TVM solve for interest rate, revisited
I made some fixes, and changes to the interface, here is the update
1. _find_rate() does not do time-symmetry anymore. tvm() already does. 2. _iter_i() updated with cleaner code 3. _iter_i2() removed. Halley's method may have trouble with tiny rate 4. edge_rate(n,i,pv,pmt,fv) can now return big edge, if i = false Code: function EFF(i,n,div) i=div and i/n or i; return expm1(log1p(i)*n) end (06-23-2022 07:04 PM)Albert Chan Wrote: f value should read as if whole column get shifted up. Now it is easier to read, verbose show (i, f(i)), without shifting column It also show initial guess rate (previously hidden) lua> tvm_begin(40, nil, 900, 1000, -1000, true) Code: -0.5 -4.547473508864641e-11 Now, we can also supply rate guess (not recommeded for general use) Code assumed user guess is bad, might overshoot, and use next one as initial guess. lua> tvm_begin(40, 0, 900, 1000, -1000, true) Code: 0 997.5 Update 6/16/2024 Now, it can use big edge if i=false, small edge if i = nil lua> tvm_begin(40, false, 900, 1000, -1000, true) Code: -0.5263157894736842 -52.63157894737378 I am unsured when to use special branch (from f(0),f'(0),f''(0)) for iter_i(). Because of quadratic fit, it does not work well with huge compounding effect. When rate is tiny, general branch (using f(i) formula) does not work. For now, I think a compromise may be best: 1+n*i*i == 1 Update 6/25/24 patch is making more sense now, because below 2 are equivalent: NPMT(n, i, pv, pmt, fv) == NPMT(n/2, i*(i+2), pv, pmt*(i+2), fv) RHS rate = (1+i)^2-1 = i*(i+2) --> number of payments cut in half. n → n/2 --> payments about doubled, pmt → pmt*(1+i) + pmt = pmt*(2+i) LHS==RHS, we cannot base only on rate to decide when to switch. We need to get rough invariant. If i is small, (n/2) * (i*(i+2)) ≈ (n*i) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)