]> git.mxchange.org Git - core.git/blobdiff - contrib/exp/exp2.php
Continued:
[core.git] / contrib / exp / exp2.php
index 22e985d3a0fa6b888922a2f5afad22b2ed8db952..c51211e0eb8b696efbb6f7736ba5721f084a4f92 100644 (file)
@@ -4,25 +4,25 @@ error_reporting(E_ALL | E_STRICT);
 bcscale(20);
 
 $balance = 1;
-$years = 100;
-$rate = 0.05;
+$years = 2017;
+$rate = 0.03;
 
 $totalMonths = $years * 12;
 
 print 'Invest ' . $balance . ' EUR and come back later.' . PHP_EOL;
 
 for ($i = 1; $i <= $totalMonths; $i++) {
-       if ($i % 12 == 0) {
-               $rate = bcdiv($rate, 1.01);
-       } // END - if
+       // Reduce interest rate every month
+       $rate = bcdiv($rate, 1.00001);
 
+       // Calculate interest
        $interest = bcmul($balance, $rate);
+
+       // ... and add it to balance
        $balance = bcadd($balance, $interest);
 
        print 'Month ' . $i . ': rate=' . bcmul($rate, 100) . '%,interest=' . $interest . ',balance=' . $balance . PHP_EOL;
-} // END - foreach
+}
 
 print 'After ' . $totalMonths . ' months (' . $years . ' years) you have ' . $balance . ' EUR back.' . PHP_EOL;
 //print 'Length:' . strlen($balance) . PHP_EOL;
-
-?>