[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Everything about COBOL
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
  Sorting in REXX: The Bubble Sort
  REXX Password Generator
  Using REXX to capture displayed output of TSO command
  Count records in REXX
  REXX program to calculate present value of money
  REXX function to format a number in currency format
  REXX function to produce a fixed-length number
  REXX program to produce lottery numbers
  REXX: what does your phone number spell?
  REXX Practice Problems.
  Just Enough REXX Tutorial
  Setting up to Execute REXX Programs on TSO/ISPF
  How to execute a REXX program
  REXX Boolean operators
  Comparison of CLIST language and REXX
  REXX Comparison operators
  REXX Debugging: the TRACE verb
  Using REXX OUTTRAP
  Reserved REXX Variables
  Executing REXX through JCL.
  Writing ISPF Edit Macros in REXX
  REXX program to unload a PDS
  REXX book: The REXX Language on TSO
  REXX Functions Book
  QMF Procedures Written in REXX
  Using REXX Subroutines with the QMF Calc panel
  REXX error codes (RC)
  REXX programming language manuals
  Books on REXX programming
  The REXX Files
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > REXX   > REXX Net Present Value

Calulate net present value of a future amount

What is the current value of a future amount of money?
Illustrates terminal dialogue and DATATYPE
/*REXX DISCOUNT
  calculates present value of money
   How much do I have to invest now, to get $?? at a later date
  please name it:
    on TSO: member name DISCOUNT
    on CMS: file name   DISCOUNT EXEC A1
    on DOS, with personal REXX: DISCOUNT.REX
    on OS/2, DISCOUNT.CMD
  discount amount  calculator

  present value = fv * (1 + ic) ** (-n)
  note x ** (-n) = 1 /(x**n)
  ic = rate of interest (expressed as decimal fraction
       per compounding period)
  n  = number of interest periods
       compounding_frequency * how_many_years
  fv = future value, how much you want at later date

 TSO: to execute from TSO line mode or ready mode:
    %DISCOUNT

    TSO: if you can't execute by previous method:
    EXEC 'userid.REXX.EXEC(DISCOUNT)'

  
  for REXX information, books see
   http://theamericanprogrammer.com

  
*/
reply_from_terminal = "YES"
do while reply_from_terminal = "YES"

  /* get from terminal*/
  call clearit
  say "How much do I have to invest now, to get $?? at a later date"
  say
  say "$?? must be invested now for w years at annual interest rate of x%"
  say "compounded y times per year in order to have $z"
  say
  say "Please enter the amount you wish to have"
  pull fv
  say "please enter yearly percent of interest (e.g. 7 for 7%)"
  pull yearly_percent_of_interest
  say "Please enter number of years money is kept in account"
  pull how_many_years
  say "How many times is interest compounded per year?"
  say "for example, if yearly, enter 1"
  say "               monthly, enter 12"
  say "               weekly,  enter 52"
  say "               daily,   enter 365"
  pull compounding_frequency

  /* verify */
  if fv = "" then leave
  if yearly_percent_of_interest = "" then iterate
  if compounding_frequency = "" then iterate
  if number_of_years = "" then iterate
  if datatype(fv) <> "NUM" then iterate
  if datatype(yearly_percent_of_interest) <> "NUM" then iterate
  if datatype(compounding_frequency) <> "NUM" then iterate
  if datatype(how_many_years) <> "NUM" then iterate

  /* compute*/
  yearly_rate_of_interest = yearly_percent_of_interest / 100
  ic = yearly_rate_of_interest / compounding_frequency
  n  = how_many_years * compounding_frequency
  /* compute with intermediate results */
  i1 = 1 + ic
  i2 = i1 ** n
  i3 = 1 / i2
  pv = fv * i3

  /* display */
  say "$"pv "must be invested now for " how_many_years " years",
      "at annual interest rate of " yearly_percent_of_interest"%"
  say "compounded " compounding_frequency " times per year ",
      "in order to have  $"fv
  say
  say "Do you want to do another? YES/NO"
  pull reply_from_terminal
end /* do until */


exit
clearit:
Parse source op_system .
Select
  when op_system = "TSO" then "CLRSCRN"
  when op_system = "CMS" then "VMFCLEAR"
  when op_system = "DOS" then call scrclear /*Personal Rexx */
  when op_system = "OS/2" then "CLS"
otherwise nop
end
return

Learn how to use all the features of REXX: REXX Programming Book for TSO (published 2012)

[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |