Skip to content

Commit

Permalink
Rewrite ChildDepTaxCredit function
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Jan 25, 2019
1 parent 32d5c6d commit f47e16f
Show file tree
Hide file tree
Showing 9 changed files with 561 additions and 537 deletions.
76 changes: 50 additions & 26 deletions taxcalc/calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def Adj(e03150, e03210, c03260,
-------
c02900 : total Form 1040 adjustments, which are not included in AGI
"""
# Form 2555 foreign earned income deduction is assumed to be zero
# Form 2555 foreign earned income exclusion is assumed to be zero
# Form 1040 adjustments that are included in expanded income:
c02900 = ((1. - ALD_StudentLoan_hc) * e03210 +
c03260 +
Expand Down Expand Up @@ -983,7 +983,7 @@ def GainsTax(e00650, c01000, c23650, p23250, e01100, e58990, e00200,
dwks19 = 0.

# final calculations done no matter what the value of hasqdivltcg
c05100 = c24580 # because no foreign earned income deduction
c05100 = c24580 # because foreign earned income exclusion is assumed zero
c05700 = 0. # no Form 4972, Lump Sum Distributions
taxbc = c05700 + c05100
return (dwks10, dwks13, dwks14, dwks19, c05700, taxbc)
Expand Down Expand Up @@ -1102,7 +1102,7 @@ def NetInvIncTax(e00300, e00600, e02000, e26270, c01000,
Computes Net Investment Income Tax (NIIT) amount assuming that
all annuity income is excluded from net investment income.
"""
modAGI = c00100 # no deducted foreign earned income to add
modAGI = c00100 # no foreign earned income exclusion to add
if not NIIT_PT_taxed:
NII = max(0., e00300 + e00600 + c01000 + e02000 - e26270)
else: # do not subtract e26270 from e02000
Expand Down Expand Up @@ -1226,33 +1226,57 @@ def EITC(MARS, DSI, EIC, c00100, e00300, e00400, e00600, c01000,


@iterate_jit(nopython=True)
def ChildDepTaxCredit(n24, MARS, c00100, exact,
CTC_c, CTC_ps, CTC_prt, prectc, nu05,
CTC_c_under5_bonus, XTOT, num,
def ChildDepTaxCredit(n24, MARS, c00100, XTOT, num, c05200,
e07260, CR_ResidentialEnergy_hc,
e07300, CR_ForeignTax_hc,
c07180,
c07230,
e07240, CR_RetirementSavings_hc,
c07200,
CTC_c, CTC_ps, CTC_prt, exact,
DependentCredit_Child_c, DependentCredit_Nonchild_c,
FilerCredit_c, dep_credit):
"""
Computes pre-CTC amount (prectc) and nonrefundable dependent credit.
"""
modAGI = c00100 # no foreign earned income deduction to add to AGI
# calculate and phase-out pre-CTC amount
base_ctc = CTC_c * n24 + CTC_c_under5_bonus * nu05
prectc = base_ctc
if prectc > 0. and modAGI > CTC_ps[MARS - 1]:
excess = modAGI - CTC_ps[MARS - 1]
if exact == 1: # exact calculation as on tax forms
excess = 1000. * math.ceil(excess / 1000.)
prectc = max(0., prectc - CTC_prt * excess)
# calculate and phase-out dependent credit after pre-CTC is phased out
dep_credit = (DependentCredit_Child_c * n24 +
DependentCredit_Nonchild_c * max(0, XTOT - n24 - num) +
FilerCredit_c[MARS - 1])
if dep_credit > 0. and modAGI > CTC_ps[MARS - 1]:
CTC_c_under5_bonus, nu05, FilerCredit_c,
prectc, c07220):
"""
Computes amounts on "Child Tax Credit and Credit for Other Dependents
Worksheet" in 2018 Publication 972, which pretain to these two
nonrefundable tax credits.
"""
# Worksheet Part 1
line1 = ((CTC_c + DependentCredit_Child_c) * n24 +
CTC_c_under5_bonus * nu05)
line2 = (DependentCredit_Nonchild_c * max(0, XTOT - n24 - num) +
FilerCredit_c[MARS - 1])
line3 = line1 + line2
modAGI = c00100 # no foreign earned income exclusion to add to AGI (line6)
if line3 > 0. and modAGI > CTC_ps[MARS - 1]:
excess = modAGI - CTC_ps[MARS - 1]
if exact == 1: # exact calculation as on tax forms
excess = 1000. * math.ceil(excess / 1000.)
dep_credit = max(0., dep_credit - CTC_prt * excess)
return (prectc, dep_credit)
line10 = max(0., line3 - CTC_prt * excess)
else:
line10 = line3
if line10 > 0.:
# Worksheet Part 2
line11 = c05200
line12 = (e07260 * (1. - CR_ResidentialEnergy_hc) +
e07300 * (1. - CR_ForeignTax_hc) +
c07180 + # child & dependent care expense credit
c07230 + # education credit
e07240 * (1. - CR_RetirementSavings_hc) +
c07200) # Schedule R credit
line13 = line11 - line12
line14 = 0.
line15 = max(0., line13 - line14)
line16 = min(line10, line15) # credit is capped by tax liability
else:
line16 = 0.
if line1 > 0.:
prectc = line10 # post phaseout credit
else:
prectc = 0.
c07220 = line16 # combined nonrefundable CTC and ODTC amount
return (prectc, c07220)


@iterate_jit(nopython=True)
Expand Down
12 changes: 6 additions & 6 deletions taxcalc/tests/cpscsv_agg_expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ AMT Income ($b) 7814.3 8898.7 9080.7 9412.1 10234.2 108
AMT Liability ($b) 10.6 13.4 13.8 15.6 1.3 1.4 1.4 1.4 1.4 1.4
AMT Filers (#m) 2.8 3.5 3.7 4.0 0.2 0.3 0.3 0.2 0.3 0.3
Tax before Credits ($b) 1120.1 1297.3 1330.3 1380.7 1380.7 1489.3 1594.3 1686.2 1773.7 1860.1
Refundable Credits ($b) 67.2 68.6 68.8 68.2 79.0 78.5 78.2 78.6 79.8 80.4
Nonrefundable Credits ($b) 26.7 27.0 27.1 27.4 90.0 92.1 93.8 95.2 96.4 97.6
Refundable Credits ($b) 67.2 68.6 68.8 68.2 81.4 80.9 80.5 81.0 81.6 82.2
Nonrefundable Credits ($b) 26.7 27.0 27.1 27.4 82.2 84.2 85.8 87.1 88.3 89.4
Reform Surtaxes ($b) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Other Taxes ($b) 6.7 7.8 8.0 8.1 8.6 9.6 10.4 11.2 11.8 12.5
Ind Income Tax ($b) 1032.9 1209.5 1242.4 1293.2 1220.4 1328.3 1432.8 1523.6 1609.3 1694.6
Ind Income Tax ($b) 1032.9 1209.5 1242.4 1293.2 1225.8 1333.8 1438.4 1529.2 1615.7 1701.0
Payroll Taxes ($b) 933.0 1069.6 1096.3 1140.9 1193.6 1260.9 1326.1 1384.6 1441.3 1498.8
Combined Liability ($b) 1965.9 2279.0 2338.8 2434.1 2414.0 2589.2 2758.8 2908.2 3050.6 3193.3
With Income Tax <= 0 (#m) 58.0 54.1 55.2 56.0 59.7 59.9 60.1 60.6 61.2 61.8
With Combined Tax <= 0 (#m) 36.0 34.9 35.7 36.3 38.1 38.5 39.1 39.8 40.5 41.3
Combined Liability ($b) 1965.9 2279.0 2338.8 2434.1 2419.4 2594.7 2764.4 2913.8 3057.0 3199.8
With Income Tax <= 0 (#m) 58.0 54.1 55.2 56.0 58.4 58.6 58.8 59.4 60.0 60.6
With Combined Tax <= 0 (#m) 36.0 34.9 35.7 36.3 38.1 38.6 39.2 39.8 40.5 41.3
12 changes: 6 additions & 6 deletions taxcalc/tests/pufcsv_agg_expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ AMT Income ($b) 8771.5 9427.3 9882.8 10021.5 10515.6 114
AMT Liability ($b) 38.5 41.0 43.9 45.7 47.5 23.6 25.1 26.6 27.8 28.9
AMT Filers (#m) 4.1 4.5 4.8 4.9 5.2 0.8 0.8 0.8 0.8 0.8
Tax before Credits ($b) 1340.3 1498.7 1580.6 1600.3 1699.8 1712.9 1829.5 1905.2 1974.4 2049.6
Refundable Credits ($b) 105.6 104.0 104.3 104.4 105.0 120.2 121.2 122.0 123.7 126.5
Nonrefundable Credits ($b) 67.0 66.9 67.4 67.2 68.4 127.2 130.1 131.7 132.9 134.5
Refundable Credits ($b) 105.6 104.0 104.3 104.4 105.0 124.0 124.9 125.8 127.6 129.5
Nonrefundable Credits ($b) 67.0 66.9 67.4 67.2 68.4 121.4 124.3 125.8 127.0 128.6
Reform Surtaxes ($b) 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Other Taxes ($b) 26.2 33.9 35.5 33.1 39.4 44.2 46.9 46.7 47.1 48.0
Ind Income Tax ($b) 1194.0 1361.6 1444.4 1461.7 1565.8 1509.7 1625.1 1698.3 1765.0 1836.6
Ind Income Tax ($b) 1194.0 1361.6 1444.4 1461.7 1565.8 1511.7 1627.2 1700.3 1767.0 1839.6
Payroll Taxes ($b) 947.8 982.0 1026.6 1050.9 1094.3 1144.8 1207.7 1268.5 1322.9 1376.3
Combined Liability ($b) 2141.9 2343.6 2470.9 2512.6 2660.0 2654.5 2832.8 2966.8 3087.9 3212.8
With Income Tax <= 0 (#m) 68.9 68.4 68.3 69.4 70.1 76.9 76.9 77.1 77.5 78.0
With Combined Tax <= 0 (#m) 39.5 39.8 39.9 40.6 41.3 43.3 43.6 44.0 44.4 45.0
Combined Liability ($b) 2141.9 2343.6 2470.9 2512.6 2660.0 2656.6 2834.9 2968.8 3089.9 3215.9
With Income Tax <= 0 (#m) 68.9 68.4 68.3 69.4 70.1 76.4 76.4 76.6 77.0 77.5
With Combined Tax <= 0 (#m) 39.5 39.8 39.9 40.6 41.3 43.5 43.8 44.2 44.6 45.1
6 changes: 3 additions & 3 deletions taxcalc/tests/reforms_expect.csv
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ rid,res1,res2,res3,res4
53,-107.5,-109.0,-112.3,-115.9
54,28.7,31.2,33.0,32.3
55,85.4,89.8,95.8,101.9
56,-8.8,-8.5,-8.2,-8.0
57,-13.9,-13.6,-13.3,-13.1
58,0.0,-30.3,-33.2,-38.2
56,-22.2,-22.3,-22.4,-22.4
57,-22.2,-22.3,-22.4,-22.4
58,0.0,-32.6,-35.6,-40.5
59,-14.5,-16.0,-16.6,-16.1
60,-16.0,-17.6,-18.3,-17.8
61,-64.6,-65.0,-65.4,-65.6
Expand Down
Loading

0 comments on commit f47e16f

Please sign in to comment.