-
Notifications
You must be signed in to change notification settings - Fork 1
/
annual-percentage-yield.py
57 lines (48 loc) · 1.42 KB
/
annual-percentage-yield.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
def calculateBalance(depositedAmount, interestRate, compoundingPeriods):
value = 1 + (interestRate / 100) / compoundingPeriods
interest = 1
while compoundingPeriods > 0:
interest *= value
compoundingPeriods -= 1
return round(depositedAmount * interest, 2)
def calculateAPY(interestRate, compoundingPeriods):
value = 1 + (interestRate / 100) / compoundingPeriods
return pow(value, compoundingPeriods) - 1
banks = [
{
"name": "Standard Chartered Bank",
"interestRate": 4,
"compoundingPeriods": 3
},
{
"name": "Brac Bank",
"interestRate": 3,
"compoundingPeriods": 4
},
{
"name": "City Bank",
"interestRate": 5,
"compoundingPeriods": 6
},
]
MAX_APY = float('-inf')
preferredBank = {}
for bank in banks:
currentAPY = calculateAPY(bank["interestRate"], bank["compoundingPeriods"])
if currentAPY > MAX_APY:
MAX_APY = currentAPY
preferredBank = bank
balance = calculateBalance(1000, preferredBank["interestRate"], preferredBank["compoundingPeriods"])
message = f"The balance ${balance} in {preferredBank['name']} after one year"
print(message)
# APY = [1, 2, 3]
# if APY[0] > APY[1]:
# if APY[0] > APY[2]:
# print(0)
# elif APY[2] > APY[1]:
# print(2)
# elif APY[0] > APY[2]:
# if APY[0] > APY[1]:
# print(0)
# elif APY[1] > APY[2]:
# print(1)