def main(): # Enter yearly interest rate annualInterestRate = eval(input ("Enter yearly interest rate, for example, 7.25: ")) # Enter number of years numberOfYears = eval(input( "Enter number of years as an integer: ")) # Enter loan amount loanAmount = eval(input( "Enter loan amount, for example, 120000.95: ")) # Enter a borrwer borrower = input("Enter a borrower's name: ") # Create a Loan object loan = Loan(annualInterestRate, numberOfYears, loanAmount, borrower) # Display loan date, monthly payment, and total payment print("The loan is for", loan.getBorrower()) print("The monthly payment is", format( loan.getMonthlyPayment(), '.2f')) print("The total payment is", format( loan.getTotalPayment(), '.2f'))
def testNewLoan(self): termLoan = Loan.createTermLoan(300, 0.5, 0.8) self.assertEquals(300, termLoan.commitment) self.assertEquals(120, termLoan.capital()) revolver = Loan.createRevolver(300, 0.5, 0.8, date(2013, 8, 15)) self.assertTrue(None != revolver.expiry) self.assertEquals(130, revolver.capital()) RCTL = Loan.createRCTL(300, 0.5, 0.8, 200) self.assertEquals(200, RCTL.outstanding) self.assertEquals(140, RCTL.capital())
def main(argv): initialBalance = int(sys.argv[1]) interestRate = int(sys.argv[2]) term = int(sys.argv[3]) myLoan = Loan(initialBalance, interestRate, term, 0) myLoan.computeMonthlyPayment() header = '{:<10s} {:<17s} {:<15s} {:<14s} {:<18s}'.format("Month", "Balance In", "Interest", "Payment", "Balance Out") print(header) for a in range(1, term + 1): results = '{:>5} {:>15.2f} {:>15.2f} {:>14.2f} {:18.2f}'.format( a, myLoan.remainingBalance(a), myLoan.interestAccrued(a), myLoan.monthlyPayment, myLoan.remainingBalance(a+1)) print(results)
def work_application(self): print(f"\nWorking an Application") if not self.fake_db["applications_list"]: print(f"No Applications exist. Please create an Application...") self.menu_handler("Loan Menu") else: app_id = input(f"Enter application id... ") print(f"\n1 Approve") print(f"2 Deny") decision = int(input(f"Enter choice... ")) if decision == 1: owner = self.fake_db["people_list"][input( f"Enter owner id... ")] interest = input(f"Input interest rate... ") temp_ln = Loan( *self.fake_db["application_list"][app_id]. approve_application(self, app_id, owner, interest)) self.fake_db["loan_list"].append(temp_ln) self.write_db() elif decision == 2: self.fake_db["application_list"].deny_application() self.write_db() else: self.menu_handler("Loan Menu") self.menu_handler("Loan Menu")
def main(): annualInterestRate = eval( input("Enter yearly interest rate, for example, 7.25: ")) numberOfYears = eval(input("Enter number of years as integer: ")) loanAmount = eval(input("Enter loan amount, ex 120000.95: ")) borrower = input("Enter a borrowers name: ") # Create a loan object loan = Loan(annualInterestRate, numberOfYears, loanAmount, borrower) print("the loan is for", loan.getBorrower()) print("the monthly payment is", format(loan.getMonthlyPayment(), ".2f")) print("the total payment is", format(loan.getTotalPayment(), ".2f"))
def test(store): from Book import Book from Author import Author from Loan import Loan from Wrote import Wrote from Shelf import Shelf classics = Shelf() classics.setName('Classics') store.addObject(classics) store.saveChanges() ed = Author() ed.setName('Edmund Wells') david = Book() wrote = Wrote() ed.addToWrote(wrote) david.addToAuthors(wrote) david.setTitle('David Coperfield') david.setPublisher('Monty Python') loan = Loan() loan.setBorrower('A. Git') david.addToLoans(loan) david.setShelf(classics) store.addObject(david) store.saveChanges() # create a clone of the book and associated objects grate = david.clone() grate.setTitle('Grate Expections') store.addObject(grate) store.saveChanges() assert david is not grate assert len(grate.authors()) == 1 assert david.authors()[0] is not grate.authors()[0] assert grate.authors()[0].author() is ed assert len(grate.loans()) == 0 assert grate.shelf() is david.shelf() assert grate.publisher() == 'Monty Python'
def main(): # Enter yearly interest rate annualInterestRate = eval(input("Enter yearly interest rate, for example, 7.25: ")) # Enter number of years numberOfYears = eval(input("Enter number of years as an integer: ")) # Enter loan amount loanAmount = eval(input("Enter loan amount, for example, 120000.95: ")) # Enter a borrower borrower = input("Enter a borrower's name: ") # Create a Loan object loan = Loan(annualInterestRate, numberOfYears, loanAmount, borrower) # Display loan date, monthly payment, and total payment print("The loan is for", loan.getBorrower()) print("The monthly payment is", format(loan.getMonthlyPayment(), ".2f")) print("The total payment is", format(loan.getTotalPayment(), ".2f"))
def main(): # Enter yearly interest rate annualInterestRate = eval(input("请输入年利率,例如 7.25 :")) # Enter number of years numberOfYears = eval(input("请输入贷款年限,整数:")) # Enter loan amount loanAmount = eval(input("请输入贷款总数,例如 120000.95 :")) # Enter a borrower borrower = input("请输入贷款人姓名:") # Create a Loan object loan = Loan(annualInterestRate, numberOfYears, loanAmount, borrower) # Display loan date, monthly payment, and total payment print("The loan is for", loan.getBorrower()) print("The monthly payment is", format(loan.getMonthlyPayment(), ".2f")) print("The total payment is", format(loan.getTotalPayment(), ".2f"))
def buyProperty(self, property_obj): current_month = self.calendar.month # buy property property_value = property_obj.value_history[current_month] down_payment = self.down_payment_percentage * property_value / 100.0 # TODO: function for calcing down payment self.savings_history[current_month] -= down_payment self.properties.append(property_obj) # take on loan new_loan = Loan(property_value - down_payment, current_month) self.loans.append(new_loan)
def main(): # Enter yearly interest rate. annualInterestRate = float(input ("Enter yearly interest rate, for example, 7.25: ")) # Enter number of years. numberOfYears = int(input( "Enter number of years as an integer: ")) # Enter loan amount. loanAmount = float(input( "Enter loan amount, for example, 120000.95: ")) # Enter a borrower. borrower = input("Enter a borrower's name: ") # Enter reason. reason = input("Enter a reason for the loan: ") # Create a Loan object. loan = Loan(annualInterestRate, numberOfYears, loanAmount, borrower, reason) # Display loan date, monthly payment, and total payment. print("The borrower is", loan.getBorrower(), "for", loan.getReason()) print("The monthly payment is", format( loan.getMonthlyPayment(), '.2f')) print("The total payment is", format( loan.getTotalPayment(), '.2f'))
def _populate_db(self): """Add mocked data to database""" user_1 = User(name='FirstName', surname="FirstSurname") user_2 = User(name='SecondName', surname="SecondName") loan_1 = Loan(balance=56, currency='GBP') report_1 = Report( body='body1', loan=loan_1, title='TitleReport1', user=user_1, ) report_2 = Report(user=user_2, title='TitleReport2') db.session.add(report_1) db.session.add(report_2) db.session.commit()
def test008_loan(self): L = Loan(self.D, '18252023049', 'cjs123456') L.loan(u'善楼贷', u'等额本息', '6', '20000', u'扩大经营')
def getLoan(self, user): from Loan import Loan loan = Loan.objects(movie=self, user=user).first() return loan
def compute_impacts(self): # setup a loan portfolio # loan_portfolio = LoanPortfolio() # loan with all contributions (mi)_all # loan_all = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment + sum(self.contributions)) loan_all.check_loan_parameters() loan_all.compute_schedule() # loan with no contributions (mi)_0 # loan_none = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment) loan_none.check_loan_parameters() loan_none.compute_schedule() micro_impact_interest_paid_all = \ (loan_none.total_interest_paid - loan_all.total_interest_paid) / loan_all.total_interest_paid micro_impact_duration_all = -\ (loan_none.time_to_loan_termination - loan_all.time_to_loan_termination) / loan_all.time_to_loan_termination # micro_impact_interest_paid_all = loan_none.total_interest_paid / loan_all.total_interest_paid # micro_impact_duration_all = loan_none.time_to_loan_termination / loan_all.time_to_loan_termination # print(f'\nIndex\tInterestPaid\tDuration\tMIInterest\tMIDuration') # print(f'ALL\t', # round(loan_all.total_interest_paid, 2), f'\t\t', loan_all.time_to_loan_termination) # print(f'0\t', # round(loan_none.total_interest_paid, 2), f'\t\t', loan_none.time_to_loan_termination, f'\t\t', # round(micro_impact_interest_paid_all, 4), f'\t\t', round(micro_impact_duration_all, 4)) df = pd.DataFrame(columns=[ 'Index', 'InterestPaid', 'Duration', 'MIInterest', 'MIDuration' ]) list = [ 'ALL', round(loan_all.total_interest_paid, 2), loan_all.time_to_loan_termination, None, None ] df.loc[len(df)] = list list = [ 0, round(loan_none.total_interest_paid, 2), loan_none.time_to_loan_termination, round(micro_impact_interest_paid_all, 4), round(micro_impact_duration_all, 4) ] df.loc[len(df)] = list i = 2 # iterate over each contribution (mi)_index # for index, contribution in enumerate(self.contributions): loan_index = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment + sum(self.contributions) - contribution) loan_index.check_loan_parameters() loan_index.compute_schedule() micro_impact_interest_paid = \ (loan_index.total_interest_paid - loan_all.total_interest_paid) / loan_all.total_interest_paid micro_impact_duration = \ (loan_index.time_to_loan_termination - loan_all.time_to_loan_termination) / loan_all.time_to_loan_termination # micro_impact_interest_paid = loan.total_interest_paid / loan_all.total_interest_paid # micro_impact_duration = loan.time_to_loan_termination / loan_all.time_to_loan_termination # print(index+1, f'\t', # round(loan_index.total_interest_paid, 2), f'\t\t', loan_index.time_to_loan_termination, f'\t\t', # round(micro_impact_interest_paid, 4), f'\t\t', round(micro_impact_duration, 4)) list = [ i - 1, round(loan_index.total_interest_paid, 2), loan_index.time_to_loan_termination, round(micro_impact_interest_paid, 4), round(micro_impact_duration, 4) ] df.loc[len(df)] = list i += 1 df = df.reset_index(drop=True) return df
def compute_impacts(self): # setup a loan portfolio # loan_portfolio = LoanPortfolio() # loan with all contributions (mi)_all # loan_all = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment + sum(self.contributions)) loan_all.check_loan_parameters() loan_all.compute_schedule() # loan with no contributions (mi)_0 # loan_none = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment) loan_none.check_loan_parameters() loan_none.compute_schedule() micro_impact_interest_paid_all = \ (loan_none.total_interest_paid - loan_all.total_interest_paid) / loan_all.total_interest_paid micro_impact_duration_all = -\ (loan_none.time_to_loan_termination - loan_all.time_to_loan_termination) / loan_all.time_to_loan_termination # micro_impact_interest_paid_all = loan_none.total_interest_paid / loan_all.total_interest_paid # micro_impact_duration_all = loan_none.time_to_loan_termination / loan_all.time_to_loan_termination self.results.append(['Index','InterestPaid','Duration','MIInterest','MIDuration']) self.results.append(['All', round(loan_all.total_interest_paid, 2), loan_all.time_to_loan_termination, None, None ]) self.results.append(['0', round(loan_none.total_interest_paid, 2), loan_none.time_to_loan_termination, round(micro_impact_interest_paid_all, 4), round(micro_impact_duration_all, 4) ]) # iterate over each contribution (mi)_index # for index, contribution in enumerate(self.contributions): loan_index = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment + sum(self.contributions) - contribution) loan_index.check_loan_parameters() loan_index.compute_schedule() micro_impact_interest_paid = \ (loan_index.total_interest_paid - loan_all.total_interest_paid) / loan_all.total_interest_paid micro_impact_duration = \ (loan_index.time_to_loan_termination - loan_all.time_to_loan_termination) / loan_all.time_to_loan_termination # micro_impact_interest_paid = loan.total_interest_paid / loan_all.total_interest_paid # micro_impact_duration = loan.time_to_loan_termination / loan_all.time_to_loan_termination self.results.append([str(index+1), round(loan_index.total_interest_paid, 2), loan_index.time_to_loan_termination, round(micro_impact_interest_paid, 4), round(micro_impact_duration, 4) ])
from Loan import Loan from PaymentSchedules import Standard_Repayment from PaymentSchedules import Extended_Repayment from PaymentSchedules import Graduated_Repayment from PaymentSchedules import ICR l = Loan() p = ICR(l, income=60000) total_payment_count = l.loan_length * p.payment_frequency stepsize = 1 medschool = 12 * 4 #months of forebearance l.CalculateInterest(period=12 * 4) l.Capitalization() #residency starts p.ChangeIncomeLevel(60000) while l.debt_timestep < total_payment_count: if l.debt_timestep == 12.0 * 6: p.ChangeIncomeLevel(200000) l.CalculateInterest(period=stepsize) payment = p.CurrentPayment(l) l.MakePayment(payment=payment)
def main(): l = Loan() l.setBorrower("스니") print("borrower is ", l.getBorrower())
def compute_impacts(self): table = "" dict = {} # setup a loan portfolio # loan_portfolio = LoanPortfolio() # loan with all contributions (mi)_all # loan_all = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment + sum(self.contributions)) loan_all.check_loan_parameters() loan_all.compute_schedule() # loan with no contributions (mi)_0 # loan_none = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment) loan_none.check_loan_parameters() loan_none.compute_schedule() micro_impact_interest_paid_all = \ (loan_none.total_interest_paid - loan_all.total_interest_paid) / loan_all.total_interest_paid micro_impact_duration_all = -\ (loan_none.time_to_loan_termination - loan_all.time_to_loan_termination) / loan_all.time_to_loan_termination # micro_impact_interest_paid_all = loan_none.total_interest_paid / loan_all.total_interest_paid # micro_impact_duration_all = loan_none.time_to_loan_termination / loan_all.time_to_loan_termination table += '\nIndex\tInterestPaid\tDuration\tMIInterest\tMIDuration' table += '\nALL \t\t' + str(round( loan_all.total_interest_paid, 2)) + '\t\t' + str( loan_all.time_to_loan_termination) table += '\n0\t\t\t' + str(round( loan_none.total_interest_paid, 2)) + '\t\t' + str( loan_none.time_to_loan_termination) table += '\t\t' + str(round(micro_impact_interest_paid_all, 4)) + '\t' + str( round(micro_impact_duration_all, 4)) dict["All"] = ("All", round(loan_all.total_interest_paid, 2), loan_all.time_to_loan_termination, "", "") dict[0] = (0, round(loan_all.total_interest_paid, 2), loan_all.time_to_loan_termination, round(micro_impact_interest_paid_all, 4), round(micro_impact_duration_all, 4)) # iterate over each contribution (mi)_index # for index, contribution in enumerate(self.contributions): loan_index = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment + sum(self.contributions) - contribution) loan_index.check_loan_parameters() loan_index.compute_schedule() micro_impact_interest_paid = \ (loan_index.total_interest_paid - loan_all.total_interest_paid) / loan_all.total_interest_paid micro_impact_duration = \ (loan_index.time_to_loan_termination - loan_all.time_to_loan_termination) / loan_all.time_to_loan_termination # micro_impact_interest_paid = loan.total_interest_paid / loan_all.total_interest_paid # micro_impact_duration = loan.time_to_loan_termination / loan_all.time_to_loan_termination table += '\n' + str(index + 1) + '\t\t\t' + str( round(loan_index.total_interest_paid, 2)) + '\t\t' + str( loan_index.time_to_loan_termination) table += '\t\t' + str(round(micro_impact_interest_paid, 4)) + '\t' + str( round(micro_impact_duration, 4)) dict[index + 1] = (index + 1, round(loan_index.total_interest_paid, 2), loan_index.time_to_loan_termination, round(micro_impact_interest_paid, 4), round(micro_impact_duration, 4)) print(table) print("111") return (dict)
def compute_impacts(self): # setup a loan portfolio # loan_portfolio = LoanPortfolio() # loan with all contributions (mi)_all # loan_all = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment + sum(self.contributions)) loan_all.check_loan_parameters() loan_all.compute_schedule() # loan with no contributions (mi)_0 # loan_none = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment) loan_none.check_loan_parameters() loan_none.compute_schedule() micro_impact_interest_paid_all = \ (loan_none.total_interest_paid - loan_all.total_interest_paid) / loan_all.total_interest_paid micro_impact_duration_all = -\ (loan_none.time_to_loan_termination - loan_all.time_to_loan_termination) / loan_all.time_to_loan_termination # micro_impact_interest_paid_all = loan_none.total_interest_paid / loan_all.total_interest_paid # micro_impact_duration_all = loan_none.time_to_loan_termination / loan_all.time_to_loan_termination print(f'\nIndex\tInterestPaid\tDuration\tMIInterest\tMIDuration') print(f'ALL \t\t', round(loan_all.total_interest_paid, 2), f'\t\t', loan_all.time_to_loan_termination) print(f'0\t\t\t', round(loan_none.total_interest_paid, 2), f'\t\t', loan_none.time_to_loan_termination, f'\t\t', round(micro_impact_interest_paid_all, 4), f'\t', round(micro_impact_duration_all, 4)) # iterate over each contribution (mi)_index # #res = ['Index', 'InterestPaid', 'Duration', 'MIInterest', 'MIDuration'] res = [[0, round(loan_none.total_interest_paid, 2), loan_none.time_to_loan_termination, round(micro_impact_interest_paid_all, 4), round(micro_impact_duration_all, 4)]] for index, contribution in enumerate(self.contributions): loan_index = Loan(principal=self.principal, rate=self.rate, payment=self.payment, extra_payment=self.extra_payment + sum(self.contributions) - contribution) loan_index.check_loan_parameters() loan_index.compute_schedule() micro_impact_interest_paid = \ (loan_index.total_interest_paid - loan_all.total_interest_paid) / loan_all.total_interest_paid micro_impact_duration = \ (loan_index.time_to_loan_termination - loan_all.time_to_loan_termination) / loan_all.time_to_loan_termination # micro_impact_interest_paid = loan.total_interest_paid / loan_all.total_interest_paid # micro_impact_duration = loan.time_to_loan_termination / loan_all.time_to_loan_termination print(index+1, f'\t\t\t', round(loan_index.total_interest_paid, 2), f'\t\t', loan_index.time_to_loan_termination, f'\t\t', round(micro_impact_interest_paid, 4), f'\t', round(micro_impact_duration, 4)) res.append([index+1, round(loan_index.total_interest_paid, 2), loan_index.time_to_loan_termination, round(micro_impact_interest_paid, 4), round(micro_impact_duration, 4)]) return res
def setUp(self): self.loan1 = Loan(TestLoan.bal1, TestLoan.rate1, TestLoan.num1, 0) self.loan1.computeMonthlyPayment() self.loan2 = Loan(TestLoan.bal2, TestLoan.rate2, TestLoan.num2, 0) self.loan2.computeMonthlyPayment()
class TestLoan(unittest.TestCase): # one set of loan parameters bal1 = 1200 rate1 = .12 num1 = 12 pmt1 = 106.61854641401 bal1_6 = 717.350320703218 bal1_11 = 210.080657084758 bal1_16 = -323.064857489090 int1_6 = 7.17350320703218 int1_11 = 2.10080657084758 int1_16 = -3.23064857489090 bal2 = 5000 rate2 = .24 num2 = 15 pmt2 = 389.12736125122 bal2_6 = 3495.369600693820 bal2_11 = 1834.136060908720 bal2_15 = 381.497412991396 int2_6 = 69.90739201387640 int2_11 = 36.68272121817440 int2_15 = 7.62994825982792 def setUp(self): self.loan1 = Loan(TestLoan.bal1, TestLoan.rate1, TestLoan.num1, 0) self.loan1.computeMonthlyPayment() self.loan2 = Loan(TestLoan.bal2, TestLoan.rate2, TestLoan.num2, 0) self.loan2.computeMonthlyPayment() def test_1_monthly_payment(self): self.assertAlmostEqual(self.loan1.monthlyPayment, TestLoan.pmt1) def test_1_remaining_balance(self): self.assertAlmostEqual(self.loan1.remainingBalance(11), TestLoan.bal1_11) self.assertAlmostEqual(self.loan1.remainingBalance(6), TestLoan.bal1_6) self.assertAlmostEqual(self.loan1.remainingBalance(16), TestLoan.bal1_16) def test_1_interest_accrued(self): self.assertAlmostEqual(self.loan1.interestAccrued(6), TestLoan.int1_6) self.assertAlmostEqual(self.loan1.interestAccrued(16), TestLoan.int1_16) self.assertAlmostEqual(self.loan1.interestAccrued(11), TestLoan.int1_11) def test_2_monthly_payment(self): self.assertAlmostEqual(self.loan1.monthlyPayment, TestLoan.pmt1) def test_2_remaining_balance(self): self.assertAlmostEqual(self.loan2.remainingBalance(11), TestLoan.bal2_11) self.assertAlmostEqual(self.loan2.remainingBalance(6), TestLoan.bal2_6) self.assertAlmostEqual(self.loan2.remainingBalance(15), TestLoan.bal2_15) def test_2_interest_accrued(self): self.assertAlmostEqual(self.loan2.interestAccrued(6), TestLoan.int2_6) self.assertAlmostEqual(self.loan2.interestAccrued(15), TestLoan.int2_15) self.assertAlmostEqual(self.loan2.interestAccrued(11), TestLoan.int2_11)