diff --git a/changelog.d/property-allowance-charge-bound.changed.md b/changelog.d/property-allowance-charge-bound.changed.md new file mode 100644 index 0000000000..2da9980784 --- /dev/null +++ b/changelog.d/property-allowance-charge-bound.changed.md @@ -0,0 +1 @@ +Work out the winter fuel payment charge in the property allowance election only where it can change the choice. Add `winter_fuel_payment_charge_ceiling`, the most the charge could be whatever benefits are received, and settle each election on income tax before the charge wherever the ceilings on the two routes cannot reverse it. Each household's landlords now decide in their own order, and every household's next decision is compared in one pair of branches, so the elections that turn on the charge are compared on income tax including it together rather than once per round and rank. Where an input or a structural reform replaces income tax, the ceiling, the charge, the payments it recovers or entitlement to them, or a reform neutralises income tax or the ceiling, every election is still compared on income tax including the charge. Routes, income tax and household net income are unchanged; a Microcosm UK 2024-25 microsimulation builds and calculates 2026 household net income in about half the time. diff --git a/policyengine_uk/tests/policy/baseline/gov/hmrc/income_tax/charges/winter_fuel_payment_charge_ceiling.yaml b/policyengine_uk/tests/policy/baseline/gov/hmrc/income_tax/charges/winter_fuel_payment_charge_ceiling.yaml new file mode 100644 index 0000000000..f8860bad13 --- /dev/null +++ b/policyengine_uk/tests/policy/baseline/gov/hmrc/income_tax/charges/winter_fuel_payment_charge_ceiling.yaml @@ -0,0 +1,109 @@ +# The most the winter fuel payment charge could be, whatever benefits anyone +# receives: the largest amount of each payment whose age and residence +# conditions the person meets (SI 2025/969 reg 3; SSI 2024/351 reg 10 as +# substituted by SSI 2025/282), when the charge has effect and total income +# exceeds £35,000 (ITEPA 2003 s.681I(1)(b)), and nothing otherwise. The +# charge itself is never more. + +- name: 2025 pensioner in England over the threshold gets the higher amount + # The higher Winter Fuel Payment, £300, whatever their age or household. + # Under 80 and not on a relevant benefit, they are paid and charged £200. + period: 2025 + input: + people: + pensioner: + age: 70 + total_income_charged_to_tax: 35_001 + benunits: + unit: + members: [pensioner] + pension_credit: 0 + households: + household: + members: [pensioner] + country: ENGLAND + output: + winter_fuel_payment_charge_ceiling: [300] + winter_fuel_payment_charge: [200] + +- name: 2025 total income of exactly £35,000 has no ceiling + # s.681I(1)(b): total income must exceed £35,000. + period: 2025 + input: + people: + pensioner: + age: 70 + total_income_charged_to_tax: 35_000 + households: + household: + members: [pensioner] + country: ENGLAND + output: + winter_fuel_payment_charge_ceiling: [0] + +- name: 2025 Pension Credit exempts from the charge but not the ceiling + # s.681I(4): Pension Credit exempts the claimant. The ceiling leaves benefit + # receipt out. + period: 2025 + input: + people: + pensioner: + age: 70 + total_income_charged_to_tax: 40_000 + benunits: + unit: + members: [pensioner] + pension_credit: 100 + households: + household: + members: [pensioner] + country: WALES + output: + winter_fuel_payment_charge_ceiling: [300] + winter_fuel_payment_charge: [0] + +- name: 2025 pensioner in Scotland gets the higher PAWHP amount + # SSI 2024/351 reg 10 as substituted: £305.10 for 2025-26. + period: 2025 + absolute_error_margin: 0.01 + input: + people: + pensioner: + age: 70 + total_income_charged_to_tax: 40_000 + households: + household: + members: [pensioner] + country: SCOTLAND + output: + winter_fuel_payment_charge_ceiling: [305.1] + +- name: 2025 working-age person has no ceiling + # Neither payment's age condition is met. + period: 2025 + input: + people: + worker: + age: 50 + total_income_charged_to_tax: 60_000 + households: + household: + members: [worker] + country: ENGLAND + output: + winter_fuel_payment_charge_ceiling: [0] + +- name: 2024 has no ceiling before the charge has effect + # FA 2026 Sch. 10 para. 5: the charge has effect from 2025-26. + period: 2024 + input: + people: + pensioner: + age: 70 + total_income_charged_to_tax: 60_000 + households: + household: + members: [pensioner] + country: ENGLAND + output: + winter_fuel_payment_charge_ceiling: [0] diff --git a/policyengine_uk/tests/test_property_income_properties.py b/policyengine_uk/tests/test_property_income_properties.py index fc1dc77508..5ea41141c3 100644 --- a/policyengine_uk/tests/test_property_income_properties.py +++ b/policyengine_uk/tests/test_property_income_properties.py @@ -17,6 +17,7 @@ from hypothesis import strategies as st from policyengine_uk import Simulation +from policyengine_uk.model_api import GBP, Person, Reform, Variable, add pytestmark = pytest.mark.usefixtures("cloned_uk_tax_benefit_system") @@ -571,3 +572,165 @@ def test_a_landlord_without_finance_costs_takes_the_allowance_even_where_it_cost set_pensioner_inputs(sim, drawn, routes & ~claimants) with_expenses = sim.calculate("income_tax", PENSIONER_YEAR).astype(float) assert with_expenses[pinned] == pytest.approx(5_187.40, abs=0.01) + + +# Reviews r1 and r2 of #2695. winter_fuel_payment_charge_ceiling bounds the +# charge as the model works it out, and the election settles choices on tax +# before the charge only where that ceiling cannot reverse them. Where an +# input or a structural reform replaces income tax, the ceiling, the charge, +# the payments it recovers or entitlement to them, or neutralises income tax +# or the ceiling, every choice is still compared on income tax including the +# charge. Each landlord below has £3,300 of receipts and £200 of expenses in +# England, so total income £800 lower with the allowance, and lower tax +# before the charge with expenses; the charge on the expenses route makes the +# allowance cheaper. +CHARGE_YEAR = 2026 + + +class winter_fuel_payment_charge(Variable): + """A reform's charge: half the payment, over £30,000 of total income.""" + + value_type = float + entity = Person + label = "Winter fuel payment charge, tapered" + definition_period = "year" + unit = GBP + + def formula(person, period, parameters): + p = parameters(period).gov.hmrc.income_tax.charges.winter_fuel_payment + payment = add( + person, + period, + ["winter_fuel_payment", "pension_age_winter_heating_payment"], + ) + on_relevant_benefit = add(person, period, p.relevant_benefits) > 0 + over_threshold = person("total_income", period) > 30_000 + return p.in_effect * 0.5 * payment * over_threshold * ~on_relevant_benefit + + +class tapered_charge(Reform): + def apply(self): + self.update_variable(winter_fuel_payment_charge) + + +class neutralised_ceiling(Reform): + def apply(self): + self.neutralize_variable("winter_fuel_payment_charge_ceiling") + + +class neutralised_income_tax(Reform): + def apply(self): + self.neutralize_variable("income_tax") + + +def landlord(age, **values): + person = dict( + age=age, + property_rental_income=3_300, + property_income=3_100, + property_finance_costs=1_200, + ) + person.update(values) + return { + "people": { + "landlord": {name: {CHARGE_YEAR: value} for name, value in person.items()} + }, + "households": { + "home": {"members": ["landlord"], "region": {CHARGE_YEAR: "NORTH_WEST"}} + }, + } + + +def taxes_on_route(situation, reform, uses_allowance): + situation["people"]["landlord"]["uses_property_allowance"] = { + CHARGE_YEAR: uses_allowance + } + sim = Simulation(situation=situation, reform=reform) + return [ + float(sim.calculate(variable, CHARGE_YEAR)[0]) + for variable in ("income_tax", "income_tax_before_winter_fuel_payment_charge") + ] + + +CHARGE_BEYOND_THE_CEILING = { + # Review r1's case: a payment given to someone under pensionable age. + "payment_given_under_pensionable_age": ( + 60, + dict(employment_income=32_000, winter_fuel_payment=200), + None, + ), + "entitlement_given_under_pensionable_age": ( + 60, + dict(employment_income=32_000, winter_fuel_payment_eligible=True), + None, + ), + # Tax before the charge is £400 lower with expenses, beyond the £300 + # higher Winter Fuel Payment, but the £500 payment given exceeds it. + "payment_given_above_the_largest_amount": ( + 70, + dict( + private_pension_income=32_000, + property_finance_costs=2_800, + winter_fuel_payment=500, + ), + None, + ), + "charge_tapered_by_a_reform": ( + 70, + dict(private_pension_income=27_000), + tapered_charge, + ), + # Total income £35,100 with expenses and £34,300 with the allowance, so + # the £200 charge falls only on the expenses route. + "ceiling_given_as_nothing": ( + 70, + dict(private_pension_income=32_000, winter_fuel_payment_charge_ceiling=0), + None, + ), + "ceiling_neutralised_by_a_reform": ( + 70, + dict(private_pension_income=32_000), + neutralised_ceiling, + ), +} + + +@pytest.mark.parametrize( + "age, values, reform", + CHARGE_BEYOND_THE_CEILING.values(), + ids=CHARGE_BEYOND_THE_CEILING, +) +def test_a_charge_beyond_the_ceiling_is_still_compared(age, values, reform): + chosen = Simulation(situation=landlord(age, **values), reform=reform) + route = bool(chosen.calculate("uses_property_allowance", CHARGE_YEAR)[0]) + tax, before_charge = taxes_on_route(landlord(age, **values), reform, route) + other_tax, other_before_charge = taxes_on_route( + landlord(age, **values), reform, not route + ) + assert tax < other_tax + # Tax before the charge alone would choose the other route. + assert before_charge > other_before_charge + + +INCOME_TAX_THE_SAME_ON_BOTH_ROUTES = { + "income_tax_given_as_an_input": (dict(income_tax=6_000), None), + # Review r2: a neutralised variable keeps the parts it adds. + "income_tax_neutralised_by_a_reform": (dict(), neutralised_income_tax), +} + + +@pytest.mark.parametrize( + "values, reform", + INCOME_TAX_THE_SAME_ON_BOTH_ROUTES.values(), + ids=INCOME_TAX_THE_SAME_ON_BOTH_ROUTES, +) +def test_income_tax_the_same_on_both_routes_leaves_the_default(values, reform): + """Income tax is the same on both routes, so the choice is a tie and the + default, expenses for receipts above the allowance, stands, although tax + before the charge is lower with the allowance.""" + values = dict(employment_income=40_000, property_finance_costs=100, **values) + sim = Simulation(situation=landlord(50, **values), reform=reform) + assert not sim.calculate("uses_property_allowance", CHARGE_YEAR)[0] + _, before_charge_using = taxes_on_route(landlord(50, **values), reform, True) + _, before_charge_not_using = taxes_on_route(landlord(50, **values), reform, False) + assert before_charge_using < before_charge_not_using diff --git a/policyengine_uk/tests/test_winter_fuel_payment_charge_ceiling_properties.py b/policyengine_uk/tests/test_winter_fuel_payment_charge_ceiling_properties.py new file mode 100644 index 0000000000..e6dcb3dfbb --- /dev/null +++ b/policyengine_uk/tests/test_winter_fuel_payment_charge_ceiling_properties.py @@ -0,0 +1,101 @@ +"""The winter fuel payment charge never exceeds its ceiling. + +The property allowance election (uses_property_allowance) settles a choice on +income tax before the charge wherever the most the charge could be on either +route (winter_fuel_payment_charge_ceiling) cannot reverse it. That is the +choice income tax including the charge gives only if, for every person on +every route, the charge is between nothing and the ceiling, and nothing where +the ceiling is nothing. + +Invariants, in 2025 and 2026, for households of one or two families in each +of the four countries, with adults either side of State Pension age and of 80, +total income either side of £35,000, Pension Credit and Universal Credit +claimed or not, and landlords with and without finance costs, on the model's +own routes and with everyone using the property allowance or nobody: + +1. The charge is never negative and never more than the ceiling. +2. Where the ceiling is nothing, so is the charge. +""" + +import numpy as np +from hypothesis import HealthCheck, given, settings +from hypothesis import strategies as st + +from policyengine_uk import Simulation + +COUNTRIES = ["ENGLAND", "WALES", "SCOTLAND", "NORTHERN_IRELAND"] +AGES = [50, 65, 66, 70, 79, 80, 85] +PENSIONS = [0, 11_500, 34_000, 35_000, 36_000, 60_000] +PROPERTY_RECEIPTS = [0, 900, 3_300, 12_000] +FINANCE_COSTS = [0, 675, 1_200, 6_000] +PROPERTY_SETTINGS = settings( + max_examples=6, + deadline=None, + derandomize=True, + suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large], +) +ROUTES = [None, True, False] + + +@st.composite +def adult(draw): + receipts = draw(st.sampled_from(PROPERTY_RECEIPTS)) + return dict( + age=draw(st.sampled_from(AGES)), + private_pension_income=draw(st.sampled_from(PENSIONS)), + employment_income=draw(st.sampled_from([0, 0, 20_000])), + property_rental_income=receipts, + property_income=receipts * draw(st.sampled_from([0.8, 0.95])), + property_finance_costs=draw(st.sampled_from(FINANCE_COSTS)) if receipts else 0, + ) + + +@st.composite +def household(draw): + families = [ + dict( + adults=[draw(adult()) for _ in range(draw(st.integers(1, 2)))], + claims_pc=draw(st.booleans()), + claims_uc=draw(st.booleans()), + ) + for _ in range(draw(st.integers(1, 2))) + ] + return dict(families=families, country=draw(st.sampled_from(COUNTRIES))) + + +def situation(households, year, uses_allowance): + people, benunits, homes = {}, {}, {} + for h, home in enumerate(households): + members = [] + for f, family in enumerate(home["families"]): + names = [] + for a, values in enumerate(family["adults"]): + name = f"p{h}_{f}_{a}" + people[name] = { + variable: {year: value} for variable, value in values.items() + } + if uses_allowance is not None: + people[name]["uses_property_allowance"] = {year: uses_allowance} + names.append(name) + benunits[f"b{h}_{f}"] = { + "members": names, + "would_claim_pc": {year: family["claims_pc"]}, + "would_claim_uc": {year: family["claims_uc"]}, + } + members += names + homes[f"h{h}"] = {"members": members, "country": {year: home["country"]}} + return {"people": people, "benunits": benunits, "households": homes} + + +@PROPERTY_SETTINGS +@given(st.lists(household(), min_size=1, max_size=4), st.sampled_from([2025, 2026])) +def test_the_charge_never_exceeds_its_ceiling(households, year): + for uses_allowance in ROUTES: + simulation = Simulation(situation=situation(households, year, uses_allowance)) + charge = np.asarray(simulation.calculate("winter_fuel_payment_charge", year)) + ceiling = np.asarray( + simulation.calculate("winter_fuel_payment_charge_ceiling", year) + ) + assert (charge >= 0).all(), (uses_allowance, charge, households) + assert (charge <= ceiling + 1e-4).all(), (uses_allowance, charge, ceiling) + assert (charge[ceiling == 0] == 0).all(), (uses_allowance, charge, ceiling) diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/uses_property_allowance.py b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/uses_property_allowance.py index e5facece38..a188f51545 100644 --- a/policyengine_uk/variables/gov/hmrc/income_tax/allowances/uses_property_allowance.py +++ b/policyengine_uk/variables/gov/hmrc/income_tax/allowances/uses_property_allowance.py @@ -1,3 +1,5 @@ +from pathlib import Path + from policyengine_uk.model_api import * # Inputs to income tax that do not depend on how property profits are @@ -18,24 +20,86 @@ # Marriage Allowance, or a shared winter fuel payment and so its charge), so # a second round rarely changes anything. MAX_ROUNDS = 3 +# Income tax is tax before the winter fuel payment charge plus the charge. +INCOME_TAX_PARTS = [ + "income_tax_before_winter_fuel_payment_charge", + "winter_fuel_payment_charge", +] +# The tax before the charge, and the most the charge could be, need nobody's +# benefits; the charge itself needs everyone's. +CEILING = "winter_fuel_payment_charge_ceiling" +BEFORE_CHARGE = [ + "income_tax_before_winter_fuel_payment_charge", + CEILING, +] +# What the ceiling bounds: the charge, the payments it recovers and +# entitlement to them, as the model works them out. Neutralising one of them +# leaves the charge nil, within the ceiling. +CHARGE_DEFINITIONS = [ + "winter_fuel_payment_charge", + "winter_fuel_payment", + "pension_age_winter_heating_payment", + "winter_fuel_payment_eligible", + "pawhp_eligible", +] + +def ceiling_bounds_the_charge(simulation, period): + """Whether income tax is tax before the charge plus the charge, and the + ceiling bounds the charge, for the period. -def income_tax_with_route(simulation, name, period, uses_allowance): - """Each person's income tax with the given choices of property allowance. + Both hold while the model works out income tax, the ceiling, the charge, + the payments it recovers and entitlement to them itself: no input sets + one for the period (a household calculation can give a payment to a + person under pensionable age), and no structural reform replaces one (a + reform can taper the charge) or neutralises income tax or the ceiling. + Nothing calculates them before this election, which they all wait on, so + a value held for the period is an input. + """ + system = simulation.tax_benefit_system + income_tax = system.get_variable("income_tax") + # A neutralised variable keeps its parts but is nil. + if ( + list(income_tax.adds or ()) != INCOME_TAX_PARTS + or income_tax.formulas + or income_tax.is_neutralized + or system.get_variable(CEILING).is_neutralized + ): + return False + for name in ["income_tax", CEILING] + CHARGE_DEFINITIONS: + if simulation.get_array(name, period) is not None: + return False + for name in [CEILING] + CHARGE_DEFINITIONS: + formula = system.get_variable(name).get_formula(period) + if formula is None: + return False + # The model keeps each formula in a file named after its variable + # under policyengine_uk/variables. A replacement kept in such a file + # would pass; structural reforms live elsewhere (policyengine_uk/ + # reforms, or the caller's own code). + source = Path(formula.__code__.co_filename) + if source.name != f"{name}.py" or "variables" not in source.parts: + return False + return True + + +def with_route(simulation, name, period, uses_allowance, variables): + """Each person's values of the variables with the given choices of + property allowance. - The tax includes the winter fuel payment charge. A route can change the - person's total income, which is after the property allowance, and their - Pension Credit, and so whether the charge applies (s.681I(1)(b) and (4)). - The branch shares the simulation's cached arrays - until it writes, and is dropped afterwards so a later period starts from - a fresh branch. + A route can change the person's total income, which is after the + property allowance, and their Pension Credit, and so whether the winter + fuel payment charge applies (s.681I(1)(b) and (4)). The branch shares the + simulation's cached arrays until it writes, and is dropped afterwards so + a later period starts from a fresh branch. """ while name in simulation.branches or name == simulation.branch_name: name += "_" branch = simulation.get_branch(name) try: branch.set_input("uses_property_allowance", period, uses_allowance) - return branch.populations["person"]("income_tax", period) + person = branch.populations["person"] + return [person(variable, period) for variable in variables] finally: del simulation.branches[name] @@ -53,7 +117,15 @@ class uses_property_allowance(Variable): "only if they elect for it; with finance costs to relieve, each " "election is made only if it lowers the person's own income tax, " "including the winter fuel payment charge, with everyone else's " - "route held fixed. " + "route held fixed. Tax before the charge settles that comparison " + "wherever the most the charge could be on either route " + "(winter_fuel_payment_charge_ceiling) cannot reverse it; the charge " + "itself, which needs everyone's benefits on each route, is worked " + "out only where it can. Where an input or a structural reform " + "replaces income tax, the ceiling, the charge, the payments it " + "recovers or entitlement to them, or a reform neutralises income tax " + "or the ceiling, the ceiling does not apply and every choice is " + "compared on income tax including the charge. " "Ties keep the default, so a person with receipts within the " "allowance keeps full relief even where electing out would carry " "finance costs forward. Without finance costs to relieve, the " @@ -120,33 +192,96 @@ def formula(person, period, parameters): # tax (a partner's through the Marriage Allowance; anyone's, through # the shared winter fuel payment, when it changes who is entitled), # and comparing their switches at once would count that. Rounds - # repeat until nobody changes, for at most MAX_ROUNDS: routes still - # changing in the last round are kept as they stand. + # repeat until nobody in the household changes, for at most + # MAX_ROUNDS: routes still changing in the last round are kept as + # they stand. With one person deciding in a household, everyone + # else's route is fixed throughout, so one round settles it. + # Households do not move each other's tax, so each keeps its own + # place in that order, and every household's next decision is + # compared in the same pair of branches. order = person.get_rank( person.household, np.zeros(person.count), condition=choosing ) - for _ in range(MAX_ROUNDS): - changed = False - for rank in range(int(order.max()) + 1): - deciding = choosing & (order == rank) - tax_using = income_tax_with_route( - simulation, "property_allowance_used", period, route | deciding + deciders = person.household.sum(choosing) + rank = np.zeros(person.count, dtype=int) + rounds = np.ones(person.count, dtype=int) + changed = np.zeros(person.count, dtype=bool) + done = deciders == 0 + bounded = ceiling_bounds_the_charge(simulation, period) + while not done.all(): + deciding = choosing & ~done & (order == rank) + using = route | deciding + not_using = route & ~deciding + if bounded: + tax_using, most_charge_using = with_route( + simulation, "property_allowance_used", period, using, BEFORE_CHARGE ) - tax_not_using = income_tax_with_route( + tax_not_using, most_charge_not_using = with_route( simulation, "property_allowance_not_used", period, - route & ~deciding, + not_using, + BEFORE_CHARGE, + ) + # On each route the charge is between nothing and its + # ceiling, so the allowance saves at least the saving before + # the charge less the ceiling using it, and at most that + # saving plus the ceiling not using it. Where those bounds + # share a sign, beyond a penny and float32 rounding, the + # choice is the one tax including the charge gives. + saving = tax_not_using - tax_using + rounding = 0.01 + 1e-6 * (abs(tax_using) + abs(tax_not_using)) + unsettled = ( + deciding + & ((most_charge_using > 0) | (most_charge_not_using > 0)) + & (saving - most_charge_using < rounding) + & (saving + most_charge_not_using > -rounding) + ) + else: + # Nothing bounds the charge: every choice turns on it. + most_charge_using = most_charge_not_using = np.full( + person.count, np.inf ) - # Tax is computed to the penny; smaller differences are - # rounding. - saving = np.round(tax_not_using - tax_using, 2) - prefers_allowance = where(full_relief, saving >= 0, saving > 0) - decided = where(deciding, prefers_allowance, route) - changed = changed or bool((decided != route).any()) - route = decided - # With one person deciding per household, everyone else's route - # was fixed throughout, so one round settles it. - if order.max() == 0 or not changed: - break + unsettled = deciding + if (deciding & ~unsettled).any(): + # The rest wait, and their households with them, until no + # household can decide without the charge. + deciding = deciding & ~unsettled + else: + # Every household's next decision turns on the charge: + # compare them all on income tax including it, worked out on + # each route where some ceiling is above nothing (where it is + # nothing, so is the charge, and tax before it is the tax). + if (unsettled & (most_charge_using > 0)).any(): + (tax_using,) = with_route( + simulation, + "property_allowance_used", + period, + using, + ["income_tax"], + ) + if (unsettled & (most_charge_not_using > 0)).any(): + (tax_not_using,) = with_route( + simulation, + "property_allowance_not_used", + period, + not_using, + ["income_tax"], + ) + # Tax is computed to the penny; smaller differences are rounding. + saving = np.round(tax_not_using - tax_using, 2) + prefers_allowance = where(full_relief, saving >= 0, saving > 0) + decided = where(deciding, prefers_allowance, route) + changed = changed | person.household.any(decided != route) + route = decided + # Each household that decided moves to its next decider, and at + # the end of a round to another round or to its settled routes. + moved = person.household.any(deciding) + rank = where(moved, rank + 1, rank) + round_over = moved & (rank == deciders) + again = round_over & changed & (deciders > 1) & (rounds < MAX_ROUNDS) + done = done | (round_over & ~again) + rank = where(again, 0, rank) + rounds = where(again, rounds + 1, rounds) + changed = changed & ~round_over return route diff --git a/policyengine_uk/variables/gov/hmrc/income_tax/charges/winter_fuel_payment_charge_ceiling.py b/policyengine_uk/variables/gov/hmrc/income_tax/charges/winter_fuel_payment_charge_ceiling.py new file mode 100644 index 0000000000..24f961e8f7 --- /dev/null +++ b/policyengine_uk/variables/gov/hmrc/income_tax/charges/winter_fuel_payment_charge_ceiling.py @@ -0,0 +1,71 @@ +from policyengine_uk.model_api import * + +# The amounts each payment the charge recovers can take +# (winter_heating_payment_amount). +AMOUNTS = [ + "lower", + "higher", + "lower_shared", + "higher_shared_with_under_80", + "higher_shared_with_80_or_over", +] + + +class winter_fuel_payment_charge_ceiling(Variable): + value_type = float + entity = Person + label = "Most winter fuel payment charge whatever benefits are received" + documentation = ( + "The most the winter fuel payment charge (winter_fuel_payment_charge) " + "could be for the person, whoever in their household receives which " + "benefits: the largest amount of each payment whose age and residence " + "conditions they meet, when the charge has effect and their total " + "income exceeds the threshold, and nothing otherwise. Whether they " + "are entitled to a payment beyond those conditions, which amount it " + "is, and whether a relevant benefit exempts them all turn on benefit " + "receipt, which this leaves out, so the charge as the model works it " + "out is never more than this. An input of a payment or of " + "entitlement to one, or a structural reform of either or of the " + "charge, can take the charge above it; the property allowance " + "election (uses_property_allowance) then does not rely on it. " + "Otherwise it lets the election compare tax before the charge " + "wherever the charge cannot change the choice, without working out " + "benefits on both routes." + ) + definition_period = YEAR + unit = GBP + reference = ( + "https://www.legislation.gov.uk/ukpga/2003/1/section/681I", + "https://www.legislation.gov.uk/uksi/2025/969/regulation/2", + "https://www.legislation.gov.uk/uksi/2025/969/regulation/3", + "https://www.legislation.gov.uk/nisr/2025/142/regulation/2", + "https://www.legislation.gov.uk/nisr/2025/142/regulation/3", + "https://www.legislation.gov.uk/ssi/2024/351/regulation/10", + "https://www.legislation.gov.uk/ssi/2025/282/regulation/9/made", + ) + + def formula(person, period, parameters): + charge = parameters(period).gov.hmrc.income_tax.charges.winter_fuel_payment + wfp = parameters(period).gov.dwp.winter_fuel_payment + pawhp = parameters(period).gov.social_security_scotland.pawhp + country = person.household("country", period).decode_to_str() + # Either age the payments test, in any year: deliberately wider than + # the State Pension age test winter_fuel_payment_eligible applies + # from the 2024 qualifying week, so it also covers the Pension Credit + # qualifying age before then and reforms that move either timetable. + pension_age = person("is_SP_age", period) | person( + "has_attained_state_pension_credit_qualifying_age", period + ) + meets_wfp_conditions = np.isin(country, wfp.eligibility.countries) & ( + pension_age | (not wfp.eligibility.state_pension_age_requirement) + ) + meets_pawhp_conditions = ( + pawhp.active + & (country == "SCOTLAND") + & (pension_age | (not pawhp.eligibility.state_pension_age_requirement)) + ) + most_payment = meets_wfp_conditions * max( + wfp.amount[amount] for amount in AMOUNTS + ) + meets_pawhp_conditions * max(pawhp.amount[amount] for amount in AMOUNTS) + over_threshold = person("total_income", period) > charge.income_threshold + return charge.in_effect * most_payment * over_threshold