## 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)