Post Reply 
Request TVM formula guidance
12-11-2014, 06:36 PM (This post was last modified: 12-14-2014 12:52 AM by Dieter.)
Post: #6
RE: Request TVM formula guidance
(12-11-2014 10:02 AM)iMatt04bit Wrote:  
(12-03-2014 09:17 PM)Dieter Wrote:  Even with very small values of i ?-)
It works with an interest value entry of 0.005/12, and up to 999/12.

That's not "small". ;-) Try something like 1E-14/12. Or anything that rounds to 1 if you evaluate 1+R.

Quote:I am very interested in applying the two functions you mention.

These functions, ln1+x and e^x-1 have been discussed several times here. The classic method by W. Kahan for ln1+x can be found in the HP15C advanced functions handbook, others have been discussed in this forum, for instance here.

Quote:I found the real one and its working well.
Its really odd how that version and similar others were producing reasonable results. At times I think it had better results than the real thing.

If you consider the way Newton's method works, it's well possible that a slightly wrong derivative may work better (or worse) than the correct one.

Quote:I really hope this is the right way, it seemed so from examples I have reviewed.
I still think it takes far too many iterations to solve.
The partial derivatives that I was using solved much faster.
But still the same format of x = x - fxA/fxB was in use.
Do you know how fast this should solve?
A rough estimate of expected iterations?

Let's take a look at your example.

Quote:For an initial value/guess of i, there is a set of conditional code statements which calculates an estimate depending on variations of the TVM inputs of PV,PMT,FV and if all are non-zero, or if one of them is zero, and also per signs. The estimates are within 0.5 of the solution at times, and aimed slightly above the expected value of i.

Does this mean the estimate is off by 50% or by 0.5%?
The latter would be sensational. ;-)

Quote:I save the prior value of computed interest, payment, and the result of the TVM formula in fxA. The differences of these values are compared on each iteration. When little or no difference it is time to break out of the loop.

Please see my previous post on this question.

Now let's take a look at your example case.
I have removed most of the data and left only x, the current approximation for the interest rate.

Code:

Using: N: 10  PV: 50.00  PMT: -30.00  FV: 400.00

Using i guess of: 60.200000000000000

   1)  x: 57.315104488758620
   2)  x: 55.592803486013310
   3)  x: 54.577156381714110 
// snipped
  56)  x: 14.435871328079948
  57)  x: 14.435871328079937
Break countdown (5) on abs(fxA) < 1e-12 : -0.000000000000426
I is:
   53.172213268384730%
   14.435871328079937%

WHAT? FIFTY-SEVEN ITERATIONS? #-)
You must be kidding. There's definitely something going wrong here.

I tried the quick-and-dirty spreadsheet I once used to estimate an initial guess for the interest rate. My first guesses for this case were 9,836% and 60%. Starting with these, the iteration converges as follows. The third column shows the results for your estimate 60,2% which works equally well.

Code:

 0)    9,836 06557 37705      60,000 00000 00000      60,200 00000 00000
 1)   13,745 64880 79411      53,563 10589 39787      53,582 35595 39331
 2)   14,416 85886 71670      53,174 01364 11121      53,174 19311 90885
 3)   14,435 85632 97618      53,172 21330 74545      53,172 21331 56320
 4)   14,435 87132 80707      53,172 21326 83847      53,172 21326 83847
 5)   14,435 87132 80799      53,172 21326 83847      53,172 21326 83847
 6)   14,435 87132 80799      53,172 21326 83847      53,172 21326 83847

As you can see, the approximation converges after five resp. four (!) iterations.

So it looks like there is something wrong with your iteration loop. Your initial guess of 60,2% is fine and converges within four iterations as well, so there must be something wrong within the loop.

Convergence should develop roughly quadratic, and this is true for the example above. Take a look at the right column starting at 60,2%. The first approximation has two correct digits, the next one four, then eight and finally all 15 digits are correct. The left column shows the same pattern: the first approximation has 1–2 valid digits, and then three, six, twelve and finally all digits are correct.

You may check whether the derivative is really correct by comparing its results with a numeric approximation: calculate f(r) and f(r+0,0001) and divide the difference of these two by 0,0001.

Addendum:
It looks like both your f(r) and f'(r) are not correct. Starting with 60,2%, the TVM equation (fxA) should return a value of 4,2065 and not 42,065 as stated in your results. Also the first derivative at this point (fxB) is roughly 56,81 and not 14,581. The correct values lead to a first approximation of 0,602 – 4,2065/56,81 = 0,52795... or 52,8%.

The second iteration then should give fxA = –0,234 and fxB = 62,97 which leads to a new x of 53,17% – which is already exact to four significant digits.

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)