Skip to content

Commit

Permalink
Merge pull request PSLmodels#2785 from martinholmer/fix-qbi-calc
Browse files Browse the repository at this point in the history
Fix qualified business income calculation
  • Loading branch information
jdebacker authored Jul 28, 2024
2 parents d36d8db + 5621d50 commit fb0c3c0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
6 changes: 4 additions & 2 deletions taxcalc/calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ def StdDed(DSI, earned, STD, age_head, age_spouse, STD_Aged, STD_Dep,


@iterate_jit(nopython=True)
def TaxInc(c00100, standard, c04470, c04600, MARS, e00900, e26270,
def TaxInc(c00100, standard, c04470, c04600, MARS, e00900, c03260, e26270,
e02100, e27200, e00650, c01000, PT_SSTB_income,
PT_binc_w2_wages, PT_ubia_property, PT_qbid_rt,
PT_qbid_taxinc_thd, PT_qbid_taxinc_gap, PT_qbid_w2_wages_rt,
Expand All @@ -1236,6 +1236,8 @@ def TaxInc(c00100, standard, c04470, c04600, MARS, e00900, e26270,
Filing (marital) status. (1=single, 2=joint, 3=separate, 4=household-head, 5=widow(er))
e00900: float
Schedule C business net profit/loss for filing unit
c03260: float
Self-employment (SECA) tax above-the-line deduction
e26270: float
Schedule E: combined partnership and S-corporation net income/loss
e02100: float
Expand Down Expand Up @@ -1287,7 +1289,7 @@ def TaxInc(c00100, standard, c04470, c04600, MARS, e00900, e26270,
pre_qbid_taxinc = max(0., c00100 - max(c04470, standard) - c04600)
# calculate qualified business income deduction
qbided = 0.
qbinc = max(0., e00900 + e26270 + e02100 + e27200)
qbinc = max(0., e00900 - c03260 + e26270 + e02100 + e27200)
if qbinc > 0. and PT_qbid_rt > 0.:
qbid_before_limits = qbinc * PT_qbid_rt
lower_thd = PT_qbid_taxinc_thd[MARS - 1]
Expand Down
14 changes: 7 additions & 7 deletions taxcalc/tests/cpscsv_agg_expect.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Itemized Deduction ($b),1218.6,612.0,655.1,745.4,862.7,881.9,887.6,913.8,963.1,2
Standard Deduction Filers (#m),124.3,175.3,176.9,176.9,175.8,178.5,182.5,185.5,187.2,139.1
Standard Deduction ($b),1092.1,2951.3,3026.1,3080.8,3091.9,3231.4,3549.4,3806.5,3937.8,1613.3
Personal Exemption ($b),1383.6,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,2081.6
Taxable Income ($b),6230.6,7957.5,8321.1,8613.6,10047.9,10330.1,10946.2,11424.1,11987.7,11782.5
Regular Tax ($b),1108.0,1379.7,1448.7,1497.0,1762.5,1837.0,1937.0,2016.0,2122.8,2339.6
AMT Income ($b),8319.8,10210.9,10628.5,10963.9,12471.9,12819.7,13656.7,14316.6,14982.4,15074.1
Taxable Income ($b),6230.6,7959.2,8322.8,8615.4,10049.9,10332.2,10948.3,11426.3,11990.0,11782.5
Regular Tax ($b),1108.0,1380.0,1449.0,1497.4,1762.8,1837.4,1937.4,2016.4,2123.2,2339.6
AMT Income ($b),8319.8,10212.6,10630.3,10965.7,12473.9,12821.8,13658.8,14318.8,14984.7,15074.1
AMT Liability ($b),8.1,0.4,0.4,0.5,1.4,0.7,0.7,0.6,0.6,17.2
AMT Filers (#m),2.6,0.1,0.1,0.1,0.2,0.1,0.1,0.1,0.1,4.1
Tax before Credits ($b),1116.0,1380.1,1449.1,1497.6,1763.9,1837.6,1937.7,2016.6,2123.4,2356.8
Tax before Credits ($b),1116.0,1380.4,1449.4,1497.9,1764.3,1838.0,1938.1,2017.0,2123.8,2356.8
Refundable Credits ($b),70.8,102.5,102.7,655.0,827.1,98.5,106.4,111.6,112.1,97.7
Nonrefundable Credits ($b),32.7,97.2,99.1,99.2,0.0,107.7,108.3,109.3,111.2,29.9
Nonrefundable Credits ($b),32.7,97.2,99.2,99.2,0.0,107.7,108.3,109.3,111.2,29.9
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),5.5,10.7,11.3,12.6,13.9,14.4,16.5,17.6,18.8,19.9
Ind Income Tax ($b),1018.1,1191.1,1258.5,755.9,950.6,1645.8,1739.6,1813.3,1918.8,2249.0
Ind Income Tax ($b),1018.1,1191.4,1258.9,756.3,951.0,1646.2,1740.0,1813.7,1919.2,2249.0
Payroll Taxes ($b),1040.8,1141.6,1194.9,1217.9,1318.7,1421.6,1506.7,1582.0,1656.7,1730.7
Combined Liability ($b),2059.0,2332.7,2453.4,1973.9,2269.3,3067.4,3246.2,3395.3,3575.5,3979.7
Combined Liability ($b),2059.0,2333.0,2453.8,1974.2,2269.7,3067.8,3246.6,3395.7,3575.9,3979.7
With Income Tax <= 0 (#m),88.1,96.2,97.0,135.4,127.8,96.1,97.9,99.2,99.6,97.4
With Combined Tax <= 0 (#m),62.8,65.4,66.4,98.2,97.7,67.9,69.3,70.5,71.3,70.7
UBI Benefits ($b),0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
Expand Down
16 changes: 8 additions & 8 deletions taxcalc/tests/pufcsv_agg_expect.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Itemized Deduction ($b),1274.3,602.7,633.9,692.3,761.9,782.7,786.5,805.6,831.9,2
Standard Deduction Filers (#m),145.2,174.8,177.2,178.5,179.6,182.8,186.8,190.0,192.8,164.8
Standard Deduction ($b),1239.3,2865.3,2954.5,3025.8,3081.1,3234.0,3549.8,3811.2,3966.7,1856.2
Personal Exemption ($b),1365.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1959.2
Taxable Income ($b),8112.2,9177.8,9519.0,9905.8,12001.6,11926.1,12690.7,13123.1,13695.7,13377.8
Regular Tax ($b),1656.8,1712.0,1777.9,1838.0,2281.2,2282.4,2421.4,2487.7,2598.8,2792.6
AMT Income ($b),10512.4,11342.1,11748.2,12178.7,14329.2,14354.5,15322.6,15942.9,16631.0,16934.0
Taxable Income ($b),8112.2,9179.2,9520.5,9907.3,12003.2,11927.7,12692.4,13124.8,13697.6,13377.8
Regular Tax ($b),1656.8,1712.3,1778.2,1838.3,2281.5,2282.7,2421.7,2488.0,2599.2,2792.6
AMT Income ($b),10512.4,11343.5,11749.7,12180.1,14330.8,14356.1,15324.3,15944.7,16632.8,16934.0
AMT Liability ($b),51.3,22.1,23.0,25.1,27.8,27.4,28.8,30.3,31.8,85.1
AMT Filers (#m),5.7,0.2,0.2,0.3,0.4,0.3,0.3,0.3,0.3,7.4
Tax before Credits ($b),1708.1,1734.1,1800.9,1863.1,2309.1,2309.8,2450.2,2518.0,2630.7,2877.6
Refundable Credits ($b),102.9,117.5,118.5,642.0,802.6,119.2,127.1,133.0,135.2,121.9
Nonrefundable Credits ($b),67.0,127.3,129.2,128.5,47.6,140.8,143.3,144.0,145.9,78.0
Tax before Credits ($b),1708.1,1734.4,1801.1,1863.4,2309.4,2310.1,2450.5,2518.3,2631.0,2877.6
Refundable Credits ($b),102.9,117.5,118.5,642.0,802.6,119.2,127.0,133.0,135.2,121.9
Nonrefundable Credits ($b),67.0,127.3,129.2,128.5,47.6,140.9,143.3,144.0,145.9,78.0
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),40.0,44.8,43.6,52.9,84.9,61.5,66.5,65.2,66.0,64.2
Ind Income Tax ($b),1578.2,1534.1,1596.8,1145.5,1543.7,2111.3,2246.4,2306.2,2415.6,2742.0
Ind Income Tax ($b),1578.2,1534.3,1597.0,1145.8,1544.0,2111.6,2246.7,2306.5,2415.9,2742.0
Payroll Taxes ($b),1083.8,1133.3,1185.4,1209.0,1306.0,1403.4,1489.3,1563.9,1637.9,1711.0
Combined Liability ($b),2662.0,2667.4,2782.2,2354.5,2849.7,3514.7,3735.6,3870.2,4053.5,4452.9
Combined Liability ($b),2662.0,2667.7,2782.4,2354.8,2850.0,3515.0,3736.0,3870.5,4053.8,4452.9
With Income Tax <= 0 (#m),92.8,98.6,99.7,131.7,125.0,100.3,101.9,103.4,104.4,101.0
With Combined Tax <= 0 (#m),63.4,65.6,66.8,102.1,94.5,68.9,70.2,71.6,72.6,72.4
UBI Benefits ($b),0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
Expand Down
17 changes: 12 additions & 5 deletions taxcalc/tests/test_calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ def test_EITC(test_tuple, expected_value, skip_jit):
c04600 = [0.00, 0.00, 0.00, 0.00]
MARS = [2, 2, 2, 4]
e00900 = [352000.00, 23000.00, 0.00, 0.00]
c03260 = [13516.17, 1624.90, 0.00, 0.00]
e26270 = [0.00, 0.00, 11000.00, 6000.00]
e02100 = [0.00, 0.00, 0.00, 0.00]
e27200 = [0.00, 0.00, 0.00, 0.00]
Expand All @@ -572,38 +573,44 @@ def test_EITC(test_tuple, expected_value, skip_jit):
qbided = [0.0, 0.0, 0.0, 0.0] # unimportant for function

tuple0 = (
c00100[0], standard[0], c04470[0], c04600[0], MARS[0], e00900[0], e26270[0],
c00100[0], standard[0], c04470[0], c04600[0], MARS[0], e00900[0],
c03260[0], e26270[0],
e02100[0], e27200[0], e00650[0], c01000[0], PT_SSTB_income[0],
PT_binc_w2_wages[0], PT_ubia_property[0], PT_qbid_rt,
PT_qbid_taxinc_thd, PT_qbid_taxinc_gap, PT_qbid_w2_wages_rt,
PT_qbid_alt_w2_wages_rt, PT_qbid_alt_property_rt, c04800[0],
PT_qbid_ps, PT_qbid_prt, qbided[0], PT_qbid_limit_switch)
expected0 = (490860.66, 0)
tuple1 = (
c00100[1], standard[1], c04470[1], c04600[1], MARS[1], e00900[1], e26270[1],
c00100[1], standard[1], c04470[1], c04600[1], MARS[1], e00900[1],
c03260[1], e26270[1],
e02100[1], e27200[1], e00650[1], c01000[1], PT_SSTB_income[1],
PT_binc_w2_wages[1], PT_ubia_property[1], PT_qbid_rt,
PT_qbid_taxinc_thd, PT_qbid_taxinc_gap, PT_qbid_w2_wages_rt,
PT_qbid_alt_w2_wages_rt, PT_qbid_alt_property_rt, c04800[1],
PT_qbid_ps, PT_qbid_prt, qbided[1], PT_qbid_limit_switch)
expected1 = (284075.10, 4600)
expected1 = (284400.08, 4275.02)
tuple2 = (
c00100[2], standard[2], c04470[2], c04600[2], MARS[2], e00900[2], e26270[2],
c00100[2], standard[2], c04470[2], c04600[2], MARS[2], e00900[2],
c03260[2], e26270[2],
e02100[2], e27200[2], e00650[2], c01000[2], PT_SSTB_income[2],
PT_binc_w2_wages[2], PT_ubia_property[2], PT_qbid_rt,
PT_qbid_taxinc_thd, PT_qbid_taxinc_gap, PT_qbid_w2_wages_rt,
PT_qbid_alt_w2_wages_rt, PT_qbid_alt_property_rt, c04800[2],
PT_qbid_ps, PT_qbid_prt, qbided[2], PT_qbid_limit_switch)
expected2 = (579300.00, 0)
tuple3 = (
c00100[3], standard[3], c04470[3], c04600[3], MARS[3], e00900[3], e26270[3],
c00100[3], standard[3], c04470[3], c04600[3], MARS[3], e00900[3],
c03260[3], e26270[3],

e02100[3], e27200[3], e00650[3], c01000[3], PT_SSTB_income[3],
PT_binc_w2_wages[3], PT_ubia_property[3], PT_qbid_rt,
PT_qbid_taxinc_thd, PT_qbid_taxinc_gap, PT_qbid_w2_wages_rt,
PT_qbid_alt_w2_wages_rt, PT_qbid_alt_property_rt, c04800[3],
PT_qbid_ps, PT_qbid_prt, qbided[3], PT_qbid_limit_switch)
expected3 = (57500.00, 1200)


@pytest.mark.parametrize(
'test_tuple,expected_value', [
(tuple0, expected0),
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/test_reforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,4 @@ def test_ext_reform(tests_path):
iitax_ext = calc_ext.array('iitax')
rdiff = iitax_ext - iitax_end
weighted_sum_rdiff = (rdiff * calc_end.array('s006')).sum() * 1.0e-9
assert np.allclose([weighted_sum_rdiff], [-224.91], rtol=0.0, atol=0.01)
assert np.allclose([weighted_sum_rdiff], [-224.45], rtol=0.0, atol=0.01)

0 comments on commit fb0c3c0

Please sign in to comment.