]> git.mxchange.org Git - core.git/blobdiff - contrib/exp/exp2.php
Some improvements ...
[core.git] / contrib / exp / exp2.php
index 22e985d3a0fa6b888922a2f5afad22b2ed8db952..b6040fc543f68f9407f21e13844cac84ae30bb27 100644 (file)
@@ -5,18 +5,20 @@ bcscale(20);
 
 $balance = 1;
 $years = 100;
-$rate = 0.05;
+$rate = 0.02;
 
 $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.001);
 
+       // 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;