TVM solve for interest rate, revisited
|
07-16-2022, 02:58 PM
Post: #29
|
|||
|
|||
RE: TVM solve for interest rate, revisited
(07-11-2022 09:08 PM)Albert Chan Wrote: (*) Another way is simply get a better guess. Had we put back pmt term, we get: newx = function(x) return expm1(log1p(-(pv+fv)/(pmt/x+pv))/n) end newx(x = ±Inf) reduced to quoted pmt=0 approximation. x ← newx(x) work well for huge x; it is almost as good as Newton's method. x - (newx - x) / (newx - x)' ≈ x - (newx - x) / (0 - 1) = newx lua> require'fun'() lua> genx = function(f,x) f=f(x); return f, f, f-x end lua> n,pv,pmt,fv = 10, -100, 10, 1e10 lua> iter(genx,newx,Inf) :take(8) :each(print) Code: 5.309573444801933 -Inf Some references, for how Lua iterator work https://luafun.github.io/under_the_hood.html#iterators http://lua-users.org/wiki/IteratorsTutorial https://www.lua.org/pil/7.1.html |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)