CFLib.org – Common Function Library Project

calcIRR(arrCashFlow)

Last updated November 13, 2014

author

CF Ninja

Version: 1 | Requires: CF6 | Library: FinancialLib

Description:
Calculates Internal Rate of Return (IRR) similar to excel IRR function.

Return Values:
Returns a numeric value.

Example:

<cfscript>
    cFlow = arrayNew(1);
    cFlow[1] = -4000;
    cFlow[2] = 1200;
    cFlow[3] = 1410;
    cFlow[4] = 1875;
    cFlow[5] = 1050;
    
    myIRR = calcIRR(cFlow);
 </cfscript>    

 <cfdump var="#cFlow#">
 <cfoutput>irr = #myIRR#</cfoutput>

Parameters:

Name Description Required
arrCashFlow Array of cashflow. Yes

Full UDF Source:

<!---
 Calculate IRR.
 
 @param arrCashFlow      Array of cashflow. (Required)
 @return Returns a numeric value. 
 @author CF Ninja (coldfusion.ninja@hotmail.com) 
 @version 1, November 13, 2014 
--->
<cffunction name="calcIRR" output="false">
    <cfargument name="arrCashFlow" type="Array" required="yes" hint="array of cashflow">
    <cfscript>
        var guess = 0.1;
        var inc   = 0.00001;
        do {
            guess += inc;
            npv = 0; //net present value
            for (var i=1; i<=arrayLen(arguments.arrCashFlow); i++)    {
                npv += arguments.arrCashFlow[i] / ((1 + guess) ^ i);    
            }
            
        } while ( npv > 0 );
        
        guess =  guess * 100;
    </cfscript>
    <cfreturn guess>
</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson