(11C) Solve for [i] given [n] [PMT] [FV]
04-11-2018, 08:04 AM (This post was last modified: 04-12-2018 01:35 PM by Gamo.)
Post: #1
 Gamo Senior Member Posts: 471 Joined: Dec 2016
(11C) Solve for [i] given [n] [PMT] [FV]
Financial program to solve for [i] the interest given Period [n], Payment [PMT] and Future Value [FV]

LBL A for [n]
LBL B for [i] (To solve for Interest)
LBL C for [PMT]
LBL E for [FV]
LBL D for Reset

This program didn't use Sign Convention when pay out show negative value.

Example:
Switch to USER mode: f USER
D > 0.00 (Reset)

180 > A > 180 (input period [n])
180 > C > 180 (input payment [PMT])
45000 > E > 45000 (input future value [FV])

B > 0.35 (answer for interest [i])

Remark: If try this example using Financial Calculator like HP-12C make sure the Payment [PMT] is negative --> -180

Program:
Code:
 *LBL A    // [n] STO 1 RTN *LBL C    // [PMT] STO 3 RTN *LBL E    // [FV] STO 5 RTN *LBL B    // [i] RCL 5 RCL 3 ÷ STO 6 RCL 1 - LSTx 1 - x² RCL 6 + ÷ 2 x 0 X=Y RTN CLx Rv STO 2 *LBL 1 RCL 2 1 + STO 6 RCL 1 Y^X STO 7 1 - RCL 2 ÷ RCL 3 x RCL 5 - RCL 1 RCL 2 x RCL 7 RCL 6 ÷ x 1 + RCL 7 - RCL 2 x² ÷ RCL 3 x ÷ FIX 9 STO - 2 PSE ABS EEX 6 CHS X≤Y GTO 1 RCL 2 FIX 2 EEX 2 x RTN *LBL D CLx STO 1 STO 2 STO 3 STO 5 STO 6 STO 7 RTN

Gamo
04-11-2018, 12:58 PM
Post: #2
 rprosperi Senior Member Posts: 3,361 Joined: Dec 2013
RE: (11C) Solve for [i] given [n] [PMT] [FV]
(04-11-2018 08:04 AM)Gamo Wrote:  This program didn't use Sign Convention when pay out show negative value.

Using negative for money paid out is nearly universal, so I would suggest changing to adopt that if you want other folks to understand and use the program intuitively.

--Bob Prosperi
04-11-2018, 06:54 PM
Post: #3
 Dieter Senior Member Posts: 2,398 Joined: Dec 2013
RE: (11C) Solve for [i] given [n] [PMT] [FV]
(04-11-2018 08:04 AM)Gamo Wrote:  Financial program to solve for [i] the interest given Period [n], Payment [PMT] and Future Value [FV]

OK, the program works. But...

- why do you use "0 X=Y?" instead of "X=0?" ?
- what is the PSE after this test for? It shows a brief "0,00" – and that's it.
- why do you use ENTER x instead of a simple x² ?

A PSE would make sense if it follows the STO–2 command. This way the user can see how (and if at all) the iteration converges as the displayed correction term gets smaller.

Style guide: it's a good idea to have the program end at a common end point. So the test if the initial guess for i is zero better should not simply stop there with a RTN, but instead jump to the end where the solution is returned.

Dieter
04-12-2018, 01:43 PM
Post: #4
 Gamo Senior Member Posts: 471 Joined: Dec 2016
RE: (11C) Solve for [i] given [n] [PMT] [FV]
Thank You Dieter

I have make some changed to the program from your suggestion.
This updated version now can view the iteration in fix 9 when done the final answer return to fix 2

Gamo
04-13-2018, 04:56 AM
Post: #5
 Gamo Senior Member Posts: 471 Joined: Dec 2016
RE: (11C) Solve for [i] given [n] [PMT] [FV]
This update solve for [i] with either group of three known variables.
[n] [PMT] [PV]
[n] [PMT] [FV]

LBL A [n]
LBL B Reset
LBL C [PMT]
LBL D [PV]
LBL E [FV]

Procedure: To solve [i]
input [n] [PMT] [PV] > GSB 1 (answer [i])
input [n] [PMT] [FV] > GSB 2 (answer [i])

Example:
36 > A > 36 ( input [n] )
360 > C > 360 ( input [PMT] )
360000 > E > 360000 ( input *[FV] )
*GSB > 2 > 14.94 ( Answer [i] )

36 > A > 36 ( input [n] )
360 > C > 360 ( input [PMT] )
1000 > D > 1000 ( input *[PV] )
*GSB > 1 > 36 ( Answer [i] )

Program:
Code:
 *LBL A    // [n]  STO 1  RTN  *LBL C    // [PMT]  STO 3  RTN *LBL D    // [PV] STO 4 RTN  *LBL E    // [FV]  STO 5  RTN *LBL 1 RCL 3 RCL 4 ÷ ENTER 1/x RCL 1 x² ÷ - STO 2 0 X=Y RTN CLx *LBL 3 RCL 2 1 + STO 6 RCL 1 Y^X STO 7 RCL 4 RCL 3 ÷ RCL 2 x 1 - x 1 + RCL 2 x LSTx RCL 1 x RCL 6 ÷ RCL 7 - 1 + ÷ FIX 9 STO+2 PSE ABS EEX CHS 6 X≤Y GTO 3 RCL 2 FIX 2 EEX 2 x RTN *LBL 2  RCL 5  RCL 3  ÷  STO 6  RCL 1  -  LSTx  1  -  x² RCL 6  +  ÷  2  x  0  X=Y  RTN  CLx  Rv  STO 2  *LBL 4  RCL 2  1  +  STO 6  RCL 1  Y^X  STO 7  1  -  RCL 2  ÷  RCL 3  x  RCL 5  -  RCL 1  RCL 2  x  RCL 7  RCL 6  ÷  x  1  +  RCL 7  -  RCL 2  x² ÷  RCL 3  x  ÷  FIX 9  STO - 2  PSE  ABS  EEX  6  CHS  X≤Y  GTO 4  RCL 2  FIX 2  EEX  2  x  RTN  *LBL B    //  Reset  CLx  REG  RTN
04-14-2018, 06:59 PM
Post: #6
 Dieter Senior Member Posts: 2,398 Joined: Dec 2013
RE: (11C) Solve for [i] given [n] [PMT] [FV]
(04-13-2018 04:56 AM)Gamo Wrote:  This update solve for [i] with either group of three known variables.
[n] [PMT] [PV]
[n] [PMT] [FV]
...
Procedure: To solve [i]
input [n] [PMT] [PV] > GSB 1 (answer [i])
input [n] [PMT] [FV] > GSB 2 (answer [i])

Sounds a bit complicated, doesn't it ?-)

Why don't you simply take the usual approach with one single TVM equation which includes both PV and FV so that the interest rate can be calculated the same way for either case. That's a proven method since the days of the HP65. ;-)

Dieter
04-15-2018, 05:49 PM
Post: #7
 Dieter Senior Member Posts: 2,398 Joined: Dec 2013
RE: (11C) Solve for [i] given [n] [PMT] [FV]
(04-14-2018 06:59 PM)Dieter Wrote:  Why don't you simply take the usual approach with one single TVM equation which includes both PV and FV so that the interest rate can be calculated the same way for either case.

I now have tried such a progam. Caveat: this is experimental code with some room for improvement. But it seems to work.

Code:
001  LBL A 002  STO 1 003  RTN 004  LBL C 005  STO 3 006  RTN 007  LBL D 008  STO 4 009  RTN 010  LBL E 011  STO 5 012  RTN 013  LBL B 014  RCL 4 015  RCL 5 016  + 017  RCL 1 018  RCL 3 019  x 020  + 021  RCL 1 022  1 023  - 024  RCL 5 025  x 026  RCL 1 027  1 028  + 029  RCL 4 030  x 031  - 032  / 033  2 034  x 035  STO 2 036  x=0? 037  GTO 2 038  LBL 1 039  RCL 4 040  RCL 5 041  + 042  RCL 2 043  1 044  + 045  STO 6 046  RCL 1 047  y^x 048  STO 7 049  1 050  - 051  / 052  RCL 4 053  + 054  RCL 4 055  RCL 5 056  + 057  RCL 1 058  x 059  RCL 2 060  x 061  RCL 7 062  x 063  RCL 6 064  / 065  RCL 7 066  1 067  - 068  x^2 069  / 070  - 071  X<>Y 072  RCL 2 073  x 074  RCL 3 075  + 076  X<>Y 077  / 078  STO-2 079  RCL 2 080  / 081  EEX 082  6 083  x 084  INT 085  x≠0? 086  GTO 1 087  LBL 2 088  RCL 2 089  EEX 090  2 091  x 092  RTN 093  LBL 0 094  CLX 095  STO 1 096  STO 2 097  STO 3 098  STO 4 099  STO 5 100  FIX 2 101  RTN

Feel free to insert a PSE after line 078 or 080.
You may also include a loop counter that cancels the iteration after, say, 12 loops.

- This program uses the well-known sign convention. So for your above examples enter PMT with negative sign.
- GSB 0 initializes the program and clears the relevant registers.
- [A] stores n
- [B] calculates i
- [C] stores PMT
- [D] stores PV
- [E] stores FV

Initialize with GSB 0 first.
Enter n, PMT, PV and FV with the respective keys in any order.
Press [B] to solve for i.

The initial guess for i is calculated this way:

Code:
           PV + n*PMT + FV i0 = 2 * ———————————————————          PV*(n+1) - FV*(n-1)

Now try it and see what you get.

Dieter
04-16-2018, 01:41 PM (This post was last modified: 04-16-2018 01:42 PM by Gamo.)
Post: #8
 Gamo Senior Member Posts: 471 Joined: Dec 2016
RE: (11C) Solve for [i] given [n] [PMT] [FV]
I did put the program to try on HP-11C and result is very good with the example from my previous post.

36 > A > 36 ( input [n] )
360 > C > -360 ( input [PMT] )
360000 > E > 360000 ( input *[FV] )
B > 14.94 ( Answer [i] )

36 > A > 36 ( input [n] )
360 > C > -360 ( input [PMT] )
1000 > D > 1000 ( input *[PV] )
B > 36 ( Answer [i] )

[n] [PV] [FV] solve for [i]
GSB > 0
36 > A [n]
-1 > D [PV]
2 > E [FV]

Gamo
04-16-2018, 06:24 PM (This post was last modified: 04-16-2018 06:58 PM by Dieter.)
Post: #9
 Dieter Senior Member Posts: 2,398 Joined: Dec 2013
RE: (11C) Solve for [i] given [n] [PMT] [FV]
(04-16-2018 01:41 PM)Gamo Wrote:  [n] [PV] [FV] solve for [i]
GSB > 0
36 > A [n]
-1 > D [PV]
2 > E [FV]

The program also seems to handle simple compound interest (PMT=0) quite well. But here a direct solution exists, and this should be returned by the program. Just change the lines after LBL B this way:

Code:
LBL B RCL 3 x≠0? GTO 3 RCL 5 RCL 4 / CHS RCL 1 1/x y^x 1 - STO 2 GTO 2 LBL 3 RCL 1 x RCL 4 + RCL 5 + ...continue with line 021 of the original version  i.e. RCL 1   1   -   etc.

So goto line 20 of the original program ("+"), delete all lines until you see LBL B and insert the lines above.

Another suggestion: when the program calculates (1+i) and (1+i)^n usually two or more digits are lost. Imagine i=1E–10 so that 1+i rounds to 1 which leads to the same result as if i was zero. That's why checking the relative error in line 78...80 does not always make sense, it can even cause problems as the program may not reach the desired relative accuracy (cf. example 2 in this post in the current TVM thread). So please replace the sequence STO–2 RCL 2 / with a simple STO–2, i.e. remove the two lines with the division by R2.

Here is an example for the mentioned problem which shows that it can occur even with completely "normal" data like i=12% and n=20. The exact result for (1+i)^n is 9,646293093. Buf if i is merely 1E–9 off, i.e. 1+i=1,120000001 instead of 1,12, the power is evaluated as 9,646293266 – only 7 out of 10 digits are exact.

Dieter
 « Next Oldest | Next Newest »

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