Last active
May 1, 2021 20:54
-
-
Save nbren12/8983c0257455ec1381b27417e0c553fe to your computer and use it in GitHub Desktop.
2020 IRS Tax + Capital Gains
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Copyright 2021 Noah D. Brenowitz | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
""" | |
def round_cents(cents): | |
return round(cents / 100) | |
def get_tax_married_joint(x): | |
"""From 2020 Tax Computation Worksheet Schedule B | |
pp 77 of instructions | |
If x < 100k/year, then look up value in the "Tax Table"...just one value shown below | |
""" | |
if x > 518_400_00: | |
return 0.37 * x - 35_573_00 | |
elif x > 207_350_00: | |
return 0.32 * x - 25_205_00 | |
elif x > 163_300_00: | |
return 0.32 * x - 18_984_50 | |
elif x > 100_000_00: | |
return 0.24 * x - 5_920_50 | |
# the tax table: | |
if 10_000_00 <= x < 10_050_00: | |
return 1003_00 | |
if 44_350_00 <= x < 44_400_00: | |
return 4930_00 | |
if x == 0: | |
return 0 | |
raise NotImplementedError( | |
f"{x} not implemented. Look up the value in the tax table (pp. 70ish) and modify this function.") | |
# a few examples from the tax table (you will probably need to add yourself) | |
def smaller_of(x, y): | |
"""smaller of in IRS parlance means the closest one to zero""" | |
if abs(x) < abs(y): | |
return x | |
else: | |
return y | |
def at_least_0(x): | |
return x if x > 0 else 0 | |
def tax_with_capital_gains(schedule_d_15, schedule_d_16, box_3a_1040, box_15_1040, status='married_jointly'): | |
"""Capital gains worksheet line 16 1040 (see page 35 of instructions) | |
https://www.freefilefillableforms.com/data/fd/inst/2020%20Instruction%201040.pdf | |
Args: | |
schedule_d_15 (int): Line 15 of Schedule D in cents | |
schedule_d_16 (int): Line 16 of Schedule D in cents | |
box_3a_1040 (int): qualified dividends (Line 3a 1040) | |
box_15_1050 (int): taxable income (line 15 1040) | |
Returns: | |
Tax (Line 16 1040) in *dollars* | |
""" | |
cap_tax_rate = 0.15 | |
work = {} | |
work[1] = box_15_1040 | |
work[2] = box_3a_1040 | |
if schedule_d_15 <= 0: | |
work[3] = 0 | |
elif schedule_d_16 <= 0: | |
work[3] = 0 | |
else: | |
work[3] = smaller_of(schedule_d_15, schedule_d_16) | |
work[4] = work[2] + work[3] | |
work[5] = at_least_0(work[1] - work[4]) | |
work[6] = { | |
"married_jointly": 80000_00, | |
"head_of_household": 53600_00, | |
"single": 40000_00, | |
"married_separate": 40_000_00 | |
}[status] | |
work[7] = smaller_of(work[1], work[6]) | |
work[8] = smaller_of(work[5], work[7]) | |
work[9] = work[7] - work[8] | |
work[10] = smaller_of(work[1], work[4]) | |
work[11] = work[9] | |
work[12] = work[10] - work[11] | |
work[13] = { | |
"married_jointly": 496600_00, | |
"head_of_household": 469050_00, | |
"single": 441450_00, | |
"married_separate": 248_300_00 | |
}[status] | |
work[14] = smaller_of(work[1], work[13]) | |
work[15] = work[5] + work[9] | |
work[16] = at_least_0(work[14] - work[15]) | |
work[17] = smaller_of(work[12], work[16]) | |
work[18] = work[17] * cap_tax_rate | |
work[19] = work[9] + work[17] | |
work[20] = work[10] - work[19] | |
work[21] = work[20] * 0.20 | |
work[22] = get_tax_married_joint(work[5]) | |
work[23] = work[18] + work[21] + work[22] | |
work[24] = get_tax_married_joint(work[1]) | |
work[25] = smaller_of(work[23], work[24]) | |
return round_cents(work[25]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment