Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
<?php // RAY_irr.php
error_reporting(E_ALL);
// COMPUTE (IRR) INTERNAL RATE OF RETURN - ITERATIVE METHOD, ANNUAL
// SOME TEST DATA
$cashflow = array
( -100.0 // INITIAL INVESTMENT
, 5.0 // ANNUAL INTEREST OR DIVIDEND PAYMENTS
, 5.0
, 5.0
, 5.0
, 5.0
, 110.0 // CASH OUT
)
;
// TEST THE FUNCTION AND SHOW THE WORK PRODUCT
$irr = irr($cashflow);
echo " CASH: ";print_r($cashflow);
echo " IRR: $irr";
// DETERMINE INTERNAL RATE OF RETURN FROM AN ARRAY OF ANNUAL PAYMENTS
function irr($cashflow)
{
// DETERMINE IF GROSS CASHFLOW IS POSITIVE
$cash = round(array_sum($cashflow),2);
if ($cash == 0.0) return 0.0;
if ($cash > 0.0) $iterator = 0.0001;
if ($cash < 0.0) $iterator = -0.0001;
$interest = 0.0;
$npv = 1.0;
$years = count($cashflow) - 1;
while ( (round(abs($npv),4) > 0.0) )
{
$interest = round($interest + $iterator,4);
$year = 0;
$npv = 0.0;
while ($year <= $years)
{
$yearly = $cashflow[$year];
// DENOMINATOR IS (1 + r)**t
$denominator = pow((1+$interest), $year);
$denominator = round($denominator,6);
$npv = $npv + ( $yearly / $denominator );
$year++;
}
if (($iterator > 0.0) && ($npv < 0.0) ) break;
if (($iterator < 0.0) && ($npv > 0.0) ) break;
}
return round((($interest-$iterator) * 100.0),2);
} // END FUNCTION irr
<?php // RAY_irr.php
error_reporting(E_ALL);
// COMPUTE (IRR) INTERNAL RATE OF RETURN - ITERATIVE METHOD, ANNUAL
// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28324332.html
// SOME TEST DATA
$cashflow = array
( -1000.0 // INITIAL INVESTMENT
, 400.0 // ANNUAL INTEREST OR DIVIDEND PAYMENTS
, 400.0
, 400.0
)
;
// TEST THE FUNCTION AND SHOW THE WORK PRODUCT
$irr = irr($cashflow);
echo " CASH: ";print_r($cashflow);
echo " IRR: $irr";
// DETERMINE INTERNAL RATE OF RETURN FROM AN ARRAY OF ANNUAL PAYMENTS
function irr($cashflow, $accuracy=4)
{
// DETERMINE IF GROSS CASHFLOW IS POSITIVE
$cash = round(array_sum($cashflow), $accuracy);
if ($cash == 0.0) return 0.0;
if ($cash > 0.0) $iterator = pow(10,-$accuracy);
if ($cash < 0.0) $iterator = -pow(10,-$accuracy);
$interest = 0.0;
$npv = 1.0;
$years = count($cashflow) - 1;
while ( (round(abs($npv),$accuracy) > 0.0) )
{
$interest = round($interest + $iterator,$accuracy);
$year = 0;
$npv = 0.0;
while ($year <= $years)
{
$yearly = $cashflow[$year];
// DENOMINATOR IS (1 + r)**t
$denominator = pow((1+$interest), $year);
$denominator = round($denominator,$accuracy);
$npv = $npv + ( $yearly / $denominator );
$year++;
}
if (($iterator > 0.0) && ($npv < 0.0) ) break;
if (($iterator < 0.0) && ($npv > 0.0) ) break;
}
return round((($interest-$iterator) * 100.0),$accuracy);
} // END FUNCTION irr
what is the last input option 'cash out'When analyzing multiple discounted cash flows, your investment is typically treated as a negative value and the returns of interest, dividend yields, etc., are treated as positive values. In the example, the "cash out" value would represent liquidation of the investment at a future date. This would occur if a bond matured and the principal was returned or a rental property is sold for cash.
Have i ran it right?Sort of. There is a lot of deep background involved in making these calculations. The cash flows are not usually as hard-and-fast as you see in these theoretical examples, and interest on loans usually does not compound annually; there are different compounding periods for different financial instruments. Mortgages, for example, are typically compounded continuously.
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.