Post Reply 
PC-1211, PC-1250, etc. TVM
06-07-2024, 01:45 AM (This post was last modified: 06-18-2024 09:52 AM by Albert Chan.)
Post: #28
RE: PC-1211, PC-1250, etc. TVM
(06-06-2024 11:34 PM)dm319 Wrote:  
(06-06-2024 12:27 AM)Albert Chan Wrote:  And, many thanks to your examples.
I actually discovered a Plus42 bug, for rate very close to 0%.

Me too! (not that surprising). Is this re: example 5 above? My code gets stuck with f and f0 dancing around zero.

Yes, code had issue with example 5 (close to 0% bug).
Plus42 should have this fixed soon. (issue sent)

Plus42 previous version, secant's method did hang for some cases.
Now, with true Newton's method and edge guess, this issue goes away.

Here is closer to Plus42 do_i_pct_yr(), termination criteria based from Y, not I
It does not relied on quadratic convergence, but finite ULP's: ULP(FNF) ≥ ULP(M)
Rate search will not get stuck, even if no solution exist.

10 INPUT "B,N,P,M,F? ";B,N,P,M,F
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=A+M+(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) @ D=(P+F)/S*(1-N*(S+1)/(S+S/I))+P
50 FNF=((P+F)/S+P)*I+M @ 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

Code:
>run ! 1
B,N,P,M,F? 1,40,900,-40,-1000
 4.16666666667       -5.1783387869
 4.7524512828        -.0080716937
 4.75336718645       -.0000000187
 4.75336718857        0
 4.75336718857
>run ! 2
B,N,P,M,F? 1,40,900,-400,-1000
 66.6666666667       -66.666666756
 79.9999999644       -.000000183
 80.000000001         0
 80.000000001
>run ! 3
B,N,P,M,F? 0,365*24*60*60,0,-0.01,331667.0067
-3.01507228575E-6     6.2977646195E-3
-1.1099216589E-7      7.022277322E-4
 3.07577857249E-7     1.52692719E-5
 3.17093002025E-7     7.8839E-9
 3.17097920006E-7     0
 3.17097920006E-7
>res * n
 10.0000000053 
>run ! 4
B,N,P,M,F? 0,365*24*60,0,-0.01,5527.7829015
-1.80904354932E-4     6.2977549796E-3
-6.659604136E-6       7.022284099E-4
 1.84546671641E-5     1.52693549E-5
 1.90255801068E-5     7.8841E-9
 1.90258751938E-5    -6.E-14
 1.90258751927E-5
>res * n
 10.0000000013
>run ! 5
B,N,P,M,F? 0,365*24*60,0,-0.01,5260.382426
-1.90100247286E-4     .005827435363
-2.2550930229E-5      6.131837704E-4
-1.232943057E-7       1.15811690742E-5
 3.16928059687E-7     4.4652E-9
 3.17097921452E-7    -8.E-14
 3.1709791993E-7
>res * 60*n
 10.0000000029
>run ! 6
B,N,P,M,F? 0,32,-999999,0,1000000
 0                    .03125
 3.12500161133E-6     0
 3.12500161133E-6
>run ! 7
B,N,P,M,F? 0,360,0,-1000,1000000
-.1                   2306.3389698
 .313028391463        504.47068744
 .471270710313        62.96905732
 .497374290776        1.51994784
 .49803616688         .0009567
 .498036584009        0
 .498036584009

Update:
1. Small rate branch test (1+I=1) --> (1+N*I*I=1)
    Small rate branch does quadratic fit, not suitable for huge compounding effect.
2. time-symmetry to keep size of P small, possibly less cancellation error.
    With this change, "smallest" edge rate is simply M/F
3. Final Newton correction cut in half, to reduce error radius.
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 - Albert Chan - 06-07-2024 01:45 AM
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: 20 Guest(s)