def search(hvalue, periods, rate, desiredpay): # Define a new Bisection search function # Start with an interval that we know contains a solution a = 0 # Set one side of the interval as a = 0 b = hvalue # Set the other side of the interval as b = hvalue # "hvalue equals to the home price, which is upper bound of down payment" while True: # Start the loop import mortgage # Import the mortgage module c = (a + b) / 2 # Bisect the interval dpayment = c # Define dpayment (down payment) loan = hvalue - dpayment # Define loan Fc = mortgage.mortgage_payment(loan, periods, rate) - desiredpay # Calculate F(c) to determine which side of the origin interval contains the solution if abs(Fc) < 0.000001: return dpayment # If F(c) is infinately close to zero, the search is finished # Return c, which is also the down payment, as the result of the function elif Fc < 0: # If F(c) is below 0, then the solution is in the left side of the interval b = c # Replace b with c and continue else: # If F(c) is above 0, then the solution is in the right side of the interval a = c # Replace a with c and continue
import math, mortgage home = float(input('Home price: ')) mindown = int(input('Minimum down payment: ')) maxdown = int(input('Maximum down payment: ')) interest = float(input('Interest rate: ')) term = float(input('Loan term (years): ')) periods = term * 12 rate = interest / 100 / 12 for down in range(mindown, maxdown, 1000): loan = home - float(down) monthly = mortgage.mortgage_payment(loan, periods, rate) print(str(down) + " " + str(round(monthly, 2)))
#Creating input functions home_value = float(input("Home Value: ")) min_down_payment = int(input("Minimum Downpayment: ")) max_down_payment = int(input("Maximum Downpayment: ")) term = float(input("Term in years: ")) interest_rate = float(input("Interest Rate: ")) #Calculating loan amount for down_payment in range(min_down_payment, max_down_payment, 1000): def loan(home_value, down_payment): return(home_value - down_payment) l = float(loan(home_value, down_payment)) #Calculating monthly periods def monthly_period(term): return(term*12) p = float(monthly_period(term)) #Calculating monthly interest rate def monthly_rate(interest_rate): return((interest_rate/100)/12) r = float(monthly_rate(interest_rate)) #Calculating morgtage values m = mortgage.mortgage_payment(l, p, r) m = round(m, 2) print (down_payment, m) #end
return(term*12) p = float(monthly_period(term)) #Calculating monthly interest rate def monthly_rate(interest_rate): return((interest_rate/100)/12) r = float(monthly_rate(interest_rate)) #Setting the range for down_payment min_down_payment = 0 max_down_payment = home_value #Running a bisection function to find the value of the Downpayment while True: d = (min_down_payment + max_down_payment)/2 Fl = mortgage.mortgage_payment(home_value - d, p, r) if abs(Fl - d_monthly_payment) < 1: break elif Fl < d_monthly_payment: #print("max is reduced") max_down_payment = d else: #print("min is increased") min_down_payment = d print("Downpayment: ", round(d, 2)) #end
#Importing all modules import mortgage #Creating input functions home_value = float(input("Home Value: ")) down_payment = float(input("Downpayment: ")) term = float(input("Term in years: ")) interest_rate = float(input("Interest Rate: ")) #Calculating loan amount def loan(home_value, down_payment): return(home_value - down_payment) l = float(loan(home_value, down_payment)) #Calculating monthly periods def monthly_period(term): return(term*12) p = float(monthly_period(term)) #Calculating monthly interest rate def monthly_rate(interest_rate): return((interest_rate/100)/12) r = float(monthly_rate(interest_rate)) #Calculating mortgage payment m = float(mortgage.mortgage_payment(l, p, r)) final_mortgage_payment = round(m, 2) print("Monthly payment: ", final_mortgage_payment) #end
import math, mortgage home = float(input('Home price: ')) interest = float(input('Interest rate: ')) term = float(input('Loan term (years): ')) monthlygoal = float(input('Desired monthly payment: ')) loanhi = home loanlo = 0 periods = term * 12 rate = interest / 100 / 12 while True: loan = (loanlo + loanhi) / 2 floan = mortgage.mortgage_payment(loan, periods, rate) - monthlygoal if abs(floan) < 0.01: break elif floan < 0: loanlo = loan else: loanhi = loan down = home - loan print("\nDown payment: " + str(round(down, 2)))