# Clarion Community Help

### Site Tools

npv_net_present_value_.htm
 Navigation:  Templates > Guide to all Templates > Additional Libraries and Templates > Finance Library >====== NPV (net present value) ======

NPV(investment,cashflows,periods,rate)

 NPV Computes net present value of an investment. investment A numeric constant or variable containing the initial cost of the investment (a negative number). cashflows[] A single dimensioned DECIMAL array containing the amounts of money paid out and received during discrete accounting periods. periods[] A single dimensioned DECIMAL array containing period numbers identifying the discrete accounting periods in which cash flows occurred. Rate A numeric constant or variable containing the desired periodic rate of return.

NPV determines the viability of an investment proposal by calculating the present value of future returns, discounted at the marginal cost of capital minus the cost of the investment (investment). The cashflows parameter is an array of money paid out and received during the course of the investment. The periods parameter is an array which contains the period number in which a corresponding cash flow occurred. The desired periodic rate of return (rate) for the investment is also specified. Investment should contain a negative number (a cost).

Periodic rate may be calculated as follows:

PeriodicRate = AnnualInterestRate / (PeriodsPerYear * 100)

Cashflows and periods MUST both be DECIMAL arrays of single dimension and equal size. The last element in the periods array MUST contain a zero to terminate the NPV analysis.

Return Data Type:     DECIMAL

Internal Formulas:

Example:

CashFlows           DECIMAL(18,2),DIM(1000)

CashFlowPeriods     DECIMAL(4),DIM(1000)

InvestmentAmount    DECIMAL(18,2)

DesiredInterestRate DECIMAL(31,15)

NetValue            DECIMAL(18,2)

InvestmentTransactions FILE,DRIVER('TOPSPEED'),|

KeyIdPeriodNumber KEY(INVTRN:Id,INVTRN:PeriodNumber),NOCASE,PRIMARY

Notes             MEMO(1024)

Record            RECORD,PRE()

Id                 DECIMAL(8)

PeriodNumber       DECIMAL(8)

Date               ULONG

Type               STRING(20)

Amount             DECIMAL(16,2)

END

END

CODE

CLEAR(CashFlows)                 !initialize queue

CLEAR(CashFlowPeriods)           !initialize queue

CLEAR(InvestmentAmount)

CLEAR(TRANSACTION:RECORD)        !initialize record buffer

DesiredInterestRate = INV:NominalReturnRate / (100 * INV:PeriodsPerYear)

transcnt# = 0

TRANSACTION:Id = INV:Id          !prime record buffer

TRANSACTION:PeriodNumber = 0

SET(TRANSACTION:KeyIdPeriodNumber,TRANSACTION:KeyIdPeriodNumber) !position file

LOOP                                   !loop for all transactions

IF ERRORCODE() OR TRANSACTION:Id NOT = INV:Id  !if no more transactions

BREAK                                         !break from loop

ELSE                                           !else process transaction

transcnt# += 1

CashFlows[transcnt#] = TRANSACTION:Amount

CashFlowPeriods[transcnt#] = TRANSACTION:PeriodNumber

END                       !endelse process transaction

END                        !endloop all transactions

NetValue = NPV(InvestmentAmount,CashFlows,CashFlowPeriods,DesiredInterestRate)