(15C) Yet Another Time Value of Money Program
08-14-2023, 03:05 AM (This post was last modified: 08-14-2023 05:29 PM by HobbitJack.)
Post: #1
 HobbitJack Junior Member Posts: 2 Joined: Nov 2021
(15C) Yet Another Time Value of Money Program
Note for Moderators: I may have accidentally posted this thread twice due to a misclick on my part. This is the correct version.

This is yet another program for the purpose of solving TVM (Time Value of Money) problems on the HP-15C. I believe this program fills a middle ground between other TVM programs, in terms of size and functionality. Whereas other programs are either large and involve many, many labels, or are fairly small and are unable to solve full TVM problems for each variable without significant manipulation, this program is able to solve the TVM equation (specifically, the equation given in the HP-15CE edition of the Advanced Functions Handbook) for any of the five variables -- that is, N (the number of payment and compounding periods), %i (the interest rate per payment/compounding period, in percent), PV (the present value, that is, the amount gained or lost at the start of the first payment/compounding period), PMT (the constant payment made in or out each payment/compounding period), or FV (the future value of the loan or investment, when the final period/payment is made).

This program's benefits over existing solutions can be summed up as follows:
- Fairly Small: This program requires only 43 program steps and 52/53 bytes (8 registers + 3/44 bytes; depends on number of label used) of program memory to remain stored. The user can also strip out program steps 019-030 (inclusive) to save extra memory, if the End/Begin behavior option is not viewed as needed or memory is at a premium.
- Uses Few Resources: This program only uses one label when not in use, and only requires one more when actively being used, and only uses the 5 registers (R0-R4) used to store the TVM variables, and only uses one Flag variable (Flag 7) in read only to read End/Begin behavior
- Versatile: This program is able to solve for all 5 TVM variables through the same loader program structure. It also can use Flag variable 7 to set End/Begin behavior.

This program has a number of minor drawbacks compared to other similar programs. These are as follows:
- Requires a Loader Program: A loader program, of 4 instructions and 4-6 bytes (depending on label used to store the loader program and main program) is required to be used to solve for any variable. This loader program will be given below but is simple enough and can be intuitively remembered without memorization given a familiarity with the functionality of the program and the solver.
- Less Intuitive Operation: This program requires the memorization of which registers refer to which TVM variables, and is also less intuitive in that solving for a variable requires changing the STO instruction in the loader program, rather than merely changing which button is pressed. These are in the same order as the buttons are on the HP-12C, so it is hoped that users with familiarity with that system will have less difficulty migrating to this program.

USAGE: Key Number of Payment Periods into R0, Percent Interest Rate per Payment Period into R1, Present Value into R2, Per-Period Payment into R3, and Future Value into R4. Store 0 for the unknown. Create a program with a label, a sto instruction into the register for the unknown variable, a gsb instruction to the label of the program in memory, and a rtn instruction. key in initial guess (not always necessary), clear Flag 7 for End and set Flag 7 for Begin, and use SOLVE on your loader program.

Note that the label used for the GSB instruction in the loader program should match the label used for the main program, and that the register for the STO instruction should match the register for the variable for which you wish to solve.

MAIN PROGRAM:
Code:
 52/53 BYTE 7 REG + 3/4 001   lbl [#]       42, 21, [#] 002   rcl 1         45, 1 003   2             2 004   10^           13 005   /             10 006   1             1 007   +             40 008   rcl 0         45, 0 009   CHS           16 010   ^             14 011   CHS           16 012   1             1 013   +             40 014   2             2 015   10^           13 016   *             20 017   rcl / 1       45, 10, 1 018   rcl * 3       45, 20, 3 019   1             1 020   f? 7          43, 6, 7 021   rcl 1         45 1 022   f? 7          43, 6, 7 023   2             2 024   f? 7          43, 6, 7 025   10^           13 026   f? 7          43, 6, 7 027   /             10 028   f? 7          43, 6, 7 029   +             40 030   *             20 031   rcl + 2       45, 40, 2 032   rcl 1         45, 1 033   2             2 034   10^           13 035   /             10 036   1             1 037   +             40 038   rcl 0         45, 0 039   CHS           16 040   ^             14 041   rcl * 4       45, 20, 4 042   +             40 043   rtn           43, 32

 001   lbl [#]       42, 21, [#] 002   sto [#]       44, [#] 003   gsb [#]       31, [#] 004   rtn           43, 32