User Tools

Site Tools


irr_internal_rate_of_return_.htm
Navigation:  Templates > Guide to all Templates > Additional Libraries and Templates > Finance Library >====== IRR (internal rate of return) ====== Previous pageReturn to chapter overviewNext page

IRR(investment,cashflows,periods,rate)

IRR Computes the internal rate of return on 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.

IRR determines the rate of return on an investment (investment). The result is computed by determining the rate that equates the present value of future cash flows to the cost of the initial 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)

C6H0012.jpg

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 IRR analysis.

Return Data Type:     DECIMAL

Internal Formulas:

IRR.jpg

The IRR function performs binary search iterations to home in on the return value. If more than 50 such iterations are required, a value of zero is returned.

Example:

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

CashFlowPeriods     DECIMAL(4),DIM(1000)

InvestmentAmount    DECIMAL(18,2)

DesiredInterestRate DECIMAL(31,15)

Return              DECIMAL(10,6)

InvestmentTransactions FILE,DRIVER('TOPSPEED'),|

           NAME('busmath\!InvestmentTransactions'),PRE(INV),CREATE,THREAD

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

  NEXT(InvestmentTransactions)    !read next record

  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

 Return = IRR(InvestmentAmount,CashFlows,CashFlowPeriods,DesiredInterestRate)

 Return *= (100 * INV:PeriodsPerYear)       !normalize IRR to percent

irr_internal_rate_of_return_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1