Adjusted a bit, still not accurate enough and may not reflect inflation
authorRoland Haeder <roland@mxchange.org>
Thu, 14 May 2015 18:01:22 +0000 (20:01 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 14 May 2015 18:01:22 +0000 (20:01 +0200)
correctly.

Signed-off-by: Roland Häder <roland@mxchange.org>
contrib/exp/exp2.php

index 22e985d3a0fa6b888922a2f5afad22b2ed8db952..03b7108a216c4237d35d8d72330860955534f334 100644 (file)
@@ -12,11 +12,13 @@ $totalMonths = $years * 12;
 print 'Invest ' . $balance . ' EUR and come back later.' . PHP_EOL;
 
 for ($i = 1; $i <= $totalMonths; $i++) {
 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);
        $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;
        $balance = bcadd($balance, $interest);
 
        print 'Month ' . $i . ': rate=' . bcmul($rate, 100) . '%,interest=' . $interest . ',balance=' . $balance . PHP_EOL;