Skip to content

Instantly share code, notes, and snippets.

@suminb
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save suminb/4e42e2b19129f890ab5b to your computer and use it in GitHub Desktop.
Save suminb/4e42e2b19129f890ab5b to your computer and use it in GitHub Desktop.
import inspect
#: Annual percentage rate of your savings account, certificate of deposit, etc.
APR = 0.032
TAX_RATE = 0.154
class Terms:
def __init__(self, deposit, rent, utilities, commute_time, commute_cost):
frame = inspect.currentframe()
args, _, _, values = inspect.getargvalues(frame)
for key in args[1:]:
setattr(self, key, float(values[key]))
@property
def values(self):
return self.deposit, self.rent, self.utilities, self.commute_time, \
self.commute_cost
def annual_costs(deposit, rent, utilities, commute_time, commute_cost):
"""Calculate the annual cost of renting a premises.
:param deposit: Fully refundable deposit
:param rent: Monthly rent
:param utilities: Monthly utility costs
:param commute_time: Commute time in minutes (one way)
:param commute_cost: Commute cost in minutes (one way)
"""
oppt_cost = deposit * APR * (1 - TAX_RATE)
# Assuming you have a full-time job (40 hours/week) and get 15-day paid
# vacations per year, and there are about 25 holidays per year on average.
working_days = (52 * 5) - (15 + 25)
costs = oppt_cost + ((rent + utilities) * 12) \
+ commute_cost * working_days * 2
time = commute_time * working_days * 2
return costs, time / 60.0
def compare(t1, t2):
"""Compare two different rent contracts."""
annual_costs1 = annual_costs(*t1.values)
annual_costs2 = annual_costs(*t2.values)
cost_diff = annual_costs2[0] - annual_costs1[0]
time_diff = annual_costs2[1] - annual_costs1[1]
return cost_diff, time_diff
def make_assessment(t1, t2):
cost_diff, time_diff = compare(t1, t2)
print("You are spending {} to save {} hours annually.".format(
round(cost_diff, 2), round(-time_diff, 2)))
if time_diff >= 0:
print("You're not saving any time at all.")
else:
sufficient_hourly_wage = cost_diff / -time_diff
if sufficient_hourly_wage < 0:
print("This is an absolute win. What are you waiting for?")
else:
print("Unless you are making {} per hour, don't move.".format(
round(sufficient_hourly_wage, 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment