Post Reply 
Request TVM formula guidance
12-17-2014, 01:56 AM
Post: #8
RE: Request TVM formula guidance
I found the problem in the solver code and its resolved now.
There was a misplaced sign for the derivative and the rate needed a correction.
I am using R in the formulas, where R = x/100, so after x = (fxA/fxB * 100) it works well now with results matching up exactly to the hp12c emu and usually exact or 1e-10 difference to the hp20b emu. I tested it with all the TVM scenarios in the hp12c manual, where I turned the scenarios to solve for the interest rate.

I am using the following formulas, where x is the interest rate in the form displayed on the calculator. Where fxA is the TVM solution to zero, and fxB the derivative.

Code:
R = x/100;
fxA = PV + (1+R*K) * PMT * ((1-Math.pow(1+R,-N))/R) + FV * Math.pow(1+R,-N);
fxB = (1/Math.pow(R,2)) * Math.pow(1+R,(-N-1)) * (-FV * N * Math.pow(R,2) + K * N * PMT * Math.pow(R,2) + N * PMT * R - PMT * R * Math.pow(1+R,N) + PMT * R - PMT * Math.pow(1+R,N) + PMT);

I feel like the Newton method loses resolution for extremely small numbers, like 0.005/100 for an interest rate or smaller. And it has a breaking point on the larger scale (more than 99999999) for the interest rate (can be solved on the hp20b).
The reason for the problem with large numbers is the size of the value in fxB.

So for an alternative I am experimenting with the Secant method (I have it working). Wiki is such a great resource.
It should work well for extremely large numbers since it only requires the TVM solution formula (fxA) and 2 points, which are easy, just use p1=guess + guess/2 and p2=guess - guess/2.

Before the loop:
Code:
x0 = i + i/2;
x1 = i - i/2;

This is the code for the Secant method (in the loop):
Code:
R = x0/100;
fx0 = PV + (1+R*K) * PMT * ((1-Math.pow(1+R,-N))/R) + FV * Math.pow(1+R,-N);
R = x1/100;
fx1 = PV + (1+R*K) * PMT * ((1-Math.pow(1+R,-N))/R) + FV * Math.pow(1+R,-N);

x1 = x1 - fx1 * ((x1 - x0)/(fx1 - fx0));

There are an impressive amount of root finder methods out there, so its hard to know what others may prove useful for an alternative. I think a primary concern is the difficulty in solving small numbers that approach zero.

I want to thank everyone for the help - its much appreciated.
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 - iMatt04bit - 12-17-2014 01:56 AM
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)