From 93daf9e9b79a79d18a74c338e30f06ed901e62ff Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 10 Oct 2026 10:03:01 -0400 Subject: [PATCH 1/2] Count a negative income source as nil in Pension Credit income MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pension_credit_income summed each source as it stood, so a property loss reduced the claimant's other income: a 75-year-old with a £20,000 pension and a £30,000 property loss had nil income and the full guarantee credit. State Pension Credit Act 2002 s. 15(1) and SPC Regulations 2002 reg. 15 list receipts, and nothing lets a loss on one be set against another. Each person-level source is now floored at zero. The earnings sources are not changed. Fixes #2255 Co-Authored-By: Claude Opus 5.5 --- changelog.d/2255.fixed.md | 1 + .../pension_credit/pension_credit_income.yaml | 66 ++++++++++++++++++ .../test_pension_credit_income_losses.py | 67 +++++++++++++++++++ .../pension_credit/pension_credit_income.py | 8 ++- 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 changelog.d/2255.fixed.md create mode 100644 policyengine_uk/tests/test_pension_credit_income_losses.py diff --git a/changelog.d/2255.fixed.md b/changelog.d/2255.fixed.md new file mode 100644 index 0000000000..aaa325480a --- /dev/null +++ b/changelog.d/2255.fixed.md @@ -0,0 +1 @@ +- Stopped a negative income source, such as a property loss, from reducing a claimant's other Pension Credit income. diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_income.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_income.yaml index b6cf5c9493..1df4917653 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_income.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_income.yaml @@ -123,3 +123,69 @@ private_pension_wealth: 200_000 output: pension_credit_assessable_capital: 12_000 + +# Issue #2255. State Pension Credit Act 2002 s. 15(1) and SPC Regulations 2002 +# reg. 15 list receipts; nothing lets a loss on one be set against another +# (https://www.legislation.gov.uk/uksi/2002/1792/regulation/15). A property +# loss used to wipe out the pension here and pay the full guarantee credit. +- name: A property loss does not reduce other Pension Credit income. + period: 2026 + absolute_error_margin: 1 + input: + people: + person: + age: 75 + private_pension_income: 20_000 + property_income: -30_000 + benunits: + benunit: + members: person + households: + household: + members: person + region: WALES + tenure_type: OWNED_OUTRIGHT + output: + property_income_after_finance_costs: -30_000 + pension_credit_income: 18_514 + pension_credit: 0 + +- name: The same person without the property loss has the same Pension Credit income. + period: 2026 + absolute_error_margin: 1 + input: + people: + person: + age: 75 + private_pension_income: 20_000 + benunits: + benunit: + members: person + households: + household: + members: person + region: WALES + tenure_type: OWNED_OUTRIGHT + output: + pension_credit_income: 18_514 + pension_credit: 0 + +- name: Positive property income still counts in Pension Credit income. + period: 2026 + absolute_error_margin: 1 + input: + people: + person: + age: 75 + private_pension_income: 20_000 + property_income: 3_000 + benunits: + benunit: + members: person + households: + household: + members: person + region: WALES + tenure_type: OWNED_OUTRIGHT + output: + pension_credit: 0 diff --git a/policyengine_uk/tests/test_pension_credit_income_losses.py b/policyengine_uk/tests/test_pension_credit_income_losses.py new file mode 100644 index 0000000000..7bfaa5983f --- /dev/null +++ b/policyengine_uk/tests/test_pension_credit_income_losses.py @@ -0,0 +1,67 @@ +"""A loss on one income source does not reduce Pension Credit income (#2255). + +State Pension Credit Act 2002 s. 15(1) and the State Pension Credit +Regulations 2002 reg. 15 list the receipts that count as income. Nothing lets +a negative amount on one be set against another. +""" + +import pytest +from hypothesis import given, settings +from hypothesis import strategies as st + +from policyengine_uk import Simulation + +YEAR = 2026 + + +def _pension_credit(pension: float, property_income: float) -> tuple[float, float]: + sim = Simulation( + situation={ + "people": { + "person": { + "age": {YEAR: 75}, + "private_pension_income": {YEAR: pension}, + "property_income": {YEAR: property_income}, + } + }, + "benunits": {"benunit": {"members": ["person"]}}, + "households": { + "household": { + "members": ["person"], + "region": {YEAR: "WALES"}, + "tenure_type": {YEAR: "OWNED_OUTRIGHT"}, + } + }, + } + ) + return ( + float(sim.calculate("pension_credit_income", YEAR)[0]), + float(sim.calculate("pension_credit", YEAR)[0]), + ) + + +pensions = st.integers(min_value=0, max_value=40_000) +losses = st.integers(min_value=-100_000, max_value=0) +gains = st.integers(min_value=0, max_value=20_000) + + +@settings(max_examples=12, deadline=None) +@given(pension=pensions, loss=losses) +def test_a_property_loss_counts_as_nil(pension, loss): + assert _pension_credit(pension, loss) == pytest.approx( + _pension_credit(pension, 0), abs=0.01 + ) + + +@settings(max_examples=12, deadline=None) +@given(pension=pensions, lower=losses, extra=gains) +def test_pension_credit_never_rises_with_property_income(pension, lower, extra): + _, credit_lower = _pension_credit(pension, lower) + _, credit_higher = _pension_credit(pension, lower + extra) + assert credit_higher <= credit_lower + 0.01 + + +def test_issue_2255_reproducer(): + income, credit = _pension_credit(20_000, -30_000) + assert income == pytest.approx(18_514, abs=1) + assert credit == 0 diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_income.py b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_income.py index 1160800f3a..67ef2d101d 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_income.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_income.py @@ -25,7 +25,13 @@ def formula(benunit, period, parameters): total = 0 for source in sources: if person.entity.get_variable(source).entity.is_person: - total += benunit.sum(person(source, period) * is_claimant_or_partner) + # Each prescribed item is a receipt (State Pension Credit Act + # 2002 s. 15(1); SPC Regs 2002 reg. 15), and nothing lets a + # loss on one be set against another, so a negative source, + # such as a property loss, counts as nil. + total += benunit.sum( + max_(0, person(source, period)) * is_claimant_or_partner + ) else: total += add(benunit, period, [source]) From cd2b2e8e15dac41cddb01e8bf7ecee3064a597d8 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 10 Oct 2026 16:50:51 -0400 Subject: [PATCH 2/2] Count a self-employment loss as nil in Pension Credit earnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pension_credit_earnings summed wages and self-employment income, so a trading loss cut the earnings counted: £10,000 of wages with an £8,000 loss counted as £2,000 and raised the award from £2,376 to £10,376. Computation of Earnings Regulations 1996 reg. 13(12), applied to Pension Credit by SPC Regulations 2002 reg. 17B(5)(b), bars setting a loss in one employment against earnings in another. Each earnings source is now floored at zero. Also from the review of the property-loss fix: assert the Pension Credit income in the positive property income case, state the second invariant as tested (never higher than with no property income), run each Hypothesis example as one simulation, and reword the formula comment. Co-Authored-By: Claude Opus 5.5 --- changelog.d/2255.fixed.md | 2 +- .../pension_credit_earnings.yaml | 47 +++++- .../pension_credit/pension_credit_income.yaml | 29 ++++ .../test_pension_credit_income_losses.py | 149 +++++++++++++----- .../pension_credit/pension_credit_earnings.py | 7 +- .../pension_credit/pension_credit_income.py | 8 +- 6 files changed, 195 insertions(+), 47 deletions(-) diff --git a/changelog.d/2255.fixed.md b/changelog.d/2255.fixed.md index aaa325480a..2e58071506 100644 --- a/changelog.d/2255.fixed.md +++ b/changelog.d/2255.fixed.md @@ -1 +1 @@ -- Stopped a negative income source, such as a property loss, from reducing a claimant's other Pension Credit income. +- Stopped a negative income source, such as a property loss or a self-employment loss, from reducing a claimant's other Pension Credit income. diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_earnings.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_earnings.yaml index 6570a74d76..35c1ea27de 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_earnings.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_earnings.yaml @@ -64,4 +64,49 @@ benunit: members: [person] output: - pension_credit_earnings: 0 \ No newline at end of file + pension_credit_earnings: 0 + +# Issue #2255. Computation of Earnings Regulations 1996 reg. 13(12), applied to +# Pension Credit by SPC Regulations 2002 reg. 17B(5)(b): "any loss incurred in +# any one of his employments shall not be offset against his earnings in any +# other of his employments" +# (https://www.legislation.gov.uk/uksi/1996/2745/regulation/13). +- name: A self-employment loss is not set against wages + period: 2023 + input: + people: + person: + employment_income: 10_000 + self_employment_income: -8_000 + benunits: + benunit: + members: [person] + output: + pension_credit_earnings: 10_000 + +- name: A self-employment loss alone gives nil earnings + period: 2023 + input: + people: + person: + employment_income: 0 + self_employment_income: -8_000 + benunits: + benunit: + members: [person] + output: + pension_credit_earnings: 0 + +- name: A partner's self-employment loss is not set against the claimant's wages + period: 2023 + input: + people: + person: + employment_income: 10_000 + partner: + self_employment_income: -8_000 + benunits: + benunit: + members: [person, partner] + output: + pension_credit_earnings: 10_000 diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_income.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_income.yaml index 1df4917653..a69dfec245 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_income.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_income.yaml @@ -188,4 +188,33 @@ region: WALES tenure_type: OWNED_OUTRIGHT output: + # 20,000 + 3,000, less income tax of 20% of (23,000 - 12,570) = 2,086. + pension_credit_income: 20_914 pension_credit: 0 + +# Issue #2255, earnings. A self-employment loss is not set against wages +# (Computation of Earnings Regulations 1996 reg. 13(12), applied by SPC +# Regulations 2002 reg. 17B(5)(b)). The loss used to cut Pension Credit income +# from 10,000 to 2,000 and raise the award from 2,376 to 10,376. +- name: A self-employment loss does not reduce Pension Credit income from wages. + period: 2026 + absolute_error_margin: 1 + input: + people: + person: + age: 70 + employment_income: 10_000 + self_employment_income: -8_000 + benunits: + benunit: + members: person + households: + household: + members: person + region: WALES + tenure_type: OWNED_OUTRIGHT + output: + pension_credit_earnings: 10_000 + pension_credit_income: 10_000 + # 238 x 52 = 12,376, less income of 10,000. + pension_credit: 2_376 diff --git a/policyengine_uk/tests/test_pension_credit_income_losses.py b/policyengine_uk/tests/test_pension_credit_income_losses.py index 7bfaa5983f..94e4b5e535 100644 --- a/policyengine_uk/tests/test_pension_credit_income_losses.py +++ b/policyengine_uk/tests/test_pension_credit_income_losses.py @@ -1,8 +1,12 @@ """A loss on one income source does not reduce Pension Credit income (#2255). -State Pension Credit Act 2002 s. 15(1) and the State Pension Credit -Regulations 2002 reg. 15 list the receipts that count as income. Nothing lets -a negative amount on one be set against another. +State Pension Credit Act 2002 ss. 15 to 16 and the State Pension Credit +Regulations 2002 regs. 15 to 18 say what counts as income. Nothing in them +lets a negative amount on one source be set against another, and for earnings +the Computation of Earnings Regulations 1996 reg. 13(12), applied by SPC +Regulations reg. 17B(5)(b), says so: "any loss incurred in any one of his +employments shall not be offset against his earnings in any other of his +employments". """ import pytest @@ -12,56 +16,121 @@ from policyengine_uk import Simulation YEAR = 2026 +INPUTS = ( + "private_pension_income", + "property_income", + "employment_income", + "self_employment_income", +) -def _pension_credit(pension: float, property_income: float) -> tuple[float, float]: +def _pension_credit(cases: list[dict]) -> list[tuple[float, float]]: + """Pension Credit income and award for single pensioners, one per case. + + Each case gives annual amounts for any of INPUTS; the rest are nil. All + the cases go into one simulation, which costs about the same as one. + """ + people, benunits, households = {}, {}, {} + for i, case in enumerate(cases): + people[f"person_{i}"] = { + "age": {YEAR: 75}, + **{name: {YEAR: case.get(name, 0)} for name in INPUTS}, + } + benunits[f"benunit_{i}"] = {"members": [f"person_{i}"]} + households[f"household_{i}"] = { + "members": [f"person_{i}"], + "region": {YEAR: "WALES"}, + "tenure_type": {YEAR: "OWNED_OUTRIGHT"}, + } sim = Simulation( situation={ - "people": { - "person": { - "age": {YEAR: 75}, - "private_pension_income": {YEAR: pension}, - "property_income": {YEAR: property_income}, - } - }, - "benunits": {"benunit": {"members": ["person"]}}, - "households": { - "household": { - "members": ["person"], - "region": {YEAR: "WALES"}, - "tenure_type": {YEAR: "OWNED_OUTRIGHT"}, - } - }, + "people": people, + "benunits": benunits, + "households": households, } ) - return ( - float(sim.calculate("pension_credit_income", YEAR)[0]), - float(sim.calculate("pension_credit", YEAR)[0]), - ) + income = sim.calculate("pension_credit_income", YEAR) + credit = sim.calculate("pension_credit", YEAR) + return [(float(a), float(b)) for a, b in zip(income, credit)] -pensions = st.integers(min_value=0, max_value=40_000) +amounts = st.integers(min_value=0, max_value=40_000) losses = st.integers(min_value=-100_000, max_value=0) -gains = st.integers(min_value=0, max_value=20_000) +property_incomes = st.integers(min_value=-100_000, max_value=20_000) + + +def batches(*strategies): + return st.lists(st.tuples(*strategies), min_size=1, max_size=8) + +def _paired(cases: list[dict], baselines: list[dict]): + """Results for each case beside its baseline, from one simulation.""" + results = _pension_credit(cases + baselines) + return zip(results[: len(cases)], results[len(cases) :]) -@settings(max_examples=12, deadline=None) -@given(pension=pensions, loss=losses) -def test_a_property_loss_counts_as_nil(pension, loss): - assert _pension_credit(pension, loss) == pytest.approx( - _pension_credit(pension, 0), abs=0.01 + +@settings(max_examples=5, deadline=None) +@given(batch=batches(amounts, losses)) +def test_a_property_loss_counts_as_nil(batch): + pairs = _paired( + [ + {"private_pension_income": pension, "property_income": loss} + for pension, loss in batch + ], + [{"private_pension_income": pension} for pension, _ in batch], ) + for with_loss, without in pairs: + assert with_loss == pytest.approx(without, abs=0.01) + +@settings(max_examples=5, deadline=None) +@given(batch=batches(amounts, property_incomes)) +def test_pension_credit_is_never_higher_than_with_no_property_income(batch): + # Not monotonicity in general: the model's property allowance makes + # Pension Credit step up between two positive property incomes. + pairs = _paired( + [ + {"private_pension_income": pension, "property_income": amount} + for pension, amount in batch + ], + [{"private_pension_income": pension} for pension, _ in batch], + ) + for (_, credit), (_, credit_without) in pairs: + assert credit <= credit_without + 0.01 -@settings(max_examples=12, deadline=None) -@given(pension=pensions, lower=losses, extra=gains) -def test_pension_credit_never_rises_with_property_income(pension, lower, extra): - _, credit_lower = _pension_credit(pension, lower) - _, credit_higher = _pension_credit(pension, lower + extra) - assert credit_higher <= credit_lower + 0.01 +@settings(max_examples=5, deadline=None) +@given(batch=batches(amounts, amounts, losses)) +def test_a_self_employment_loss_counts_as_nil(batch): + pairs = _paired( + [ + { + "private_pension_income": pension, + "employment_income": wages, + "self_employment_income": loss, + } + for pension, wages, loss in batch + ], + [ + {"private_pension_income": pension, "employment_income": wages} + for pension, wages, _ in batch + ], + ) + for with_loss, without in pairs: + assert with_loss == pytest.approx(without, abs=0.01) -def test_issue_2255_reproducer(): - income, credit = _pension_credit(20_000, -30_000) - assert income == pytest.approx(18_514, abs=1) - assert credit == 0 + +def test_issue_2255_reproducers(): + (property_loss, trading_loss) = _pension_credit( + [ + {"private_pension_income": 20_000, "property_income": -30_000}, + {"employment_income": 10_000, "self_employment_income": -8_000}, + ] + ) + # 20,000 less income tax of 20% of (20,000 - 12,570). + assert property_loss == (pytest.approx(18_514, abs=1), 0) + # 238 x 52 = 12,376, less wages of 10,000. + assert trading_loss == ( + pytest.approx(10_000, abs=1), + pytest.approx(2_376, abs=1), + ) diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_earnings.py b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_earnings.py index c4a6137b6a..75d452b78e 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_earnings.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_earnings.py @@ -15,6 +15,8 @@ class pension_credit_earnings(Variable): reference = ( "https://www.legislation.gov.uk/ukpga/2002/16/section/5", "https://www.legislation.gov.uk/uksi/2002/1792/regulation/17A", + "https://www.legislation.gov.uk/uksi/2002/1792/regulation/17B", + "https://www.legislation.gov.uk/uksi/1996/2745/regulation/13", ) def formula(benunit, period, parameters): @@ -22,5 +24,8 @@ def formula(benunit, period, parameters): period ).gov.dwp.pension_credit.guarantee_credit.earnings_sources person = benunit.members - earnings = add(person, period, sources) + # A loss in one employment is not set against earnings in another + # (Computation of Earnings Regs 1996 reg. 13(12), applied by SPC + # Regs 2002 reg. 17B(5)(b)), so a negative source counts as nil. + earnings = sum(max_(0, person(source, period)) for source in sources) return benunit.sum(earnings * person("is_claimant_or_partner", period)) diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_income.py b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_income.py index 67ef2d101d..944419416e 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_income.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_income.py @@ -25,10 +25,10 @@ def formula(benunit, period, parameters): total = 0 for source in sources: if person.entity.get_variable(source).entity.is_person: - # Each prescribed item is a receipt (State Pension Credit Act - # 2002 s. 15(1); SPC Regs 2002 reg. 15), and nothing lets a - # loss on one be set against another, so a negative source, - # such as a property loss, counts as nil. + # Nothing in the State Pension Credit Act 2002 ss. 15 to 16 + # or SPC Regs 2002 regs. 15 to 18 lets a loss on one source + # be set against another, so a negative source, such as a + # property loss, counts as nil. total += benunit.sum( max_(0, person(source, period)) * is_claimant_or_partner )