( ),
, .
, counter, 1:
def getFixedPayment(balance, annualInterestRate, counter=12):
totalLoan = balance + (balance*annualInterestRate)
monthlyPayment = roundup(totalLoan/12.0)
newBalance = totalLoan - monthlyPayment
if counter < 12:
newPayment = newBalance / counter + 1
else:
newPayment = newBalance / counter
if counter == 1:
return roundup(newPayment/12)
else:
return getFixedPayment(balance,annualInterestRate,counter-1)
counter > 1, " ",
, counter - 1.
, counter = 12,
11 .
:
def getFixedPayment(balance, annualInterestRate):
totalLoan = balance + (balance*annualInterestRate)
monthlyPayment = roundup(totalLoan/12.0)
newBalance = totalLoan - monthlyPayment
newPayment = newBalance / counter + 1
return roundup(newPayment/12)
? .
, .
- 3 ,
, :
T ,r , 4%, 1.04, , T * r.x
, x , ?
(T - x) * r
x , T - x,
.
x, :
((T - x) * r - x) * r
x.
- x, :
((T - x) * r - x) * r - x <= 0
, x:
((T - x) * r - x) * r <= x
(T - x) * r - x <= x / r
(T - x) * r <= x / r + x
T - x <= x / r / r + x / r
T <= x / r / r + x / r + x
T <= x * (1 / r / r + 1 / r + 1)
T / (1 / r / r + 1 / r + 1) <= x
3 .
, , :
T / (1 / r / r / r + 1 / r / r + 1 / r + 1) <= x
, T / m, T / (m / r + 1).
, .
,
, .... !
def getFixedPayment(balance, annual_interest_rate, counter=12, interest=...):
if counter == 1:
return roundup(balance / interest)
monthly_interest_rate = annual_interest_rate / 12
r = 1 + monthly_interest_rate
return getFixedPayment(balance, annual_interest_rate, counter - 1, ...)
, .
calc.py,
python -mdoctest calc.py.
, ,
, .
def getFixedPayment(balance, annual_interest_rate, counter=12, interest=...):
"""
>>> getFixedPayment(3329, 0.2)
310
>>> getFixedPayment(4773, 0.2)
440
>>> getFixedPayment(3926, 0.2)
360
>>> getFixedPayment(265, 0.18)
30
>>> getFixedPayment(263, 0.18)
30
>>> getFixedPayment(317, 0.25)
30
>>> getFixedPayment(720, 0.2)
70
>>> getFixedPayment(4284, 0.2)
400
>>> getFixedPayment(3834, 0.15)
350
>>> getFixedPayment(3045, 0.18)
280
>>> getFixedPayment(4461, 0.2)
410
>>> getFixedPayment(4657, 0.04)
400
>>> getFixedPayment(3395, 0.2)
310
>>> getFixedPayment(4045, 0.15)
370
>>> getFixedPayment(3963, 0.18)
360
"""
if counter == 1:
return roundup(balance / interest)
monthly_interest_rate = annual_interest_rate / 12
r = 1 + monthly_interest_rate
return getFixedPayment(balance, annual_interest_rate, counter - 1, ...)