Post Reply 
PC-1211, PC-1250, etc. TVM
06-05-2024, 07:16 PM (This post was last modified: 06-08-2024 09:05 PM by robve.)
Post: #22
RE: PC-1211, PC-1250, etc. TVM
(06-05-2024 12:34 PM)Albert Chan Wrote:  Since Sharp does not have EXPM1, LOGP1, lets try without them.

Thanks, this is more clear.

EXPM1 LNP1 are easy to implement to compute TVM more accurately using a few terms of their series when applicable (up to 4th term of the series with 10 digits precision since 1+0.01^4/4 is close to 1 no need to use 5th term):

' compute L=LN(1+J) and S=(1+J)^-N and R=S-1
40 J=.01*I,K=1+J*B,C=0 : IF ABS J>=.01 LET L=LN(1+J) : GOTO 42
41 L=J*J,L=J-L/2+J*L/3-L*L/4
42 S=-N*L : IF ABS S>=.01 LET S=EXP S,R=S-1 : RETURN
43 R=S*S,R=S+R/2-S*R/6+R*R/24,S=R+1 : RETURN


With this, the secant method works quite well and is quick, small and simple. We just need to replace LN(1+J) with L and use the improved S and R:

Code:
10 "B" B=B=0 : PRINT "BGN=";MID$("NY",B+1,1) : END
11 "C" C=C=0 : BEEP C : END
12 "N" AREAD N : IF C GOSUB 40 : N=LN((M*K/J-F)/(M*K/J+P))/L
13 PRINT "N=";N : END
14 "J" AREAD I : IF C GOSUB 30
15 PRINT "I%=";I : END
16 "V" AREAD P : IF C GOSUB 40 : P=K*M*R/J-F*S
17 PRINT "PV=";P : END
18 "M" AREAD M : IF C GOSUB 40 : M=(F*S+P)*J/K/R
19 PRINT "PMT=";M : END
20 "F" AREAD F : IF C GOSUB 40 : F=(K*M*R/J-P)/S
21 PRINT "FV=";F : END
' solve Y=NPMT=0 for rate I with the secant method
30 G=9,I=1 : GOSUB 38
31 V=I,I=I/2 : GOSUB 38
32 IF ABS(Y-W)<I GOTO 31
33 T=I,I=I-(I-V)*Y/(Y-W),V=T : GOSUB 38
34 IF SGN Y=SGN W IF ABS Y<ABS W GOTO 33
35 IF Y<>0 IF W<>0 IF Y<>W IF G LET G=G-1 : GOTO 33
' pick weighted average (interpolation):
36 IF SGN Y<>SGN W LET I=(I*ABS W+V*ABS Y)/(ABS Y+ABS W)
37 RETURN
38 W=Y : GOSUB 40 : Y=K*M-(P+F*S)*J/R : RETURN
' compute L=LN(1+J) and S=(1+J)^-N and R=S-1
40 J=.01*I,K=1+J*B,C=0 : IF ABS J>=.01 LET L=LN(1+J) : GOTO 42
41 L=J*J,L=J-L/2+J*L/3-L*L/4
42 S=-N*L : IF ABS S>=.01 LET S=EXP S,R=S-1 : RETURN
43 R=S*S,R=S+R/2-S*R/6+R*R/24,S=R+1 : RETURN

Line 32 is added to avoid the initial secant slope to be zero in extreme cases when the rate is very small, such as in examples 3,4,5 below.

The program always terminates with a result or gives an error (not likely, but could be in extreme and unrealistic TVM cases). When G counts down to zero from 9, the result is likely not correct because a root wasn't reliably found (not likely, but can happen in extreme TVM problems).

1) B=1,N=40,PV=900,FV=-1000,PMT=-40
comp I% => 4.753367189% is exact

2) B=1,N=40,PV=900,FV=-1000,PMT=-400
comp I% => 80% is exact in 10 digits, but 80.0000000009845%
comp FV => -1462.657745 (should be -1000, but TI BA gives -900(*) and Sharp EL-735 gives -975.11 and HP prime gives -1001.6 so it's tricky to compute FV accurately)

3) from http://www.voidware.com/tvm.htm
B=0,N=365*24*60*60,PV=0,PMT=-0.01,I%=10/N,
comp FV => 331667.0067 is exact
comp I% => 3.170979194E-07 is almost exact 3.170979198E-07 except for the last digit is 4 instead of 8

4) same as 3 but take N=365*24*60 and I%=10/N:
comp FV => 5527.782898 is exact
comp I% => 1.902587519E-05 is exact

5) same as 3 but take N=365*24*60 and I%=10/60/N:
comp FV => 5260.377543 is exact
comp I% => 3.170979051E-07 is very close to exact 3.170979198E-07

6) from http://www.voidware.com/tvm.htm (the hard example 2)
B=0,N=32,PV=-999999,FV=1000000,PMT=0
comp I% => 3.125027014E-06 is very close to exact 3.125E-06

7) B=0,N=360,PV=0,PMT=-1000,FV=1000000
comp I% => 4.980365842E-01 is exact (note that this is 5.976% APR)

EDIT: as a sanity check, I verified this program with 27 TVM problems with solutions posted by a university finance department's lectures.

To use this program on a Sharp pocket computer:
- Switch begin mode on/off: DEF-B
- Enter values: DEF-N or DEF-J (I%) or DEF-V (PV) or DEF-M (PMT) or DEF-F (FV)
- Calculate: press DEF-C (beep) then DEF-N or DEF-J or DEF-V or DEF-M or DEF-F

EDIT 2: once the N, PV, PMT, FV and I% are entered or computed and BGN is on/off, you can obtain amortization by adding five lines to the program:

Code:
50 "A" AREAD A : J=.01*I,R=P-F,T=0,V=0
51 FOR K=1 TO N : S=R*J,Q=-M-S,R=R-Q
52 IF K>=A LET T=T+S,V=V+Q : PRINT STR$ K;" ";INT(100*S+.5)/100;"int ";INT(100*Q+.5)/100;"prn"
53 NEXT K
54 END

Enter a period value then press DEF-A. When the interest paid and principle paid values are shown, press ENTER again to show the next period and so on.

The values T, V and R are the accumulated interest, accumulated principal and remaining balance. It should be easy to amend the program for direct P1/P2 and ACC computations if so desired.

EDIT 3: updated line 30 with I=1 to improve interest rate computation accuracy

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
PC-1211, PC-1250, etc. TVM - Dave Britten - 03-30-2021, 04:58 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 03-30-2021, 05:07 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 04-01-2021, 05:50 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 05-29-2024, 09:17 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 05-31-2024, 01:11 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-01-2024, 01:07 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-02-2024, 09:46 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-03-2024, 06:44 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-04-2024, 12:26 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-04-2024, 11:35 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-05-2024 07:16 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-05-2024, 10:06 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-06-2024, 11:02 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-08-2024, 06:19 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-08-2024, 09:21 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-09-2024, 12:06 AM
RE: PC-1211, PC-1250, etc. TVM - rprosperi - 06-09-2024, 01:22 PM
RE: PC-1211, PC-1250, etc. TVM - nickapos - 06-12-2024, 05:20 AM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-06-2024, 11:34 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-07-2024, 02:30 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-08-2024, 08:38 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-09-2024, 10:12 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-11-2024, 07:13 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-11-2024, 10:32 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-12-2024, 12:29 AM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-12-2024, 12:45 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-12-2024, 04:58 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-22-2024, 12:12 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-22-2024, 08:39 PM



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