| px | top | add code | search | signup | login | help |
<?php
/*
* Author : Lucas Baltes (lucas@think-ahead.nl)
* Company : Think Ahead BV
* http://www.think-ahead.nl
*
* Date : March 8th, 2000
* Version : 0.1
* Purpose : Calculate net present value (netpv or npv)
* Copyright : 2000 - Think Ahead BV
*
* Syntax : float npv(float $rate, array $values)
*
* Warning :
* If the results don't match the values you calculate using Excel
* or possible other applications you need to include a 0 as
* the first argument in your $values array.
*
* The npv function includes the 0 argument in the $values array,
* which corresponds to a cash payment occurring at time zero,
* the present time period. Excel and possibly other applications
* do not include the 0 argument. In order to compare the results
* from this function, you may need to insert the value 0.0 as the
* first value in the $values array.
*
* Copyright :
* Permission to use and modify this software and its
* documentation for any purpose other than its incorporation
* into a commercial product is hereby granted without fee,
* as long as the author is notified that this piece of software
* is being used in other applications.
*
* Permission to copy and distribute this software and its
* documentation only for non-commercial use is also granted
* without fee, provided, however, that the above copyright
* notice appear in all copies, that both that copyright notice
* and this permission notice appear in supporting documentation.
*
* The author makes no representations about the suitability
* of this software for any purpose. It is provided ''as is'',
* without express or implied warranty.
*/
function npv($rate, $values) {
for ($i=0;$i<=count($values);$i+=1) {
$npv = $values[count($values) - $i] + $npv / (1 + $rate);
}
return $npv;
}
// example for using npv
print npv(0.09, array(0,30,40,50,60,70));
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.