-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHDB_Loan_Calculator_2.py
145 lines (113 loc) · 5.28 KB
/
HDB_Loan_Calculator_2.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Coded by MJ. LI from Singapore Polytechnic (D.EEE), Royal Melbourne Institute of Tech (B.BUS MGMT) #
# Buy me a coffee? Send $USDT to ERC20 @ 0x250870A148EAbcE8F1C5AC4D55E48983f73fFb77 #
# DO NOT CHANGE THIS COMMENT, YOUR COFFEE FUNDS ARE APPRECIATED, THANK YOU. #
import time
import sys
def progressbar(it, prefix="", size=60, out=sys.stdout):
count = len(it)
start = time.time() # time estimate start
def show(j):
x = int(size*j/count)
# time estimate calculation and string
remaining = ((time.time() - start) / j) * (count - j)
mins, sec = divmod(remaining, 60) # limited to minutes
time_str = f"{int(mins):02}:{sec:03.1f}"
print(f"{prefix}[{u'█'*x}{('.'*(size-x))}] {j}/{count} Est wait {time_str}", end='\r', file=out, flush=True)
show(0.1) # avoid div/0
for i, item in enumerate(it):
yield item
show(i+1)
print("\n", flush=True, file=out)
print(f"> Welcome to HDB Public housing payment structure calculator done by MJ. LI")
calculator = 0
while calculator == 0:
print(f"> What is your monthly individual/spouse combined income before CPF deduction?" )
mth_income = float(input(">$"))
print(f" ")
if mth_income > 14000:
print(f"> You are not eligible for public housing due to EXCEEDING the INCOME CEILING" )
print(f"")
print(f"> Do you want to recalculate? 'yes' or 'no'")
recalculate = input(">").lower()
print(f" ")
if recalculate == "yes":
continue
elif recalculate == "no":
break
else:
print(f"> What is the price of the property?")
t_property_cost = float(input(">$"))
print(f" ")
print(f"> How many years of installment are you going to take?")
years = float(input(">"))
print(f" ")
print(f"> Which loan are you going to take? HDB or bank? reply with 'hdb' or 'bank'")
interest_type = str(input(">").lower())
print(f" ")
if interest_type == "hdb":
interest_rate = float(2.6)
elif interest_type == "bank":
print(f"> What was the interest rate % quoted from the Banks?")
interest_rate = float(input(">"))
print(f" ")
t_months = 12 * years
max_loan = float(mth_income * 0.3 * t_months)
t_down_payment = float(t_property_cost * 0.2)
principal_loan = float(t_property_cost - t_down_payment)
if max_loan < principal_loan:
t_downpayment = float((principal_loan - max_loan) + t_down_payment)
else:
t_downpayment = float(t_down_payment)
cash_payment = float(t_downpayment * 0.25)
cpf_payment = float(t_downpayment * 0.75)
principal = float(t_property_cost-t_downpayment)
m_installment = float(principal_loan*(1+(interest_rate/100))**years / (12*years))
m_cpf = float(0.2 * mth_income)
m_deducted_cash = round(m_installment - m_cpf, 2)
if m_deducted_cash < 0:
m_cpf = round(m_installment + m_deducted_cash, 2)
m_deducted_cash = 0
if mth_income < m_installment:
m_deducted_cash = 0
t_down_payment = round(t_down_payment + principal_loan - m_cpf * 12 * years, 2)
elif mth_income > m_installment:
print(f"> Would you be willing to cover the remaining monthly mortgage OUT-OF-POCKET? 'yes' or 'no'?")
pocket = input(">").lower()
if pocket == "no":
m_deducted_cash = 0
t_down_payment = t_down_payment + principal_loan - m_cpf * 12 * years
elif pocket == "yes":
m_deducted_cash = m_deducted_cash
print(f" ")
for i in progressbar(range(100), "Calculating: ", 40):
time.sleep(0.01)
print(f"> Your complete down payment WITHOUT utilizing CPF Savings: ")
print(f"> ${t_down_payment}/-")
print(f" ")
for i in progressbar(range(100), "Calculating: ", 40):
time.sleep(0.01)
print(f"> If using CPF Savings partially for the down payment, cash payment reduced to 5%: ")
print(f"> ${cash_payment}/-")
print(f" ")
print(f"> The outstanding 15% down payment payable using CPF Savings: ")
print(f"> ${cpf_payment}/-")
print(f" ")
for i in progressbar(range(100), "Calculating: ", 40):
time.sleep(0.01)
print(f"> Your monthly CPF Savings deduction for the next {years} years:")
print(f"> ${m_cpf}/-")
print(f" ")
print(f"> Your monthly OUT-OF-POCKET expenses for the next {years} years: ")
print(f"> ${m_deducted_cash}/-")
print(f" ")
leftover_cash = round(mth_income - m_deducted_cash - m_cpf, 2)
print(f"> Your surplus in bank account each month after covering your HDB mortgage from your income: ")
print(f"> ${leftover_cash}/-")
print(f" ")
print(f"> Do you want to recalculate? 'yes' or 'no' ")
recalculate = input(">").lower()
print(f" ")
if recalculate == "yes":
continue
elif recalculate == "no":
break