3 from money import money
6 """A class to represent tax brackets and some operations on them."""
8 def __init__(self, brackets):
9 self.brackets = copy.deepcopy(brackets)
11 def compute_taxes_for_income(self, income):
12 """Compute the tax bill for income given our brackets."""
15 (threshold, rate) = self.get_bracket_for_income(income)
16 taxes_due += (income - threshold) * rate
18 assert taxes_due >= 0, "Somehow computed negative tax bill?!"
21 def get_bracket_for_income(self, income):
22 """Return the bracket that the last dollar of income was in."""
23 assert income > 0, "Income should be >0 to be taxed"
26 for bracket in self.brackets:
27 # Bracket is a tuple of (monetary_threshold,
28 # tax_rate). So bracket[0] is a dollar amount and
29 # bracket[1] is a tax rate. e.g. ( 250000, 0.20 )
30 # indicates that every dollar you earn over 250K is
32 if (income > bracket[0] and rate < bracket[1]):
33 threshold = bracket[0]
35 return (threshold, rate)
37 def get_bracket_above_income(self, income):
38 """Return the next bracket above the one activated by income."""
39 assert income > 0, "Income should be >0 to be taxed"
43 # Walk the income tax brackets and look for the one just above
44 # the one this year's income is activating.
45 for bracket in self.brackets:
46 if (bracket[0] > income and bracket[1] < rate):
47 threshold = bracket[0]
50 # Note: this can return (None, 1.0) iff the income is already
51 # in the top tax bracket.
52 return (threshold, rate)
54 def get_bracket_below_income(self, income):
55 """Return the next bracket below the one activated by income."""
56 assert income > 0, "Income should be >0 to be taxed"
57 bracket = self.get_bracket_for_income(income)
59 return self.get_bracket_for_income(income)
61 def get_effective_tax_rate_for_income(self, income):
62 """Compute and return the effective tax rate for an income."""
63 if income <= 0: return 0
64 tax_bill = self.compute_taxes_for_income(income)
65 return float(tax_bill) / income
67 def adjust_with_multiplier(self, multiplier):
68 """Every year the IRS adjusts the income tax brackets for inflation."""
69 for bracket in self.brackets:
71 bracket[0] *= multiplier
74 """Print out the tax brackets we're using in here."""
75 for x in self.brackets:
76 print "{:<20} -> {:<3}".format(x[0], utils.format_rate(x[1]))