-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMIT-PS4_Retirement.py
74 lines (59 loc) · 2.02 KB
/
MIT-PS4_Retirement.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
#Problem Set 4
#Name: Arko Annuk
#Time: 6:45
#Problem 1
def nestEggFixed (salary, save, growthRate, years):
F = []
firstYear = salary*save*0.01
F.append(firstYear)
while len(F) <years:
nextYear = F[-1]*(1+0.01*growthRate)+salary*save*0.01
F.append(nextYear)
print (F)
#Problem 2
def nestEggVariable(salary,save,growthRates):
#growthRates parameter needs to be defined as a list
savingsRecord=[]
firstYear = salary*save*0.01
savingsRecord.append(firstYear)
del growthRates[0]
for x in growthRates:
nextYear = savingsRecord[-1]*(1+0.01*x)+salary*save*0.01
savingsRecord.append(nextYear)
print (savingsRecord)
#Problem 3
def postRetirement(savings, growthRates, expenses):
savingsRecord=[]
firstYear = savings*(1+0.01*growthRates[0])-expenses
savingsRecord.append(firstYear)
del growthRates[0]
for x in growthRates:
nextYear = savingsRecord[-1]*(1+0.01*x)-expenses
savingsRecord.append(nextYear)
print (savingsRecord)
#Problem 4
def findMaxExpenses(salary, save, preRetireGrowthRates, postRetireGrowthRates, epsilon):\
preSavingsRecord=[]
preFirstYear = salary*save*0.01
preSavingsRecord.append(preFirstYear)
del preRetireGrowthRates[0]
for x in preRetireGrowthRates:
preNextYear = preSavingsRecord[-1]*(1+0.01*x)+salary*save*0.01
preSavingsRecord.append(preNextYear)
print (preSavingsRecord)
savings = preSavingsRecord[-1]
print (savings)
expenses=1000
postSavingsRecord=[]
for expenses in range (salary):
postFirstYear = savings*(1+0.01*postRetireGrowthRates[0])-expenses
postSavingsRecord.append(postFirstYear)
for x in postRetireGrowthRates[1:]:
postNextYear = postSavingsRecord[-1]*(1+0.01*x)-expenses
postSavingsRecord.append(postNextYear)
if postSavingsRecord[-1]<=epsilon:
print (expenses)
break
else:
postSavingsRecord.clear()
expenses=+1