Exemple #1
0
 /**
  * Compute amount accrued on a principal using compound interest.
  * The interest rate is annual.
  * $startDate must be less than or equal to $endDate.
  * 
  * @param double $principal
  * @param double $annualRate
  * @param date $startDate
  * @param date $endDate
  * @param int $plusOneDay
  * @return double amount
  */
 public function amountDueOld($principal, $annualRate, $startDate, $endDate, $plusOneDay)
 {
     $noOfDays = Defaults::countdays($startDate, $endDate) + $plusOneDay;
     $years = 0;
     for ($year = substr($startDate, 0, 4); $year <= substr($endDate, 0, 4); $year++) {
         $daysInAYear = Defaults::daysInAYear($startDate);
         if ($noOfDays >= $daysInAYear) {
             $noOfDays = $noOfDays - $daysInAYear;
             $years++;
         }
     }
     $years = empty($daysInAYear) ? 0 : $years + $noOfDays / $daysInAYear;
     return round($principal * pow(1 + $annualRate / 100, $years), 3);
 }