我怎样才能在PHP中复制Excel FVfunction?

我将一些相当复杂的计算从Excel电子表格转换为PHP。 我被困在Excel的FV函数的转换,这是定义如此:

FV( interest_rate, number_payments, payment, PV, Type ) 

我已经在这里工作了2个小时,而且还有一些我错过了。 从本质上讲,我需要将这个function复制到一个等价的PHP函数中,并采用所有前面提到的参数。

任何帮助将不胜感激。

从PHPExcel函数库略微修改:

 /** * FV * * Returns the Future Value of a cash flow with constant payments and interest rate (annuities). * * @param float $rate Interest rate per period * @param int $nper Number of periods * @param float $pmt Periodic payment (annuity) * @param float $pv Present Value * @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period * @return float */ function FV($rate = 0, $nper = 0, $pmt = 0, $pv = 0, $type = 0) { // Validate parameters if ($type != 0 && $type != 1) { return False; } // Calculate if ($rate != 0.0) { return -$pv * pow(1 + $rate, $nper) - $pmt * (1 + $rate * $type) * (pow(1 + $rate, $nper) - 1) / $rate; } else { return -$pv - $pmt * $nper; } } // function FV() echo FV(0.0149562574418, 4, 43.875, -250); 

返回85.818510876629

// unit testing

 class ExcelTest extends \PHPUnit_Framework_TestCase { public function test_it_calculates_fv_value() { $test_data = [ [ 0.005, 10, -200, -500, 1, 2581.4033740601 ], [ 0.01, 12, -1000, null, null, 12682.503013197 ], [ 0.009166666667, 35, -2000, null, 1, 82846.246372418 ], [ 0.005, 12, -100, -1000, 1, 2301.4018303409 ], [ 0.004166666667, 60, -1000, null, null, 68006.082841536 ], [ 0.025, 16, -2000, 0, 1, 39729.460894166 ], [ 0.0, 12, -100, -100, null, 1300 ] ]; $test_case_id = 0; foreach($test_data as $test_case) { $test_case_id++; list($rate, $nper, $pmt, $pv, $type, $expected_result) = $test_case; $this->assertEquals($expected_result, Excel::FV($rate, $nper, $pmt, $pv, $type), "Test case $test_case_id failed", 0.0000001); } } } 
 function fv($r,$n,$p,$pv=0) { $sum = $pv; for ( $i=0;$i<$n;$i++ ) { $sum += $sum*$r + $p; } return $sum; } echo fv(0.1,4,10,100); 

Type参数的扩展名留给读者来练习。

我正面临类似的问题,并得到了这个职位的人的帮助,我希望别人也发现它的帮助

我有同样的问题,并发现这个非常好的function。 以上两点不适合我的需要…

$ R为费率,$ n为期数,$ pmt为付款金额

函数PV($ R,$ n,$ pmt,$ m = 1){

$ Z = 1 /(1 +($ R / $ m));

返回($ pmt * $ Z *(1-pow($ Z,$ n)))/(1 – $ Z);

}

 echo PV(0,00333333, 180, 1221); 

不要忘记,如果你想知道,如果你以每年1221欧元的价格以每年4%的速度支付15年后你将得到多less,你将不得不按12分的比例分180个月。