Post Reply 
Request TVM formula guidance
12-14-2014, 04:24 PM (This post was last modified: 12-14-2014 09:02 PM by Dieter.)
Post: #7
RE: Request TVM formula guidance
(12-11-2014 10:02 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
...
// the derivative as best I know
...

Since there seems to be something wrong with your iterative calculation, here's a first suggestion on how to handle the TVM function, its derivative and the iterative approximation. You may want to try it and see what you get.

Here r is the (decimal) interest rate (e.g. 0.05 for 5%) and k is either 0 or 1, depending on END or BEGIN mode.

Since the equations will try to divide by zero if r=0, it might be a good idea to provide a first guess for r which equals the approximation that would follow an estimate of r=0. I used the following formula:

Code:
  r = 2 * (pv + n * pmt + fv)  /  ((fv * (2*k-1 + n) + pv * (2*k-1 - n)))

– If r = 0 we're already done: r=0 is the exact solution.
– If r > 0 we have a first approximation that will be improved during the following iteration loop.
– If r < 0 using half that (r := r/2) as the initial guess seems to work better, especially for large n.

Now the iteration may start. The TVM function and its derivate may be evaluated quite efficiently this way:

Code:
  q = 1 + r
  a = q ^ (-n)
  b = pmt / r * (1 - a)

  TVMfunction   =  pv + b * (1 + k * r) + fv * a
  TVMderivative =  n * a / q * (pmt * (1 / r + k) - fv) - b / r

Finally r is adjusted:

Code:
  correction = TVMfunction / TVMderivative
  r = r - correction

Repeat this until abs(correction) is sufficiently small, e.g. ≤ abs(1E-12 * r), or the max. number of iterations is ecceded (which means no convergence and should throw an error).

For your example case this yiels the following results:

Code:
 #  Approximation for r    TVM(r)   /    TVM'(r)    =   correction
-------------------------------------------------------------------
 0  0,09836 06557 37705    20,8922      -624,4903      -3,3455 E-2
 1  0,13181 54769 78560     4,3458      -381,4222      -1,1394 E-2
 2  0,14320 92370 54887     0,36344     -319,0893      -1,1390 E-3
 3  0,14434 82151 43331     0,003289    -313,3273      -1,0497 E-5
 4  0,14435 87123 97370     2,7676 E-7  -313,2746      -8,8343 E-10
 5  0,14435 87132 80800    -9,948 E-14  -313,2746       3,1754 E-16
 6  0,14435 87132 80799

BTW the TVM equation may be written in numerous different ways. Some can be evaluated more easily, some less so, some provide faster convergence, others converge slower. So the way the TVM equation is shown in the 12C manual may not be the final word. ;-)

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: 2 Guest(s)