Post Reply 
TVM solve for interest rate, revisited
06-22-2024, 11:46 AM
Post: #51
RE: TVM solve for interest rate, revisited
(06-15-2024 03:29 PM)Albert Chan Wrote:  I am updating old with new, in iter_i(), post #31

OLD: s=i/EFF(i,n); k=(pv+fv)*s; fp = -k*((n*s-1)+(n-1)*i)/(i+i*i) + pv; f = k + pv*i + pmt
NEW: s=EFF(i,n)  ; k=(pv+fv)/s; fp =  k*(1-n*(s+1)/(s+s/i)) + pv;         f = (k+pv)*i + pmt

I tested both versions with car lease example, n,pv,pmt,fv = 36,30000,-550,-15000
Using Plus42 reference, solved i = 0.00580507281942013213837742298371094

With default setup (i=nil), old way error = 1 ULP, new = -2 ULP
Note: error = exact - approx --> positive ULP means under-estimated.

This is 1 example, 1 guess, and little differences. We can't tell which is better.

I then compare example against million random guesses = random() - 0.5 (same sets)
Also, tested whether Newton final correction make sense (default was half-correction)

Newton     none               half             full
ULP     old     new       old     new       old     new

-9      0       0         0       0         0       0
-8      0       0         0       0         0       0
-7      0       0         0       0         0       0
-6      0       0         0       0         0       0
-5      25645   31924     25645   31924     25645   31924
-4      56093   55614     56093   55614     165769  55614
-3      87030   86220     87030   86220     166564  168111
-2      119581  111874    119581  111874    164470  164696
-1      146559  142173    256235  142173    169406  169815
0       159774  155031    238969  235542    168496  166121
1       136685  132674    181565  185453    139650  136125
2       109676  107594    23186   136616    0       107594
3       79195   80511     8731    11133     0       0
4       44880   52779     2965    3451      0       0
5       22847   27642     0       0         0       0
6       8722    11090     0       0         0       0
7       2965    3451      0       0         0       0
8       339     1380      0       0         0       0
9       9       43        0       0         0       0 

Final Newton correction produce better rate, with error within ±5 ULP
Half correction produce better looking bell-shaped curve, centerd at 0 ULP
Full correction looks good too, but distribution flattened, skewed to one side.

Same problem can be solved in time-reversed way:

Newton     none               half             full
ULP     old     new       old     new       old     new

-9      0       0         0       0         0       0
-8      0       0         0       0         0       0
-7      0       0         0       0         0       0
-6      0       0         0       0         23745   27474
-5      899     0         0       0         0       0
-4      54374   60232     54374   60232     54374   60232
-3      87113   89638     87113   89638     164745  165200
-2      117888  112837    118787  112837    166925  168921
-1      144228  139168    167973  166642    144228  139168
0       157697  159256    235329  234442    166737  168343
1       164800  162206    213815  218283    167998  164772
2       110643  105890    110643  106266    111248  105890
3       77632   75186     9062    9094      0       0
4       49015   56077     2299    2566      0       0
5       23745   27474     605     0         0       0
6       9040    9087      0       0         0       0
7       2299    2566      0       0         0       0
8       605     376       0       0         0       0
9       22      7         0       0         0       0

No correction, time-reversed setup looks just as bad.
Half-correction, time-reversed or not, looks about the same.
Full correction still skewed, but now with a weird overshoot (error = -6 ULP).

Old and new way seems to be similarly accurate.
Time-reversed to limit size of pv, and final half-correction seems best == tvm() default Smile
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: TVM solve for interest rate, revisited - Albert Chan - 06-22-2024 11:46 AM



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