(71B) calculate interest rate
01-06-2020, 09:16 PM (This post was last modified: 01-09-2020 01:43 PM by Albert Chan.)
Post: #8
 Albert Chan Senior Member Posts: 1,914 Joined: Jul 2018
RE: (71B) calculate interest rate
Some improvements over my 3-points fit rate finder (post #6)
• FNF may be more accurate, using Fused Multiply Add.
FNF = FMA(EXPM1(N*LOGP1(I))/I, P*I+M, F+P)
• FNF(0) singularity removed, now FNF(0) = F+P + M*N
• We use harmonic mean of I1,I2 for X1.
• We use (0, FNF(0)) and (X1,Y1) to estimated X2.
But, point "0" might be too far, giving bad interpolated rate.
Instead of interpolation for Y=0 for X2, we cut the corrections in half (thus the factor 0.5)
Quote:10 INPUT "n, fv, pv, pmt ? ";N,F,P,M
20 DEF FNS(X1,Y1,X2,Y2)=X1-Y1*(X2-X1)/(Y2-Y1)
30 DEF FNF(I)
40 A=N @ IF I THEN A=EXPM1(N*LOGP1(I))/I
50 B=P*I+M @ A0=A*B
60 A1=A*1000001 @ A1=A+A1-A1 @ A=A-A1
70 B1=B*1000001 @ B1=B+B1-B1 @ B=B-B1
80 FNF=(F+P+A0)-(A0-A1*B1-A1*B-B1*A-A*B)
90 END DEF
100 X1=4*(F+P+M*N)/((N-1)*(F-M*N)-(3*N+1)*P)
110 Y1=FNF(X1) @ DISP X1,Y1 @ IF Y1=0 THEN END
120 X2=X1+.5*X1*Y1/(F+P+M*N-Y1)
130 Y2=FNF(X2) @ DISP X2,Y2 @ IF Y2=0 THEN END
140 X3=FNS(X1,Y1,X2,Y2)
150 Y3=FNF(X3) @ DISP X3,Y3 @ IF Y3=0 THEN END
160 E3=-Y3*FNS((X3-X2)/(Y3-Y2),Y2,(X3-X1)/(Y3-Y1),Y1)
170 X1=X2 @ Y1=Y2 @ X2=X3 @ Y2=Y3 @ X3=X3+E3
180 IF .00001*E3+X3-X3 THEN 150
190 DISP X3

>RUN
n, fv, pv, pmt ? 168, 10925.76, 0, -45
4.36103281596E-3 ﻿ ﻿ ﻿ ﻿ -190.348820115
4.24431571126E-3 ﻿ ﻿ ﻿ ﻿ -70.197349875
4.17612485668E-3 ﻿ ﻿ ﻿ ﻿ -.75216795
4.17538334438E-3 ﻿ ﻿ ﻿ ﻿ -.000041145
4.17538330381E-3
>RUN
n, fv, pv, pmt ? 600, 1e6, 0, -250
4.93576250272E-3 ﻿ ﻿ ﻿ ﻿ 78873.4148425
5.18818567872E-3 ﻿ ﻿ ﻿ ﻿ -26668.4502875
5.12440307537E-3 ﻿ ﻿ ﻿ ﻿ 1206.531985
5.12720670893E-3 ﻿ ﻿ ﻿ ﻿ -1.0521275
5.12720426781E-3 ﻿ ﻿ ﻿ ﻿ .0000175
5.12720426785E-3
>RUN
n, fv, pv, pmt ? 30,50000,1000,-1000
3.76850605653E-2 ﻿ ﻿ ﻿ ﻿ -930.964898075
3.68851990742E-2 ﻿ ﻿ ﻿ ﻿ -289.785021642
3.65236969622E-2 ﻿ ﻿ ﻿ ﻿ -3.12429013971
3.65197437154E-2 ﻿ ﻿ ﻿ ﻿ -1.49842044802E-4
3.65197435258E-2
 « Next Oldest | Next Newest »

 Messages In This Thread (71B) calculate interest rate - Albert Chan - 12-20-2019, 04:14 PM RE: (71B) calculate interest rate - Joe Horn - 12-20-2019, 08:36 PM RE: (71B) calculate interest rate - Albert Chan - 12-20-2019, 10:10 PM RE: (71B) calculate interest rate - J-F Garnier - 12-21-2019, 03:44 PM RE: (71B) calculate interest rate - Albert Chan - 12-22-2019, 03:07 PM RE: (71B) calculate interest rate - Albert Chan - 12-29-2019, 02:46 PM RE: (71B) calculate interest rate - Albert Chan - 01-02-2020, 05:43 PM RE: (71B) calculate interest rate - Albert Chan - 01-06-2020 09:16 PM RE: (71B) calculate interest rate - Albert Chan - 02-13-2020, 03:41 PM

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