home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best Objectech Shareware Selections
/
UNTITLED.iso
/
boss
/
data
/
dbas
/
004
/
finance.prg
< prev
next >
Wrap
Text File
|
1992-07-01
|
22KB
|
504 lines
*-------------------------------------------------------------------------------
*-- Program...: FINANCE.PRG
*-- Programmer: Ken Mayer (KENMAYER)
*-- Date......: 06/25/1992
*-- Notes.....: These finance functions are for use with interest rates and
*-- such. See the file README.TXT for details about the use of this
*-- library file.
*--
*-- NOTES ABOUT THESE ROUTINES
*-- The functions that use (1+nRate)^nPeriods require that the
*-- rate be stated in the same terms as the compounding period.
*-- That is, for monthly compounding the nRate should be the annual
*-- rate / 12, and the nPeriods the number of months, and so forth.
*--
*-- If the situation involves continuous compounding, state the
*-- rate as the exponent of the annual rate, less 1, and state the
*-- periods in years. Accordingly, to find the value in 30 months
*-- of a $1000 investment continuously compounded at 6%, use:
*-- FuturVal(1000,exp(.06)-1,30/12)
*--
*-- These functions (except NPV(), which sums a series of equal
*- or unequal cash flows), are designed for use with a single
*-- "investment", one payment or receipt. If the problem involves
*-- a series of equal payments or receipts like a mortgage loan,
*-- a Holiday Club or an annuity, the fv() and pv() functions
*-- built in to dBASE IV should be used instead where possible.
*-------------------------------------------------------------------------------
FUNCTION Discount
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/1992
*-- Notes.......: Compute the present value of an amount to be received at the
*-- end of a number of periods given a periodic interest rate.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: Discount(<nFuturVal>,<nRate>,<nPeriods>)
*-- Example.....: ?Discount(1000,.08,6)
*-- Returns.....: Numeric
*-- Parameters..: nFuturVal = the amount to be received/paid in the future
*-- nRate = the periodic rate of interest
*-- nPeriods = the number of periods
*-------------------------------------------------------------------------------
parameters nFuturVal, nRate, nPeriods
RETURN nFuturVal / ( 1 + nRate ) ^ nPeriods
*-- EoF: Discount()
FUNCTION FuturVal
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/1992
*-- Notes.......: Compute the future value of an initial amount at compound
*-- interest received at a given periodic rate for a number of
*-- periods.
*-- Written for.: dBASE IV, 1.0
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: FuturVal(<nPresVal>,<nRate>,<nPeriods>)
*-- Example.....: ?FuturVal(10000,.06,48)
*-- Returns.....: Numeric
*-- Parameters..: nPresVal = Present Value
*-- nRate = Periodic interest rate
*-- nPeriods = Number of periods to calculate for
*-------------------------------------------------------------------------------
parameters nPresVal, nRate, nPeriods
RETURN nPresVal * ( 1 + nRate ) ^ nPeriods
*-- EoF: FuturVal()
FUNCTION Rate
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/1992
*-- Notes.......: Compute rate of periodic interest needed to produce a future
*-- value from a present value in a given number of periods. If
*-- the periods are not years, you'll probably want to multiply
*-- the rate returned by the number of periods in a year to
*-- obtain the equivalent annual rate.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: Rate(<nFutVal>,<nPresVal>,<nPeriods>)
*-- Example.....: ?Rate(50000,10000,48)
*-- Returns.....: Numeric
*-- Parameters..: nFutVal = Future Value
*-- nPresVal = Present Value
*-- nPeriods = Number of periods to calculate for
*-------------------------------------------------------------------------------
parameters nFutVal, nPresVal, nPeriods
RETURN ( nFutVal / nPresVal ) ^ ( 1 / nPeriods ) - 1
*-- EoF: Rate()
FUNCTION ContRate
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/1992
*-- Notes.......: Rate if compounding is continuous. Periods must be years.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: None
*-- Calls.......: RATE() Function in FINANCE.PRG
*-- Called by...: Any
*-- Usage.......: ContRate(<nFutVal>,<nPresVal>,<nYears>)
*-- Example.....: ?ContRate(50000,10000,4)
*-- Returns.....: Numeric
*-- Parameters..: nFutVal = Future Value
*-- nPresVal = Present Value
*-- nYears = Number of years to calculate for
*-------------------------------------------------------------------------------
parameters nFutVal, nPresVal, nYears
RETURN log( 1 + Rate( nFutval, nPresval, nYears ) )
*-- EoF: ContRate()
FUNCTION NPV
*-------------------------------------------------------------------------------
*-- Programmer..: Tony Lima (TONYLIMA) and Jay Parsons (JPARSONS)
*-- Date........: 03/01/1992
*-- Notes.......: Net present value of array aCashflow[ nPeriods ]
*-- Calculates npv given assumed rate and # periods.
*-- See "Other inputs" below for instructions/details ...
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: NPV(<nRate>,<nPeriods>)
*-- Example.....: ? NPV( .06, 6 )
*-- Returns.....: Float = value of the project at given rate
*-- Parameters..: nRate = Interest Rate
*-- : nPeriods = Number of Periods to calculate for
*-- Other inputs: Requires the array aCashflow[ ] set up before calling.
*-- : Each of its elements [n] holds the cash flow at the
*-- : beginning of period n, with a negative amount indicating
*-- : a cash outflow. Elements of value 0 must be included for
*-- : all periods with no cash flow, and all periods must be of
*-- : equal length.
*-- : If the project is expected to require an immediate outlay
*-- : of $6,000 and to return $2,000 at the end of each of the
*-- : first five years thereafter, the array will be:
*-- : aCashflow[1] = -6000
*-- : aCashflow[2] = 2000
*-- : aCashflow[3] = 2000
*-- : * * *
*-- : aCashflow[6] = 2000
*-- :
*-- : If the cash flows are at the end of the periods, rather
*-- : than at the beginning, assign 0 to aCashFlow[1], then
*-- : assign cash flows successively. aCashFlow[2] will then
*-- : represent the cash flow at the end of period 1, rather
*-- : than at the beginning of period 2, which is the same thing.
*-- :
*-- : Rewriting the function to have array name passed as a
*-- : parameter is possible, but will slow down execution to an
*-- : extent that will be very noticeable if this function is being
*-- : repeatedly executed, as by Zeroin() to find an Internal Rate
*-- : of Return.
*-------------------------------------------------------------------------------
parameters nRate, nPeriods
private nDiscount, nFactor, nPeriod, nNpv
nPeriod = 1
nNpv = aCashflow[ 1 ]
nDiscount = float( 1 )
nFactor = 1 / ( 1 + nRate )
do while nPeriod < nPeriods
nPeriod