From c974960f3599b7f5739d4965ea3e4026f76949db Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Fri, 6 Sep 2024 03:31:22 +0000 Subject: [PATCH 01/11] LA County LIFE transit discount Fixes #4525 --- changelog_entry.yaml | 4 ++++ .../federal_income/capital_gains/dwks6.yaml | 23 ++++++++++++++++++ .../regular_tax_before_credits.py | 24 +++++++++++++------ .../tax/federal_income/capital_gains/dwks6.py | 18 ++++++++++---- .../tax/federal_income/capital_gains/dwks9.py | 23 ++++++++++++++---- 5 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/dwks6.yaml diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29bb2d..f84d0e1d420 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: minor + changes: + added: + - Refactor the regular_tax_before_credits variable and add unit tests. diff --git a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/dwks6.yaml b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/dwks6.yaml new file mode 100644 index 00000000000..4954d9a1aaf --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/dwks6.yaml @@ -0,0 +1,23 @@ +- name: qualified_dividend_income larger than investment_income_form_4952 + period: 2019 + input: + qualified_dividend_income: 2_000 + investment_income_form_4952: 1_000 + output: + dwks6: 1_000 + +- name: qualified_dividend_income smaller than investment_income_form_4952 + period: 2019 + input: + qualified_dividend_income: 1_000 + investment_income_form_4952: 2_000 + output: + dwks6: 0 + +- name: investment_income_form_4952 smaller than 0 + period: 2019 + input: + qualified_dividend_income: 2_000 + investment_income_form_4952: -2_000 + output: + dwks6: 2_000 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/before_credits/regular_tax_before_credits.py b/policyengine_us/variables/gov/irs/tax/federal_income/before_credits/regular_tax_before_credits.py index 5db2d6cc7a4..e2a00bcbc22 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/before_credits/regular_tax_before_credits.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/before_credits/regular_tax_before_credits.py @@ -8,23 +8,33 @@ class regular_tax_before_credits(Variable): label = "Regular tax before credits" documentation = "Regular tax on regular taxable income before credits" unit = USD + reference = ( + "https://www.irs.gov/pub/irs-pdf/f6251.pdf", + "https://www.irs.gov/pub/irs-pdf/i6251.pdf", + ) def formula(tax_unit, period, parameters): filing_status = tax_unit("filing_status", period) - dwks1 = tax_unit("taxable_income", period) + taxable_income = tax_unit("taxable_income", period) # dwks1 capital_gains = parameters(period).gov.irs.capital_gains.brackets - dwks16 = min_(capital_gains.thresholds["1"][filing_status], dwks1) - dwks17 = min_(tax_unit("dwks14", period), dwks16) - dwks20 = dwks16 - dwks17 + capital_gain_taxable_threshold = min_( + capital_gains.thresholds["1"][filing_status], taxable_income + ) # dwks16 + dwks17 = min_( + tax_unit("dwks14", period), capital_gain_taxable_threshold + ) + dwks20 = capital_gain_taxable_threshold - dwks17 lowest_rate_tax = capital_gains.rates["1"] * dwks20 # Break in worksheet lines dwks13 = tax_unit("dwks13", period) dwks21 = min_(dwks1, dwks13) dwks22 = dwks20 dwks23 = max_(0, dwks21 - dwks22) - dwks25 = min_(capital_gains.thresholds["2"][filing_status], dwks1) + dwks25 = min_( + capital_gains.thresholds["2"][filing_status], taxable_income + ) dwks19 = tax_unit("dwks19", period) dwks26 = min_(dwks19, dwks20) dwks27 = max_(0, dwks25 - dwks26) @@ -40,12 +50,12 @@ def formula(tax_unit, period, parameters): ) dwks10 = tax_unit("dwks10", period) dwks34 = dwks10 + dwks19 - dwks36 = max_(0, dwks34 - dwks1) + dwks36 = max_(0, dwks34 - taxable_income) dwks37 = max_(0, dwks33 - dwks36) dwks38 = 0.25 * dwks37 # Break in worksheet lines dwks39 = dwks19 + dwks20 + dwks28 + dwks31 + dwks37 - dwks40 = dwks1 - dwks39 + dwks40 = taxable_income - dwks39 dwks41 = 0.28 * dwks40 # Compute regular tax using bracket rates and thresholds diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks6.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks6.py index 076d4815176..b20ebb08f13 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks6.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks6.py @@ -7,10 +7,20 @@ class dwks6(Variable): label = "DWKS6" unit = USD definition_period = YEAR + reference = ( + "https://www.irs.gov/pub/irs-pdf/f6251.pdf", + "https://www.irs.gov/pub/irs-pdf/i6251.pdf", + ) def formula(tax_unit, period, parameters): - dwks2 = add(tax_unit, period, ["qualified_dividend_income"]) - dwks3 = tax_unit("investment_income_form_4952", period) + qualified_dividends = add( + tax_unit, period, ["qualified_dividend_income"] + ) # dwks2 # Form 1040 line 3a + investment_interest = tax_unit( + "investment_income_form_4952", period + ) # dwks3 # From 6251 line 2c # dwks4 always assumed to be zero - dwks5 = max_(0, dwks3) - return max_(0, dwks2 - dwks5) + adjusted_investment_interest = max_(0, investment_interest) # dwks5 + return max_( + 0, qualified_dividends - adjusted_investment_interest + ) # dwks6 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks9.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks9.py index 03cf47d2809..3db4d363fea 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks9.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks9.py @@ -7,20 +7,33 @@ class dwks9(Variable): label = "DWKS9" unit = USD definition_period = YEAR + reference = ( + "https://www.irs.gov/pub/irs-pdf/f6251.pdf", + "https://www.irs.gov/pub/irs-pdf/i6251.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + ) def formula(tax_unit, period, parameters): - p23250 = add( + total_cap_gains_and_dividends = add( tax_unit, period, ["long_term_capital_gains", "qualified_dividend_income"], - ) + ) # p23250 c23650 = tax_unit("c23650", period) - dwks7 = min_(p23250, c23650) # SchD lines 15 and 16, respectively + dwks7 = min_( + total_cap_gains_and_dividends, c23650 + ) # SchD lines 15 and 16, respectively # dwks8 = min(dwks3, dwks4) # dwks9 = max(0., dwks7 - dwks8) # BELOW TWO STATEMENTS ARE UNCLEAR IN LIGHT OF dwks9=... COMMENT - e01100 = add(tax_unit, period, ["non_sch_d_capital_gains"]) - c24510 = where(e01100 > 0, e01100, max_(0, dwks7) + e01100) + non_sch_d_capital_gains = add( + tax_unit, period, ["non_sch_d_capital_gains"] + ) # e01100 + c24510 = where( + non_sch_d_capital_gains > 0, + non_sch_d_capital_gains, + max_(0, dwks7) + non_sch_d_capital_gains, + ) return max_( 0, c24510 - min_(0, tax_unit("investment_income_form_4952", period)), From e49d578f23369a49730278b6fcc0d5d8ae7103a3 Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Fri, 6 Sep 2024 03:40:14 +0000 Subject: [PATCH 02/11] format --- .../regular_tax_before_credits.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py index b2334a5d91d..6f19b03a932 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py @@ -11,13 +11,17 @@ class regular_tax_before_credits(Variable): def formula(tax_unit, period, parameters): filing_status = tax_unit("filing_status", period) - taxable_income = tax_unit("taxable_income", period) # dwks1 + taxable_income = tax_unit("taxable_income", period) # dwks1 capital_gains = parameters(period).gov.irs.capital_gains.brackets - capital_gain_taxable_threshold = min_(capital_gains.thresholds["1"][filing_status], taxable_income) # dwks16 - dwks17 = min_(tax_unit("dwks14", period), dwks16) - dwks20 = dwks16 - dwks17 + capital_gain_taxable_threshold = min_( + capital_gains.thresholds["1"][filing_status], taxable_income + ) # dwks16 + dwks17 = min_( + tax_unit("dwks14", period), capital_gain_taxable_threshold + ) + dwks20 = capital_gain_taxable_threshold - dwks17 lowest_rate_tax = capital_gains.rates["1"] * dwks20 # Break in worksheet lines dwks13 = tax_unit("dwks13", period) From 44be2e3a25dc289522494cb532ef96dfe75a6dd2 Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Tue, 10 Sep 2024 09:48:45 +0000 Subject: [PATCH 03/11] dwks 6 & 9 --- ...al_gains_reduced_by_investment_income.yaml | 43 +++++++++++++++++++ ...ends_by_adjusted_investment_interest.yaml} | 6 +-- .../regular_tax_before_credits.py | 4 +- ...ital_gains_reduced_by_investment_income.py | 41 ++++++++++++++++++ .../tax/federal_income/capital_gains/dwks9.py | 40 ----------------- ...idends_by_adjusted_investment_interest.py} | 6 ++- 6 files changed, 94 insertions(+), 46 deletions(-) create mode 100644 policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.yaml rename policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/{dwks6.yaml => reduced_qualified_dividends_by_adjusted_investment_interest.yaml} (71%) create mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py delete mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks9.py rename policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/{dwks6.py => reduced_qualified_dividends_by_adjusted_investment_interest.py} (81%) diff --git a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.yaml b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.yaml new file mode 100644 index 00000000000..6b29c09c5d4 --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.yaml @@ -0,0 +1,43 @@ +- name: non_sch_d_capital_gains > 0, investment_income_form_4952 > 0 + period: 2019 + input: + long_term_capital_gains: 2_000 + qualified_dividend_income: 2_000 + net_capital_gains: 1_000 + non_sch_d_capital_gains: 3_000 + investment_income_form_4952: 2_000 + output: # 3000 - min(0, 2000) + adjusted_capital_gains_reduced_by_investment_income: 3_000 + +- name: non_sch_d_capital_gains > 0, investment_income_form_4952 < 0 + period: 2019 + input: + long_term_capital_gains: 2_000 + qualified_dividend_income: 2_000 + net_capital_gains: 1_000 + non_sch_d_capital_gains: 3_000 + investment_income_form_4952: -2_000 + output: # 3000 - min(0, -2000) + adjusted_capital_gains_reduced_by_investment_income: 5_000 + +- name: non_sch_d_capital_gains < 0, investment_income_form_4952 < 0 + period: 2019 + input: + long_term_capital_gains: 2_000 + qualified_dividend_income: 2_000 + net_capital_gains: 1_000 + non_sch_d_capital_gains: -1_000 + investment_income_form_4952: -2_000 + output: # min(2000 + 2000, 1000) - 1000 - min(0, -2000) + adjusted_capital_gains_reduced_by_investment_income: 2_000 + +- name: non_sch_d_capital_gains < 0, investment_income_form_4952 > 0 + period: 2019 + input: + long_term_capital_gains: 2_000 + qualified_dividend_income: 2_000 + net_capital_gains: 1_000 + non_sch_d_capital_gains: -3_000 + investment_income_form_4952: 2_000 + output: # min(2000 + 2000, 1000) - 3000 - min(0, 2000) + adjusted_capital_gains_reduced_by_investment_income: 0 diff --git a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/dwks6.yaml b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.yaml similarity index 71% rename from policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/dwks6.yaml rename to policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.yaml index 4954d9a1aaf..1b0bab9da47 100644 --- a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/dwks6.yaml +++ b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.yaml @@ -4,7 +4,7 @@ qualified_dividend_income: 2_000 investment_income_form_4952: 1_000 output: - dwks6: 1_000 + reduced_qualified_dividends_by_adjusted_investment_interest: 1_000 - name: qualified_dividend_income smaller than investment_income_form_4952 period: 2019 @@ -12,7 +12,7 @@ qualified_dividend_income: 1_000 investment_income_form_4952: 2_000 output: - dwks6: 0 + reduced_qualified_dividends_by_adjusted_investment_interest: 0 - name: investment_income_form_4952 smaller than 0 period: 2019 @@ -20,4 +20,4 @@ qualified_dividend_income: 2_000 investment_income_form_4952: -2_000 output: - dwks6: 2_000 + reduced_qualified_dividends_by_adjusted_investment_interest: 2_000 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py index 6f19b03a932..9c3010d6f5e 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py @@ -39,7 +39,9 @@ def formula(tax_unit, period, parameters): dwks32 = capital_gains.rates["3"] * dwks31 # Break in worksheet lines dwks33 = min_( - tax_unit("dwks9", period), + tax_unit( + "adjusted_capital_gains_reduced_by_investment_income", period + ), add(tax_unit, period, ["unrecaptured_section_1250_gain"]), ) dwks10 = tax_unit("dwks10", period) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py new file mode 100644 index 00000000000..2336c7b09c1 --- /dev/null +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py @@ -0,0 +1,41 @@ +from policyengine_us.model_api import * + + +class adjusted_capital_gains_reduced_by_investment_income(Variable): + value_type = float + entity = TaxUnit + label = "Adjusted capital gains reduced by investment income" # DWKS9 + unit = USD + definition_period = YEAR + reference = ( + "https://www.irs.gov/pub/irs-pdf/f6251.pdf", + "https://www.irs.gov/pub/irs-pdf/i6251.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + ) + + def formula(tax_unit, period, parameters): + total_cap_gains_and_dividends = add( + tax_unit, + period, + ["long_term_capital_gains", "qualified_dividend_income"], + ) # p23250 + net_capital_gains = tax_unit("net_capital_gains", period) # c23650 + capped_net_capital_gains = min_( + total_cap_gains_and_dividends, net_capital_gains + ) # dwks7 # SchD lines 15 and 16, respectively + # dwks8 = min(dwks3, dwks4) + # adjusted_capital_gains_reduced_by_investment_income = max(0., capped_net_capital_gains - dwks8) + # BELOW TWO STATEMENTS ARE UNCLEAR IN LIGHT OF adjusted_capital_gains_reduced_by_investment_income=... COMMENT + non_sch_d_capital_gains = add( + tax_unit, period, ["non_sch_d_capital_gains"] + ) # e01100 + cpaital_gains_adjusted_for_non_sch_d_gains = where( + non_sch_d_capital_gains > 0, + non_sch_d_capital_gains, + max_(0, capped_net_capital_gains) + non_sch_d_capital_gains, + ) # c24510 + return max_( + 0, + cpaital_gains_adjusted_for_non_sch_d_gains + - min_(0, tax_unit("investment_income_form_4952", period)), + ) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks9.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks9.py deleted file mode 100644 index 3db4d363fea..00000000000 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks9.py +++ /dev/null @@ -1,40 +0,0 @@ -from policyengine_us.model_api import * - - -class dwks9(Variable): - value_type = float - entity = TaxUnit - label = "DWKS9" - unit = USD - definition_period = YEAR - reference = ( - "https://www.irs.gov/pub/irs-pdf/f6251.pdf", - "https://www.irs.gov/pub/irs-pdf/i6251.pdf", - "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", - ) - - def formula(tax_unit, period, parameters): - total_cap_gains_and_dividends = add( - tax_unit, - period, - ["long_term_capital_gains", "qualified_dividend_income"], - ) # p23250 - c23650 = tax_unit("c23650", period) - dwks7 = min_( - total_cap_gains_and_dividends, c23650 - ) # SchD lines 15 and 16, respectively - # dwks8 = min(dwks3, dwks4) - # dwks9 = max(0., dwks7 - dwks8) - # BELOW TWO STATEMENTS ARE UNCLEAR IN LIGHT OF dwks9=... COMMENT - non_sch_d_capital_gains = add( - tax_unit, period, ["non_sch_d_capital_gains"] - ) # e01100 - c24510 = where( - non_sch_d_capital_gains > 0, - non_sch_d_capital_gains, - max_(0, dwks7) + non_sch_d_capital_gains, - ) - return max_( - 0, - c24510 - min_(0, tax_unit("investment_income_form_4952", period)), - ) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks6.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py similarity index 81% rename from policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks6.py rename to policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py index b20ebb08f13..ffc1c0d3f54 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks6.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py @@ -1,10 +1,12 @@ from policyengine_us.model_api import * -class dwks6(Variable): +class reduced_qualified_dividends_by_adjusted_investment_interest(Variable): value_type = float entity = TaxUnit - label = "DWKS6" + label = ( + "Reduced qualified dividends by adjusted investment interest" # DWKS6 + ) unit = USD definition_period = YEAR reference = ( From 3224d6fc0cbbde68d9d2197e83deb7ebc058cace Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:17:53 +0000 Subject: [PATCH 04/11] dwks 6 & 9 --- .../regular_tax_before_credits.py | 4 +++ ...ital_gains_reduced_by_investment_income.py | 29 +++++++++---------- .../federal_income/capital_gains/dwks06.py | 16 ---------- .../federal_income/capital_gains/dwks09.py | 27 ----------------- ...vidends_by_adjusted_investment_interest.py | 15 +++++----- 5 files changed, 25 insertions(+), 66 deletions(-) delete mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks06.py delete mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks09.py diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py index 9c3010d6f5e..31e32dea3c1 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py @@ -8,6 +8,10 @@ class regular_tax_before_credits(Variable): label = "Regular tax before credits" documentation = "Regular tax on regular taxable income before credits" unit = USD + reference = ( + "https://www.irs.gov/pub/irs-pdf/f6251.pdf", + "https://www.irs.gov/pub/irs-pdf/i6251.pdf", + ) def formula(tax_unit, period, parameters): filing_status = tax_unit("filing_status", period) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py index 2336c7b09c1..d1931e33d93 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py @@ -4,38 +4,35 @@ class adjusted_capital_gains_reduced_by_investment_income(Variable): value_type = float entity = TaxUnit - label = "Adjusted capital gains reduced by investment income" # DWKS9 + label = "IRS Form 1040 Schedule D worksheet (part 2 of 6)" # DWKS09 unit = USD definition_period = YEAR reference = ( - "https://www.irs.gov/pub/irs-pdf/f6251.pdf", - "https://www.irs.gov/pub/irs-pdf/i6251.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040.pdf", + "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", ) def formula(tax_unit, period, parameters): - total_cap_gains_and_dividends = add( + # SchD lines 15 and 16, respectively + qdiv_plus_ltcg = add( tax_unit, period, ["long_term_capital_gains", "qualified_dividend_income"], ) # p23250 - net_capital_gains = tax_unit("net_capital_gains", period) # c23650 capped_net_capital_gains = min_( - total_cap_gains_and_dividends, net_capital_gains - ) # dwks7 # SchD lines 15 and 16, respectively + qdiv_plus_ltcg, tax_unit("net_capital_gains", period) + ) # dwks7 # dwks8 = min(dwks3, dwks4) # adjusted_capital_gains_reduced_by_investment_income = max(0., capped_net_capital_gains - dwks8) # BELOW TWO STATEMENTS ARE UNCLEAR IN LIGHT OF adjusted_capital_gains_reduced_by_investment_income=... COMMENT - non_sch_d_capital_gains = add( - tax_unit, period, ["non_sch_d_capital_gains"] - ) # e01100 - cpaital_gains_adjusted_for_non_sch_d_gains = where( - non_sch_d_capital_gains > 0, - non_sch_d_capital_gains, - max_(0, capped_net_capital_gains) + non_sch_d_capital_gains, + other_cg = add(tax_unit, period, ["non_sch_d_capital_gains"]) # e01100 + mod_cg = where( + other_cg > 0, + other_cg, + max_(0, capped_net_capital_gains) + other_cg, ) # c24510 return max_( 0, - cpaital_gains_adjusted_for_non_sch_d_gains - - min_(0, tax_unit("investment_income_form_4952", period)), + mod_cg - min_(0, tax_unit("investment_income_form_4952", period)), ) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks06.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks06.py deleted file mode 100644 index 41ad0d2ba0d..00000000000 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks06.py +++ /dev/null @@ -1,16 +0,0 @@ -from policyengine_us.model_api import * - - -class dwks06(Variable): - value_type = float - entity = TaxUnit - definition_period = YEAR - label = "IRS Form 1040 Schedule D worksheet (part 1 of 6)" - unit = USD - - def formula(tax_unit, period, parameters): - dwks02 = add(tax_unit, period, ["qualified_dividend_income"]) - dwks03 = tax_unit("investment_income_form_4952", period) - # dwks04 always assumed to be zero - dwks05 = max_(0, dwks03) - return max_(0, dwks02 - dwks05) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks09.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks09.py deleted file mode 100644 index 30c949c0285..00000000000 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks09.py +++ /dev/null @@ -1,27 +0,0 @@ -from policyengine_us.model_api import * - - -class dwks09(Variable): - value_type = float - entity = TaxUnit - definition_period = YEAR - label = "IRS Form 1040 Schedule D worksheet (part 2 of 6)" - unit = USD - - def formula(tax_unit, period, parameters): - # SchD lines 15 and 16, respectively - qdiv_plus_ltcg = add( - tax_unit, - period, - ["long_term_capital_gains", "qualified_dividend_income"], - ) - dwks07 = min_(qdiv_plus_ltcg, tax_unit("net_capital_gains", period)) - # dwks08 = min(dwks03, dwks04) - # dwks09 = max(0., dwks07 - dwks08) - # BELOW TWO STATEMENTS ARE UNCLEAR IN LIGHT OF dwks09=... COMMENT - other_cg = add(tax_unit, period, ["non_sch_d_capital_gains"]) - mod_cg = where(other_cg > 0, other_cg, max_(0, dwks07) + other_cg) - return max_( - 0, - mod_cg - min_(0, tax_unit("investment_income_form_4952", period)), - ) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py index ffc1c0d3f54..a678b6ad0bc 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py @@ -4,23 +4,24 @@ class reduced_qualified_dividends_by_adjusted_investment_interest(Variable): value_type = float entity = TaxUnit - label = ( - "Reduced qualified dividends by adjusted investment interest" # DWKS6 - ) + label = "IRS Form 1040 Schedule D worksheet (part 1 of 6)" # DWKS06 unit = USD definition_period = YEAR reference = ( - "https://www.irs.gov/pub/irs-pdf/f6251.pdf", - "https://www.irs.gov/pub/irs-pdf/i6251.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040.pdf", + "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", ) def formula(tax_unit, period, parameters): + # Form 1040 line 3a qualified_dividends = add( tax_unit, period, ["qualified_dividend_income"] - ) # dwks2 # Form 1040 line 3a + ) # dwks2 + # From 6251 line 2c investment_interest = tax_unit( "investment_income_form_4952", period - ) # dwks3 # From 6251 line 2c + ) # dwks3 # dwks4 always assumed to be zero adjusted_investment_interest = max_(0, investment_interest) # dwks5 return max_( From 858ddc26f36a250f46026eeb520e3d2aa21da3ea Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:09:09 +0000 Subject: [PATCH 05/11] dwks10 --- ...ted_dividends_gains_whether_has_gains.yaml | 51 +++++++++++++++++++ ...puted_dividends_gains_whether_has_gains.py | 40 +++++++++++++++ .../federal_income/capital_gains/dwks10.py | 28 ---------- 3 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.yaml create mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.py delete mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks10.py diff --git a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.yaml b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.yaml new file mode 100644 index 00000000000..c1303a4e944 --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.yaml @@ -0,0 +1,51 @@ +- name: has_qdiv_or_ltcg + period: 2019 + input: + reduced_qualified_dividends_by_adjusted_investment_interest: 1_000 + adjusted_capital_gains_reduced_by_investment_income: 1_000 + long_term_capital_gains: 2_000 + qualified_dividend_income: 2_000 + net_capital_gains: 1_000 + non_sch_d_capital_gains: 1_000 + has_qdiv_or_ltcg: true + output: # 1000 + 1000 + computed_dividends_gains_whether_has_gains: 2_000 + +- name: no has_qdiv_or_ltcg, add_qdiv_or_ltcg > net_capital_gains + period: 2019 + input: + reduced_qualified_dividends_by_adjusted_investment_interest: 1_000 + adjusted_capital_gains_reduced_by_investment_income: 1_000 + long_term_capital_gains: 2_000 + qualified_dividend_income: 2_000 + net_capital_gains: 1_000 + non_sch_d_capital_gains: 2_000 + has_qdiv_or_ltcg: false + output: # min(2000 + 2000, 1000) + 2000 + computed_dividends_gains_whether_has_gains: 3_000 + +- name: no has_qdiv_or_ltcg, add_qdiv_or_ltcg < net_capital_gains + period: 2019 + input: + reduced_qualified_dividends_by_adjusted_investment_interest: 1_000 + adjusted_capital_gains_reduced_by_investment_income: 1_000 + long_term_capital_gains: 2_000 + qualified_dividend_income: 2_000 + net_capital_gains: 5_000 + non_sch_d_capital_gains: 2_000 + has_qdiv_or_ltcg: false + output: # min(2000 + 2000, 5000) + 2000 + computed_dividends_gains_whether_has_gains: 6_000 + +- name: no has_qdiv_or_ltcg, net_capital_gains < 0 + period: 2019 + input: + reduced_qualified_dividends_by_adjusted_investment_interest: 1_000 + adjusted_capital_gains_reduced_by_investment_income: 1_000 + long_term_capital_gains: 2_000 + qualified_dividend_income: 2_000 + net_capital_gains: -1_000 + non_sch_d_capital_gains: 4_000 + has_qdiv_or_ltcg: false + output: # max(0, min(2000 + 2000, -1000)) + 4000 + computed_dividends_gains_whether_has_gains: 4_000 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.py new file mode 100644 index 00000000000..09452118950 --- /dev/null +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.py @@ -0,0 +1,40 @@ +from policyengine_us.model_api import * + + +class computed_dividends_gains_whether_has_gains(Variable): + value_type = float + entity = TaxUnit + definition_period = YEAR + label = "IRS Form 1040 Schedule D worksheet (part 3 of 6)" # DWKS10 + unit = USD + reference = ( + "https://www.irs.gov/pub/irs-pdf/f1040.pdf", + "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + ) + + def formula(tax_unit, period, parameters): + if_gains = add( + tax_unit, + period, + [ + "reduced_qualified_dividends_by_adjusted_investment_interest", + "adjusted_capital_gains_reduced_by_investment_income", + ], + ) # dwks6 & 9 + if_no_gains = max_( + 0, + min_( + add( + tax_unit, + period, + ["long_term_capital_gains", "qualified_dividend_income"], + ), + tax_unit("net_capital_gains", period), + ), + ) + add(tax_unit, period, ["non_sch_d_capital_gains"]) + return where( + tax_unit("has_qdiv_or_ltcg", period), + if_gains, + if_no_gains, + ) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks10.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks10.py deleted file mode 100644 index 1aa2bd720e3..00000000000 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks10.py +++ /dev/null @@ -1,28 +0,0 @@ -from policyengine_us.model_api import * - - -class dwks10(Variable): - value_type = float - entity = TaxUnit - definition_period = YEAR - label = "IRS Form 1040 Schedule D worksheet (part 3 of 6)" - unit = USD - - def formula(tax_unit, period, parameters): - dwks10_if_gains = add(tax_unit, period, ["dwks06", "dwks09"]) - dwks10_if_no_gains = max_( - 0, - min_( - add( - tax_unit, - period, - ["long_term_capital_gains", "qualified_dividend_income"], - ), - tax_unit("net_capital_gains", period), - ), - ) + add(tax_unit, period, ["non_sch_d_capital_gains"]) - return where( - tax_unit("has_qdiv_or_ltcg", period), - dwks10_if_gains, - dwks10_if_no_gains, - ) From c66272bf42c4d7714c80f237f279344883deb253 Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Tue, 17 Sep 2024 04:13:12 +0000 Subject: [PATCH 06/11] all dwks --- ...ted_final_gains_after_all_adjustments.yaml | 43 +++++++++++++++++++ ..._after_1250_and_28_percent_rate_gains.yaml | 43 +++++++++++++++++++ .../taxable_income_minus_gains.yaml | 26 +++++++++++ ...ital_gains_reduced_by_investment_income.py | 0 ...puted_dividends_gains_whether_has_gains.py | 0 ...puted_final_gains_after_all_adjustments.py | 41 ++++++++++++++++++ ...ns_after_1250_and_28_percent_rate_gains.py | 38 ++++++++++++++++ ...vidends_by_adjusted_investment_interest.py | 0 .../dwks/taxable_income_minus_gains.py | 25 +++++++++++ .../federal_income/capital_gains/dwks13.py | 19 -------- .../federal_income/capital_gains/dwks14.py | 14 ------ .../federal_income/capital_gains/dwks19.py | 20 --------- 12 files changed, 216 insertions(+), 53 deletions(-) create mode 100644 policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_final_gains_after_all_adjustments.yaml create mode 100644 policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_gains_after_1250_and_28_percent_rate_gains.yaml create mode 100644 policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/taxable_income_minus_gains.yaml rename policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/{ => dwks}/adjusted_capital_gains_reduced_by_investment_income.py (100%) rename policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/{ => dwks}/computed_dividends_gains_whether_has_gains.py (100%) create mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py create mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_gains_after_1250_and_28_percent_rate_gains.py rename policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/{ => dwks}/reduced_qualified_dividends_by_adjusted_investment_interest.py (100%) create mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/taxable_income_minus_gains.py delete mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks13.py delete mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks14.py delete mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks19.py diff --git a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_final_gains_after_all_adjustments.yaml b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_final_gains_after_all_adjustments.yaml new file mode 100644 index 00000000000..bdd9c8689e7 --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_final_gains_after_all_adjustments.yaml @@ -0,0 +1,43 @@ +- name: has_qdiv_or_ltcg, taxable_income_minus_gains < taxable_income < capital_gains + period: 2019 + input: + filing_status: SINGLE + taxable_income: 4_000 + taxable_income_minus_gains: 3_000 + computed_dividends_gains_whether_has_gains: 2_000 + has_qdiv_or_ltcg: true + output: # max(min(39375, 4000, 3000), 4000 - 2000) * 1 + computed_final_gains_after_all_adjustments: 3_000 + +- name: has_qdiv_or_ltcg, capital_gains < taxable_income_minus_gains < taxable_income + period: 2021 + input: + filing_status: SINGLE + taxable_income: 50_000 + taxable_income_minus_gains: 45_000 + computed_dividends_gains_whether_has_gains: 20_000 + has_qdiv_or_ltcg: true + output: # max(min(40400, 50000, 45000), 50000 - 20000) * 1 + computed_final_gains_after_all_adjustments: 40_400 + +- name: has_qdiv_or_ltcg, capital_gains < taxable_income_minus_gains < taxable_income, taxable_income < computed_dividends_gains_whether_has_gains + period: 2021 + input: + filing_status: SINGLE + taxable_income: 10_000 + taxable_income_minus_gains: 5_000 + computed_dividends_gains_whether_has_gains: 20_000 + has_qdiv_or_ltcg: true + output: # max(min(40000, 10000, 5000), 10000 - 20000) * 1 + computed_final_gains_after_all_adjustments: 5_000 + +- name: no has_qdiv_or_ltcg + period: 2021 + input: + filing_status: SINGLE + taxable_income: 10_000 + taxable_income_minus_gains: 5_000 + computed_dividends_gains_whether_has_gains: 20_000 + has_qdiv_or_ltcg: false + output: # max(min(40000, 10000, 5000), 10000 - 20000) * 0 + computed_final_gains_after_all_adjustments: 0 diff --git a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_gains_after_1250_and_28_percent_rate_gains.yaml b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_gains_after_1250_and_28_percent_rate_gains.yaml new file mode 100644 index 00000000000..9977058b7fa --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_gains_after_1250_and_28_percent_rate_gains.yaml @@ -0,0 +1,43 @@ +- name: has_qdiv_or_ltcg, added_1250_and_28_percent_rate_gains < adjusted_capital_gains_reduced_by_investment_income + period: 2019 + input: + unrecaptured_section_1250_gain: 1_000 + capital_gains_28_percent_rate_gain: 1_000 + adjusted_capital_gains_reduced_by_investment_income: 3_000 + computed_dividends_gains_whether_has_gains: 2_000 + has_qdiv_or_ltcg: true + output: # (2000 - min(1000 + 1000, 3000)) * 1 + computed_gains_after_1250_and_28_percent_rate_gains: 0 + +- name: has_qdiv_or_ltcg, added_1250_and_28_percent_rate_gains < adjusted_capital_gains_reduced_by_investment_income + period: 2019 + input: + unrecaptured_section_1250_gain: 1_000 + capital_gains_28_percent_rate_gain: 1_000 + adjusted_capital_gains_reduced_by_investment_income: 1_000 + computed_dividends_gains_whether_has_gains: 2_000 + has_qdiv_or_ltcg: true + output: # (2000 - min(1000 + 1000, 1000)) * 1 + computed_gains_after_1250_and_28_percent_rate_gains: 1_000 + +- name: no has_qdiv_or_ltcg + period: 2019 + input: + unrecaptured_section_1250_gain: 1_000 + capital_gains_28_percent_rate_gain: 1_000 + adjusted_capital_gains_reduced_by_investment_income: 1_000 + computed_dividends_gains_whether_has_gains: 2_000 + has_qdiv_or_ltcg: false + output: # (2000 - min(1000 + 1000, 1000)) * 0 + computed_gains_after_1250_and_28_percent_rate_gains: 0 + +- name: negative result + period: 2019 + input: + unrecaptured_section_1250_gain: 2_000 + capital_gains_28_percent_rate_gain: 1_000 + adjusted_capital_gains_reduced_by_investment_income: 4_000 + computed_dividends_gains_whether_has_gains: 2_000 + has_qdiv_or_ltcg: true + output: # (2000 - min(2000 + 1000, 4000)) * 1 + computed_gains_after_1250_and_28_percent_rate_gains: -1_000 diff --git a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/taxable_income_minus_gains.yaml b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/taxable_income_minus_gains.yaml new file mode 100644 index 00000000000..bcc9a3fe943 --- /dev/null +++ b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/taxable_income_minus_gains.yaml @@ -0,0 +1,26 @@ +- name: has_qdiv_or_ltcg, taxable_income > computed_gains_after_1250_and_28_percent_rate_gains + period: 2019 + input: + taxable_income: 3_000 + computed_gains_after_1250_and_28_percent_rate_gains: 1_000 + has_qdiv_or_ltcg: true + output: # (3000 - 1000) * 1 + taxable_income_minus_gains: 2_000 + +- name: has_qdiv_or_ltcg, taxable_income < computed_gains_after_1250_and_28_percent_rate_gains + period: 2019 + input: + taxable_income: 3_000 + computed_gains_after_1250_and_28_percent_rate_gains: 4_000 + has_qdiv_or_ltcg: true + output: # (3000 - 4000) * 1 + taxable_income_minus_gains: 0 + +- name: no has_qdiv_or_ltcg + period: 2019 + input: + taxable_income: 3_000 + computed_gains_after_1250_and_28_percent_rate_gains: 1_000 + has_qdiv_or_ltcg: false + output: # (3000 - 1000) * 0 + taxable_income_minus_gains: 0 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/adjusted_capital_gains_reduced_by_investment_income.py similarity index 100% rename from policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/adjusted_capital_gains_reduced_by_investment_income.py rename to policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/adjusted_capital_gains_reduced_by_investment_income.py diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_dividends_gains_whether_has_gains.py similarity index 100% rename from policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/computed_dividends_gains_whether_has_gains.py rename to policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_dividends_gains_whether_has_gains.py diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py new file mode 100644 index 00000000000..76f2b1b9389 --- /dev/null +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py @@ -0,0 +1,41 @@ +from policyengine_us.model_api import * + + +class computed_final_gains_after_all_adjustments(Variable): + value_type = float + entity = TaxUnit + definition_period = YEAR + label = "IRS Form 1040 Schedule D worksheet (part 6 of 6)" # DWKS19 + unit = USD + reference = ( + "https://www.irs.gov/pub/irs-pdf/f1040.pdf", + "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + ) + + def formula(tax_unit, period, parameters): + taxable_income_minus_gains = tax_unit( + "taxable_income_minus_gains", period + ) # dwks14 + capital_gains = parameters(period).gov.irs.capital_gains.brackets + filing_status = tax_unit("filing_status", period) + taxable_income = tax_unit("taxable_income", period) # dwks1 + min_capital_gains_and_taxable_income = min_( + capital_gains.thresholds["1"][filing_status], taxable_income + ) # dwks16 + min_capital_gains_and_taxable_income_and_taxable_income_minus_gains = ( + min_( + taxable_income_minus_gains, + min_capital_gains_and_taxable_income, + ) + ) # dwks17 + computed_dividends_gains_whether_has_gains = tax_unit( + "computed_dividends_gains_whether_has_gains", period + ) # dwks10 + taxable_income_minus_computed_dividends_gains_whether_has_gains = max_( + 0, taxable_income - computed_dividends_gains_whether_has_gains + ) # dwks18 + return max_( + min_capital_gains_and_taxable_income_and_taxable_income_minus_gains, + taxable_income_minus_computed_dividends_gains_whether_has_gains, + ) * tax_unit("has_qdiv_or_ltcg", period) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_gains_after_1250_and_28_percent_rate_gains.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_gains_after_1250_and_28_percent_rate_gains.py new file mode 100644 index 00000000000..78909bbdba2 --- /dev/null +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_gains_after_1250_and_28_percent_rate_gains.py @@ -0,0 +1,38 @@ +from policyengine_us.model_api import * + + +class computed_gains_after_1250_and_28_percent_rate_gains(Variable): + value_type = float + entity = TaxUnit + definition_period = YEAR + label = "IRS Form 1040 Schedule D worksheet (part 4 of 6)" # DWKS13 + unit = USD + reference = ( + "https://www.irs.gov/pub/irs-pdf/f1040.pdf", + "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + ) + + def formula(tax_unit, period, parameters): + unrecaptured_section_1250_gain = add( + tax_unit, period, ["unrecaptured_section_1250_gain"] + ) # e24515 + # Sch D lines 18 and 19, respectively + added_1250_and_28_percent_rate_gains = ( + unrecaptured_section_1250_gain + + add(tax_unit, period, ["capital_gains_28_percent_rate_gain"]) + ) # dwks11 + adjusted_capital_gains_reduced_by_investment_income = tax_unit( + "adjusted_capital_gains_reduced_by_investment_income", period + ) # dwks09 + min_adjusted_gains_and_added_gains = min_( + adjusted_capital_gains_reduced_by_investment_income, + added_1250_and_28_percent_rate_gains, + ) # dwks12 + computed_dividends_gains_whether_has_gains = tax_unit( + "computed_dividends_gains_whether_has_gains", period + ) # dwks10 + return ( + computed_dividends_gains_whether_has_gains + - min_adjusted_gains_and_added_gains + ) * tax_unit("has_qdiv_or_ltcg", period) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/reduced_qualified_dividends_by_adjusted_investment_interest.py similarity index 100% rename from policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/reduced_qualified_dividends_by_adjusted_investment_interest.py rename to policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/reduced_qualified_dividends_by_adjusted_investment_interest.py diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/taxable_income_minus_gains.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/taxable_income_minus_gains.py new file mode 100644 index 00000000000..2c2bf521c41 --- /dev/null +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/taxable_income_minus_gains.py @@ -0,0 +1,25 @@ +from policyengine_us.model_api import * + + +class taxable_income_minus_gains(Variable): + value_type = float + entity = TaxUnit + definition_period = YEAR + label = "IRS Form 1040 Schedule D worksheet (part 5 of 6)" # DWKS14 + unit = USD + reference = ( + "https://www.irs.gov/pub/irs-pdf/f1040.pdf", + "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + ) + + def formula(tax_unit, period, parameters): + taxable_income = tax_unit("taxable_income", period) # dwks1 + computed_gains_after_1250_and_28_percent_rate_gains = tax_unit( + "computed_gains_after_1250_and_28_percent_rate_gains", period + ) # dwks13 + return max_( + 0, + taxable_income + - computed_gains_after_1250_and_28_percent_rate_gains, + ) * tax_unit("has_qdiv_or_ltcg", period) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks13.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks13.py deleted file mode 100644 index 87753639b46..00000000000 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks13.py +++ /dev/null @@ -1,19 +0,0 @@ -from policyengine_us.model_api import * - - -class dwks13(Variable): - value_type = float - entity = TaxUnit - definition_period = YEAR - label = "IRS Form 1040 Schedule D worksheet (part 4 of 6)" - unit = USD - - def formula(tax_unit, period, parameters): - e24515 = add(tax_unit, period, ["unrecaptured_section_1250_gain"]) - dwks11 = e24515 + add( - tax_unit, period, ["capital_gains_28_percent_rate_gain"] - ) # Sch D lines 18 and 19, respectively - dwks09 = tax_unit("dwks09", period) - dwks12 = min_(dwks09, dwks11) - dwks10 = tax_unit("dwks10", period) - return (dwks10 - dwks12) * tax_unit("has_qdiv_or_ltcg", period) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks14.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks14.py deleted file mode 100644 index 335d8e77527..00000000000 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks14.py +++ /dev/null @@ -1,14 +0,0 @@ -from policyengine_us.model_api import * - - -class dwks14(Variable): - value_type = float - entity = TaxUnit - definition_period = YEAR - label = "IRS Form 1040 Schedule D worksheet (part 5 of 6)" - unit = USD - - def formula(tax_unit, period, parameters): - dwks01 = tax_unit("taxable_income", period) - dwks13 = tax_unit("dwks13", period) - return max_(0, dwks01 - dwks13) * tax_unit("has_qdiv_or_ltcg", period) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks19.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks19.py deleted file mode 100644 index 3d647d75f0c..00000000000 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks19.py +++ /dev/null @@ -1,20 +0,0 @@ -from policyengine_us.model_api import * - - -class dwks19(Variable): - value_type = float - entity = TaxUnit - definition_period = YEAR - label = "IRS Form 1040 Schedule D worksheet (part 6 of 6)" - unit = USD - - def formula(tax_unit, period, parameters): - dwks14 = tax_unit("dwks14", period) - capital_gains = parameters(period).gov.irs.capital_gains.brackets - filing_status = tax_unit("filing_status", period) - dwks01 = tax_unit("taxable_income", period) - dwks16 = min_(capital_gains.thresholds["1"][filing_status], dwks01) - dwks17 = min_(dwks14, dwks16) - dwks10 = tax_unit("dwks10", period) - dwks18 = max_(0, dwks01 - dwks10) - return max_(dwks17, dwks18) * tax_unit("has_qdiv_or_ltcg", period) From 3ddad34eea88381711f5fe56df12e798151afdb7 Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Thu, 19 Sep 2024 02:37:52 +0000 Subject: [PATCH 07/11] reference --- .../regular_tax_before_credits.py | 16 ++++++++++------ ...capital_gains_reduced_by_investment_income.py | 6 ++++-- ...computed_dividends_gains_whether_has_gains.py | 5 ++--- ...computed_final_gains_after_all_adjustments.py | 12 +++++++++--- ...gains_after_1250_and_28_percent_rate_gains.py | 8 ++++++-- ..._dividends_by_adjusted_investment_interest.py | 10 +++++----- .../dwks/taxable_income_minus_gains.py | 9 +++++---- 7 files changed, 41 insertions(+), 25 deletions(-) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py index 31e32dea3c1..1460656b2a0 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py @@ -9,22 +9,26 @@ class regular_tax_before_credits(Variable): documentation = "Regular tax on regular taxable income before credits" unit = USD reference = ( - "https://www.irs.gov/pub/irs-pdf/f6251.pdf", - "https://www.irs.gov/pub/irs-pdf/i6251.pdf", + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): - filing_status = tax_unit("filing_status", period) + # Schedule D Tax Worksheet line 1 taxable_income = tax_unit("taxable_income", period) # dwks1 - + # Schedule D Tax Worksheet line 15 + filing_status = tax_unit("filing_status", period) capital_gains = parameters(period).gov.irs.capital_gains.brackets - + # Schedule D Tax Worksheet line 16 capital_gain_taxable_threshold = min_( capital_gains.thresholds["1"][filing_status], taxable_income ) # dwks16 + # Schedule D Tax Worksheet line 17 dwks17 = min_( - tax_unit("dwks14", period), capital_gain_taxable_threshold + tax_unit("taxable_income_minus_gains", period), + capital_gain_taxable_threshold, ) + # Schedule D Tax Worksheet line 20 dwks20 = capital_gain_taxable_threshold - dwks17 lowest_rate_tax = capital_gains.rates["1"] * dwks20 # Break in worksheet lines diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/adjusted_capital_gains_reduced_by_investment_income.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/adjusted_capital_gains_reduced_by_investment_income.py index d1931e33d93..1a3dd072780 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/adjusted_capital_gains_reduced_by_investment_income.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/adjusted_capital_gains_reduced_by_investment_income.py @@ -8,9 +8,8 @@ class adjusted_capital_gains_reduced_by_investment_income(Variable): unit = USD definition_period = YEAR reference = ( - "https://www.irs.gov/pub/irs-pdf/f1040.pdf", - "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): @@ -20,10 +19,13 @@ def formula(tax_unit, period, parameters): period, ["long_term_capital_gains", "qualified_dividend_income"], ) # p23250 + # Schedule D Tax Worksheet line 7 capped_net_capital_gains = min_( qdiv_plus_ltcg, tax_unit("net_capital_gains", period) ) # dwks7 + # Schedule D Tax Worksheet line 8 # dwks8 = min(dwks3, dwks4) + # Schedule D Tax Worksheet line 9 # adjusted_capital_gains_reduced_by_investment_income = max(0., capped_net_capital_gains - dwks8) # BELOW TWO STATEMENTS ARE UNCLEAR IN LIGHT OF adjusted_capital_gains_reduced_by_investment_income=... COMMENT other_cg = add(tax_unit, period, ["non_sch_d_capital_gains"]) # e01100 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_dividends_gains_whether_has_gains.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_dividends_gains_whether_has_gains.py index 09452118950..9e93c79beb8 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_dividends_gains_whether_has_gains.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_dividends_gains_whether_has_gains.py @@ -8,12 +8,11 @@ class computed_dividends_gains_whether_has_gains(Variable): label = "IRS Form 1040 Schedule D worksheet (part 3 of 6)" # DWKS10 unit = USD reference = ( - "https://www.irs.gov/pub/irs-pdf/f1040.pdf", - "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", - "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): + # Schedule D Tax Worksheet line 10 if_gains = add( tax_unit, period, diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py index 76f2b1b9389..5780155b314 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py @@ -8,33 +8,39 @@ class computed_final_gains_after_all_adjustments(Variable): label = "IRS Form 1040 Schedule D worksheet (part 6 of 6)" # DWKS19 unit = USD reference = ( - "https://www.irs.gov/pub/irs-pdf/f1040.pdf", - "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", - "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): + # Schedule D Tax Worksheet line 14 taxable_income_minus_gains = tax_unit( "taxable_income_minus_gains", period ) # dwks14 + # Schedule D Tax Worksheet line 15 capital_gains = parameters(period).gov.irs.capital_gains.brackets filing_status = tax_unit("filing_status", period) + # Schedule D Tax Worksheet line 1 taxable_income = tax_unit("taxable_income", period) # dwks1 + # Schedule D Tax Worksheet line 16 min_capital_gains_and_taxable_income = min_( capital_gains.thresholds["1"][filing_status], taxable_income ) # dwks16 + # Schedule D Tax Worksheet line 17 min_capital_gains_and_taxable_income_and_taxable_income_minus_gains = ( min_( taxable_income_minus_gains, min_capital_gains_and_taxable_income, ) ) # dwks17 + # Schedule D Tax Worksheet line 10 computed_dividends_gains_whether_has_gains = tax_unit( "computed_dividends_gains_whether_has_gains", period ) # dwks10 + # Schedule D Tax Worksheet line 18 taxable_income_minus_computed_dividends_gains_whether_has_gains = max_( 0, taxable_income - computed_dividends_gains_whether_has_gains ) # dwks18 + # Schedule D Tax Worksheet line 21? return max_( min_capital_gains_and_taxable_income_and_taxable_income_minus_gains, taxable_income_minus_computed_dividends_gains_whether_has_gains, diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_gains_after_1250_and_28_percent_rate_gains.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_gains_after_1250_and_28_percent_rate_gains.py index 78909bbdba2..68a26b1857b 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_gains_after_1250_and_28_percent_rate_gains.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_gains_after_1250_and_28_percent_rate_gains.py @@ -8,9 +8,8 @@ class computed_gains_after_1250_and_28_percent_rate_gains(Variable): label = "IRS Form 1040 Schedule D worksheet (part 4 of 6)" # DWKS13 unit = USD reference = ( - "https://www.irs.gov/pub/irs-pdf/f1040.pdf", - "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): @@ -18,20 +17,25 @@ def formula(tax_unit, period, parameters): tax_unit, period, ["unrecaptured_section_1250_gain"] ) # e24515 # Sch D lines 18 and 19, respectively + # Schedule D Tax Worksheet line 11 added_1250_and_28_percent_rate_gains = ( unrecaptured_section_1250_gain + add(tax_unit, period, ["capital_gains_28_percent_rate_gain"]) ) # dwks11 + # Schedule D Tax Worksheet line 9 adjusted_capital_gains_reduced_by_investment_income = tax_unit( "adjusted_capital_gains_reduced_by_investment_income", period ) # dwks09 + # Schedule D Tax Worksheet line 12 min_adjusted_gains_and_added_gains = min_( adjusted_capital_gains_reduced_by_investment_income, added_1250_and_28_percent_rate_gains, ) # dwks12 + # Schedule D Tax Worksheet line 10 computed_dividends_gains_whether_has_gains = tax_unit( "computed_dividends_gains_whether_has_gains", period ) # dwks10 + # Schedule D Tax Worksheet line 13 return ( computed_dividends_gains_whether_has_gains - min_adjusted_gains_and_added_gains diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/reduced_qualified_dividends_by_adjusted_investment_interest.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/reduced_qualified_dividends_by_adjusted_investment_interest.py index a678b6ad0bc..748cc5fc94b 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/reduced_qualified_dividends_by_adjusted_investment_interest.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/reduced_qualified_dividends_by_adjusted_investment_interest.py @@ -8,22 +8,22 @@ class reduced_qualified_dividends_by_adjusted_investment_interest(Variable): unit = USD definition_period = YEAR reference = ( - "https://www.irs.gov/pub/irs-pdf/f1040.pdf", - "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", - "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): - # Form 1040 line 3a + # Schedule D Tax Worksheet line 2 qualified_dividends = add( tax_unit, period, ["qualified_dividend_income"] ) # dwks2 - # From 6251 line 2c + # Schedule D Tax Worksheet line 3 investment_interest = tax_unit( "investment_income_form_4952", period ) # dwks3 # dwks4 always assumed to be zero + # Schedule D Tax Worksheet line 5 adjusted_investment_interest = max_(0, investment_interest) # dwks5 + # Schedule D Tax Worksheet line 6 return max_( 0, qualified_dividends - adjusted_investment_interest ) # dwks6 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/taxable_income_minus_gains.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/taxable_income_minus_gains.py index 2c2bf521c41..aa2dcc3353f 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/taxable_income_minus_gains.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/taxable_income_minus_gains.py @@ -8,16 +8,17 @@ class taxable_income_minus_gains(Variable): label = "IRS Form 1040 Schedule D worksheet (part 5 of 6)" # DWKS14 unit = USD reference = ( - "https://www.irs.gov/pub/irs-pdf/f1040.pdf", - "https://www.irs.gov/pub/irs-pdf/i1040gi.pdf", - "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): - taxable_income = tax_unit("taxable_income", period) # dwks1 + # Schedule D Tax Worksheet line 1 + taxable_income = tax_unit("taxable_income", period) # + # Schedule D Tax Worksheet line 13 computed_gains_after_1250_and_28_percent_rate_gains = tax_unit( "computed_gains_after_1250_and_28_percent_rate_gains", period ) # dwks13 + # Schedule D Tax Worksheet line 14 return max_( 0, taxable_income From 21a2f6ae1490db534bd023b8f8aed9a5bac25c0b Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Thu, 19 Sep 2024 03:10:53 +0000 Subject: [PATCH 08/11] reference year --- .../alternative_minimum_tax/regular_tax_before_credits.py | 2 +- .../dwks/computed_final_gains_after_all_adjustments.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py index 1460656b2a0..32b5c1ccdca 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py @@ -10,7 +10,7 @@ class regular_tax_before_credits(Variable): unit = USD reference = ( "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", - "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", + "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=16", ) def formula(tax_unit, period, parameters): diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py index 5780155b314..b024f8e6128 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py @@ -8,7 +8,7 @@ class computed_final_gains_after_all_adjustments(Variable): label = "IRS Form 1040 Schedule D worksheet (part 6 of 6)" # DWKS19 unit = USD reference = ( - "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", + "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=16", ) def formula(tax_unit, period, parameters): @@ -40,7 +40,7 @@ def formula(tax_unit, period, parameters): taxable_income_minus_computed_dividends_gains_whether_has_gains = max_( 0, taxable_income - computed_dividends_gains_whether_has_gains ) # dwks18 - # Schedule D Tax Worksheet line 21? + # Schedule D Tax Worksheet line 19 return max_( min_capital_gains_and_taxable_income_and_taxable_income_minus_gains, taxable_income_minus_computed_dividends_gains_whether_has_gains, From 8f5738c65fa356baf2bc50bb0bec4389ae3fa37a Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:43:45 +0000 Subject: [PATCH 09/11] yearly additional steps --- .../gov/irs/capital_gains/in_effect.yaml | 15 +++++ .../capital_gains/taxable_income_limit.yaml | 55 +++++++++++++++++++ ...ted_final_gains_after_all_adjustments.yaml | 29 +++++++--- .../regular_tax_before_credits.py | 2 +- ...puted_final_gains_after_all_adjustments.py | 33 +++++++++-- 5 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 policyengine_us/parameters/gov/irs/capital_gains/in_effect.yaml create mode 100644 policyengine_us/parameters/gov/irs/capital_gains/taxable_income_limit.yaml diff --git a/policyengine_us/parameters/gov/irs/capital_gains/in_effect.yaml b/policyengine_us/parameters/gov/irs/capital_gains/in_effect.yaml new file mode 100644 index 00000000000..2ebe87f6ce2 --- /dev/null +++ b/policyengine_us/parameters/gov/irs/capital_gains/in_effect.yaml @@ -0,0 +1,15 @@ +description: Whether the additional lines apply to Schedule D Tax Worksheet. +values: + 0000-01-01: false + 2018-01-01: true +metadata: + unit: bool + period: year + label: Schedule D Tax Worksheet additional line in effect + reference: + - title: 2017 Instructions for Schedule D - line 19 + href: https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=15 + - title: 2018 Instructions for Schedule D - line 18b + href: https://www.irs.gov/pub/irs-prior/i1040sd--2018.pdf#page=19 + - title: 2019 Instructions for Schedule D - line 19 + href: https://www.irs.gov/pub/irs-prior/i1040sd--2019.pdf#page=16 diff --git a/policyengine_us/parameters/gov/irs/capital_gains/taxable_income_limit.yaml b/policyengine_us/parameters/gov/irs/capital_gains/taxable_income_limit.yaml new file mode 100644 index 00000000000..981d80dc999 --- /dev/null +++ b/policyengine_us/parameters/gov/irs/capital_gains/taxable_income_limit.yaml @@ -0,0 +1,55 @@ +description: Taxable income thresholds and limits. +metadata: + unit: currency-USD + period: year + label: Taxable income thresholds + breakdown: filing_status + reference: + - title: 2018 Instructions for Schedule D - line 18b + href: https://www.irs.gov/pub/irs-prior/i1040sd--2018.pdf#page=19 + - title: 2019 Instructions for Schedule D - line 19 + href: https://www.irs.gov/pub/irs-prior/i1040sd--2019.pdf#page=16 + - title: 2020 Instructions for Schedule D - line 19 + href: https://www.irs.gov/pub/irs-prior/i1040sd--2020.pdf#page=16 + - title: 2021 Instructions for Schedule D - line 19 + href: https://www.irs.gov/pub/irs-prior/i1040sd--2021.pdf#page=16 + - title: 2022 Instructions for Schedule D - line 19 + href: https://www.irs.gov/pub/irs-prior/i1040sd--2022.pdf#page=16 + - title: 2023 Instructions for Schedule D - line 19 + href: https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16 + +SINGLE: + 2018-01-01: 157_500 + 2019-01-01: 160_725 + 2020-01-01: 163_300 + 2021-01-01: 164_925 + 2022-01-01: 170_050 + 2023-01-01: 182_100 +JOINT: + 2018-01-01: 315_000 + 2019-01-01: 321_450 + 2020-01-01: 326_600 + 2021-01-01: 329_850 + 2022-01-01: 340_100 + 2023-01-01: 364_200 +SEPARATE: + 2018-01-01: 157_500 + 2019-01-01: 160_725 + 2020-01-01: 163_300 + 2021-01-01: 164_925 + 2022-01-01: 170_050 + 2023-01-01: 182_100 +HEAD_OF_HOUSEHOLD: + 2018-01-01: 157_500 + 2019-01-01: 160_700 + 2020-01-01: 163_300 + 2021-01-01: 164_900 + 2022-01-01: 170_050 + 2023-01-01: 182_100 +SURVIVING_SPOUSE: + 2018-01-01: 315_000 + 2019-01-01: 321_450 + 2020-01-01: 326_600 + 2021-01-01: 329_850 + 2022-01-01: 340_100 + 2023-01-01: 364_200 diff --git a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_final_gains_after_all_adjustments.yaml b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_final_gains_after_all_adjustments.yaml index bdd9c8689e7..7bc19f1e6b5 100644 --- a/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_final_gains_after_all_adjustments.yaml +++ b/policyengine_us/tests/policy/baseline/gov/irs/tax/federal_income/capital_gains/computed_final_gains_after_all_adjustments.yaml @@ -1,43 +1,54 @@ - name: has_qdiv_or_ltcg, taxable_income_minus_gains < taxable_income < capital_gains - period: 2019 + period: 2017 input: filing_status: SINGLE taxable_income: 4_000 taxable_income_minus_gains: 3_000 computed_dividends_gains_whether_has_gains: 2_000 has_qdiv_or_ltcg: true - output: # max(min(39375, 4000, 3000), 4000 - 2000) * 1 + output: # max(min(37950, 4000, 3000), 4000 - 2000) * 1 computed_final_gains_after_all_adjustments: 3_000 - name: has_qdiv_or_ltcg, capital_gains < taxable_income_minus_gains < taxable_income - period: 2021 + period: 2017 input: filing_status: SINGLE taxable_income: 50_000 taxable_income_minus_gains: 45_000 computed_dividends_gains_whether_has_gains: 20_000 has_qdiv_or_ltcg: true - output: # max(min(40400, 50000, 45000), 50000 - 20000) * 1 - computed_final_gains_after_all_adjustments: 40_400 + output: # max(min(37950, 50000, 45000), 50000 - 20000) * 1 + computed_final_gains_after_all_adjustments: 37_950 - name: has_qdiv_or_ltcg, capital_gains < taxable_income_minus_gains < taxable_income, taxable_income < computed_dividends_gains_whether_has_gains - period: 2021 + period: 2017 input: filing_status: SINGLE taxable_income: 10_000 taxable_income_minus_gains: 5_000 computed_dividends_gains_whether_has_gains: 20_000 has_qdiv_or_ltcg: true - output: # max(min(40000, 10000, 5000), 10000 - 20000) * 1 + output: # max(min(37950, 10000, 5000), 10000 - 20000) * 1 computed_final_gains_after_all_adjustments: 5_000 - name: no has_qdiv_or_ltcg - period: 2021 + period: 2017 input: filing_status: SINGLE taxable_income: 10_000 taxable_income_minus_gains: 5_000 computed_dividends_gains_whether_has_gains: 20_000 has_qdiv_or_ltcg: false - output: # max(min(40000, 10000, 5000), 10000 - 20000) * 0 + output: # max(min(37950, 10000, 5000), 10000 - 20000) * 0 computed_final_gains_after_all_adjustments: 0 + +- name: with additional steps + period: 2018 + input: + filing_status: SINGLE + taxable_income: 200_000 + taxable_income_minus_gains: 190_000 + computed_dividends_gains_whether_has_gains: 50_000 + has_qdiv_or_ltcg: true + output: # max(min(157500, 200000, 190000), 200000 - 50000) * 1 + computed_final_gains_after_all_adjustments: 157_500 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py index 32b5c1ccdca..eed574703e2 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py @@ -10,7 +10,7 @@ class regular_tax_before_credits(Variable): unit = USD reference = ( "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", - "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=16", + "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=15", ) def formula(tax_unit, period, parameters): diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py index b024f8e6128..77667e516da 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/capital_gains/dwks/computed_final_gains_after_all_adjustments.py @@ -8,7 +8,9 @@ class computed_final_gains_after_all_adjustments(Variable): label = "IRS Form 1040 Schedule D worksheet (part 6 of 6)" # DWKS19 unit = USD reference = ( - "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=16", + "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=15", + "https://www.irs.gov/pub/irs-prior/i1040sd--2018.pdf#page=19", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): @@ -40,8 +42,27 @@ def formula(tax_unit, period, parameters): taxable_income_minus_computed_dividends_gains_whether_has_gains = max_( 0, taxable_income - computed_dividends_gains_whether_has_gains ) # dwks18 - # Schedule D Tax Worksheet line 19 - return max_( - min_capital_gains_and_taxable_income_and_taxable_income_minus_gains, - taxable_income_minus_computed_dividends_gains_whether_has_gains, - ) * tax_unit("has_qdiv_or_ltcg", period) + + p = parameters(period).gov.irs.capital_gains + # 2017 and years before + if not p.in_effect: + # Schedule D Tax Worksheet line 19 + return max_( + min_capital_gains_and_taxable_income_and_taxable_income_minus_gains, + taxable_income_minus_computed_dividends_gains_whether_has_gains, + ) * tax_unit("has_qdiv_or_ltcg", period) + # 2018 and years after + else: + # Schedule D Tax Worksheet line 18b for 2018, or line 19 for years after + taxable_income_limit = min_( + taxable_income, p.taxable_income_limit[filing_status] + ) + # Schedule D Tax Worksheet line 18c for 2018, or line 20 for years after + taxable_income_minus_gains_limit = min_( + taxable_income_minus_gains, taxable_income_limit + ) + # Schedule D Tax Worksheet line 19 for 2018, or line 21 for years after + return max_( + taxable_income_minus_computed_dividends_gains_whether_has_gains, + taxable_income_minus_gains_limit, + ) * tax_unit("has_qdiv_or_ltcg", period) From ac34157293f7b685e52b209a17c24b46ba22c967 Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Thu, 26 Sep 2024 08:28:54 +0000 Subject: [PATCH 10/11] regular_tax_before_credits --- .../regular_tax_before_credits.py | 153 +++++++++++++----- 1 file changed, 116 insertions(+), 37 deletions(-) diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py index eed574703e2..8113c44ea8a 100644 --- a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/regular_tax_before_credits.py @@ -11,6 +11,8 @@ class regular_tax_before_credits(Variable): reference = ( "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=15", + "https://www.irs.gov/pub/irs-prior/i1040sd--2018.pdf#page=19", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", ) def formula(tax_unit, period, parameters): @@ -20,50 +22,119 @@ def formula(tax_unit, period, parameters): filing_status = tax_unit("filing_status", period) capital_gains = parameters(period).gov.irs.capital_gains.brackets # Schedule D Tax Worksheet line 16 - capital_gain_taxable_threshold = min_( + min_capital_gains_and_taxable_income_1 = min_( capital_gains.thresholds["1"][filing_status], taxable_income ) # dwks16 # Schedule D Tax Worksheet line 17 - dwks17 = min_( - tax_unit("taxable_income_minus_gains", period), - capital_gain_taxable_threshold, + min_capital_gains_and_taxable_income_and_taxable_income_minus_gains = ( + min_( + tax_unit("taxable_income_minus_gains", period), + min_capital_gains_and_taxable_income_1, + ) + ) # dwks17 = min_(tax_unit("dwks14", period), dwks16) + # Schedule D Tax Worksheet line 20 for 2017 and 2018, or line 22 for years after + capital_gains_taxable_difference_after_gains_adjustments = ( + min_capital_gains_and_taxable_income_1 + - min_capital_gains_and_taxable_income_and_taxable_income_minus_gains + ) # dwks20 = dwks16 - dwks17 + lowest_rate_tax = ( + capital_gains.rates["1"] + * capital_gains_taxable_difference_after_gains_adjustments ) - # Schedule D Tax Worksheet line 20 - dwks20 = capital_gain_taxable_threshold - dwks17 - lowest_rate_tax = capital_gains.rates["1"] * dwks20 # Break in worksheet lines - dwks13 = tax_unit("dwks13", period) - dwks21 = min_(dwks1, dwks13) - dwks22 = dwks20 - dwks23 = max_(0, dwks21 - dwks22) - dwks25 = min_(capital_gains.thresholds["2"][filing_status], dwks1) - dwks19 = tax_unit("dwks19", period) - dwks26 = min_(dwks19, dwks20) - dwks27 = max_(0, dwks25 - dwks26) - dwks28 = min_(dwks23, dwks27) - dwks29 = capital_gains.rates["2"] * dwks28 - dwks30 = dwks22 + dwks28 - dwks31 = dwks21 - dwks30 - dwks32 = capital_gains.rates["3"] * dwks31 + # Schedule D Tax Worksheet line 13 + computed_gains_after_1250_and_28_percent_rate_gains = tax_unit( + "computed_gains_after_1250_and_28_percent_rate_gains", period + ) # dwks13 + # Schedule D Tax Worksheet line 21 for 2017 and 2018, or line 23 for years after + minimum_of_taxable_income_and_adjusted_gains_after_special_rates_adjustments = min_( + taxable_income, computed_gains_after_1250_and_28_percent_rate_gains + ) # dwks21 = min_(dwks1, dwks13) + # Schedule D Tax Worksheet line 22 for 2017 and 2018, or line 24 for years after + capital_gains_taxable_difference_after_gains_adjustments_2 = capital_gains_taxable_difference_after_gains_adjustments # dwks22 = dwks20 + # Schedule D Tax Worksheet line 23 for 2017 and 2018, or line 25 for years after + adjusted_taxable_income_after_special_gains_and_threshold_deductions = max_( + 0, + minimum_of_taxable_income_and_adjusted_gains_after_special_rates_adjustments + - capital_gains_taxable_difference_after_gains_adjustments_2, + ) # dwks23 = max_(0, dwks21 - dwks22) + # Schedule D Tax Worksheet line 25 for 2017 and 2018, or line 27 for years after + min_capital_gains_and_taxable_income_2 = min_( + capital_gains.thresholds["2"][filing_status], taxable_income + ) # dwks25 = min_(capital_gains.thresholds["2"][filing_status], dwks1) + computed_final_gains_after_all_adjustments = tax_unit( + "computed_final_gains_after_all_adjustments", period + ) # dwks19 + minimum_of_adjusted_gains_and_taxable_difference_after_gains_adjustments = min_( + computed_final_gains_after_all_adjustments, + capital_gains_taxable_difference_after_gains_adjustments, + ) # dwks26 = min_(dwks19, dwks20) + # Schedule D Tax Worksheet line 27 for 2017 and 2018, or line 29 for years after + non_negative_adjusted_income_after_gains_and_taxable_difference_deductions = max_( + 0, + min_capital_gains_and_taxable_income_2 + - minimum_of_adjusted_gains_and_taxable_difference_after_gains_adjustments, + ) # dwks27 = max_(0, dwks25 - dwks26) + # Schedule D Tax Worksheet line 28 for 2017 and 2018, or line 30 for years after + dwks28 = min_( + adjusted_taxable_income_after_special_gains_and_threshold_deductions, + non_negative_adjusted_income_after_gains_and_taxable_difference_deductions, + ) # dwks28 = min_(dwks23, dwks27) + # Schedule D Tax Worksheet line 29 for 2017 and 2018, or line 31 for years after + dwks29 = ( + capital_gains.rates["2"] * dwks28 + ) # dwks29 = capital_gains.rates["2"] * dwks28 + # Schedule D Tax Worksheet line 30 for 2017 and 2018, or line 32 for years after + dwks30 = ( + capital_gains_taxable_difference_after_gains_adjustments_2 + dwks28 + ) # dwks30 = dwks22 + dwks28 + # Schedule D Tax Worksheet line 31 for 2017 and 2018, or line 33 for years after + dwks31 = ( + minimum_of_taxable_income_and_adjusted_gains_after_special_rates_adjustments + - dwks30 + ) # dwks31 = dwks21 - dwks30 + # Schedule D Tax Worksheet line 32 for 2017 and 2018, or line 34 for years after + dwks32 = ( + capital_gains.rates["3"] * dwks31 + ) # dwks32 = capital_gains.rates["3"] * dwks31 # Break in worksheet lines + # Schedule D Tax Worksheet line 33 for 2017 and 2018, or line 35 for years after dwks33 = min_( tax_unit( "adjusted_capital_gains_reduced_by_investment_income", period - ), - add(tax_unit, period, ["unrecaptured_section_1250_gain"]), - ) - dwks10 = tax_unit("dwks10", period) - dwks34 = dwks10 + dwks19 - dwks36 = max_(0, dwks34 - dwks1) - dwks37 = max_(0, dwks33 - dwks36) - dwks38 = 0.25 * dwks37 + ), # dwks9 + add( + tax_unit, period, ["unrecaptured_section_1250_gain"] + ), # Unrecaptured Section 1250 Gain Worksheet—Line 19 + ) # dwks33 + # Schedule D Tax Worksheet line 10 + dwks10 = tax_unit("dwks10", period) # dwks10 + # Schedule D Tax Worksheet line 34 for 2017 and 2018, or line 36 for years after + dwks34 = ( + dwks10 + computed_final_gains_after_all_adjustments + ) # dwks34 = dwks10 + dwks19 + # Schedule D Tax Worksheet line 36 for 2017 and 2018, or line 38 for years after + dwks36 = max_(0, dwks34 - dwks1) # dwks36 = max_(0, dwks34 - dwks1) + # Schedule D Tax Worksheet line 37 for 2017 and 2018, or line 39 for years after + dwks37 = max_(0, dwks33 - dwks36) # dwks37 = max_(0, dwks33 - dwks36) + # Schedule D Tax Worksheet line 38 for 2017 and 2018, or line 40 for years after + dwks38 = 0.25 * dwks37 # dwks38 # Break in worksheet lines - dwks39 = dwks19 + dwks20 + dwks28 + dwks31 + dwks37 - dwks40 = dwks1 - dwks39 - dwks41 = 0.28 * dwks40 + # Schedule D Tax Worksheet line 39 for 2017 and 2018, or line 41 for years after + dwks39 = ( + computed_final_gains_after_all_adjustments + + dwks20 + + dwks28 + + dwks31 + + dwks37 + ) # dwks39 = dwks19 + dwks20 + dwks28 + dwks31 + dwks37 + # Schedule D Tax Worksheet line 40 for 2017 and 2018, or line 42 for years after + dwks40 = taxable_income - dwks39 # dwks40 = dwks1 - dwks39 + # Schedule D Tax Worksheet line 41 for 2017 and 2018, or line 43 for years after + dwks41 = 0.28 * dwks40 # dwks41 # Compute regular tax using bracket rates and thresholds - reg_taxinc = max_(0, dwks19) + reg_taxinc = max_(0, computed_final_gains_after_all_adjustments) p = parameters(period).gov.irs.income bracket_tops = p.bracket.thresholds bracket_rates = p.bracket.rates @@ -78,7 +149,9 @@ def formula(tax_unit, period, parameters): bracket_bottom = bracket_top # Return to worksheet lines - dwks42 = reg_tax + # Schedule D Tax Worksheet line 42 for 2017 and 2018, or line 44 for years after + dwks42 = reg_tax # dwks 42 + # Schedule D Tax Worksheet line 43 for 2017 and 2018, or line 45 for years after dwks43 = sum( [ dwks29, @@ -88,11 +161,17 @@ def formula(tax_unit, period, parameters): dwks42, lowest_rate_tax, ] - ) - dwks44 = tax_unit("income_tax_main_rates", period) - dwks45 = min_(dwks43, dwks44) + ) # dwks43 + # Schedule D Tax Worksheet line 44 for 2017 and 2018, or line 46 for years after + income_tax_main_rates = tax_unit( + "income_tax_main_rates", period + ) # dwks44 + # Schedule D Tax Worksheet line 45 for 2017 and 2018, or line 47 for years after + dwks45 = min_( + dwks43, income_tax_main_rates + ) # dwks45 = min_(dwks43, dwks44) hasqdivltcg = tax_unit("hasqdivltcg", period) - return where(hasqdivltcg, dwks45, dwks44) + return where(hasqdivltcg, dwks45, income_tax_main_rates) taxbc = variable_alias("taxbc", regular_tax_before_credits) From 5645c67709fcf44f77100db58b5ce174ddd2653c Mon Sep 17 00:00:00 2001 From: Matty <31402450+Mshuning@users.noreply.github.com> Date: Wed, 30 Oct 2024 03:11:38 +0000 Subject: [PATCH 11/11] seperate --- ...able_difference_after_gains_adjustments.py | 40 +++++++++++ .../middle_rate_tax.py | 67 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/capital_gains_taxable_difference_after_gains_adjustments.py create mode 100644 policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/middle_rate_tax.py diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/capital_gains_taxable_difference_after_gains_adjustments.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/capital_gains_taxable_difference_after_gains_adjustments.py new file mode 100644 index 00000000000..b1ccdcd5c31 --- /dev/null +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/capital_gains_taxable_difference_after_gains_adjustments.py @@ -0,0 +1,40 @@ +from policyengine_us.model_api import * + + +class capital_gains_taxable_difference_after_gains_adjustments(Variable): + value_type = float + entity = TaxUnit + definition_period = YEAR + label = ( + "Capital gains taxable difference after gains adjustments" # DWKS20 + ) + unit = USD + reference = ( + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=15", + "https://www.irs.gov/pub/irs-prior/i1040sd--2018.pdf#page=19", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", + ) + + def formula(tax_unit, period, parameters): + # Schedule D Tax Worksheet line 1 + taxable_income = tax_unit("taxable_income", period) # dwks1 + # Schedule D Tax Worksheet line 15 + filing_status = tax_unit("filing_status", period) + capital_gains = parameters(period).gov.irs.capital_gains.brackets + # Schedule D Tax Worksheet line 16 + min_capital_gains_and_taxable_income_1 = min_( + capital_gains.thresholds["1"][filing_status], taxable_income + ) # dwks16 + # Schedule D Tax Worksheet line 17 + min_capital_gains_and_taxable_income_and_taxable_income_minus_gains = ( + min_( + tax_unit("taxable_income_minus_gains", period), + min_capital_gains_and_taxable_income_1, + ) + ) # dwks17 = min_(tax_unit("dwks14", period), dwks16) + # Schedule D Tax Worksheet line 20 for 2017 and 2018, or line 22 for years after + return ( + min_capital_gains_and_taxable_income_1 + - min_capital_gains_and_taxable_income_and_taxable_income_minus_gains + ) # dwks20 = dwks16 - dwks17 diff --git a/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/middle_rate_tax.py b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/middle_rate_tax.py new file mode 100644 index 00000000000..8fb89aa5f61 --- /dev/null +++ b/policyengine_us/variables/gov/irs/tax/federal_income/alternative_minimum_tax/middle_rate_tax.py @@ -0,0 +1,67 @@ +from policyengine_us.model_api import * + + +class middle_rate_tax(Variable): + value_type = float + entity = TaxUnit + definition_period = YEAR + label = "Middle rate tax" # DWKS29 + unit = USD + reference = ( + "https://www.irs.gov/pub/irs-pdf/f1040sd.pdf", + "https://www.irs.gov/pub/irs-prior/i1040sd--2017.pdf#page=15", + "https://www.irs.gov/pub/irs-prior/i1040sd--2018.pdf#page=19", + "https://www.irs.gov/pub/irs-prior/i1040sd--2023.pdf#page=16", + ) + + def formula(tax_unit, period, parameters): + # Schedule D Tax Worksheet line 1 + taxable_income = tax_unit("taxable_income", period) # dwks1 + # Schedule D Tax Worksheet line 24 + filing_status = tax_unit("filing_status", period) + capital_gains = parameters(period).gov.irs.capital_gains.brackets + computed_gains_after_1250_and_28_percent_rate_gains = tax_unit( + "computed_gains_after_1250_and_28_percent_rate_gains", period + ) # dwks13 + # Schedule D Tax Worksheet line 20 for 2017 and 2018, or line 22 for years after + capital_gains_taxable_difference_after_gains_adjustments = tax_unit( + "capital_gains_taxable_difference_after_gains_adjustments", period + ) + # Schedule D Tax Worksheet line 21 for 2017 and 2018, or line 23 for years after + minimum_of_taxable_income_and_adjusted_gains_after_special_rates_adjustments = min_( + taxable_income, computed_gains_after_1250_and_28_percent_rate_gains + ) # dwks21 = min_(dwks1, dwks13) + # Schedule D Tax Worksheet line 22 for 2017 and 2018, or line 24 for years after + capital_gains_taxable_difference_after_gains_adjustments_2 = capital_gains_taxable_difference_after_gains_adjustments # dwks22 = dwks20 + # Schedule D Tax Worksheet line 23 for 2017 and 2018, or line 25 for years after + adjusted_taxable_income_after_special_gains_and_threshold_deductions = max_( + 0, + minimum_of_taxable_income_and_adjusted_gains_after_special_rates_adjustments + - capital_gains_taxable_difference_after_gains_adjustments_2, + ) # dwks23 = max_(0, dwks21 - dwks22) + # Schedule D Tax Worksheet line 25 for 2017 and 2018, or line 27 for years after + min_capital_gains_and_taxable_income_2 = min_( + capital_gains.thresholds["2"][filing_status], taxable_income + ) # dwks25 = min_(capital_gains.thresholds["2"][filing_status], dwks1) + computed_final_gains_after_all_adjustments = tax_unit( + "computed_final_gains_after_all_adjustments", period + ) # dwks19 + minimum_of_adjusted_gains_and_taxable_difference_after_gains_adjustments = min_( + computed_final_gains_after_all_adjustments, + capital_gains_taxable_difference_after_gains_adjustments, + ) # dwks26 = min_(dwks19, dwks20) + # Schedule D Tax Worksheet line 27 for 2017 and 2018, or line 29 for years after + non_negative_adjusted_income_after_gains_and_taxable_difference_deductions = max_( + 0, + min_capital_gains_and_taxable_income_2 + - minimum_of_adjusted_gains_and_taxable_difference_after_gains_adjustments, + ) # dwks27 = max_(0, dwks25 - dwks26) + # Schedule D Tax Worksheet line 28 for 2017 and 2018, or line 30 for years after + dwks28 = min_( + adjusted_taxable_income_after_special_gains_and_threshold_deductions, + non_negative_adjusted_income_after_gains_and_taxable_difference_deductions, + ) # dwks28 = min_(dwks23, dwks27) + # Schedule D Tax Worksheet line 29 for 2017 and 2018, or line 31 for years after + return ( + capital_gains.rates["2"] * dwks28 + ) # dwks29 = capital_gains.rates["2"] * dwks28