Advertisement
kabads

credit bisection

Oct 14th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. balance = 999999
  2. annualInterestRate = 0.18
  3. startbalance = balance
  4. monthlyinterest = annualInterestRate/12
  5. lower = balance/12
  6. upper = (balance*((1+monthlyinterest)**12/12))
  7. balance = startbalance
  8. minpayment = (upper+lower)/2.0
  9. while True:
  10.     for a in range(12):
  11.         balance = balance - minpayment
  12.         balance = balance + balance * monthlyinterest
  13.         #balance = (balance - minpayment) * ( 1 + monthlyinterest)
  14.         print "month: " + str(a) + " balance: " + str(balance)
  15.     if abs(balance)<0.08:
  16.        
  17.         break;
  18.     if balance <0:
  19.         upper = minpayment
  20.         print "upper minpayment has changed to: " + str(minpayment)
  21.     else:
  22.         lower = minpayment
  23.         print "lower minpayment has changed to: " + str(minpayment)
  24.     minpayment = (lower+upper)/2.0
  25.     balance = startbalance
  26.  
  27.  
  28. #ans = payYear(startbalance, balance, monthlyinterest)
  29. print "minpayment is: " + str(round(minpayment, 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement