Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- goal = 100000
- in_years = True
- # Help To Buy
- def htb(P=1200, r=0.04, c=200):
- m = 1
- balance = []
- months = []
- while P <= goal:
- if m % 12 == 0:
- gains = (P * r)
- P += gains
- if in_years:
- months.append(m / 12.)
- else:
- months.append(m)
- balance.append(P)
- m += 1
- P += c
- return months, balance
- # Lifetime
- def lft(P=1200, r=0.075, c=4000/12.):
- m = 1
- balance = []
- months = []
- while P <= goal:
- if m % 12 == 0:
- gains = (P * r)
- P += gains
- P += 1000
- if in_years:
- months.append(m / 12.)
- else:
- months.append(m)
- balance.append(P)
- m += 1
- P += c
- return months, balance
- # Calculate
- htb_m, htb_b = htb()
- lft_m, lft_b = lft()
- # Plot
- plt.plot(htb_m, htb_b)
- plt.plot(lft_m, lft_b)
- plt.ylim(0, goal+1000)
- plt.legend(['HelpToBuy ISA', 'Lifetime ISA'])
- plt.ylabel('Balance')
- x_label = 'Years' if in_years else 'Months'
- plt.xlabel(x_label)
- plt.title('Time taken to achieve goal of {}'.format(goal))
- plt.grid()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement