(11C) Solve for [i] given [n] [PMT] [FV] - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (11C) Solve for [i] given [n] [PMT] [FV] (/thread-10491.html) |
(11C) Solve for [i] given [n] [PMT] [FV] - Gamo - 04-11-2018 08:04 AM 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:
Gamo RE: (11C) Solve for [i] given [n] [PMT] [FV] - rprosperi - 04-11-2018 12:58 PM (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. RE: (11C) Solve for [i] given [n] [PMT] [FV] - Dieter - 04-11-2018 06:54 PM (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 RE: (11C) Solve for [i] given [n] [PMT] [FV] - Gamo - 04-12-2018 01:43 PM 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 RE: (11C) Solve for [i] given [n] [PMT] [FV] - Gamo - 04-13-2018 04:56 AM 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:
RE: (11C) Solve for [i] given [n] [PMT] [FV] - Dieter - 04-14-2018 06:59 PM (04-13-2018 04:56 AM)Gamo Wrote: This update solve for [i] with either group of three known variables. 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 RE: (11C) Solve for [i] given [n] [PMT] [FV] - Dieter - 04-15-2018 05:49 PM (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 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 Now try it and see what you get. Dieter RE: (11C) Solve for [i] given [n] [PMT] [FV] - Gamo - 04-16-2018 01:41 PM 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] B > 1.94 (Answer [i]) Gamo RE: (11C) Solve for [i] given [n] [PMT] [FV] - Dieter - 04-16-2018 06:24 PM (04-16-2018 01:41 PM)Gamo Wrote: [n] [PV] [FV] solve for [i] 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 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 |