Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import argparse
- from datetime import datetime, timedelta
- parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
- parser.add_argument(
- "-p", "--principle",
- default=10_000,
- type=int,
- help='The starting principal amount in dollars',
- )
- parser.add_argument(
- "-r", "--rate",
- default=15,
- type=int,
- help='The annual interest rate in percent',
- )
- parser.add_argument(
- "-c", "--annual-contribution",
- default=20_000,
- type=int,
- help='The annual contribution rate in dollars',
- )
- parser.add_argument(
- "-C", "--contribution-increase-rate",
- default=3,
- type=int,
- help='The rate at which the annual contribution rate increases in percent',
- )
- parser.add_argument(
- "-f", "--front-load-to-month",
- default=12,
- type=int,
- help='Front load to month',
- )
- parser.add_argument(
- "-y", "--years",
- default=20,
- type=int,
- help='How many years to render out to',
- )
- parser.add_argument(
- "-l", "--cost-of-living",
- default=60_000,
- type=int,
- help='The current cost of living in dollars',
- )
- parser.add_argument(
- "-L", "--cost-of-living-increase-rate",
- default=2,
- type=int,
- help='The cost of living annual increase rate in percent',
- )
- parser.add_argument(
- "-i", "--cost-of-living-retire-ratio",
- default=4,
- type=int,
- help='Used to find the point at which to retire: interest_income > cost of living * cost of living retire ratio',
- )
- args = parser.parse_args()
- principle = args.principle
- annual_contribution = args.annual_contribution
- rate = args.rate
- front_load_to_month = args.front_load_to_month
- years = args.years
- contribution_increase_rate = args.contribution_increase_rate
- cost_of_living = args.cost_of_living
- cost_of_living_increase_rate = args.cost_of_living_increase_rate
- rate = (rate / 100) / 12 #reduce APR to MPR
- months = 12 * years
- results = []
- now = datetime.now()
- def date_gen(number_of_months):
- for month in range(1, number_of_months + 1):
- yield now + timedelta(days=round(month*365.25/12))
- total_contribution = principle
- total_interest = 0
- total_draw = 0
- for t in date_gen(months):
- current_month = round((t - now).days / 365.25 * 12)
- initial_principle = principle
- principle = principle*(1-rate**(current_month+1))/(1-rate) #expression for generating interest
- interest_income = principle - initial_principle
- total_interest += interest_income
- cost_of_living *= cost_of_living_increase_rate / 12 / 100 + 1
- # If retired
- if interest_income > cost_of_living / 12 * args.cost_of_living_retire_ratio:
- principle -= cost_of_living / 12
- total_draw += cost_of_living / 12
- # Elif making a contribution this month
- elif (current_month - 1) % 12 in range(front_load_to_month):
- contribution = annual_contribution / front_load_to_month
- total_contribution += contribution
- principle += contribution
- if current_month % 12 == 0:
- annual_contribution *= contribution_increase_rate / 100 + 1
- print("year {}, balance: {:,} total_contribution: {:,} total_interest: {:,} total_draw: {:,}".format(
- t.year,
- int(principle),
- int(total_contribution),
- int(total_interest),
- int(total_draw),
- ))
Add Comment
Please, Sign In to add comment