Post Reply 
Request TVM formula guidance
12-23-2014, 02:56 AM
Post: #12
RE: Request TVM formula guidance
(12-21-2014 06:14 PM)Dieter Wrote:  
(12-20-2014 05:47 AM)iMatt04bit Wrote:  I found an improvement for the Secant method where it will solve much faster:
Code:
x0 = x0 - fx0 * ((x0 - x1)/(fx0 - fx1));

This should follow the other line with similar code.

Quote:Hmm... looks like the usual formula for the Secant method to me. ;-)

Wiki shows something like this:
x2 = x1 - f(x1) * [ (x1-x0)/(f(x1)-f(x0) ]
x3 = x2 - f(x2) * [ (x2-x1)/(f(x2)-f(x1) ]
x4 ...etc
It looks like single variable substitution returned to the input of the next iterative function. But maybe I have been staring at it for too long. Before I tried a dual solving method - the Wiki version of the function set only converged from one endpoint.

This is the code I used where I added a second convergence process as x0 = formula:
Code:
// initial guess converted to 2 points expected to provide a reasonable closed set
x0 = iguess + iguess/2;
x1 = iguess - iguess/2;

for(;;){

  // the TVM formula from the perspective of each point
  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);

  // double convergence via dual variable substitution
  x1 = x1 - fx1 * ((x1 - x0)/(fx1 - fx0));
  x0 = x0 - fx0 * ((x0 - x1)/(fx0 - fx1));

  // breakpoint code for when a solution is reached goes here
  // something like { abs(x0 - x1) < 1e-15 } and/or other methods
}


(12-20-2014 05:47 AM)iMatt04bit Wrote:  Now the secant method decrements from both x0 and x1 points as it solves.

Quote:Determining if (and how fast) the iteration converges is a quite tricky subject. Using different forms of the TVM equation may drastically change this behaviour, so the version given in the 12C manual is not neccessarily the best choise. I also would reccommend a look at the Kahan paper linked below.
I reformed the formulas to make use of the logarithmic functions and to provide for large scale numbers. Note that in the code snippet I am showing the original format of the formulas for clarity.

Which brings a question to mind: is there a min/max limit to the size of the interest rate value that the ln/log function can handle?

(12-20-2014 05:47 AM)iMatt04bit Wrote:  Min/max number of iterations to solve for 21 scenarios tested are:
Newton: 2,6 and Secant: 5,9

Quote:So Newton's method converges faster?
Yes, it also looks a bit more accurate at times, by the appearance of the fxA value vs the fx1 value.

Quote:Looking at "results.txt" the initial guesses look very good. How do you evaluate these?

I have a set of simple calculations + the one you showed me is in there.
There are 10 calculations, and depending on the TVM values some will provide a reasonable guess under certain conditions. I evaluate each result using the TVM formula, and then cheat a little by running the best one through a single pass of the Newton formula.

A last evaluation of the guess before and after the Newton is evaluated and used as the final estimate of i.

I still am experimenting with these estimating formulas.

Quote:Here's a paper by W. Kahan (who contributed much of the mathematics used in HP's calculators since the mid-Seventies and most of the later iEEE754 floating point standard): Mathematics written in sand addresses several pitfalls and problems using floating point arithmetics on computers and calculators. Especially pages 14 ff. may be interesting here as they deal with financial calculators and problems at solving for the interest rate. The "A Penny for your Thoughts" example also demonstrates why using log1p instead of pow is a good idea. You may also want to read p. 17–22 concerning the convergence of the Newton resp. Secant method.

I am already reading it - thanks very much!
This is the stuff that makes math an adventure.

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 - iMatt04bit - 12-23-2014 02:56 AM
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: 2 Guest(s)