//Вычисляет амортизацию актива используя двойной-сбалансированный метод отклонения. function DoubleDecliningBalance($Cost, $Salvage, $Life, $Period) { if (($Period < 1) or ($Life < $Period) or ($Life < 1) or ($Cost <= $Salvage)) { exit; } if ( $Life <= 2 ) { if ( $Period = 1 ) { $res=$Cost-$Salvage; } else { $res=0; } $Factor := 2.0 / $Life; $DepreciatedVal := $Cost * pow((1.0 - $Factor), $Period - 1); $res=Factor * DepreciatedVal; if $res > $DepreciatedVal - $Salvage { $res = $DepreciatedVal - $Salvage; } if $res < 0 then $res=0; end; function Annuity2($R,$N,$PaymentTime) //$CompoundRN,$Result { if ($R = 0) { $CompoundRN = 1.0; $Result = $N; } else { if (Abs($R) < 6.1E-5) { $CompoundRN = Exp($N * Log($R+1)); $Result = N*(1+(N-1)*R/2); } else { $CompoundRN = Compound($R, $N); $Result = ($CompoundRN-1) / $R; } if ($PaymentTime = 1) { $Result = $Result * (1 + $R); } return array($CompoundRN,$Result); } //Вычисляет будущую величину инвестиции. //$PaymentTime = 1-начальный период, иное конечный период function FutureValue($Rate,$NPeriods,$Payment,$PresentValue,$PaymentTime) { $Annuity=array(0,0); $Annuity := Annuity2($Rate, $NPeriods, $PaymentTime); return -$Payment * $Annuity[1] - $PresentValue * $Annuity[0]; } //Вычисляет часть интереса ссуды. function InterestPayment($Rate,$Period, $NPeriods,$PresentValue, $FutureValue,$PaymentTime) { $Crp:=Compound($Rate,$Period-1); $Arn:=Annuity2($Rate,$Nperiods,$PaymentTime); //crn return ($FutureValue*($Crp-1)-$PresentValue*($Arn[0]-$Crp))/$Arn[1]; } //Возвращает показатель интереса требующийся, чтобы увеличивать PresentValue до FutureValue. function InterestRate($NPeriods,$Payment,$PresentValue,$FutureValue, $PaymentTime) { $Result := 0; if ($NPeriods <= 0) { return $Result; exit; }; $Pmt = $Payment; if ($PaymentTime != 1) { $X = $PresentValue; $Y = $FutureValue + $Payment; } else { $X = $PresentValue + $Payment; $Y = $FutureValue; } $First = $X; $Last = $Y; $Reverse = 0; if ($First * $Payment > 0.0) { $Reverse = 1; $T = $First; $First = $Last; $Last = $T; } if ($first > 0.0) { $First = -$First; $Pmt = -$Pmt; $Last = -$Last; } if (($First == 0.0) or ($Last < 0.0)) { exit; }; $T = 0.0; for ($Count=1,$Count=$MaxIterations,$Count++) { $EnT = Exp($NPeriods * $T); if ($ent==($ent+1)) { $Result = -$Pmt / $First; if ($Reverse==1) { $Result = Exp(-Ln($Result+1)) - 1.0; } return $Result; Exit; } $ET = Exp($T); $ET1 = $ET - 1.0; if ($ET1 == 0.0) { $X = $NPeriods; $Y = $X * ($X - 1.0) / 2.0; } else { $X = $ET * (Exp(($NPeriods - 1) * $T)-1.0) / $ET1; $Y = ($NPeriods * $EnT - $ET - $X * $ET) / $ET1; } $Z = $Pmt * $X + $Last * $EnT; $Y = Ln($Z / -$First) / (($Pmt * $Y + $Last * $NPeriods *$EnT) / $Z); $T = $T - $Y; if (RelSmall($Y, $T)) { if (Reverse==0) { $T = -$T; } return Exp($T)-1.0; Exit; } } }