TVM solve for interest rate, revisited
|
06-18-2024, 11:11 AM
Post: #48
|
|||
|
|||
RE: TVM solve for interest rate, revisited
(06-15-2024 03:29 PM)Albert Chan Wrote: I recently translated find_rate() for HP71B (with test samples) Replaced with NPMT = (D-1)*(PV+FV) + PV*N*I + F0 --> FNF = NPMT/n, we have: 10 INPUT "B,N,P,M,F? ";B,N,P,M,F @ F0=(P+F+N*M)/N 12 IF B THEN P=P+M @ F=F-M ! end mode 14 IF ABS(P)>ABS(F) THEN X=F @ F=-P @ P=-X @ N=-N ! time reversed 20 DEF FNZ(I,A,B,C) @ D=(A+B)/2 @ B=A*C @ FNZ=F0+(D+B)*I @ D=D+2*B @ END DEF 30 DEF FNF(I) @ IF 1+N*I*I=1 THEN FNF=FNZ(I,(P+F)/N,P-F,(N*N-1)/12*I) @ END 40 S=EXPM1(LOGP1(I)*N) @ K=(P+F)/S @ D=K*(1-N*(S+1)/(S+S/I))+P 50 FNF=K*(I-S/N)+P*I+F0 @ END DEF 60 I=M/F @ Y=FNF(I) ! "smallest" edge guess 70 DISP 100*I,Y @ H=-Y/D @ I=I+H @ Y0=Y @ Y=FNF(I) 80 IF SGN(Y0)=SGN(Y) AND ABS(Y0)>ABS(Y) THEN 70 90 DISP 100*I,Y @ J=I-Y/D/2 @ DISP 100*J ! half-correction Running test samples shown similar result, except for Problem 5 Code: B,N,P,M,F? 0,365*24*60,0,-0.01,5260.382426 It is interesting we have a one solution case, but FNF have no sign changes. Final FNF value get worse, on the same side of root! I expect this behavior from a 2 solutions to 0 solution borderline case, but not here! The problem here is F0 is tiny (if true rate is 0, so does F0), much smaller than M Without needed cancellation, FNF is less stable. Sometimes, cancellation is good! If we do an extra iteration, indeed we have sign changes, i.e. guaranteed solution. >FNF(J) -1.546E-14 >(J-RES/D/2) * 100 ! half-correction 3.17097920515E-7 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)