Skip to content

Instantly share code, notes, and snippets.

@fpgaminer
Last active September 12, 2021 21:07
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fpgaminer/d64b7a933d1d551d9f4c4b8c0869cd61 to your computer and use it in GitHub Desktop.
Save fpgaminer/d64b7a933d1d551d9f4c4b8c0869cd61 to your computer and use it in GitHub Desktop.
import sys
# The way this worksheet seems to work is:
# A = taxes you would pay if it was just income
# B = calculate taxes on capital gains, using the capital gains tax rate schedule, BUT skip the first X dollars of the rate schedule, where X is your income
# total taxes = A + B
def income_tax (amt):
taxes = 0.0
lower_end = 0
brackets = [[18650, .1], [74900, .15], [153100, .25], [233350, .28], [416700, .33]]
for bracket in brackets:
taxable = min (amt, bracket[0]) - lower_end
lower_end = bracket[0]
taxes += max (taxable, 0) * bracket[1]
return taxes
def calculate_worksheet (income, gain):
line9 = min (74900., income + gain)
line10 = min (income, line9)
line11 = line9 - line10
line12 = min (income + gain, gain)
line13 = line9 - line10
line14 = line12 - line13
line16 = min (464850., income + gain)
line17 = income + line11
line18 = line16 - line17
line19 = min (line14, line18)
line20 = line19 * .15
line21 = line11 + line19
line22 = line12 - line21
line23 = line22 * .2
line25 = line20 + line23 + income_tax (income)
line26 = income_tax (income + gain)
#print line9
#print line10
#print line11
#print line12
#print line13
#print line14
#print line16
#print line17
#print line18
#print line19
#print line20
#print line21
#print line22
#print line23
#print line25
#print line26
return min (line25, line26)
def calculate_marginals (income, gain):
tax_a = calculate_worksheet (income, gain)
tax_b = calculate_worksheet (income + 1., gain)
income_marginal = (tax_b - tax_a) / 1.
tax_b = calculate_worksheet (income, gain + 1.)
gains_marginal = (tax_b - tax_a) / 1.
print "Taxes: ", tax_a
print "Marginals: ", income_marginal, gains_marginal
income = int(sys.argv[1])
gain = int(sys.argv[2])
calculate_marginals (income, gain)
#print calculate_worksheet (income, gain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment