Post Reply 
(32S) Accurate TVM with direct solutions
12-31-2015, 12:23 PM (This post was last modified: 12-31-2015 01:59 PM by Dieter.)
Post: #7
RE: (32S) Accurate TVM with direct solutions
(12-30-2015 03:05 PM)Jeff_Kearns Wrote:  While I applaud Dave for including his 'direct solutions' program, I have to disagree with a number of statements you each made. First of all, the accuracy of the 38-line, single-label SOLVER program is on par with that of any financial calculator. It includes both functions (e^(x–1) and ln(1+x)) to which you refer.

Jeff, I see there is code for a ln(1+x) function (line T008 ff.), but I cannot find something similar for an e^x–1 function (NB: not e^(x-1), as you posted). Line T026 ff. simply takes the e^x result and subtracts 1 from it. ;-)

That's why the solver program will produce errors for very small interest rates. For instance consider this example:

N = 10
I  = 1E–5 %
B = 0
P = 1
E = 0
F = ?

Since the interest rate is nearly zero, solving for F correctly returns F=–10,0000045 (i.e. ten times the 1,- payment plus with virtually nothing on top because of a near-zero interest rate). Fine.

Now replace "I" with 1E–15% and see what you get... The solver will return F=0, which is obviously wrong. This happens because in step T026 the e^x command returns 1 and the following subtraction of 1 yields exactly zero. This is exactly what a dedicated e^x–1 command avoids.

"But that's not a real world problem, nobody deals with interest rates that low". Well, the solver program is not able to handle zero interest rates (this causes a division by zero), so using a near-zero interest rate like 1E–20 or 1E–50 is required to handle this case. And here is where the current solver code fails.

(12-30-2015 03:05 PM)Jeff_Kearns Wrote:  I think you should type in the 38-line program and test it. You will see that it meets all your TVM needs, especially speed and accuracy ;-).

Well... not quite. ;-)

Addendum:
Here is a version that includes both ln(1+x) – using a different method that IHMO performs even better than the original one – as well as an e^x–1 implementation and some slight general improvements.

Code:
T001 LBL T
T002 INPUT N
T003 INPUT I
T004 INPUT B
T005 INPUT P
T006 INPUT F
T007 INPUT E
T008 1
T009 RCL I
T010 %
T011 +
T012 ENTER
T013 ENTER
T014 LASTx
T015 x<>y
T016 1
T017 -
T018 -
T019 x<>y
T020 ÷
T021 LASTx
T022 LN
T023 +
T024 RCLx N
T025 ENTER
T026 e^x
T027 RCLx B
T028 x<>y
T029 2
T030 ÷
T031 e^x
T032 LASTx
T033 SINH
T034 x
T035 ENTER
T036 +
T037 RCLx P
T038 100
T039 RCL÷ I
T040 RCL+ E
T041 x
T042 +
T043 RCL+ F
T044 RTN

This code implements this method for ln(1+x) and that one for e^x–1.

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


Messages In This Thread
HP 35s - TVM from Gene Wright - PedroLeiva - 12-03-2015, 12:39 PM
RE: (32S) Accurate TVM with direct solutions - Dieter - 12-31-2015 12:23 PM



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