Advertisement
Guest User

ISA Calculator

a guest
Jan 23rd, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2.  
  3. goal = 100000
  4. in_years = True
  5.  
  6. # Help To Buy
  7. def htb(P=1200, r=0.04, c=200):
  8.     m = 1
  9.     balance = []
  10.     months = []
  11.     while P <= goal:
  12.         if m % 12 == 0:
  13.             gains = (P * r)
  14.             P += gains
  15.         if in_years:
  16.             months.append(m / 12.)
  17.         else:
  18.             months.append(m)
  19.         balance.append(P)
  20.         m += 1
  21.         P += c
  22.     return months, balance
  23.  
  24. # Lifetime
  25. def lft(P=1200, r=0.075, c=4000/12.):
  26.     m = 1
  27.     balance = []
  28.     months = []
  29.     while P <= goal:
  30.         if m % 12 == 0:
  31.             gains = (P * r)
  32.             P += gains
  33.             P += 1000
  34.         if in_years:
  35.             months.append(m / 12.)
  36.         else:
  37.             months.append(m)
  38.         balance.append(P)
  39.         m += 1
  40.         P += c
  41.     return months, balance
  42.  
  43. # Calculate
  44. htb_m, htb_b = htb()
  45. lft_m, lft_b = lft()
  46.  
  47. # Plot
  48. plt.plot(htb_m, htb_b)
  49. plt.plot(lft_m, lft_b)
  50. plt.ylim(0, goal+1000)
  51. plt.legend(['HelpToBuy ISA', 'Lifetime ISA'])
  52. plt.ylabel('Balance')
  53. x_label = 'Years' if in_years else 'Months'
  54. plt.xlabel(x_label)
  55. plt.title('Time taken to achieve goal of {}'.format(goal))
  56. plt.grid()
  57. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement