Guest User

Untitled

a guest
Apr 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import argparse
  3. from datetime import datetime, timedelta
  4.  
  5.  
  6. parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  7. parser.add_argument(
  8. "-p", "--principle",
  9. default=10_000,
  10. type=int,
  11. help='The starting principal amount in dollars',
  12. )
  13. parser.add_argument(
  14. "-r", "--rate",
  15. default=15,
  16. type=int,
  17. help='The annual interest rate in percent',
  18. )
  19. parser.add_argument(
  20. "-c", "--annual-contribution",
  21. default=20_000,
  22. type=int,
  23. help='The annual contribution rate in dollars',
  24. )
  25. parser.add_argument(
  26. "-C", "--contribution-increase-rate",
  27. default=3,
  28. type=int,
  29. help='The rate at which the annual contribution rate increases in percent',
  30. )
  31. parser.add_argument(
  32. "-f", "--front-load-to-month",
  33. default=12,
  34. type=int,
  35. help='Front load to month',
  36. )
  37. parser.add_argument(
  38. "-y", "--years",
  39. default=20,
  40. type=int,
  41. help='How many years to render out to',
  42. )
  43. parser.add_argument(
  44. "-l", "--cost-of-living",
  45. default=60_000,
  46. type=int,
  47. help='The current cost of living in dollars',
  48. )
  49. parser.add_argument(
  50. "-L", "--cost-of-living-increase-rate",
  51. default=2,
  52. type=int,
  53. help='The cost of living annual increase rate in percent',
  54. )
  55. parser.add_argument(
  56. "-i", "--cost-of-living-retire-ratio",
  57. default=4,
  58. type=int,
  59. help='Used to find the point at which to retire: interest_income > cost of living * cost of living retire ratio',
  60. )
  61.  
  62. args = parser.parse_args()
  63.  
  64. principle = args.principle
  65. annual_contribution = args.annual_contribution
  66. rate = args.rate
  67. front_load_to_month = args.front_load_to_month
  68. years = args.years
  69. contribution_increase_rate = args.contribution_increase_rate
  70. cost_of_living = args.cost_of_living
  71. cost_of_living_increase_rate = args.cost_of_living_increase_rate
  72.  
  73. rate = (rate / 100) / 12 #reduce APR to MPR
  74. months = 12 * years
  75.  
  76. results = []
  77. now = datetime.now()
  78.  
  79. def date_gen(number_of_months):
  80. for month in range(1, number_of_months + 1):
  81. yield now + timedelta(days=round(month*365.25/12))
  82.  
  83.  
  84. total_contribution = principle
  85. total_interest = 0
  86. total_draw = 0
  87.  
  88. for t in date_gen(months):
  89. current_month = round((t - now).days / 365.25 * 12)
  90.  
  91. initial_principle = principle
  92. principle = principle*(1-rate**(current_month+1))/(1-rate) #expression for generating interest
  93. interest_income = principle - initial_principle
  94. total_interest += interest_income
  95. cost_of_living *= cost_of_living_increase_rate / 12 / 100 + 1
  96. # If retired
  97. if interest_income > cost_of_living / 12 * args.cost_of_living_retire_ratio:
  98. principle -= cost_of_living / 12
  99. total_draw += cost_of_living / 12
  100. # Elif making a contribution this month
  101. elif (current_month - 1) % 12 in range(front_load_to_month):
  102. contribution = annual_contribution / front_load_to_month
  103. total_contribution += contribution
  104. principle += contribution
  105.  
  106. if current_month % 12 == 0:
  107. annual_contribution *= contribution_increase_rate / 100 + 1
  108. print("year {}, balance: {:,} total_contribution: {:,} total_interest: {:,} total_draw: {:,}".format(
  109. t.year,
  110. int(principle),
  111. int(total_contribution),
  112. int(total_interest),
  113. int(total_draw),
  114. ))
Add Comment
Please, Sign In to add comment