Post Reply 
Request TVM formula guidance
12-03-2014, 09:17 PM (This post was last modified: 12-03-2014 09:33 PM by Dieter.)
Post: #4
RE: Request TVM formula guidance
(12-02-2014 05:33 AM)iMatt04bit Wrote:  The results appear precise and a match to a variety of real and simulated calculators.

Even with very small values of i ?-)

Some HP calculators use special functions like ln(1+x) or exp(x)-1 to ensure exact results even under these circumstances. Have you implemented something similar in Java? What's the working precision? Standard double precision, i.e. approx. 15 decimal digits?

(12-02-2014 05:33 AM)iMatt04bit Wrote:  I just need to know if I have a correct derivative. ...if only I had taken Calculus...

If you didn't there is always Wolfram Alpha. ;-)

(12-02-2014 05:33 AM)iMatt04bit Wrote:  // formula from the hp12c manual, solves to 0 for matched I converted to R, used below
f(x) = PV + (1+R*K) * PMT * ((1-(1+R)^-N)/R) + FV * (1+R)^-N

I assume you mean f(R), not f(x).

(12-02-2014 05:33 AM)iMatt04bit Wrote:  // the derivative as best I know
f'(x) = PV + (1+R*K) * PMT * [1/N * (1-(1+R)^-(N-1)) / (1/R)] + FV * [1/N * (1+R)^-(N-1)]

Hmmm... not quite. ;-)

(12-02-2014 05:33 AM)iMatt04bit Wrote:  // compute for +I
I = I - f(x)/f'(x)

// or for -I
I = I + f(x)/f'(x)

Could you explain this a bit more in detail?
And what about cases with, say, two different positive solutions?
What is the initial guess for i, what value does the iteration start with?
How do you handle cases where no solution exists?

(12-02-2014 05:33 AM)iMatt04bit Wrote:  // breakpoint on difference of prior computed I and current I is <= 5e-12 for fractional I | I < 1 percent
// or computed I <= 5e-15 for I | I >= 1 percent

Sorry, I do not quite understand what you want to say here.

The usual exit condition for the iteration loop is a relative (!) error near the working precision, i.e. here 1E-15. Due to numeric pitfalls this may not occur under some circumstances, so I often use another idea: Since approach Newton's method converges roughly quadratically, the idea is to quit as soon as a relative error as small as, say, 1E-10 is reached. Assuming quadratic convergence, this means that the next iteration would have an error as low as 1E-20 and thus the approximation of i would not change — so you're done and the result is fine. Just an idea...

Finally, here are two links that may be helpful:

First you may take a look at the way the TVM equation is solved in the HP41 standard application pac. The code can be found in the HP41 software section. Hint: R07 holds 1+i%/100 and R09 stores i%/100.

And finally, as you might have expected, the TVM issue has been discussed numerous time before. Maybe a look at this thread in the old forum may provide some useful information.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Request TVM formula guidance - iMatt04bit - 12-02-2014, 05:33 AM
RE: Request TVM formula guidance - Dieter - 12-03-2014 09:17 PM
RE: Request TVM formula guidance - Dieter - 12-11-2014, 06:36 PM
RE: Request TVM formula guidance - Dieter - 12-14-2014, 04:24 PM
RE: Request TVM formula guidance - Dieter - 12-17-2014, 01:21 PM
RE: Request TVM formula guidance - Dieter - 12-21-2014, 06:14 PM
RE: Request TVM formula guidance - Dieter - 12-25-2014, 12:42 PM
RE: Request TVM formula guidance - Dieter - 12-29-2014, 07:47 PM



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