forked from jamesbrownlow/class-object-for-loans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloanModify
52 lines (41 loc) · 1.35 KB
/
loanModify
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
class loan(object):
def __init__(self, name):
self._name = name
def who(self):
print(self._name)
def setPV(self, PV):
self._PV = PV
print('present value = ', self._PV)
def setRate(self, ratePct):
# set interest, apr
self._ratePct = ratePct
print('APR = ', self._ratePct, '%')
def setMonths(self, months):
self._months = months
print(self._months, 'months')
def computePmt(self):
# formula: pmt = PV*(r*(1+r)**n)/((1+r)**months -1)
r = self._ratePct / 100 / 12
self._Pmt = self._PV * (r * (1 + r) ** self._months) / ((1 + r) ** self._months - 1)
print('payment = $', round(self._Pmt, 2))
return self._Pmt
def setPmt(self, Pmt):
self._Pmt = Pmt
print("Set the payment to {}".format(round(self._Pmt, 2)))
def computePV(self):
r = self._ratePct / 100 / 12
self._PV = self._Pmt / r * (1 - (1 - r) ** (-self._months))
print("Max loan = ${}".format(-round(self._PV, 2)))
if __name__ == "__main__":
loan1 = loan('Dr J')
loan1.who()
loan1.setPV(27150) # mini cooper
loan1.setRate(1.9)
loan1.setMonths(42)
payment = loan1.computePmt()
loan2 = loan("Frank")
loan2.who()
loan2.setRate(4.4)
loan2.setMonths(48)
loan2.setPmt(399)
loan2.computePV()