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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson