-
Notifications
You must be signed in to change notification settings - Fork 0
/
home_based_on_budget.py
65 lines (41 loc) · 2.29 KB
/
home_based_on_budget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from decimal import Decimal
from currency_format import currency_format
def home_based_on_budget(monthly_budget, interest_rate, loan_term, down_payment, monthly_home_utilities, monthly_renters_insurance, monthly_avg_repair_and_maintenance):
# Variables
"""
monthly_budget
down_payment
interest_rate
loan_term
monthly_insurance_cost
monthly_utility_cost
property_tax_rate
mortgage_rate = (home_price - down_payment) * (numerator / denominator)
# Adjustment to add in property tax to the calculation
mon_bug - (home_price*property_tax)/12 = (home_price - down_payment) * (numerator / denominator)
mon_bug - (home_price*property_tax)/12 = (home_price) * (numerator / denominator) - down_payment * (numerator / denominator)
mon_bug + down_payment * (numerator / denominator) = (home_price) * (numerator / denominator) + (home_price*property_tax)/12
mon_bug + [down_payment * (numerator / denominator)] = (home_price) * ( (numerator / denominator) + property_tax)/12 )
home_price = [ mon_bug + [down_payment * (numerator / denominator)] ] / ( (numerator / denominator) + property_tax)/12 )
"""
# First version
# Calculate how much you'd have left for your mortgage rate
mortgage_rate = monthly_budget - monthly_home_utilities - monthly_renters_insurance
# Re-used from earlier mortgage rate calc but reversed here.
numerator = (interest_rate/1200)*((1+(interest_rate/1200))**(12*loan_term))
denominator = ((1+(interest_rate/1200))**(12*loan_term)) - 1
home_price = mortgage_rate * (denominator/numerator) + down_payment
# Better version
"""
mon_bug = monthly_budget - monthly_home_utilities - monthly_renters_insurance
numerator = (interest_rate/1200)*((1+(interest_rate/1200))**(12*loan_term))
denominator = ((1+(interest_rate/1200))**(12*loan_term)) - 1
nd = numerator / denominator
# property tax rate assumed at 3.6% aka 0.036
home_price = (mon_bug + (down_payment * nd)) / (nd + (0.036/12))
"""
mb_str = currency_format(monthly_budget)
hp_str = currency_format(home_price)
print()
print(f"Based on a monthly budget of {mb_str} you could afford a house worth {hp_str} given your other provided parameters.")
return home_price