CFLib.org – Common Function Library Project

calcIRR(arrCashFlow)

Last updated October 10, 2011

Version: 1 | Requires: ColdFusion MX | Library: FinancialLib

 
Rated 1 time(s). Average Rating: 5.0

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

Return Values:
Returns a numeric value.

Example:

view plain print about
<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:

view plain print about
<!---
 Calculate IRR.
 
 @param arrCashFlow      Array of cashflow. (Required)
 @return Returns a numeric value. 
 @author FALCONSEYE (falconseye@live.com) 
 @version 1, October 10, 2011 
--->

<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

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson