Post Reply 
Looking for TVM contributions
06-20-2024, 03:07 PM
Post: #74
RE: Looking for TVM contributions
(06-20-2024 04:03 AM)robve Wrote:  With last i% after overshooting the TVM model parameters space error is bad:
./tvm 480 '?' 100000 -208.333333333333343 0
1/1 i%= 1e-05 y= 0.00501045666647
2/1 i%= 7.98321085531e-11 y= 3.999917908e-08
3/1 i%= 1.03199085624e-16 y= 2.84217094304e-14
4/1 i%= 6.09287401526e-17 y= 2.84217094304e-14
4, i%=-1.39404957469160446e-17%
FVerr=5.4e+05
PVerr=5.4e+05
PMTerr=2.6e+02

Because f(ε) was not implemented, y3 and y4 almost the same.
Bad y/y' cause extrapolated i% go crazy, even its sign is wrong.

f(ε) part is a 1-liner. I think it is worth adding.

40 DEF FNF(I) @ IF N*I*I+1-1 THEN FNF=((P+F)/EXPM1(LOGP1(I)*N)+P)*I+M @ END
50 Z=P+F @ FNF=(Z+N*M+I*((Z+N*(P-F))/2+I*Z*(N*N-1)/12))/N @ END DEF

But bad i does not explain huge errors. How are they calculated?

lua> i = -1.3940495746916044e-19
lua> NFV(480, i, 1e5, -208.333333333333343, 0)
0
lua> NPV(480, i, 1e5, -208.333333333333343, 0)
0
lua> npmt(480, i, 1e5, -208.333333333333343, 0)
0

robve Wrote:iguess() adjusted for pmt this produces bad initial i% guess for some of the more extreme cases and that worries me ...
BGN mode in this case n=40 pv=900 pmt=-400 fv=-1000 gives i%=371.725

guess_i() assumed (n*i) is small, and NPMT is quadratic of rate.
Above example, if we solve actual quadratic, we have imaginary numbers.
Pade approx was used to return real guess, even if quadratic have no real root.

BTW, why is i% > 100 a problem?
I just tried 1 billion %, and it run OK (next iteration ≈ edge rate, as expected)

lua> tvm_begin(40, 1e7, 900, -400, -1000, true)
Code:
1e+07                   4999999600              500
0.8000000007450581      3.6760650345968315e-07  500.00000010323674
0.8000000000098451      0                       500.00000010323674
0.8000000000098451

robve Wrote:About the npmt curvature: adjusting npmt for positive f'' is just a sign change of npmt. But root finders don't need to care as we know, because they flip to the other side of the curve anyway (as shown above). Theoretically then they never need to flip back again unless f'' changes sign. For TVM f'' won't change sign I believe, but numerically there is a nonzero possibility that the sign of npmt may flip close to root due to inaccuracies, especially with lower precision solvers. That worries me.

Problem is in Secant's method. We are estimating slope with points, which may not be both on the outside.
Depends on where they are, we don't know how many iterations until *both points* moved outside.

Hybrid work better perhaps is due to this. It moved next point to the outside, on the first try.
Switch back to Secant with both points outside, give us nice one-sided convergence.

(04-09-2022 05:47 PM)Albert Chan Wrote:  \(\displaystyle I ≈ \frac{1}{P} - \frac{P}{N^2}\)

This is even better, and work well with big N.

find_rate() thus skip over user-supplied guess, and consider next one as initial guess.
Below example, the better guess is on the inside ... Newton pushed it out.

lua> n,pv,pmt,fv = 365*24*60*60,0,-0.01,331667.0067 -- problem 3
lua> i = pmt/fv
lua> i -- edge rate
-3.015072285753529e-08

lua> find_rate(n, i-1/i/n^2, pv, pmt, fv, true) -- perhaps better guess
Code:
3.1987564370323693e-09  -4.4522291350098525e-06 -160259.18297182902
3.1709750078970886e-09  6.720436082630066e-10   -160307.5638939386
3.1709792001110547e-09  1.5612511283791264e-17  -160307.55659320104
3.170979200111152e-09   0                       -160307.55659320077
3.170979200111152e-09
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Looking for TVM contributions - dm319 - 05-12-2024, 06:58 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:48 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:49 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:00 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 11:04 AM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 05:58 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 05:59 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 08:34 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 08:31 PM
RE: Looking for TVM contributions - dm319 - 05-15-2024, 01:00 PM
RE: Looking for TVM contributions - dm319 - 05-15-2024, 12:57 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 10:05 PM
RE: Looking for TVM contributions - dm319 - 05-25-2024, 01:43 PM
RE: Looking for TVM contributions - dm319 - 05-25-2024, 08:40 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 11:22 AM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 02:58 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 09:22 PM
RE: Looking for TVM contributions - dm319 - 06-02-2024, 02:46 PM
RE: Looking for TVM contributions - robve - 06-09-2024, 02:04 AM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 12:15 PM
RE: Looking for TVM contributions - robve - 06-09-2024, 03:29 PM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 06:05 PM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 10:00 PM
RE: Looking for TVM contributions - robve - 06-12-2024, 08:48 PM
RE: Looking for TVM contributions - robve - 06-14-2024, 03:23 PM
RE: Looking for TVM contributions - robve - 06-14-2024, 10:11 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 03:54 AM
RE: Looking for TVM contributions - dm319 - 06-12-2024, 11:56 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 03:05 AM
RE: Looking for TVM contributions - robve - 06-15-2024, 05:48 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 09:52 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 01:38 PM
RE: Looking for TVM contributions - robve - 06-16-2024, 05:18 PM
RE: Looking for TVM contributions - Werner - 06-17-2024, 05:11 PM
RE: Looking for TVM contributions - robve - 06-16-2024, 08:26 PM
RE: Looking for TVM contributions - dm319 - 06-16-2024, 11:55 PM
RE: Looking for TVM contributions - robve - 06-17-2024, 09:03 PM
RE: Looking for TVM contributions - robve - 06-18-2024, 03:27 AM
RE: Looking for TVM contributions - robve - 06-19-2024, 12:57 AM
RE: Looking for TVM contributions - robve - 06-19-2024, 02:01 AM
RE: Looking for TVM contributions - robve - 06-19-2024, 03:47 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 04:03 AM
RE: Looking for TVM contributions - Albert Chan - 06-20-2024 03:07 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 05:07 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 04:30 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 06:27 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 02:33 AM
RE: Looking for TVM contributions - robve - 06-21-2024, 09:04 PM
RE: Looking for TVM contributions - robve - 06-22-2024, 08:00 PM
RE: Looking for TVM contributions - robve - 06-23-2024, 06:03 PM
RE: Looking for TVM contributions - dm319 - 07-05-2024, 09:39 PM
RE: Looking for TVM contributions - dm319 - 07-05-2024, 09:44 PM



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