TVM solve for interest rate, revisited
|
06-21-2024, 12:44 PM
(This post was last modified: 06-25-2024 06:40 PM by Albert Chan.)
Post: #49
|
|||
|
|||
RE: TVM solve for interest rate, revisited
Code: function npmt(n,i,pv,pmt,fv) return ((pv+fv)/EFF(i,n)+pv)*i + pmt end Due to decay shape d = i/EFF(i,n), if we have 2 edges, I think zero slope (if exist) is on the left of edges center. If my gut is correct, we may use center of 2 edges to reach big root. (*) Proof welcome! Disproof with counter example also nice. Center guess may overshoot to the right, but with non-zero slope, should not go crazy big. If overshooted, we would at worst wasted 2 iteration. (next of next back to edge) If not, we saved all iterations, from big edge to center of 2 edges. If there is only 1 valid edge, it is improved with I ≈ 1/P - P/N^2 formula, where 1/P = edge. Improved guess may not be in correct region for 1-sided convergence, but Newton would fix it. Both cases, first Newton iteration will not be used to test termination. 10 INPUT "B,N,P,M,F? ";B,N,P,M,F 15 IF B THEN P=P+M @ F=F-M ! end mode 20 DEF FNZ(I,A,C) @ C=A*C @ D=(P-F+A)/2+C @ FNZ=A+M+D*I @ D=D+C @ END DEF 30 DEF FNF(I) @ IF 1+N*I*I=1 THEN FNF=FNZ(I,(P+F)/N,(N*N-1)/12*I) @ END 40 S=EXPM1(LOGP1(I)*N) 50 D=(P+F)/S*(1-N*(S+1)/(S+S/I))+P @ FNF=((P+F)/S+P)*I+M @ END DEF 51 I=-1 @ IF F THEN I=M/F 52 J=-1 @ IF P THEN J=M/-P 54 IF I<=-1 THEN I=J-1/(J*N*N) @ GOTO 60 55 IF J<=-1 THEN I=I-1/(I*N*N) @ GOTO 60 57 I=(I+J)/2 ! 2 good edges 60 DISP 100*I,FNF(I) @ I=I-RES/D @ Y=FNF(I) 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 @ IF Y THEN I=I-Y/D/2 @ DISP 100*I Line 90 only correct i when FNF(i)≠0. This is not an optimization. I want D=0 to give divide-by-0 warning, but not when FNF(i)=0 already. >run B,N,P,M,F? 0,10,50,-30,80 Code: 11.25 -16.6938992149 Center guess is on the inside, Newton pushed it out. 2 iterations less with big edge guess, but won't know until tried it. Here is a case center guess help, by a lot. (no overshoot this time) >run B,N,P,M,F? 0,10,50,-12.8277219567,80 Code: 4.81039573375 .0048896134 Same problem, but with big edge guess. >i=m/-p @ run60 Code: 25.6554439134 3.7843086116 Example with only 1 valid edge. >run ! 5 B,N,P,M,F? 0,365*24*60,0,-0.01,5260.382426 Code: 3.17141393E-7 -1.14278E-9 Same problem, but with edge guess. >i=m/f @ run 60 Code: -1.90100247286E-4 .005827435363 (*) I was picturing f(x) = npmt(n,x,pv,pmt,fv) in my head With 2 valid edges, we can make g(x) = f(edge1 + edge2 - x) 2 curves would not overlap, because of decay factor. 1 curve will have zero slope (if exist) on the left, the other on the right. Center guess (where 2 curve intersect) would not hit with zero slope. plot {(130/((1+x)^10-1)+50)*x-30, (130/((1+(.6-.375-x))^10-1)+50)*(.6-.375-x)-30}, x = -.375 .. 0.6 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 8 Guest(s)