From a2c1e603d10a54f01bf57a24dbd67be8a571888d Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Wed, 27 Sep 2023 14:53:10 -0400 Subject: [PATCH 1/9] New Brunswick Tuition Amount --- changelog_entry.yaml | 4 + .../credits/tuition_amount/eligible_age.yaml | 9 ++ ...ax_on_taxable_income_addition_amounts.yaml | 31 ++++ .../nb_tax_on_taxable_income_rate.yaml | 9 ++ .../nb_tax_on_taxable_income_threshold.yaml | 33 +++++ .../tuition_amount/tuition_threshold.yaml | 10 ++ .../tuition_amount/nb_age_eligible.yaml | 15 ++ .../nb_tuition_credit_amount.yaml | 49 +++++++ .../tuition_amount/nb_tuition_eligible.yaml | 15 ++ .../credits/tuition_amount/nb_age_eligible.py | 17 +++ .../nb_tuition_credit_amount.py | 132 ++++++++++++++++++ .../nb_tuition_credit_amount_income.py | 14 ++ .../tuition_amount/nb_tuition_eligible.py | 17 +++ 13 files changed, 355 insertions(+) create mode 100644 policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml create mode 100644 policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_addition_amounts.yaml create mode 100644 policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml create mode 100644 policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml create mode 100644 policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/tuition_threshold.yaml create mode 100644 policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.yaml create mode 100644 policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml create mode 100644 policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.yaml create mode 100644 policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.py create mode 100644 policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py create mode 100644 policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount_income.py create mode 100644 policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.py diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29bb..9f6c88bdb 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: minor + changes: + added: + - New Brunswick tuition and education amount. diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml new file mode 100644 index 000000000..d579aad28 --- /dev/null +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml @@ -0,0 +1,9 @@ +description: New Brunswick provides tuition credit amount for person above this age +values: + 2022-01-01: 16 +metadata: + unit: year + label: New Brunswick tuition credit age eligibility + reference: + - title: Students and income tax + href: https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11 \ No newline at end of file diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_addition_amounts.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_addition_amounts.yaml new file mode 100644 index 000000000..cfbc2dc1e --- /dev/null +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_addition_amounts.yaml @@ -0,0 +1,31 @@ +description: New Brunswick adds this amounts to tax on taxable income for tuition +brackets: + - threshold: + 2022-01-01: 0 + amount: + 2022-01-01: 0 + - threshold: + 2022-01-01: 44_887 + amount: + 2022-01-01: 4_219.38 + - threshold: + 2022-01-01: 89_775 + amount: + 2022-01-01: 10_871.78 + - threshold: + 2022-01-01: 145_955 + amount: + 2022-01-01: 20_152.72 + - threshold: + 2022-01-01: 166_280 + amount: + 2022-01-01: 23_778.7 + +metadata: + type: single_amount + threshold_unit: currency-CAD + rate_unit: currency + label: New Brunswick taxable income phase out rate + reference: + - title: New Brunswick tax and credits + href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=1 diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml new file mode 100644 index 000000000..8fe5571e5 --- /dev/null +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml @@ -0,0 +1,9 @@ +description: New Brunswick phases tuition credit amount for tax on taxable income at this rate +values: + 2022-01-01: 0.094 +metadata: + unit: currency-CAD + label: New Brunswick tax on taxable income rate + reference: + - title: New Brunswick tuition and education amounts + href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1 diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml new file mode 100644 index 000000000..3fb35c7da --- /dev/null +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml @@ -0,0 +1,33 @@ +description: New Brunswick phases taxable income out for tuition amount at this rate +brackets: + - threshold: + 2022-01-01: 0 + rate: + 2022-01-01: 0 + - threshold: + 2022-01-01: 44_887 + rate: + 2022-01-01: 0.1482 + - threshold: + 2022-01-01: 89_775 + rate: + 2022-01-01: 0.1652 + - threshold: + 2022-01-01: 145_955 + rate: + 2022-01-01: 0.1784 + - threshold: + 2022-01-01: 166_280 + rate: + 2022-01-01: 0.203 + +metadata: + type: marginal_rate + threshold_unit: currency-CAD + rate_unit: /1 + label: New Brunswick taxable income phase out rate + reference: + - title: New Brunswick tuition and education amounts + href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1 + - title: New Brunswick tax and credits + href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=1 diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/tuition_threshold.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/tuition_threshold.yaml new file mode 100644 index 000000000..313b981cd --- /dev/null +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/tuition_threshold.yaml @@ -0,0 +1,10 @@ +description: New Brunswick provides tuition credit amount for tuition expense above this amount. +values: + 2022-01-01: 100 +metadata: + unit: currency-CAD + period: year + label: New Brunswick tuition threshold + reference: + - title: 2023 New Brunswick Personal Tax Credits Return + href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1 diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.yaml new file mode 100644 index 000000000..6163873cf --- /dev/null +++ b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.yaml @@ -0,0 +1,15 @@ +- name: Age Ineligible + period: 2023 + input: + province_code: NB + age: 15 + output: + nb_age_eligible: false + +- name: Age eligible + period: 2023 + input: + province_code: NB + age: 16 + output: + nb_age_eligible: true diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml new file mode 100644 index 000000000..3207829ca --- /dev/null +++ b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml @@ -0,0 +1,49 @@ +- name: Lowest tax on taxable income threshold + period: 2023 + absolute_error_margin: 0.01 + input: + nb_taxable_income: 44_887 + nb_tuition_credit_amount_income: 20_000 + tuition_expenses: 10_000 + output: + nb_tuition_credit_amount: 10_000 + +- name: Second tax on taxable income threshold + period: 2023 + absolute_error_margin: 0.01 + input: + nb_taxable_income: 54_887 + nb_tuition_credit_amount_income: 20_000 + tuition_expenses: 10_000 + output: + nb_tuition_credit_amount: 10000 + +- name: Third tax on taxable income threshold + period: 2023 + absolute_error_margin: 0.01 + input: + nb_taxable_income: 139_775 + nb_tuition_credit_amount_income: 20_000 + tuition_expenses: 50_000 + output: + nb_tuition_credit_amount: 50_000 + +- name: Fourth tax on taxable income threshold + period: 2023 + absolute_error_margin: 0.01 + input: + nb_taxable_income: 145_965 + nb_tuition_credit_amount_income: 100_000 + tuition_expenses: 150_000 + output: + nb_tuition_credit_amount: 114_409.62 + +- name: Highest tax on taxable income threshold + period: 2023 + absolute_error_margin: 0.01 + input: + nb_taxable_income: 167_280 + nb_tuition_credit_amount_income: 100_000 + tuition_expenses: 160_000 + output: + nb_tuition_credit_amount: 155_124.47 diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.yaml new file mode 100644 index 000000000..25a86ed34 --- /dev/null +++ b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.yaml @@ -0,0 +1,15 @@ +- name: Tuition Ineligible + period: 2022 + input: + province_code: NB + tuition_expenses: 50 + output: + nb_tuition_eligible: false + +- name: Tuition eligible + period: 2023 + input: + province_code: NB + tuition_expenses: 101 + output: + nb_tuition_eligible: true diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.py new file mode 100644 index 000000000..fb364573c --- /dev/null +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.py @@ -0,0 +1,17 @@ +from policyengine_canada.model_api import * + + +class nb_age_eligible(Variable): + value_type = bool + entity = Person + label = "New Brunswick age eligibility" + definition_period = YEAR + reference = "https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11" + defined_for = ProvinceCode.NB + + def formula(person, period, parameters): + p = parameters( + period + ).gov.provinces.nb.tax.income.credits.tuition_amount + age = person("age", period) + return age >= p.eligible_age diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py new file mode 100644 index 000000000..b806bad51 --- /dev/null +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py @@ -0,0 +1,132 @@ +from policyengine_canada.model_api import * + + +class nb_tuition_credit_amount(Variable): + value_type = float + entity = Person + label = "New Brunswick tuition credit amount" + definition_period = YEAR + defined_for: "nb_tuition_eligible" + reference = ( + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1", + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=1", + ) + + def formula(person, period, parameters): + age = person("age", period) + tuition = person("tuition_expenses", period) # line 2 + taxable_income = person("nb_taxable_income", period) # line 4 + tuition_income = person( + "nb_tuition_credit_amount_income", period + ) # line 5 + p = parameters( + period + ).gov.provinces.nb.tax.income.credits.tuition_amount + return select( + [ + taxable_income + <= p.nb_tax_on_taxable_income_threshold.thresholds[1], + p.nb_tax_on_taxable_income_threshold.thresholds[1] + < taxable_income + < p.nb_tax_on_taxable_income_threshold.thresholds[2], + p.nb_tax_on_taxable_income_threshold.thresholds[2] + < taxable_income + < p.nb_tax_on_taxable_income_threshold.thresholds[3], + p.nb_tax_on_taxable_income_threshold.thresholds[3] + < taxable_income + < p.nb_tax_on_taxable_income_threshold.thresholds[4], + taxable_income + > p.nb_tax_on_taxable_income_threshold.thresholds[4], + ], + [ + min_(max_(taxable_income - tuition_income, 0), tuition), + min_( + max_( + ( + ( + ( + taxable_income + - p.nb_tax_on_taxable_income_threshold.thresholds[ + 1 + ] + ) + * p.nb_tax_on_taxable_income_threshold.rates[1] + + p.nb_tax_on_taxable_income_addition_amounts.amounts[ + 1 + ] + ) + / p.nb_tax_on_taxable_income_rate + ) + - tuition_income, + 0, + ), + tuition, + ), + min_( + max_( + ( + ( + ( + taxable_income + - p.nb_tax_on_taxable_income_threshold.thresholds[ + 2 + ] + ) + * p.nb_tax_on_taxable_income_threshold.rates[2] + + p.nb_tax_on_taxable_income_addition_amounts.amounts[ + 2 + ] + ) + / p.nb_tax_on_taxable_income_rate + ) + - tuition_income, + 0, + ), + tuition, + ), + min_( + max_( + ( + ( + ( + taxable_income + - p.nb_tax_on_taxable_income_threshold.thresholds[ + 3 + ] + ) + * p.nb_tax_on_taxable_income_threshold.rates[3] + + p.nb_tax_on_taxable_income_addition_amounts.amounts[ + 3 + ] + ) + / p.nb_tax_on_taxable_income_rate + ) + - tuition_income, + 0, + ), + tuition, + ), + min_( + max_( + ( + ( + ( + taxable_income + - p.nb_tax_on_taxable_income_threshold.thresholds[ + 4 + ] + ) + * p.nb_tax_on_taxable_income_threshold.rates[4] + + p.nb_tax_on_taxable_income_addition_amounts.amounts[ + 4 + ] + ) + / p.nb_tax_on_taxable_income_rate + ) + - tuition_income, + 0, + ), + tuition, + ), + ], + ) diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount_income.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount_income.py new file mode 100644 index 000000000..ec23e1feb --- /dev/null +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount_income.py @@ -0,0 +1,14 @@ +from policyengine_canada.model_api import * + + +class nb_tuition_credit_amount_income(Variable): + value_type = float + entity = Person + label = "New Brunswick income pre tax income for tuition credit amount" + unit = CAD + definition_period = YEAR + reference = ( + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=2", + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1", + ) + defined_for = ProvinceCode.NB diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.py new file mode 100644 index 000000000..1ac6f8e55 --- /dev/null +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.py @@ -0,0 +1,17 @@ +from policyengine_canada.model_api import * + + +class nb_tuition_eligible(Variable): + value_type = bool + entity = Person + label = "New Brunswick tuiton eligibility" + definition_period = YEAR + reference = "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1" + defined_for = "nb_age_eligible" + + def formula(person, period, parameters): + p = parameters( + period + ).gov.provinces.nb.tax.income.credits.tuition_amount + tuition = person("tuition_expenses", period) + return tuition >= p.tuition_threshold From 69aa43268bf58af684b832bebfecffe6d8cbe57d Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Thu, 28 Sep 2023 12:21:19 -0400 Subject: [PATCH 2/9] Simplify nb tuition credit amount python code --- .../credits/tuition_amount/eligible_age.yaml | 2 +- ...ax_on_taxable_income_addition_amounts.yaml | 31 ------- .../nb_tax_on_taxable_income_threshold.yaml | 2 +- .../nb_tuition_credit_amount.yaml | 4 +- .../nb_tuition_credit_amount.py | 90 +------------------ 5 files changed, 7 insertions(+), 122 deletions(-) delete mode 100644 policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_addition_amounts.yaml diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml index d579aad28..217be77c2 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml @@ -6,4 +6,4 @@ metadata: label: New Brunswick tuition credit age eligibility reference: - title: Students and income tax - href: https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11 \ No newline at end of file + href: https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11 diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_addition_amounts.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_addition_amounts.yaml deleted file mode 100644 index cfbc2dc1e..000000000 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_addition_amounts.yaml +++ /dev/null @@ -1,31 +0,0 @@ -description: New Brunswick adds this amounts to tax on taxable income for tuition -brackets: - - threshold: - 2022-01-01: 0 - amount: - 2022-01-01: 0 - - threshold: - 2022-01-01: 44_887 - amount: - 2022-01-01: 4_219.38 - - threshold: - 2022-01-01: 89_775 - amount: - 2022-01-01: 10_871.78 - - threshold: - 2022-01-01: 145_955 - amount: - 2022-01-01: 20_152.72 - - threshold: - 2022-01-01: 166_280 - amount: - 2022-01-01: 23_778.7 - -metadata: - type: single_amount - threshold_unit: currency-CAD - rate_unit: currency - label: New Brunswick taxable income phase out rate - reference: - - title: New Brunswick tax and credits - href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=1 diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml index 3fb35c7da..f04fcb61c 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml @@ -3,7 +3,7 @@ brackets: - threshold: 2022-01-01: 0 rate: - 2022-01-01: 0 + 2022-01-01: 0.094 - threshold: 2022-01-01: 44_887 rate: diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml index 3207829ca..59a97ac01 100644 --- a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml +++ b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml @@ -36,7 +36,7 @@ nb_tuition_credit_amount_income: 100_000 tuition_expenses: 150_000 output: - nb_tuition_credit_amount: 114_409.62 + nb_tuition_credit_amount: 114_409.57 - name: Highest tax on taxable income threshold period: 2023 @@ -46,4 +46,4 @@ nb_tuition_credit_amount_income: 100_000 tuition_expenses: 160_000 output: - nb_tuition_credit_amount: 155_124.47 + nb_tuition_credit_amount: 155124.42 diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py index b806bad51..90517079a 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py @@ -26,100 +26,16 @@ def formula(person, period, parameters): [ taxable_income <= p.nb_tax_on_taxable_income_threshold.thresholds[1], - p.nb_tax_on_taxable_income_threshold.thresholds[1] - < taxable_income - < p.nb_tax_on_taxable_income_threshold.thresholds[2], - p.nb_tax_on_taxable_income_threshold.thresholds[2] - < taxable_income - < p.nb_tax_on_taxable_income_threshold.thresholds[3], - p.nb_tax_on_taxable_income_threshold.thresholds[3] - < taxable_income - < p.nb_tax_on_taxable_income_threshold.thresholds[4], taxable_income - > p.nb_tax_on_taxable_income_threshold.thresholds[4], + > p.nb_tax_on_taxable_income_threshold.thresholds[1], ], [ min_(max_(taxable_income - tuition_income, 0), tuition), min_( max_( ( - ( - ( - taxable_income - - p.nb_tax_on_taxable_income_threshold.thresholds[ - 1 - ] - ) - * p.nb_tax_on_taxable_income_threshold.rates[1] - + p.nb_tax_on_taxable_income_addition_amounts.amounts[ - 1 - ] - ) - / p.nb_tax_on_taxable_income_rate - ) - - tuition_income, - 0, - ), - tuition, - ), - min_( - max_( - ( - ( - ( - taxable_income - - p.nb_tax_on_taxable_income_threshold.thresholds[ - 2 - ] - ) - * p.nb_tax_on_taxable_income_threshold.rates[2] - + p.nb_tax_on_taxable_income_addition_amounts.amounts[ - 2 - ] - ) - / p.nb_tax_on_taxable_income_rate - ) - - tuition_income, - 0, - ), - tuition, - ), - min_( - max_( - ( - ( - ( - taxable_income - - p.nb_tax_on_taxable_income_threshold.thresholds[ - 3 - ] - ) - * p.nb_tax_on_taxable_income_threshold.rates[3] - + p.nb_tax_on_taxable_income_addition_amounts.amounts[ - 3 - ] - ) - / p.nb_tax_on_taxable_income_rate - ) - - tuition_income, - 0, - ), - tuition, - ), - min_( - max_( - ( - ( - ( - taxable_income - - p.nb_tax_on_taxable_income_threshold.thresholds[ - 4 - ] - ) - * p.nb_tax_on_taxable_income_threshold.rates[4] - + p.nb_tax_on_taxable_income_addition_amounts.amounts[ - 4 - ] + p.nb_tax_on_taxable_income_threshold.calc( + taxable_income ) / p.nb_tax_on_taxable_income_rate ) From 1ea17d6a57bc52a6ab53c2a5e8a93fbf563f53e4 Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Thu, 28 Sep 2023 12:31:37 -0400 Subject: [PATCH 3/9] Revised format --- .../nb/tax/income/credits/tuition_amount/eligible_age.yaml | 2 +- .../credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml | 2 +- .../tuition_amount/nb_tax_on_taxable_income_threshold.yaml | 2 +- .../credits/tuition_amount/nb_tuition_credit_amount.yaml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml index 217be77c2..12e38b868 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml @@ -1,4 +1,4 @@ -description: New Brunswick provides tuition credit amount for person above this age +description: New Brunswick provides tuition credit amount for person above this age. values: 2022-01-01: 16 metadata: diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml index 8fe5571e5..31c1f76d7 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml @@ -1,4 +1,4 @@ -description: New Brunswick phases tuition credit amount for tax on taxable income at this rate +description: New Brunswick phases tuition credit amount for tax on taxable income at this rate. values: 2022-01-01: 0.094 metadata: diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml index f04fcb61c..de669ec2b 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml @@ -1,4 +1,4 @@ -description: New Brunswick phases taxable income out for tuition amount at this rate +description: New Brunswick phases taxable income out for tuition amount at this rate. brackets: - threshold: 2022-01-01: 0 diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml index 59a97ac01..77615eb07 100644 --- a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml +++ b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml @@ -16,7 +16,7 @@ nb_tuition_credit_amount_income: 20_000 tuition_expenses: 10_000 output: - nb_tuition_credit_amount: 10000 + nb_tuition_credit_amount: 10_000 - name: Third tax on taxable income threshold period: 2023 @@ -46,4 +46,4 @@ nb_tuition_credit_amount_income: 100_000 tuition_expenses: 160_000 output: - nb_tuition_credit_amount: 155124.42 + nb_tuition_credit_amount: 155_124.42 From b922cbceca7950d7e60a47f9df361cb368834ffb Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Fri, 29 Sep 2023 14:29:22 -0400 Subject: [PATCH 4/9] Breakdown Python return code and rename file name --- .../credits/tuition_amount/eligible_age.yaml | 2 +- .../nb_tax_on_taxable_income_threshold.yaml | 2 +- ...dit_amount.yaml => nb_tuition_credit.yaml} | 10 +++---- ..._credit_amount.py => nb_tuition_credit.py} | 29 +++++++++---------- 4 files changed, 20 insertions(+), 23 deletions(-) rename policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/{nb_tuition_credit_amount.yaml => nb_tuition_credit.yaml} (84%) rename policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/{nb_tuition_credit_amount.py => nb_tuition_credit.py} (64%) diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml index 12e38b868..3468c67bd 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml @@ -1,4 +1,4 @@ -description: New Brunswick provides tuition credit amount for person above this age. +description: New Brunswick provides tuition credit amount for filers above this age. values: 2022-01-01: 16 metadata: diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml index de669ec2b..328a127d1 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml @@ -1,4 +1,4 @@ -description: New Brunswick phases taxable income out for tuition amount at this rate. +description: New Brunswick phases taxable income out for tuition amount at this rate, based on taxable income. brackets: - threshold: 2022-01-01: 0 diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.yaml similarity index 84% rename from policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml rename to policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.yaml index 77615eb07..e010454fe 100644 --- a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.yaml +++ b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.yaml @@ -6,7 +6,7 @@ nb_tuition_credit_amount_income: 20_000 tuition_expenses: 10_000 output: - nb_tuition_credit_amount: 10_000 + nb_tuition_credit: 10_000 - name: Second tax on taxable income threshold period: 2023 @@ -16,7 +16,7 @@ nb_tuition_credit_amount_income: 20_000 tuition_expenses: 10_000 output: - nb_tuition_credit_amount: 10_000 + nb_tuition_credit: 10_000 - name: Third tax on taxable income threshold period: 2023 @@ -26,7 +26,7 @@ nb_tuition_credit_amount_income: 20_000 tuition_expenses: 50_000 output: - nb_tuition_credit_amount: 50_000 + nb_tuition_credit: 50_000 - name: Fourth tax on taxable income threshold period: 2023 @@ -36,7 +36,7 @@ nb_tuition_credit_amount_income: 100_000 tuition_expenses: 150_000 output: - nb_tuition_credit_amount: 114_409.57 + nb_tuition_credit: 114_409.57 - name: Highest tax on taxable income threshold period: 2023 @@ -46,4 +46,4 @@ nb_tuition_credit_amount_income: 100_000 tuition_expenses: 160_000 output: - nb_tuition_credit_amount: 155_124.42 + nb_tuition_credit: 155_124.42 diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py similarity index 64% rename from policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py rename to policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py index 90517079a..665693432 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py @@ -1,10 +1,10 @@ from policyengine_canada.model_api import * -class nb_tuition_credit_amount(Variable): +class nb_tuition_credit(Variable): value_type = float entity = Person - label = "New Brunswick tuition credit amount" + label = "New Brunswick tuition credit" definition_period = YEAR defined_for: "nb_tuition_eligible" reference = ( @@ -22,6 +22,15 @@ def formula(person, period, parameters): p = parameters( period ).gov.provinces.nb.tax.income.credits.tuition_amount + reduced_taxable_income = max_(taxable_income - tuition_income, 0) + tax_on_taxable_income = p.nb_tax_on_taxable_income_threshold.calc( + taxable_income + ) + reduced_tax_on_taxable_income = max_( + (tax_on_taxable_income / p.nb_tax_on_taxable_income_rate) + - tuition_income, + 0, + ) return select( [ taxable_income @@ -30,19 +39,7 @@ def formula(person, period, parameters): > p.nb_tax_on_taxable_income_threshold.thresholds[1], ], [ - min_(max_(taxable_income - tuition_income, 0), tuition), - min_( - max_( - ( - p.nb_tax_on_taxable_income_threshold.calc( - taxable_income - ) - / p.nb_tax_on_taxable_income_rate - ) - - tuition_income, - 0, - ), - tuition, - ), + min_(reduced_taxable_income, tuition), + min_(reduced_tax_on_taxable_income, tuition), ], ) From 8715c7ffdf9f4fbdb9a5dd6f5537b1b9695444ea Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Tue, 3 Oct 2023 15:39:19 -0400 Subject: [PATCH 5/9] Combined two eligibility files and revised format --- .../tuition_amount/nb_age_eligible.yaml | 15 -------- .../nb_tuition_credit_eligibility.yaml | 35 +++++++++++++++++++ .../tuition_amount/nb_tuition_eligible.yaml | 15 -------- .../credits/tuition_amount/nb_age_eligible.py | 17 --------- .../tuition_amount/nb_tuition_credit.py | 2 +- .../nb_tuition_credit_eligibility.py | 19 ++++++++++ .../tuition_amount/nb_tuition_eligible.py | 17 --------- 7 files changed, 55 insertions(+), 65 deletions(-) delete mode 100644 policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.yaml create mode 100644 policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.yaml delete mode 100644 policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.yaml delete mode 100644 policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.py create mode 100644 policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py delete mode 100644 policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.py diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.yaml deleted file mode 100644 index 6163873cf..000000000 --- a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.yaml +++ /dev/null @@ -1,15 +0,0 @@ -- name: Age Ineligible - period: 2023 - input: - province_code: NB - age: 15 - output: - nb_age_eligible: false - -- name: Age eligible - period: 2023 - input: - province_code: NB - age: 16 - output: - nb_age_eligible: true diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.yaml new file mode 100644 index 000000000..513910642 --- /dev/null +++ b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.yaml @@ -0,0 +1,35 @@ +- name: Age eligible and tuition ineligible + period: 2023 + input: + province_code: NB + age: 17 + tuition_expenses: 50 + output: + nb_tuition_credit_eligibility: false + +- name: Age eligible and tuition eligible + period: 2023 + input: + province_code: NB + age: 16 + tuition_expenses: 101 + output: + nb_tuition_credit_eligibility: true + +- name: Age ineligible and tuition eligible + period: 2023 + input: + province_code: NB + age: 10 + tuition_expenses: 200 + output: + nb_tuition_credit_eligibility: false + +- name: Age ineligible and tuition ineligible + period: 2023 + input: + province_code: NB + age: 10 + tuition_expenses: 30 + output: + nb_tuition_credit_eligibility: false diff --git a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.yaml b/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.yaml deleted file mode 100644 index 25a86ed34..000000000 --- a/policyengine_canada/tests/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.yaml +++ /dev/null @@ -1,15 +0,0 @@ -- name: Tuition Ineligible - period: 2022 - input: - province_code: NB - tuition_expenses: 50 - output: - nb_tuition_eligible: false - -- name: Tuition eligible - period: 2023 - input: - province_code: NB - tuition_expenses: 101 - output: - nb_tuition_eligible: true diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.py deleted file mode 100644 index fb364573c..000000000 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_age_eligible.py +++ /dev/null @@ -1,17 +0,0 @@ -from policyengine_canada.model_api import * - - -class nb_age_eligible(Variable): - value_type = bool - entity = Person - label = "New Brunswick age eligibility" - definition_period = YEAR - reference = "https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11" - defined_for = ProvinceCode.NB - - def formula(person, period, parameters): - p = parameters( - period - ).gov.provinces.nb.tax.income.credits.tuition_amount - age = person("age", period) - return age >= p.eligible_age diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py index 665693432..66ba23633 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py @@ -6,7 +6,7 @@ class nb_tuition_credit(Variable): entity = Person label = "New Brunswick tuition credit" definition_period = YEAR - defined_for: "nb_tuition_eligible" + defined_for: "nb_tuition_credit_eligibility" reference = ( "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1", "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=1", diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py new file mode 100644 index 000000000..ec08b46f1 --- /dev/null +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py @@ -0,0 +1,19 @@ +from policyengine_canada.model_api import * + + +class nb_tuition_credit_eligibility(Variable): + value_type = bool + entity = Person + label = "Eligible for the New Brunswick tuition credit" + definition_period = YEAR + reference = ("https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11", + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1") + defined_for = ProvinceCode.NB + + def formula(person, period, parameters): + p = parameters( + period + ).gov.provinces.nb.tax.income.credits.tuition_amount + age = person("age", period) + tuition = person("tuition_expenses", period) + return (age >= p.eligible_age) & (tuition >= p.tuition_threshold) \ No newline at end of file diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.py deleted file mode 100644 index 1ac6f8e55..000000000 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_eligible.py +++ /dev/null @@ -1,17 +0,0 @@ -from policyengine_canada.model_api import * - - -class nb_tuition_eligible(Variable): - value_type = bool - entity = Person - label = "New Brunswick tuiton eligibility" - definition_period = YEAR - reference = "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1" - defined_for = "nb_age_eligible" - - def formula(person, period, parameters): - p = parameters( - period - ).gov.provinces.nb.tax.income.credits.tuition_amount - tuition = person("tuition_expenses", period) - return tuition >= p.tuition_threshold From 719df9b09c38f74cf9ec764c4f2ce686ac286965 Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Tue, 3 Oct 2023 15:41:11 -0400 Subject: [PATCH 6/9] Ran make format --- .../tuition_amount/nb_tuition_credit_eligibility.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py index ec08b46f1..38fdcb687 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py @@ -6,8 +6,10 @@ class nb_tuition_credit_eligibility(Variable): entity = Person label = "Eligible for the New Brunswick tuition credit" definition_period = YEAR - reference = ("https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11", - "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1") + reference = ( + "https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11", + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1", + ) defined_for = ProvinceCode.NB def formula(person, period, parameters): @@ -16,4 +18,4 @@ def formula(person, period, parameters): ).gov.provinces.nb.tax.income.credits.tuition_amount age = person("age", period) tuition = person("tuition_expenses", period) - return (age >= p.eligible_age) & (tuition >= p.tuition_threshold) \ No newline at end of file + return (age >= p.eligible_age) & (tuition >= p.tuition_threshold) From f78c9bfabbb1a97f10b5d51789374d5a8ded0178 Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Thu, 5 Oct 2023 18:22:29 -0400 Subject: [PATCH 7/9] Renamed files and added comments to references --- ...ome_threshold.yaml => income_threshold.yaml} | 0 ...ax_on_taxable_income_rate.yaml => rate.yaml} | 1 + .../credits/tuition_amount/nb_tuition_credit.py | 17 ++++++----------- .../nb_tuition_credit_amount_income.py | 4 ++-- .../nb_tuition_credit_eligibility.py | 4 ++-- 5 files changed, 11 insertions(+), 15 deletions(-) rename policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/{nb_tax_on_taxable_income_threshold.yaml => income_threshold.yaml} (100%) rename policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/{nb_tax_on_taxable_income_rate.yaml => rate.yaml} (83%) diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/income_threshold.yaml similarity index 100% rename from policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_threshold.yaml rename to policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/income_threshold.yaml diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/rate.yaml similarity index 83% rename from policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml rename to policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/rate.yaml index 31c1f76d7..f0f6975eb 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tax_on_taxable_income_rate.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/rate.yaml @@ -7,3 +7,4 @@ metadata: reference: - title: New Brunswick tuition and education amounts href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1 + # The tuition credit amount is not mentioned in the NB income tax act diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py index 66ba23633..b8397ca51 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py @@ -8,8 +8,8 @@ class nb_tuition_credit(Variable): definition_period = YEAR defined_for: "nb_tuition_credit_eligibility" reference = ( - "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1", - "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=1", + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1", # Line 10 + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=1", # Line 8 ) def formula(person, period, parameters): @@ -23,20 +23,15 @@ def formula(person, period, parameters): period ).gov.provinces.nb.tax.income.credits.tuition_amount reduced_taxable_income = max_(taxable_income - tuition_income, 0) - tax_on_taxable_income = p.nb_tax_on_taxable_income_threshold.calc( - taxable_income - ) + tax_on_taxable_income = p.income_threshold.calc(taxable_income) reduced_tax_on_taxable_income = max_( - (tax_on_taxable_income / p.nb_tax_on_taxable_income_rate) - - tuition_income, + (tax_on_taxable_income / p.rate) - tuition_income, 0, ) return select( [ - taxable_income - <= p.nb_tax_on_taxable_income_threshold.thresholds[1], - taxable_income - > p.nb_tax_on_taxable_income_threshold.thresholds[1], + taxable_income <= p.income_threshold.thresholds[1], + taxable_income > p.income_threshold.thresholds[1], ], [ min_(reduced_taxable_income, tuition), diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount_income.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount_income.py index ec23e1feb..b4a75c34b 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount_income.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_amount_income.py @@ -8,7 +8,7 @@ class nb_tuition_credit_amount_income(Variable): unit = CAD definition_period = YEAR reference = ( - "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=2", - "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1", + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-c/5004-c-22e.pdf#page=2", # Line 31 + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1", # Line 5 ) defined_for = ProvinceCode.NB diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py index 38fdcb687..dd8bff44f 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit_eligibility.py @@ -7,8 +7,8 @@ class nb_tuition_credit_eligibility(Variable): label = "Eligible for the New Brunswick tuition credit" definition_period = YEAR reference = ( - "https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11", - "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1", + "https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11", # Tuition Amount + "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1", # Line 4 ) defined_for = ProvinceCode.NB From dd62d848ad522fe5583b025435f9b72ce2601f7b Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Thu, 12 Oct 2023 18:20:43 -0400 Subject: [PATCH 8/9] Added comments and revised codes --- .../nb/tax/income/credits/tuition_amount/eligible_age.yaml | 3 ++- .../{income_threshold.yaml => phase_out_rate.yaml} | 3 ++- .../nb/tax/income/credits/tuition_amount/rate.yaml | 6 +++--- .../income/credits/tuition_amount/tuition_threshold.yaml | 5 +++-- .../tax/income/credits/tuition_amount/nb_tuition_credit.py | 6 +++--- 5 files changed, 13 insertions(+), 10 deletions(-) rename policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/{income_threshold.yaml => phase_out_rate.yaml} (88%) diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml index 3468c67bd..611f1e493 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/eligible_age.yaml @@ -1,9 +1,10 @@ -description: New Brunswick provides tuition credit amount for filers above this age. +description: New Brunswick qualifies filers for the tuition credit above this age. values: 2022-01-01: 16 metadata: unit: year label: New Brunswick tuition credit age eligibility reference: + # The credit is not mentioned in the New Brunswick income tax act - title: Students and income tax href: https://www.canada.ca/content/dam/cra-arc/formspubs/pub/p105/p105-22e.pdf#page=11 diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/income_threshold.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/phase_out_rate.yaml similarity index 88% rename from policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/income_threshold.yaml rename to policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/phase_out_rate.yaml index 328a127d1..6cdd1ded5 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/income_threshold.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/phase_out_rate.yaml @@ -25,8 +25,9 @@ metadata: type: marginal_rate threshold_unit: currency-CAD rate_unit: /1 - label: New Brunswick taxable income phase out rate + label: New Brunswick tuition credit phase out rate reference: + # The credit is not mentioned in the New Brunswick income tax act - title: New Brunswick tuition and education amounts href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1 - title: New Brunswick tax and credits diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/rate.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/rate.yaml index f0f6975eb..b16a458fe 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/rate.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/rate.yaml @@ -1,10 +1,10 @@ -description: New Brunswick phases tuition credit amount for tax on taxable income at this rate. +description: New Brunswick divides the phased out taxable income by this rate to calculate the tuition credit. values: 2022-01-01: 0.094 metadata: unit: currency-CAD - label: New Brunswick tax on taxable income rate + label: New Brunswick phased out taxable income rate reference: + # The tuition credit amount is not mentioned in the NB income tax act - title: New Brunswick tuition and education amounts href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5004-s11/5004-s11-22e.pdf#page=1 - # The tuition credit amount is not mentioned in the NB income tax act diff --git a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/tuition_threshold.yaml b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/tuition_threshold.yaml index 313b981cd..65994f66a 100644 --- a/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/tuition_threshold.yaml +++ b/policyengine_canada/parameters/gov/provinces/nb/tax/income/credits/tuition_amount/tuition_threshold.yaml @@ -1,10 +1,11 @@ -description: New Brunswick provides tuition credit amount for tuition expense above this amount. +description: New Brunswick qualifies filers for the tuition tax credit with income above this rate. values: 2022-01-01: 100 metadata: unit: currency-CAD period: year - label: New Brunswick tuition threshold + label: New Brunswick tuition credit tuition threshold reference: + # The tuition credit amount is not mentioned in the NB income tax act - title: 2023 New Brunswick Personal Tax Credits Return href: https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1nb/td1nb-23e.pdf#page=1 diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py index b8397ca51..4c89bfe70 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py @@ -23,15 +23,15 @@ def formula(person, period, parameters): period ).gov.provinces.nb.tax.income.credits.tuition_amount reduced_taxable_income = max_(taxable_income - tuition_income, 0) - tax_on_taxable_income = p.income_threshold.calc(taxable_income) + tax_on_taxable_income = p.phase_out_rate.calc(taxable_income) reduced_tax_on_taxable_income = max_( (tax_on_taxable_income / p.rate) - tuition_income, 0, ) return select( [ - taxable_income <= p.income_threshold.thresholds[1], - taxable_income > p.income_threshold.thresholds[1], + taxable_income <= p.phase_out_rate.thresholds[1], + taxable_income > p.phase_out_rate.thresholds[1], ], [ min_(reduced_taxable_income, tuition), From 4069375bbb91cbbcb9a850ad45cf5404b448fbfc Mon Sep 17 00:00:00 2001 From: Yiwei Jia Date: Thu, 12 Oct 2023 18:25:17 -0400 Subject: [PATCH 9/9] Changed parameter name --- .../nb/tax/income/credits/tuition_amount/nb_tuition_credit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py index 4c89bfe70..5963742da 100644 --- a/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py +++ b/policyengine_canada/variables/gov/provinces/nb/tax/income/credits/tuition_amount/nb_tuition_credit.py @@ -23,9 +23,9 @@ def formula(person, period, parameters): period ).gov.provinces.nb.tax.income.credits.tuition_amount reduced_taxable_income = max_(taxable_income - tuition_income, 0) - tax_on_taxable_income = p.phase_out_rate.calc(taxable_income) + phased_out_income = p.phase_out_rate.calc(taxable_income) reduced_tax_on_taxable_income = max_( - (tax_on_taxable_income / p.rate) - tuition_income, + (phased_out_income / p.rate) - tuition_income, 0, ) return select(