Beispiel #1
0
 public function ActualAPR($amount, $closingCost, $interest, $length, $periodPayment)
 {
     if ($amount <= 0) {
         return 0;
     }
     if ($closingCost == $amount) {
         return 0;
     }
     if ($closingCost == 0) {
         return $interest;
     }
     $totalAmount = $amount - $closingCost;
     $aprA = $interest;
     $aprB = $interest;
     $aprX = 0;
     do {
         $aprA = $aprA / 2;
         $payment = Calc::PeriodPayment($totalAmount, $aprA, $length);
     } while ($payment > $periodPayment);
     do {
         $aprB = $aprB * 2;
         $payment = Calc::PeriodPayment($totalAmount, $aprB, $length);
     } while ($payment < $periodPayment);
     do {
         $aprX = ($aprA + $aprB) / 2;
         $payment = Calc::PeriodPayment($totalAmount, $aprX, $length);
         if ($payment > $periodPayment) {
             $aprB = $aprX;
         } else {
             $aprA = $aprX;
         }
     } while (abs($payment - $periodPayment) > 0.001);
     return $aprX;
 }