Post Reply 
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
-0.3689336987417774     -30.000000000000004     80.00000000000001
-0.36893369874177745    -30.000000000000007     80
-0.3689336987417775     -30.00000000000001      79.99999999999999
-0.36893369874177756    -30.000000000000014     79.99999999999999
-0.3689336987417776     -30.00000000000002      79.99999999999997

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:

Code:
    } while (y != 0.0 && fabs(y) < fabs(w))
  } while (y != 0.0 && y != w && g-- > 0);

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.
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 - Albert Chan - 06-19-2024 12:20 PM
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 - 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: 8 Guest(s)