dev-resources.site
for different kinds of informations.
PHP Mimic Excel Rate Function
Published at
10/14/2022
Categories
Author
Teddy Zugana
Categories
1 categories in total
open
<?php
define('FINANCIAL_MAX_ITERATIONS', 128);
define('FINANCIAL_PRECISION', 1.0e-08);
function RATE($nper, $pmt, $pv, $fv = 0.0, $type = 0, $guess = 0.1)
{
$rate = $guess;
if (abs($rate) < FINANCIAL_PRECISION) {
$y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv;
} else {
$f = exp($nper * log(1 + $rate));
$y = $pv * $f + $pmt * (1 / $rate + $type) * ($f - 1) + $fv;
}
$y0 = $pv + $pmt * $nper + $fv;
$y1 = $pv * $f + $pmt * (1 / $rate + $type) * ($f - 1) + $fv;
// find root by secant method
$i = $x0 = 0.0;
$x1 = $rate;
while ((abs($y0 - $y1) > FINANCIAL_PRECISION) && ($i < FINANCIAL_MAX_ITERATIONS)) {
$rate = ($y1 * $x0 - $y0 * $x1) / ($y1 - $y0);
$x0 = $x1;
$x1 = $rate;
if (($nper * abs($pmt)) > ($pv - $fv))
$x1 = abs($x1);
if (abs($rate) < FINANCIAL_PRECISION) {
$y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv;
} else {
$f = exp($nper * log(1 + $rate));
$y = $pv * $f + $pmt * (1 / $rate + $type) * ($f - 1) + $fv;
}
$y0 = $y1;
$y1 = $y;
++$i;
}
return $rate;
} // function RATE()
$nper = 240;
$pmt = 3250000;
$pv = -300000000;
$test = RATE($nper, $pmt, $pv);
echo $test*100;
?>
Articles
12 articles in total
Obfuscating “Hello world!” obfuscate on Python
read article
Secure Nginx with Let's Encrypt on Ubuntu
read article
Auto Deploy Laravel with Deployer.yml sample With Github Runner
read article
Managing Docker Containers with Portainer
read article
Nginx force http to https On 443 https Port
read article
Java FTPS disabling Certificate Check , FOR FIX FTP SSL certificate expired exception
read article
GIS MAP Leaflet JS with OPENSTREETMAP SAMPLE
read article
GIS MAP Leaflet JS with API MAPBOX SAMPLE
read article
Jaro and Jaro-Winkler distance, measuring similarity between strings on PHP.
read article
Python Scraping web page with BeautifulSoup and requests Example
read article
PHP Mimic Excel Rate Function
currently reading
How To Install unixODBC-devel on CentOS 7 and Connect DB2 V9.7
read article
Featured ones: