Post Reply 
TVM solve for interest rate, revisited
11-10-2024, 10:42 PM (This post was last modified: 11-14-2024 10:44 PM by Albert Chan.)
Post: #61
RE: TVM solve for interest rate, revisited
(11-06-2024 12:20 AM)Albert Chan Wrote:  f = c0 + sum((c1+k*x)/(r+1)^(x+1), x=0 .. n-1)
...
f = (K*(c0 r² + c1 r + k) - ((c1+k*n) r + k)) / (K r²)

From Ángel Martin's thread for IRR rate calculation, where c1 increase by step k each period.
If we add the fv term, above IRR calculations can solve TVM problem! (just set step k = 0)

Let's change variables name to match TVM: pv=c0, c1=pmt, step s=k, and add fv to the mix.
Code:
PV                      PMT           FV                        SCALE

pv*r^2 + (pmt*r+s)      0           fv*r² - s*n*r - (pmt*r+s)   1/r²                
pv*r^2               (pmt*r+s)*r    fv*r² - s*n*r               1/r²
pv                   (pmt+s/r)      fv - s*n/r                  1

K*PV + FV = 0      ; row 1
K = -FV/PV = -(fv*r² - s*n*r - (pmt*r+s)) / (pv*r^2 + (pmt*r + s))

If s = 0, formula reduced to plain TVM, we have:

K = (pmt - fv*r) / (pmt + pv*r) > 0

This explained why edge rate are [pmt/fv, pmt/-pv].
They are simply the roots for top and bottom!

Same idea for s≠0, only the edges may now have 2 roots, not 1

Just like we solve for plain TVM, we solve npmt=0, for rate
Just like we solve for plain TVM, we fit npmt (tiny rate) with a quadratic.

Code:
function npmt_step(n,s,pv,pmt,fv)
    return function(r)
        if abs(r) > 1e-6 then return npmt(n, r, pv, pmt+s/r, fv-n*s/r) end
        return pmt  - s * (1-n)/2   * (1 - (1+n)/6*r * (1 - r/2)) +
               (fv * (1 + (1-n)/2*r * (1 - (1+n)/6*r)) +
                pv * (1 + (1+n)/2*r * (1 - (1-n)/6*r))) / n
    end
end

lua> f = npmt_step(5, 5, -25, 10, 0) -- quoted IRR example
lua> S.newton(f, 0.7, nil, nil, true)
0.7                                     0
0.5670681661803514          2
0.5672303344166845          4
0.5672303344358538          6

lua> f = npmt_step(36, 0, 30000, -550, -15000) -- car lease example
lua> S.newton(f, 0, nil, nil, true)
0                                        0
0.0058695853637202935     2
0.005805080703249694       4
0.0058050728194123016     6
0.005805072819420133       7
lua> _ * 1200 -- APR %
6.96608738330416

Update: npmt_step() with an extra term for pv,fv, emphasized symmetry.

Cas> K := exp(log1p(r)*n);   /* = (1+r)^n */
Cas> C := n*r / (1-1/K);       /* compounding factor */
Cas> series(C, r)

\(1+\frac{(1+n)}{2} \cdot r+\frac{(-1+n^{2})}{12} \cdot r^{2}+\frac{(1-n^{2})}{24} \cdot r^{3}+\frac{(-19+20\cdot n^{2}-n^{4})}{720} \cdot r^{4}+\frac{(9-10\cdot n^{2}+n^{4})}{480} \cdot r^{5}+r^{6} \mathrm{order\_size}\left(r\right)\)

Code:
function npmt_step(n,s,pv,pmt,fv)
    return function(r)
        if abs(r) > 1e-6 then return npmt(n, r, pv, pmt+s/r, fv-n*s/r) end
        return ((pv + fv + n*pmt) +
              (  pv*r    * (1+n)/2 * (1 - (1-n)/6*r * (1 - r/2))) +
              ((fv*r-n*s)* (1-n)/2 * (1 - (1+n)/6*r * (1 - r/2)))) / n
    end
end

(small rate first term)*n = pv + fv + n*pmt = pv + (fv-n*s/r) + n*(pmt+s/r)
Find all posts by this user
Quote this message in a reply
11-10-2024, 10:44 PM (This post was last modified: 11-11-2024 11:40 AM by Albert Chan.)
Post: #62
RE: TVM solve for interest rate, revisited
Previous post TVM with steps option, for HP71B (updated npmt_step())

Code:
10 DESTROY ALL @ INPUT "N,S,P,M,F= ";N,S,P,M,F
20 DEF FNM(N,I,P,M,F)=((P+F)/EXPM1(LOGP1(I)*N)+P)*I+M
30 DEF FNP(N,I)=(1+N)/2*(1-(1-N)*I*(2-I)/12)
40 DEF FNF(I) @ DISP I @ IF ABS(I)>.0001 THEN FNF=FNM(N,I,P,M+S/I,F-N*S/I) @ END
50 FNF=(P+F+N*M+P*I*FNP(N,I)+(F*I-N*S)*FNP(-N,I))/N @ END DEF
60 DEF FNI(A,B)=FNROOT(A,B,FNF(FVAR))
70 INPUT "GUESS I= ";I @ DISP FNI(I-.001,I+.001)

>run
N,S,P,M,F= 5,5,-25,10,0
GUESS I= 0.7
.699
.701
.567068171084
.633034085542
.567230379538
.567230334434
.567230334434

>run
N,S,P,M,F= 36,0,30000,-550,-15000
GUESS I= 0
-.001
.001
5.86958536385E-3
5.80447251183E-3
5.80507274543E-3
5.83732905464E-3
5.80507281939E-3
5.82120093702E-3
5.80507281943E-3
5.80507281943E-3
>res * 1200 ! APR %
6.96608738332
Find all posts by this user
Quote this message in a reply
Post Reply 




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