-
Notifications
You must be signed in to change notification settings - Fork 0
/
interest_rate_comp.py
80 lines (64 loc) · 2.8 KB
/
interest_rate_comp.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
import home_functions as hf
from matplotlib import pyplot as plt
def rate_comp_plots(home_price, down_payment, interest_rate, interest_rate2, loan_term):
mortgage_rate = hf.mortgage_rate_calc(home_price, down_payment, interest_rate, loan_term)
mortgage_rate2 = hf.mortgage_rate_calc(home_price, down_payment, interest_rate2, loan_term)
# Follow up Calculations
loan_amount = home_price - down_payment
# Plottable Data
pd1 = hf.plottable_data(loan_amount, interest_rate, loan_term, mortgage_rate)
mip, mpp, mtp, months, mte, mts, mtis = pd1
pd2 = hf.plottable_data(loan_amount, interest_rate2, loan_term, mortgage_rate2)
mip2, mpp2, mtp2, months2, mte2, mts2, mtis2 = pd2
# Years from Months
years = []
for mon in months:
years.append(mon/12)
# Plotting
# Figure 1
plt.figure(figsize=(10,6))
# Subplot 1
plt.subplot(1,2,1)
plt.title("Loan Amount: $" + "{:,}".format(home_price-down_payment) + "\n"
+ "Interest Rate: " + f"{interest_rate:.2f}" + "%\n"
+ "Loan Term: " + f"{loan_term} years")
plt.plot(years, mte, 'b-', label="Cumulative House Equity")
plt.plot(years, mts, 'r-', label="Total Cumulative Payment")
plt.plot(years, mtis, 'g-', label="Total Interest Payment (Sunk Cost)")
plt.xlabel("Years")
# plt.plot(months, mte, 'b-', label="Cumulative House Equity")
# plt.plot(months, mts, 'r-', label="Total Cumulative Payment")
# plt.plot(months, mtis, 'g-', label="Total Interest Payment (Sunk Cost)")
# plt.xlabel("Months")
plt.ylabel("$")
plt.legend()
plt.grid(True)
plt.ylim(0, max(max(mts), max(mts2)) + 200000 )
# Subplot 2
plt.subplot(1,2,2)
plt.title("Loan Amount: $" + "{:,}".format(home_price-down_payment) + "\n"
+ "Interest Rate: " + f"{(interest_rate2):.2f}" + "%\n"
+ "Loan Term: " + f"{loan_term} years")
plt.plot(years, mte2, 'b-', label="Cumulative House Equity")
plt.plot(years, mts2, 'r-', label="Total Cumulative Payment")
plt.plot(years, mtis2, 'g-', label="Total Interest Payment (Sunk Cost)")
plt.xlabel("Years")
# plt.plot(months2, mte2, 'b-', label="Cumulative House Equity")
# plt.plot(months2, mts2, 'r-', label="Total Cumulative Payment")
# plt.plot(months, mtis2, 'g-', label="Total Interest Payment (Sunk Cost)")
# plt.xlabel("Months")
plt.ylabel("$")
plt.legend()
plt.grid(True)
plt.ylim(0, max(max(mts), max(mts2)) + 200000 )
#plt.show()
mip_diff = [abs(m2 - m1) for m1, m2 in zip(mtis,mtis2)]
# Figure 2
plt.figure()
#plt.plot(months/12,(mip_diff))
plt.plot(years,(mip_diff))
#plt.xlabel("Months")
plt.xlabel("Years")
plt.ylabel("Additional Costs ($)")
plt.title("Additional cumulative cost from higher interest rate")
plt.show()