Looking for TVM contributions
|
06-19-2024, 12:20 PM
Post: #67
|
|||
|
|||
RE: Looking for TVM contributions
Hi, robve
Here is plot of f(x) = ((pv+fv)/((1+x)^n-1) + pv)*x + pmt, for test sample #23 I also showed asymptote line, f(x → ∞) = pv*x + pmt plot {(130/((1+x)^10-1)+50)*x-30 , 50x-30}, x = 0 .. 1 And for the other root, also with asymptote line, f(x → -1) = -fv*x + pmt plot {(130/((1+x)^10-1)+50)*x-30 , -80x-30}, x = -0.5 .. 0 Goal is to iterate rate from the outside, going in. Edge rates are where asymptote line intersect to x-axis, thus always outside. If we iterate from the inside, Newton will definitely overshoot ... perhaps by a lot. Since asymptote line slope is more extreme (in size) than at any other point, we can use it for Secant's 2nd point, and have a second guess, also from outside. (06-19-2024 02:01 AM)robve Wrote: - optionally allow one or more retries after overshooting, this is parameter g. When g=0 we stop. When g=1 we allow one retry to run iterations again after overshooting from the current I%. I assumed when you say overshoot, it means f changes sign. With correct guess for f (concave up or down), there is no need to retry after overshoot. With wrong guess, Newton's next guess should overshoot back to the outside, so g=1 It is not as simple for Secant's method. It may take a while before *both* points are outside. Quote:- if the final iteration when we stop y=npmt() is nonzero, then we should pick the previous i%, not the last that overshot. If previous i% from the outside, overshoot is not really an overshoot, we should keep it. If previous i% from the inside, we don't really know which is better. All we know is true rate is somewhere between the two. Quote:- I'm measuring FVerror to check the TVM model's accuracy with the i% solved, not the i% rate places because some final digits simply don't matter, it's not anomalous. If i% getting very accurate (error of few ULP's), FVerror probably not that useful Example, here we compare, for a given rate, calculated PMT vs FV lua> n,i,pv,pmt,fv = 10,nil,50,-30,80 -- sample #23 lua> i = tvm(n,i,pv,pmt,fv) lua> for k=0,5 do print(i, tvm(n,i,pv,nil,fv), tvm(n,i,pv,pmt,nil)); i=nextafter(i) end Code: -0.36893369874177734 -29.999999999999996 80.00000000000001 Since rate search is solving npmt=0, it look like our solved i is good, so does (i+1ULP) Using Plus42 for reference, true rate is (i+0.87ULP) = (i+1ULP) - 0.13 ULP But from FV numbers, true rate = (i+2ULP) I am not suggesting PMT_error is better test than FV_error. It is just that solved i is too accurate for these tests to work. From what I can tell, all your methods look equally good. Quote:- for termination test I use for the Secant, Newton and Hybrid implementations: From wrong guess, we don't know if y is always improving (toward 0). Unless your guesses are from the outside, (fabs(y) < fabs(w)) is probably wrong. Quote:... Newton's derivate expression has subtle evaluation errors that get worse as we get closer to the root. Since both Newton and Secant are self-correcting, we can simply look at last 2 points. With 2 points close together, Secant's slope is going to be much worse than Newton's. With both methods use the *same* f, and Newton get better f', I would think Newton is better. Of course, final f is tiny, and not very accurate. Perhaps more accurate f' make no difference. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)