From 7a5076c4a13b6949a98177961c6c46702b262834 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 30 Sep 2026 17:28:09 -0400 Subject: [PATCH 01/48] Value means-tested capital less sale expenses and secured debt UC Regs 2013 reg. 49(1) and its legacy equivalents (HB Regs 2006 reg. 47, HB (SPC) Regs 2006 reg. 45, IS Regs 1987 reg. 49, JSA Regs 1996 reg. 111, ESA Regs 2008 reg. 113, SPC Regs 2002 reg. 19) calculate capital at market or surrender value less 10% where a sale would incur expenses and less any encumbrance secured on it. The model summed every capital source at full value. Each programme gets a capital.sale_expenses node (rate 0.1 and the sources whose sale incurs expenses: land, property and corporate_wealth, not cash savings). A shared helper applies the 10% before the encumbrance and never values an encumbered asset below nil. New household inputs carry debt secured on other residential property, non-residential property and land; the Enhanced FRS has none, so they default to zero. Co-Authored-By: Claude Opus 5.5 --- changelog.d/uc-capital-sale-expenses.fixed.md | 1 + policyengine_uk/data/uprating_indices.yaml | 3 + .../income/capital/sale_expenses/rate.yaml | 14 ++ .../income/capital/sale_expenses/sources.yaml | 22 ++ .../income/capital/sale_expenses/rate.yaml | 14 ++ .../income/capital/sale_expenses/sources.yaml | 26 +++ .../capital/sale_expenses/rate.yaml | 16 ++ .../capital/sale_expenses/sources.yaml | 28 +++ .../capital/sale_expenses/rate.yaml | 14 ++ .../capital/sale_expenses/sources.yaml | 26 +++ .../income/capital/sale_expenses/rate.yaml | 14 ++ .../income/capital/sale_expenses/sources.yaml | 26 +++ .../capital/sale_expenses/rate.yaml | 16 ++ .../capital/sale_expenses/sources.yaml | 31 +++ .../family/esa_income/esa_income_capital.yaml | 8 +- .../housing_benefit_capital.yaml | 35 ++- .../income_support_capital.yaml | 8 +- .../family/jsa_income/jsa_income_capital.yaml | 8 +- .../universal_credit/is_UC_eligible.yaml | 12 +- .../baseline/gov/dwp/capital_valuation.yaml | 218 ++++++++++++++++++ .../pension_credit_deemed_income.yaml | 6 +- .../pension_credit/pension_credit_income.yaml | 26 ++- .../test_capital_valuation_properties.py | 182 +++++++++++++++ .../tests/test_stock_capital_periods.py | 8 +- policyengine_uk/utils/capital_valuation.py | 40 ++++ .../gov/dwp/esa_income_assessable_capital.py | 10 +- .../housing_benefit_assessable_capital.py | 10 +- .../dwp/income_support_assessable_capital.py | 10 +- .../gov/dwp/jsa_income_assessable_capital.py | 10 +- .../pension_credit_assessable_capital.py | 8 +- .../universal_credit/uc_assessable_capital.py | 11 +- .../non_residential_property_secured_debt.py | 17 ++ ...other_residential_property_secured_debt.py | 17 ++ .../input/owned_land_secured_debt.py | 16 ++ 34 files changed, 869 insertions(+), 42 deletions(-) create mode 100644 changelog.d/uc-capital-sale-expenses.fixed.md create mode 100644 policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml create mode 100644 policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml create mode 100644 policyengine_uk/tests/test_capital_valuation_properties.py create mode 100644 policyengine_uk/utils/capital_valuation.py create mode 100644 policyengine_uk/variables/input/non_residential_property_secured_debt.py create mode 100644 policyengine_uk/variables/input/other_residential_property_secured_debt.py create mode 100644 policyengine_uk/variables/input/owned_land_secured_debt.py diff --git a/changelog.d/uc-capital-sale-expenses.fixed.md b/changelog.d/uc-capital-sale-expenses.fixed.md new file mode 100644 index 0000000000..34790cb3d8 --- /dev/null +++ b/changelog.d/uc-capital-sale-expenses.fixed.md @@ -0,0 +1 @@ +Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses (land, property and shares; not cash savings) and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. Adds secured-debt inputs for other residential property, non-residential property and land. diff --git a/policyengine_uk/data/uprating_indices.yaml b/policyengine_uk/data/uprating_indices.yaml index 4fbc8bc819..4dad54bc83 100644 --- a/policyengine_uk/data/uprating_indices.yaml +++ b/policyengine_uk/data/uprating_indices.yaml @@ -92,10 +92,13 @@ gov.economic_assumptions.yoy_growth.obr.per_capita.gdp: - miscellaneous_income - mortgage_capital_repayment - net_financial_wealth +- non_residential_property_secured_debt - non_residential_property_value - other_investment_income +- other_residential_property_secured_debt - other_residential_property_value - owned_land +- owned_land_secured_debt - pension_income - private_pension_wealth - private_transfer_income diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml new file mode 100644 index 0000000000..468d182cb9 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml @@ -0,0 +1,14 @@ +description: > + Share of the current market or surrender value deducted from income-related ESA + capital where there would be expenses attributable to sale. The deduction + is a flat 10% whatever the actual costs, taken before any incumbrance + secured on the asset. +values: + 2008-10-27: 0.1 +metadata: + label: Income-related ESA capital sale expense deduction + period: year + unit: /1 + reference: + - title: Employment and Support Allowance Regulations 2008 reg. 113(a) + href: https://www.legislation.gov.uk/uksi/2008/794/regulation/113 diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml new file mode 100644 index 0000000000..b1946fe614 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml @@ -0,0 +1,22 @@ +description: > + Capital sources whose sale would incur expenses, so that income-related ESA + values them at 90% of market value. Land and property always have costs of + sale. Shares are sold through a broker, so `corporate_wealth` is listed; it + also holds unit trusts, which have no costs of sale, but the dataset does + not separate them. `savings` is not listed because a bank or building + society account is valued at its balance and withdrawing money is not a sale + (see the Universal Credit parameter of the same name for the guidance). + Sources not counted as income-related ESA capital are ignored. +metadata: + label: Income-related ESA capital sources with sale expenses + period: year + unit: list + reference: + - title: Employment and Support Allowance Regulations 2008 reg. 113(a) + href: https://www.legislation.gov.uk/uksi/2008/794/regulation/113 +values: + 2008-10-27: + - owned_land + - other_residential_property_value + - non_residential_property_value + - corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml new file mode 100644 index 0000000000..ff2e4d5759 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml @@ -0,0 +1,14 @@ +description: > + Share of the current market or surrender value deducted from income-based JSA + capital where there would be expenses attributable to sale. The deduction + is a flat 10% whatever the actual costs, taken before any incumbrance + secured on the asset. +values: + 1996-10-07: 0.1 +metadata: + label: Income-based JSA capital sale expense deduction + period: year + unit: /1 + reference: + - title: Jobseeker's Allowance Regulations 1996 reg. 111(a) + href: https://www.legislation.gov.uk/uksi/1996/207/regulation/111 diff --git a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml new file mode 100644 index 0000000000..1a64a5ee2c --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml @@ -0,0 +1,26 @@ +description: > + Capital sources whose sale would incur expenses, so that income-based JSA + values them at 90% of market value. Land and property always have costs of + sale. Shares are sold through a broker, so `corporate_wealth` is listed; it + also holds unit trusts, which have no costs of sale, but the dataset does + not separate them. `savings` is not listed because a bank or building + society account is valued at its balance and withdrawing money is not a sale + (DMG 29620-29623, 29681 and 29685). Sources not counted as income-based JSA + capital are ignored. +metadata: + label: Income-based JSA capital sources with sale expenses + period: year + unit: list + reference: + - title: Jobseeker's Allowance Regulations 1996 reg. 111(a) + href: https://www.legislation.gov.uk/uksi/1996/207/regulation/111 + - title: Decision Makers' Guide chapter 29, paras. 29620-29623 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=124 + - title: Decision Makers' Guide chapter 29, paras. 29681 and 29685 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=139 +values: + 1996-10-07: + - owned_land + - other_residential_property_value + - non_residential_property_value + - corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml new file mode 100644 index 0000000000..f496742f77 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml @@ -0,0 +1,16 @@ +description: > + Share of the current market or surrender value deducted from Housing Benefit + capital where there would be expenses attributable to sale. The deduction + is a flat 10% whatever the actual costs, taken before any encumbrance + secured on the asset. +values: + 2006-04-10: 0.1 +metadata: + label: Housing Benefit capital sale expense deduction + period: year + unit: /1 + reference: + - title: The Housing Benefit Regulations 2006 reg. 47(a) + href: https://www.legislation.gov.uk/uksi/2006/213/regulation/47 + - title: The Housing Benefit (Persons who have attained the qualifying age for state pension credit) Regulations 2006 reg. 45(a) + href: https://www.legislation.gov.uk/uksi/2006/214/regulation/45 diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml new file mode 100644 index 0000000000..cb504ed3c4 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml @@ -0,0 +1,28 @@ +description: > + Capital sources whose sale would incur expenses, so that Housing Benefit + values them at 90% of market value. Land and property always have costs of + sale. Shares are sold through a broker, so `corporate_wealth` is listed; it + also holds unit trusts, which have no costs of sale, but the dataset does + not separate them. `savings` is not listed because a bank or building + society account is valued at its balance and withdrawing money is not a sale + (HBGM W1.430, W1.530-W1.531, P1.430 and P1.530-P1.531). Sources not counted + as Housing Benefit capital are ignored. +metadata: + label: Housing Benefit capital sources with sale expenses + period: year + unit: list + reference: + - title: The Housing Benefit Regulations 2006 reg. 47(a) + href: https://www.legislation.gov.uk/uksi/2006/213/regulation/47 + - title: The Housing Benefit (Persons who have attained the qualifying age for state pension credit) Regulations 2006 reg. 45(a) + href: https://www.legislation.gov.uk/uksi/2006/214/regulation/45 + - title: Housing Benefit Guidance Manual BW1, paras. W1.430 and W1.530-W1.531 + href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=36 + - title: Housing Benefit Guidance Manual BP1, paras. P1.430 and P1.530-P1.531 + href: https://assets.publishing.service.gov.uk/media/5a7ec5d840f0b6230268b71f/hbgm-bp1-assessment-of-capital.pdf#page=31 +values: + 2006-04-10: + - owned_land + - other_residential_property_value + - non_residential_property_value + - corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml new file mode 100644 index 0000000000..7cb86fe853 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml @@ -0,0 +1,14 @@ +description: > + Share of the current market or surrender value deducted from Income Support + capital where there would be expenses attributable to sale. The deduction + is a flat 10% whatever the actual costs, taken before any incumbrance + secured on the asset. +values: + 2010-01-01: 0.1 +metadata: + label: Income Support capital sale expense deduction + period: year + unit: /1 + reference: + - title: Income Support (General) Regulations 1987 reg. 49(a) + href: https://www.legislation.gov.uk/uksi/1987/1967/regulation/49 diff --git a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml new file mode 100644 index 0000000000..0af0f836b0 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml @@ -0,0 +1,26 @@ +description: > + Capital sources whose sale would incur expenses, so that Income Support + values them at 90% of market value. Land and property always have costs of + sale. Shares are sold through a broker, so `corporate_wealth` is listed; it + also holds unit trusts, which have no costs of sale, but the dataset does + not separate them. `savings` is not listed because a bank or building + society account is valued at its balance and withdrawing money is not a sale + (DMG 29620-29623, 29681 and 29685). Sources not counted as Income Support + capital are ignored. +metadata: + label: Income Support capital sources with sale expenses + period: year + unit: list + reference: + - title: Income Support (General) Regulations 1987 reg. 49(a) + href: https://www.legislation.gov.uk/uksi/1987/1967/regulation/49 + - title: Decision Makers' Guide chapter 29, paras. 29620-29623 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=124 + - title: Decision Makers' Guide chapter 29, paras. 29681 and 29685 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=139 +values: + 2010-01-01: + - owned_land + - other_residential_property_value + - non_residential_property_value + - corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml new file mode 100644 index 0000000000..b344e9dcf2 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml @@ -0,0 +1,14 @@ +description: > + Share of the current market or surrender value deducted from Pension Credit + capital where there would be expenses attributable to sale. The deduction + is a flat 10% whatever the actual costs, taken before any encumbrance + secured on the asset. +values: + 2003-10-06: 0.1 +metadata: + label: Pension Credit capital sale expense deduction + period: year + unit: /1 + reference: + - title: State Pension Credit Regulations 2002 reg. 19(a) + href: https://www.legislation.gov.uk/uksi/2002/1792/regulation/19 diff --git a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml new file mode 100644 index 0000000000..da4dae9ae1 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml @@ -0,0 +1,26 @@ +description: > + Capital sources whose sale would incur expenses, so that Pension Credit + values them at 90% of market value. Land and property always have costs of + sale. Shares are sold through a broker, so `corporate_wealth` is listed; it + also holds unit trusts, which have no costs of sale, but the dataset does + not separate them. `savings` is not listed because a bank or building + society account is valued at its balance and withdrawing money is not a sale + (DMG 84712-84716, 84731 and 84772). Sources not counted as Pension Credit + capital are ignored. +metadata: + label: Pension Credit capital sources with sale expenses + period: year + unit: list + reference: + - title: State Pension Credit Regulations 2002 reg. 19(a) + href: https://www.legislation.gov.uk/uksi/2002/1792/regulation/19 + - title: Decision Makers' Guide chapter 84, paras. 84712-84716 + href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=99 + - title: Decision Makers' Guide chapter 84, paras. 84731 and 84772 + href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=102 +values: + 2003-10-06: + - owned_land + - other_residential_property_value + - non_residential_property_value + - corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml new file mode 100644 index 0000000000..150561614f --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml @@ -0,0 +1,16 @@ +description: > + Share of the current market or surrender value deducted from Universal + Credit capital where there would be expenses attributable to sale. The + deduction is a flat 10% whatever the actual costs, taken before any + encumbrance secured on the asset. +values: + 2013-04-29: 0.1 +metadata: + label: Universal Credit capital sale expense deduction + period: year + unit: /1 + reference: + - title: The Universal Credit Regulations 2013 reg. 49(1)(a) + href: https://www.legislation.gov.uk/uksi/2013/376/regulation/49 + - title: Advice for Decision Making chapter H1, paras. H1602-H1608 + href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=44 diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml new file mode 100644 index 0000000000..969e9ac619 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml @@ -0,0 +1,31 @@ +description: > + Capital sources whose sale would incur expenses, so that Universal Credit + values them at 90% of market value. Real property always has costs of sale + (ADM H1606, citing R(IS) 21/93), so `owned_land`, + `other_residential_property_value` and `non_residential_property_value` are + listed. `savings` is not listed: the 10% applies only where selling needs + an agent, broker, solicitor or accountant (ADM H1604-H1605), the costs of + withdrawing money from a building society are not costs of sale (H1607), + and an account is valued at its balance (H1675). `corporate_wealth` is + listed because quoted shares are valued less 10% for costs of sale (H1665). + It also holds unit trusts, which have no costs of sale (H1674), and stocks + and shares ISAs, which the guidance values at their withdrawal value + (H1656); the dataset does not separate these, so the deduction also + reaches them. Sources not counted as Universal Credit capital are ignored. +metadata: + label: Universal Credit capital sources with sale expenses + period: year + unit: list + reference: + - title: The Universal Credit Regulations 2013 reg. 49(1)(a) + href: https://www.legislation.gov.uk/uksi/2013/376/regulation/49 + - title: Advice for Decision Making chapter H1, paras. H1604-H1607 + href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=44 + - title: Advice for Decision Making chapter H1, paras. H1665 and H1673-H1675 + href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=57 +values: + 2013-04-29: + - owned_land + - other_residential_property_value + - non_residential_property_value + - corporate_wealth diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/esa_income/esa_income_capital.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/esa_income/esa_income_capital.yaml index bdbbef68e0..abe48a7b5d 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/esa_income/esa_income_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/esa_income/esa_income_capital.yaml @@ -19,7 +19,9 @@ other_residential_property_value: 3_000 non_residential_property_value: 4_000 output: - esa_income_assessable_capital: 10_500 + # Savings at face value; land, shares and property less 10% for the + # expenses of sale (ESA Regs 2008 reg. 113(a)): 1,000 + 90% of 9,500. + esa_income_assessable_capital: 9_550 - name: Income-related ESA has no tariff income at the lower capital threshold period: 2026 @@ -210,4 +212,6 @@ corporate_wealth: 2_000 private_pension_wealth: 150_000 output: - esa_income_assessable_capital: 3_000 + # Savings at face value; land, shares and property less 10% for the + # expenses of sale (ESA Regs 2008 reg. 113(a)): 1,000 + 90% of 2,000. + esa_income_assessable_capital: 2_800 diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/housing_benefit/housing_benefit_capital.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/housing_benefit/housing_benefit_capital.yaml index e9a0cd47c3..c73e3b37f5 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/housing_benefit/housing_benefit_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/housing_benefit/housing_benefit_capital.yaml @@ -89,7 +89,7 @@ - name: Housing Benefit counts direct land holdings as capital period: 2025 - absolute_error_margin: 0 + absolute_error_margin: 0.01 input: people: person: @@ -103,11 +103,36 @@ households: household: members: person - owned_land: 16_001 + # 90% of 17,780 is 16,002, over the 16,000 limit after the 10% + # deduction for the expenses of sale (HB Regs 2006 reg. 47(a)). + owned_land: 17_780 output: - housing_benefit_assessable_capital: 16_001 + housing_benefit_assessable_capital: 16_002 housing_benefit_eligible: false +- name: Housing Benefit values land less 10% for the expenses of sale + period: 2025 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + in_social_housing: true + housing_benefit_reported: 1 + benunits: + benunit: + members: person + would_claim_uc: false + households: + household: + members: person + # Land worth 16,001 is valued at 14,400.90 (HB Regs 2006 reg. 47(a)), + # within the limit. + owned_land: 16_001 + output: + housing_benefit_assessable_capital: 14_400.9 + housing_benefit_eligible: true + - name: Housing Benefit counts corporate wealth as a broad financial-capital proxy period: 2025 absolute_error_margin: 0 @@ -126,7 +151,9 @@ members: person corporate_wealth: 50_000 output: - housing_benefit_assessable_capital: 50_000 + # Market value less 10% for the expenses of sale (HB Regs 2006 + # reg. 47(a)). + housing_benefit_assessable_capital: 45_000 housing_benefit_eligible: false - name: Mixed benunits split household Housing Benefit capital by adult share diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/income_support/income_support_capital.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/income_support/income_support_capital.yaml index 585884ea9c..f90e5f1a9d 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/income_support/income_support_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/income_support/income_support_capital.yaml @@ -23,7 +23,9 @@ other_residential_property_value: 3000 non_residential_property_value: 4000 output: - income_support_assessable_capital: 10500 + # Savings at face value; land, shares and property less 10% for the + # expenses of sale (IS Regs 1987 reg. 49(a)): 1,000 + 90% of 9,500. + income_support_assessable_capital: 9550 - name: Income Support has no tariff income at the lower capital threshold period: 2021 @@ -233,4 +235,6 @@ corporate_wealth: 2000 private_pension_wealth: 150000 output: - income_support_assessable_capital: 3000 + # Savings at face value; land, shares and property less 10% for the + # expenses of sale (IS Regs 1987 reg. 49(a)): 1,000 + 90% of 2,000. + income_support_assessable_capital: 2800 diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/jsa_income/jsa_income_capital.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/jsa_income/jsa_income_capital.yaml index 13ecc3d659..bc50925503 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/jsa_income/jsa_income_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/jsa_income/jsa_income_capital.yaml @@ -19,7 +19,9 @@ other_residential_property_value: 3_000 non_residential_property_value: 4_000 output: - jsa_income_assessable_capital: 10_500 + # Savings at face value; land, shares and property less 10% for the + # expenses of sale (JSA Regs 1996 reg. 111(a)): 1,000 + 90% of 9,500. + jsa_income_assessable_capital: 9_550 - name: Income-based JSA has no tariff income at the lower capital threshold period: 2025 @@ -184,4 +186,6 @@ corporate_wealth: 2_000 private_pension_wealth: 150_000 output: - jsa_income_assessable_capital: 3_000 + # Savings at face value; land, shares and property less 10% for the + # expenses of sale (JSA Regs 1996 reg. 111(a)): 1,000 + 90% of 2,000. + jsa_income_assessable_capital: 2_800 diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/is_UC_eligible.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/is_UC_eligible.yaml index fa145e20c1..fc466402eb 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/is_UC_eligible.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/is_UC_eligible.yaml @@ -259,7 +259,9 @@ members: person other_residential_property_value: 50_000 output: - uc_assessable_capital: 50_000 + # Market value less 10% for the expenses of sale (UC Regs 2013 + # reg. 49(1)(a)). + uc_assessable_capital: 45_000 is_uc_eligible: false - name: Countable non-residential property can push capital over the upper threshold @@ -277,7 +279,9 @@ members: person non_residential_property_value: 50_000 output: - uc_assessable_capital: 50_000 + # Market value less 10% for the expenses of sale (UC Regs 2013 + # reg. 49(1)(a)). + uc_assessable_capital: 45_000 is_uc_eligible: false - name: Countable corporate wealth can push capital over the upper threshold @@ -295,7 +299,9 @@ members: person corporate_wealth: 50_000 output: - uc_assessable_capital: 50_000 + # Market value less 10% for the expenses of sale (UC Regs 2013 + # reg. 49(1)(a)). + uc_assessable_capital: 45_000 is_uc_eligible: false - name: Main residence value is excluded from Universal Credit capital diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml new file mode 100644 index 0000000000..840b084ec1 --- /dev/null +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -0,0 +1,218 @@ +# Capital is valued at market value less 10% where a sale would incur +# expenses, and less any encumbrance secured on it: UC Regs 2013 reg. 49(1); +# HB Regs 2006 reg. 47; IS Regs 1987 reg. 49; JSA Regs 1996 reg. 111; ESA Regs +# 2008 reg. 113; SPC Regs 2002 reg. 19. Savings in a bank or building society +# have no sale expenses; land, property and shares do (ADM H1604-H1607). +# Expected values are worked by hand from those provisions. + +- name: UC values a mortgaged holiday home as in ADM H1602 + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # 125,000 - 10% (12,500) - 100,500 mortgage = 12,000. + other_residential_property_value: 125_000 + other_residential_property_secured_debt: 100_500 + output: + uc_assessable_capital: 12_000 + is_uc_eligible: true + # 24 steps of 250 above 6,000 at 4.35 a month: 24 * 4.35 * 12. + uc_tariff_income: 1_252.8 + +- name: UC counts cash savings at face value + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + savings: 15_000 + output: + uc_assessable_capital: 15_000 + is_uc_eligible: true + +- name: UC shares valued less sale expenses bring capital within the limit + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # 5,000 + 90% of 12,000 = 15,800, within the 16,000 limit; at full + # value the household would hold 17,000. + savings: 5_000 + corporate_wealth: 12_000 + output: + uc_assessable_capital: 15_800 + is_uc_eligible: true + # 9,800 above 6,000 is 40 steps of 250 (rounded up): 40 * 4.35 * 12. + uc_tariff_income: 2_088 + +- name: UC negative equity in a second home does not reduce savings + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # The mortgage is deducted only from the property it is secured on + # (ADM H1615-H1616), so the property is valued at nil. + savings: 10_000 + other_residential_property_value: 100_000 + other_residential_property_secured_debt: 150_000 + output: + uc_assessable_capital: 10_000 + is_uc_eligible: true + +- name: UC deducts sale expenses before the encumbrance on business premises + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # (90% of 40,000 - 20,000) + 90% of 5,000 = 16,000 + 4,500. + non_residential_property_value: 40_000 + non_residential_property_secured_debt: 20_000 + corporate_wealth: 5_000 + output: + uc_assessable_capital: 20_500 + is_uc_eligible: false + +- name: Housing Benefit values encumbered land less sale expenses + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + in_social_housing: true + housing_benefit_reported: 1 + benunits: + benunit: + members: person + would_claim_uc: false + households: + household: + members: person + # 1,000 + (90% of 20,000 - 5,000) = 14,000 (HB Regs 2006 reg. 47). + savings: 1_000 + owned_land: 20_000 + owned_land_secured_debt: 5_000 + output: + housing_benefit_assessable_capital: 14_000 + # 32 steps of 250 above 6,000 at 1 a week: 32 * 52. + housing_benefit_tariff_income: 1_664 + housing_benefit_eligible: true + +- name: Income Support values encumbered land less sale expenses + period: 2021 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # 90% of 20,000 - 5,000 = 13,000 (IS Regs 1987 reg. 49). + owned_land: 20_000 + owned_land_secured_debt: 5_000 + output: + income_support_assessable_capital: 13_000 + +- name: Income-based JSA values a mortgaged second home less sale expenses + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # 2,000 + (90% of 30,000 - 25,000) = 4,000 (JSA Regs 1996 reg. 111). + savings: 2_000 + other_residential_property_value: 30_000 + other_residential_property_secured_debt: 25_000 + output: + jsa_income_assessable_capital: 4_000 + +- name: Income-related ESA values shares less sale expenses + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 40 + benunits: + benunit: + members: person + households: + household: + members: person + # 3,000 + 90% of 10,000 = 12,000 (ESA Regs 2008 reg. 113). + savings: 3_000 + corporate_wealth: 10_000 + output: + esa_income_assessable_capital: 12_000 + +- name: Pension Credit values mortgaged business premises less sale expenses + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 70 + benunits: + benunit: + members: person + households: + household: + members: person + # 2,000 + (90% of 30,000 - 10,000) = 19,000 (SPC Regs 2002 reg. 19). + savings: 2_000 + non_residential_property_value: 30_000 + non_residential_property_secured_debt: 10_000 + output: + pension_credit_assessable_capital: 19_000 + # 18 steps of 500 above 10,000 at 1 a week: 18 * 52. + pension_credit_deemed_income: 936 diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_deemed_income.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_deemed_income.yaml index cf16632edc..5e4f8db1ae 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_deemed_income.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/pension_credit/pension_credit_deemed_income.yaml @@ -78,9 +78,11 @@ households: household: members: person - owned_land: 10_001 + # 90% of 11,120 is 10,008 after the 10% deduction for the expenses + # of sale (SPC Regs 2002 reg. 19(a)): one 500 step above 10,000. + owned_land: 11_120 output: - pension_credit_assessable_capital: 10_001 + pension_credit_assessable_capital: 10_008 pension_credit_deemed_income: 52 - name: Pension Credit does not dilute pensioner capital across unrelated adult benunits. 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..b578d941fe 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 @@ -76,10 +76,16 @@ other_residential_property_value: 55_370 savings: 455 output: - pension_credit_assessable_capital: 55_825 - pension_credit_deemed_income: 4_784 - pension_credit_income: 15_260 - pension_credit: 0 + # 455 + 90% of 55,370 (SPC Regs 2002 reg. 19(a)). Deemed income is + # 81 steps of 500 above 10,000 at 1 a week: 81 * 52 = 4,212. + pension_credit_assessable_capital: 50_288 + pension_credit_deemed_income: 4_212 + pension_credit_income: 14_688 + # Income exceeds the 12,376 guarantee, so no guarantee credit. Savings + # credit: 60% of (12,376 - 208.07 * 52) = 933.82, less 40% of + # (14,688 - 12,376) = 924.80, leaves 9.02. + guarantee_credit: 0 + pension_credit: 9.016 - name: Case 5, 2026 Pension Credit uses tariff income with the published guarantee rate. period: 2026 @@ -99,12 +105,14 @@ savings: 87_285 corporate_wealth: 12_650 output: - pension_credit_assessable_capital: 99_935 - pension_credit_deemed_income: 9_360 - pension_credit_income: 9_360 + # 87,285 + 90% of 12,650 (SPC Regs 2002 reg. 19(a)). Deemed income is + # 178 steps of 500 above 10,000 at 1 a week: 178 * 52 = 9,256. + pension_credit_assessable_capital: 98_670 + pension_credit_deemed_income: 9_256 + pension_credit_income: 9_256 standard_minimum_guarantee: 12_376 - guarantee_credit: 3_016 - pension_credit: 3_016 + guarantee_credit: 3_120 + pension_credit: 3_120 - name: Pension Credit capital disregards private pension wealth period: 2026 diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py new file mode 100644 index 0000000000..76a7aa5d1d --- /dev/null +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -0,0 +1,182 @@ +"""Property-based tests for how the means tests value capital. + +Universal Credit and each legacy means test calculate capital in the United +Kingdom at its current market or surrender value less 10% where there would +be expenses attributable to sale, and less any encumbrance secured on it (UC +Regs 2013 reg. 49(1); HB Regs 2006 reg. 47; HB (SPC) Regs 2006 reg. 45; IS +Regs 1987 reg. 49; JSA Regs 1996 reg. 111; ESA Regs 2008 reg. 113; SPC Regs +2002 reg. 19). Savings in a bank or building society incur no sale expenses; +land, property and shares do. + +Invariants, for any generated population of single-adult households: + +1. Non-increasing: every programme's assessable capital is at most the same + household's capital with the deduction switched off (rate 0, no debt). +2. Cash only: a household holding only savings has the same capital with the + deduction on or off. +3. Differential: capital equals a direct implementation of the regulation, + savings + sum over sources of max(0, 90% of value - secured debt). +4. Monotone: a higher sale-expense rate, or more secured debt, never raises + capital. +5. Isolation: debt secured on one asset never takes capital below the value + of the household's other assets, and capital is never negative. +""" + +from functools import reduce + +import numpy as np +from hypothesis import HealthCheck, given, settings +from hypothesis import strategies as st + +from policyengine_uk import Simulation + +YEAR = 2026 +PROPERTY_SETTINGS = settings( + max_examples=5, + deadline=None, + derandomize=True, + suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large], +) +# Assessable capital variable -> parameter node holding its sources and +# sale-expense rule. Pension Credit counts only pension-age adults; the +# others are tested on working-age adults (pension-age Housing Benefit +# disregards all capital for Guarantee Credit recipients). +PROGRAMMES = { + "uc_assessable_capital": "gov.dwp.universal_credit.means_test.capital", + "housing_benefit_assessable_capital": "gov.dwp.housing_benefit.means_test.capital", + "income_support_assessable_capital": "gov.dwp.income_support.means_test.capital", + "jsa_income_assessable_capital": "gov.dwp.JSA.income.capital", + "esa_income_assessable_capital": "gov.dwp.ESA.income.capital", + "pension_credit_assessable_capital": "gov.dwp.pension_credit.income.capital", +} +PENSION_AGE_ONLY = {"pension_credit_assessable_capital"} +ASSETS = [ + "savings", + "owned_land", + "corporate_wealth", + "other_residential_property_value", + "non_residential_property_value", +] +DEBTS = { + "owned_land": "owned_land_secured_debt", + "other_residential_property_value": "other_residential_property_secured_debt", + "non_residential_property_value": "non_residential_property_secured_debt", +} +amount = st.one_of(st.just(0.0), st.floats(0, 400_000, allow_nan=False)) + + +@st.composite +def households(draw, cash_only=False): + assets = {asset: draw(amount) for asset in ASSETS} + debts = {debt: draw(amount) for debt in DEBTS.values()} + if cash_only: + assets = {asset: 0.0 for asset in ASSETS} | {"savings": assets["savings"]} + debts = {debt: 0.0 for debt in debts} + return dict(age=draw(st.sampled_from([30, 70])), assets=assets, debts=debts) + + +def situation(units, debt_scale=1.0): + people, benunits, homes = {}, {}, {} + for i, unit in enumerate(units): + people[f"p{i}"] = {"age": {YEAR: unit["age"]}} + benunits[f"b{i}"] = {"members": [f"p{i}"]} + homes[f"h{i}"] = { + "members": [f"p{i}"], + **{k: {YEAR: v} for k, v in unit["assets"].items()}, + **{k: {YEAR: v * debt_scale} for k, v in unit["debts"].items()}, + } + return {"people": people, "benunits": benunits, "households": homes} + + +def rate_reform(rate): + return { + f"{node}.sale_expenses.rate": {str(YEAR): rate} for node in PROGRAMMES.values() + } + + +def calculate(units, rate=None, debt_scale=1.0): + sim = Simulation( + situation=situation(units, debt_scale), + reform=None if rate is None else rate_reform(rate), + ) + return sim, {v: np.asarray(sim.calculate(v, YEAR), dtype=float) for v in PROGRAMMES} + + +def parameter_node(sim, path): + return reduce(getattr, path.split("."), sim.tax_benefit_system.parameters(YEAR)) + + +def applies(variable, unit): + return (unit["age"] >= 67) == (variable in PENSION_AGE_ONLY) + + +def expected_capital(unit, node): + """Reg. 49(1) applied source by source, independently of the model.""" + total = 0.0 + for source in node.sources: + value = unit["assets"][source] + if source in node.sale_expenses.sources: + value *= 1 - node.sale_expenses.rate + if source in DEBTS: + value = max(0.0, value - unit["debts"][DEBTS[source]]) + total += value + return total + + +def close(a, b): + return abs(a - b) <= 1 + 1e-6 * abs(b) + + +@PROPERTY_SETTINGS +@given(st.lists(households(), min_size=1, max_size=30)) +def test_valuation_matches_the_regulation_and_never_adds_capital(units): + sim, valued = calculate(units) + _, full = calculate(units, rate=0.0, debt_scale=0.0) + for variable, path in PROGRAMMES.items(): + node = parameter_node(sim, path) + assert node.sale_expenses.rate == 0.1 + assert "savings" in node.sources + assert "savings" not in node.sale_expenses.sources + for i, unit in enumerate(units): + assert valued[variable][i] >= 0, (variable, unit) + assert valued[variable][i] <= full[variable][i] + 0.01, (variable, unit) + if applies(variable, unit): + expected = expected_capital(unit, node) + assert close(valued[variable][i], expected), (variable, unit) + # Debt secured on property never reaches the other assets. + floor = sum( + unit["assets"][s] + * (1 - node.sale_expenses.rate * (s in node.sale_expenses.sources)) + for s in node.sources + if s not in DEBTS + ) + assert valued[variable][i] >= floor - 1, (variable, unit) + + +@PROPERTY_SETTINGS +@given(st.lists(households(cash_only=True), min_size=1, max_size=30)) +def test_cash_only_households_have_no_deduction(units): + _, valued = calculate(units) + _, full = calculate(units, rate=0.0) + for variable in PROGRAMMES: + assert np.allclose(valued[variable], full[variable]), variable + for i, unit in enumerate(units): + if applies(variable, unit): + assert close(valued[variable][i], unit["assets"]["savings"]), variable + + +@PROPERTY_SETTINGS +@given( + st.lists(households(), min_size=1, max_size=30), + st.floats(0, 0.5), + st.floats(0, 0.5), + st.floats(0, 2), +) +def test_capital_is_non_increasing_in_rate_and_secured_debt(units, r1, r2, scale): + low, high = sorted([r1, r2]) + _, at_low = calculate(units, rate=low) + _, at_high = calculate(units, rate=high) + _, more_debt = calculate(units, rate=low, debt_scale=1 + scale) + for variable in PROGRAMMES: + assert np.all(at_high[variable] <= at_low[variable] + 0.01), variable + assert np.all(more_debt[variable] <= at_low[variable] + 0.01), variable diff --git a/policyengine_uk/tests/test_stock_capital_periods.py b/policyengine_uk/tests/test_stock_capital_periods.py index d36c3068b2..e694045d13 100644 --- a/policyengine_uk/tests/test_stock_capital_periods.py +++ b/policyengine_uk/tests/test_stock_capital_periods.py @@ -23,7 +23,9 @@ def test_uc_capital_stocks_are_not_prorated_in_monthly_calculations(): assert simulation.calculate("savings", "2026-01")[0] == 12_000 assert simulation.calculate("corporate_wealth", "2026-01")[0] == 12_000 - assert simulation.calculate("uc_assessable_capital", "2026-01")[0] == 36_000 + # Savings at face value; property and shares less 10% for the expenses + # of sale (UC Regs 2013 reg. 49(1)(a)): 12,000 + 2 * 10,800. + assert simulation.calculate("uc_assessable_capital", "2026-01")[0] == 33_600 assert not simulation.calculate("is_uc_eligible", "2026-01")[0] @@ -43,7 +45,9 @@ def test_pension_credit_capital_stocks_are_not_prorated_monthly(): simulation = Simulation(situation=situation) assert simulation.calculate("savings", "2026-01")[0] == 12_000 + # Land and shares less 10% for the expenses of sale (SPC Regs 2002 + # reg. 19(a)): 12,000 + 2 * 10,800. assert ( simulation.calculate("pension_credit_assessable_capital", "2026-01")[0] - == 36_000 + == 33_600 ) diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py new file mode 100644 index 0000000000..2e70896a1a --- /dev/null +++ b/policyengine_uk/utils/capital_valuation.py @@ -0,0 +1,40 @@ +"""Value means-tested capital as the capital-valuation regulations require. + +Universal Credit and each legacy means test value capital in the United +Kingdom "at its current market or surrender value less (a) where there would +be expenses attributable to sale, 10% [...]; and (b) the amount of any +encumbrances secured on it" (UC Regs 2013 reg. 49(1) and its legacy +equivalents). Each programme sets its own rate and the capital sources whose +sale would incur expenses in a ``capital.sale_expenses`` parameter node. +""" + +from policyengine_core.model_api import max_ + +# Household inputs holding the debts secured on each capital source, such as +# a mortgage on a second property. The encumbrance is deducted only from the +# asset it is secured on, so negative equity in one asset never reduces the +# value of another (ADM H1615-H1616). +SECURED_DEBT = { + "other_residential_property_value": "other_residential_property_secured_debt", + "non_residential_property_value": "non_residential_property_secured_debt", + "owned_land": "owned_land_secured_debt", +} + + +def valued_capital(value_of, sources, sale_expenses): + """Sum ``sources`` at market value less sale expenses and secured debt. + + ``value_of(variable)`` returns that household variable on the entity the + caller is working with. The sale-expense deduction comes first and the + encumbrance second (ADM H1608), and an encumbered asset is never valued + below nil. + """ + total = 0 + for source in sources: + value = value_of(source) + if source in sale_expenses.sources: + value = value * (1 - sale_expenses.rate) + if source in SECURED_DEBT: + value = max_(0, value - value_of(SECURED_DEBT[source])) + total = total + value + return total diff --git a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py index 473bcdfebb..d9e00ba312 100644 --- a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import valued_capital class esa_income_assessable_capital(Variable): @@ -7,7 +8,8 @@ class esa_income_assessable_capital(Variable): label = "Assessable capital for income-related ESA" documentation = ( "Household capital apportioned to the benefit unit for the income-related " - "ESA capital test. Because the dataset only stores these stocks at " + "ESA capital test, valued at market value less 10% where a sale would " + "incur expenses and less any debt secured on it (reg. 113). Because the dataset only stores these stocks at " "household level, the model allocates full household capital to any " "benunit with a reported income-related ESA award and only falls back to " "an adult-share proxy when nobody in the household is on that reported " @@ -23,8 +25,10 @@ def formula(benunit, period, parameters): person = benunit.members claiming_esa_income = add(benunit, period, ["esa_income_reported"]) > 0 - household_capital = sum( - benunit.max(person.household(source, period)) for source in sources + household_capital = valued_capital( + lambda variable: benunit.max(person.household(variable, period)), + sources, + ESA.capital.sale_expenses, ) benunit_adults = add(benunit, period, ["is_adult"]) household_reporting_claimants = benunit.max( diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py index c978c5f699..cf1178e0a2 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import valued_capital class housing_benefit_assessable_capital(Variable): @@ -7,7 +8,10 @@ class housing_benefit_assessable_capital(Variable): label = "Housing Benefit assessable capital" documentation = ( "Housing Benefit capital counted from the configured capital sources, " - "allocated across benunits using a household adult-share proxy." + "each valued at market value less 10% where a sale would incur " + "expenses and less any debt secured on it (reg. 47 of SI 2006/213, " + "reg. 45 of SI 2006/214), allocated across benunits using a household " + "adult-share proxy." ) definition_period = YEAR unit = GBP @@ -18,7 +22,9 @@ def formula(benunit, period, parameters): person = benunit.members any_over_SP_age = benunit.any(person("is_SP_age", period)) p = parameters(period).gov.dwp.housing_benefit.means_test.capital - household_capital = sum(household(source, period) for source in p.sources) + household_capital = valued_capital( + lambda variable: household(variable, period), p.sources, p.sale_expenses + ) benunit_adults = add(benunit, period, ["is_adult"]) household_adults = benunit.max( person.household.sum(person.household.members("is_adult", period)) diff --git a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py index e497c670f8..2afff9bedf 100644 --- a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import valued_capital class income_support_assessable_capital(Variable): @@ -7,7 +8,8 @@ class income_support_assessable_capital(Variable): label = "Assessable capital for Income Support" documentation = ( "Household capital apportioned to the benefit unit for the Income Support " - "capital test. Because the dataset only stores these stocks at household " + "capital test, valued at market value less 10% where a sale would incur " + "expenses and less any debt secured on it (reg. 49). Because the dataset only stores these stocks at household " "level, the model allocates full household capital to any benunit on the " "IS claim path and only falls back to an adult-share proxy when nobody in " "the household is on that path." @@ -27,8 +29,10 @@ def formula(benunit, period, parameters): # any benunit on the IS claim path gets the full observed household total. # If nobody in the household is on that path, fall back to an all-adults # proxy so direct inspection still returns a usable value. - household_capital = sum( - benunit.max(person.household(source, period)) for source in sources + household_capital = valued_capital( + lambda variable: benunit.max(person.household(variable, period)), + sources, + IS.means_test.capital.sale_expenses, ) benunit_adults = add(benunit, period, ["is_adult"]) household_claiming_adults = benunit.max( diff --git a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py index 2483cc9945..8fe20569d8 100644 --- a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import valued_capital class jsa_income_assessable_capital(Variable): @@ -7,7 +8,8 @@ class jsa_income_assessable_capital(Variable): label = "Assessable capital for income-based JSA" documentation = ( "Household capital apportioned to the benefit unit for the income-based " - "JSA capital test. Because the dataset only stores these stocks at " + "JSA capital test, valued at market value less 10% where a sale would " + "incur expenses and less any debt secured on it (reg. 111). Because the dataset only stores these stocks at " "household level, the model allocates full household capital to any " "benunit with a reported income-based JSA award and only falls back to " "an adult-share proxy when nobody in the household is on that reported " @@ -23,8 +25,10 @@ def formula(benunit, period, parameters): person = benunit.members claiming_jsa_income = add(benunit, period, ["jsa_income_reported"]) > 0 - household_capital = sum( - benunit.max(person.household(source, period)) for source in sources + household_capital = valued_capital( + lambda variable: benunit.max(person.household(variable, period)), + sources, + JSA.capital.sale_expenses, ) benunit_adults = add(benunit, period, ["is_adult"]) household_reporting_claimants = benunit.max( diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py index 9f4c1fde97..068fbc1872 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import valued_capital class pension_credit_assessable_capital(Variable): @@ -7,7 +8,8 @@ class pension_credit_assessable_capital(Variable): label = "Pension Credit assessable capital" documentation = ( "Pension Credit capital counted from the configured capital sources, " - "split only across pension-age adults in the household so pensioner " + "each valued at market value less 10% where a sale would incur " + "expenses and less any debt secured on it (reg. 19), split only across pension-age adults in the household so pensioner " "couples pool capital together without dilution by unrelated working-" "age adults." ) @@ -19,7 +21,9 @@ def formula(benunit, period, parameters): household = benunit.household person = benunit.members p = parameters(period).gov.dwp.pension_credit.income.capital - household_capital = sum(household(source, period) for source in p.sources) + household_capital = valued_capital( + lambda variable: household(variable, period), p.sources, p.sale_expenses + ) any_pension_age = benunit.any(person("is_SP_age", period)) benunit_pension_age_adults = benunit.sum(person("is_SP_age", period)) household_pension_age_adults = benunit.max( diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py index eef9c8f729..d2f0125a76 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import valued_capital class uc_assessable_capital(Variable): @@ -7,7 +8,9 @@ class uc_assessable_capital(Variable): label = "Universal Credit assessable capital" documentation = ( "Universal Credit capital counted from the configured capital sources, " - "with benunit-reported overrides when available." + "each valued at market value less 10% where a sale would incur " + "expenses and less any debt secured on it (reg. 49(1)), with " + "benunit-reported overrides when available." ) definition_period = YEAR unit = GBP @@ -16,8 +19,10 @@ class uc_assessable_capital(Variable): def formula(benunit, period, parameters): household = benunit.household p = parameters(period).gov.dwp.universal_credit.means_test - household_capital = sum( - household(source, period) for source in p.capital.sources + household_capital = valued_capital( + lambda variable: household(variable, period), + p.capital.sources, + p.capital.sale_expenses, ) benunit_adults = add(benunit, period, ["is_adult"]) household_reported_capital = household("household_uc_reported_capital", period) diff --git a/policyengine_uk/variables/input/non_residential_property_secured_debt.py b/policyengine_uk/variables/input/non_residential_property_secured_debt.py new file mode 100644 index 0000000000..3dc39a2996 --- /dev/null +++ b/policyengine_uk/variables/input/non_residential_property_secured_debt.py @@ -0,0 +1,17 @@ +from policyengine_uk.model_api import * + + +class non_residential_property_secured_debt(Variable): + label = "debt secured on non-residential property" + documentation = ( + "Amount owed on mortgages and other charges secured on non-residential " + "property the household owns. Means tests deduct it from that " + "property's value (UC Regs 2013 reg. 49(1)(b) and its legacy " + "equivalents)." + ) + entity = Household + definition_period = YEAR + value_type = float + unit = GBP + quantity_type = STOCK + uprating = "gov.economic_assumptions.indices.obr.per_capita.gdp" diff --git a/policyengine_uk/variables/input/other_residential_property_secured_debt.py b/policyengine_uk/variables/input/other_residential_property_secured_debt.py new file mode 100644 index 0000000000..50ec795c0d --- /dev/null +++ b/policyengine_uk/variables/input/other_residential_property_secured_debt.py @@ -0,0 +1,17 @@ +from policyengine_uk.model_api import * + + +class other_residential_property_secured_debt(Variable): + label = "debt secured on other residential property" + documentation = ( + "Amount owed on mortgages and other charges secured on residential " + "property the household owns other than the main residence, such as a " + "buy-to-let mortgage. Means tests deduct it from that property's value " + "(UC Regs 2013 reg. 49(1)(b) and its legacy equivalents)." + ) + entity = Household + definition_period = YEAR + value_type = float + unit = GBP + quantity_type = STOCK + uprating = "gov.economic_assumptions.indices.obr.per_capita.gdp" diff --git a/policyengine_uk/variables/input/owned_land_secured_debt.py b/policyengine_uk/variables/input/owned_land_secured_debt.py new file mode 100644 index 0000000000..b58b570051 --- /dev/null +++ b/policyengine_uk/variables/input/owned_land_secured_debt.py @@ -0,0 +1,16 @@ +from policyengine_uk.model_api import * + + +class owned_land_secured_debt(Variable): + label = "debt secured on owned land" + documentation = ( + "Amount owed on mortgages and other charges secured on land-only plots " + "the household owns. Means tests deduct it from that land's value (UC " + "Regs 2013 reg. 49(1)(b) and its legacy equivalents)." + ) + entity = Household + definition_period = YEAR + value_type = float + unit = GBP + quantity_type = STOCK + uprating = "gov.economic_assumptions.indices.obr.per_capita.gdp" From 0d315ed29e1e8365349fa3fa6d6b44d5adf97c1e Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 30 Sep 2026 22:07:34 -0400 Subject: [PATCH 02/48] Tighten citations and tests from the adversarial review - Each programme's sale-expense parameters now cite its GB and NI regulations, the guidance paragraph that orders the 10% before the encumbrance, and per-asset guidance with exact PDF page anchors (DMG ch 52 for ESA, HBGM Annex F for HB savings, H1656/H1665/H1673-H1675 for UC). - The source-list descriptions and changelog say plainly that corporate_wealth also holds unit trusts, ISAs, employee share options and, in datasets built before the pension split, non-DB pension wealth. - The helper and secured-debt docs say debts net within a source category. - The property-test oracle fixes the sale-expense assets and the 10% itself instead of reading the parameters, checks pension-age HB, and runs on larger populations. New hand-computed cases cover HB second homes and premises, per-source flooring between two encumbered sources, pension-age HB, and a monthly secured debt. Co-Authored-By: Claude Opus 5.5 --- changelog.d/uc-capital-sale-expenses.fixed.md | 2 +- .../income/capital/sale_expenses/rate.yaml | 12 ++- .../income/capital/sale_expenses/sources.yaml | 29 +++++-- .../income/capital/sale_expenses/rate.yaml | 15 +++- .../income/capital/sale_expenses/sources.yaml | 25 ++++-- .../capital/sale_expenses/rate.yaml | 17 +++- .../capital/sale_expenses/sources.yaml | 39 ++++++--- .../capital/sale_expenses/rate.yaml | 12 ++- .../capital/sale_expenses/sources.yaml | 25 ++++-- .../income/capital/sale_expenses/rate.yaml | 12 ++- .../income/capital/sale_expenses/sources.yaml | 31 ++++--- .../capital/sale_expenses/rate.yaml | 8 +- .../capital/sale_expenses/sources.yaml | 32 +++++--- .../family/esa_income/esa_income_capital.yaml | 4 +- .../income_support_capital.yaml | 4 +- .../family/jsa_income/jsa_income_capital.yaml | 4 +- .../baseline/gov/dwp/capital_valuation.yaml | 81 ++++++++++++++++++- .../test_capital_valuation_properties.py | 68 +++++++++++----- .../tests/test_stock_capital_periods.py | 10 ++- policyengine_uk/utils/capital_valuation.py | 29 ++++--- .../non_residential_property_secured_debt.py | 6 +- ...other_residential_property_secured_debt.py | 5 +- .../input/owned_land_secured_debt.py | 7 +- 23 files changed, 357 insertions(+), 120 deletions(-) diff --git a/changelog.d/uc-capital-sale-expenses.fixed.md b/changelog.d/uc-capital-sale-expenses.fixed.md index 34790cb3d8..6b926ace41 100644 --- a/changelog.d/uc-capital-sale-expenses.fixed.md +++ b/changelog.d/uc-capital-sale-expenses.fixed.md @@ -1 +1 @@ -Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses (land, property and shares; not cash savings) and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. Adds secured-debt inputs for other residential property, non-residential property and land. +Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and corporate_wealth, not to cash savings; corporate_wealth also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land. diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml index 468d182cb9..e360c3ff9a 100644 --- a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml @@ -1,8 +1,8 @@ description: > - Share of the current market or surrender value deducted from income-related ESA - capital where there would be expenses attributable to sale. The deduction - is a flat 10% whatever the actual costs, taken before any incumbrance - secured on the asset. + Share of the current market or surrender value deducted from income-related + ESA capital where there would be expenses attributable to sale. It is a flat + 10% whatever the actual costs, taken from the gross value before any + encumbrance secured on the asset is deducted. values: 2008-10-27: 0.1 metadata: @@ -12,3 +12,7 @@ metadata: reference: - title: Employment and Support Allowance Regulations 2008 reg. 113(a) href: https://www.legislation.gov.uk/uksi/2008/794/regulation/113 + - title: Employment and Support Allowance Regulations (Northern Ireland) 2008 reg. 113(a) + href: https://www.legislation.gov.uk/nisr/2008/280/regulation/113 + - title: Decision Makers' Guide chapter 52, para. 52624 + href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=116 diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml index b1946fe614..40f6f3fb9a 100644 --- a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml @@ -1,11 +1,18 @@ description: > Capital sources whose sale would incur expenses, so that income-related ESA - values them at 90% of market value. Land and property always have costs of - sale. Shares are sold through a broker, so `corporate_wealth` is listed; it - also holds unit trusts, which have no costs of sale, but the dataset does - not separate them. `savings` is not listed because a bank or building - society account is valued at its balance and withdrawing money is not a sale - (see the Universal Credit parameter of the same name for the guidance). + values them at 90% of market value. Costs of sale normally arise where an + agent, broker, auctioneer, solicitor or accountant is needed, and real + property always has them (DMG 52622), so `owned_land`, + `other_residential_property_value` and `non_residential_property_value` are + listed. `savings` is not listed: a bank or building society account is + valued at its balance, and the costs of withdrawing money are not costs of + sale (DMG 52620-52623 and 52685). `corporate_wealth` is listed because + shares are valued less 10% for the costs of selling them (DMG 52671). + It is a mixed variable, though: it also holds unit trusts, which have no + costs of sale (DMG 52681), stocks and shares ISAs and employee share + options, and datasets built before private pension wealth was split out also + fold non-defined-benefit pension wealth into it, which is not capital at + all. The deduction reaches all of these until the data separate them. Sources not counted as income-related ESA capital are ignored. metadata: label: Income-related ESA capital sources with sale expenses @@ -14,6 +21,16 @@ metadata: reference: - title: Employment and Support Allowance Regulations 2008 reg. 113(a) href: https://www.legislation.gov.uk/uksi/2008/794/regulation/113 + - title: Employment and Support Allowance Regulations (Northern Ireland) 2008 reg. 113(a) + href: https://www.legislation.gov.uk/nisr/2008/280/regulation/113 + - title: Decision Makers' Guide chapter 52, paras. 52620-52622 + href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=115 + - title: Decision Makers' Guide chapter 52, para. 52623 + href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=116 + - title: Decision Makers' Guide chapter 52, para. 52671 + href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=126 + - title: Decision Makers' Guide chapter 52, paras. 52681 and 52685 + href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=128 values: 2008-10-27: - owned_land diff --git a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml index ff2e4d5759..e67f83c653 100644 --- a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml @@ -1,8 +1,11 @@ description: > - Share of the current market or surrender value deducted from income-based JSA - capital where there would be expenses attributable to sale. The deduction - is a flat 10% whatever the actual costs, taken before any incumbrance - secured on the asset. + Share of the current market or surrender value deducted from income-based + JSA capital where there would be expenses attributable to sale. It is a flat + 10% whatever the actual costs, taken from the gross value before any + encumbrance secured on the asset is deducted. Before 1 October 2007 the same + deduction sat in reg. 111(a)(i) alongside a separate valuation for National + Savings Certificates; SI 2007/2618 substituted the regulation in its current + form. values: 1996-10-07: 0.1 metadata: @@ -12,3 +15,7 @@ metadata: reference: - title: Jobseeker's Allowance Regulations 1996 reg. 111(a) href: https://www.legislation.gov.uk/uksi/1996/207/regulation/111 + - title: Jobseeker's Allowance Regulations (Northern Ireland) 1996 reg. 111(a), as substituted by S.R. 2007/396 reg. 7(11) + href: https://www.legislation.gov.uk/nisr/2007/396/regulation/7 + - title: Decision Makers' Guide chapter 29, para. 29624 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=125 diff --git a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml index 1a64a5ee2c..538833841b 100644 --- a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml @@ -1,12 +1,19 @@ description: > Capital sources whose sale would incur expenses, so that income-based JSA - values them at 90% of market value. Land and property always have costs of - sale. Shares are sold through a broker, so `corporate_wealth` is listed; it - also holds unit trusts, which have no costs of sale, but the dataset does - not separate them. `savings` is not listed because a bank or building - society account is valued at its balance and withdrawing money is not a sale - (DMG 29620-29623, 29681 and 29685). Sources not counted as income-based JSA - capital are ignored. + values them at 90% of market value. Costs of sale normally arise where an + agent, broker, auctioneer, solicitor or accountant is needed, and real + property always has them (DMG 29622), so `owned_land`, + `other_residential_property_value` and `non_residential_property_value` are + listed. `savings` is not listed: a bank or building society account is + valued at its balance, and the costs of withdrawing money are not costs of + sale (DMG 29620-29623 and 29685). `corporate_wealth` is listed because + shares are valued less 10% for the costs of selling them (DMG 29671). It is + a mixed variable, though: it also holds unit trusts, which have no costs of + sale (DMG 29681), stocks and shares ISAs and employee share options, and + datasets built before private pension wealth was split out also fold non- + defined-benefit pension wealth into it, which is not capital at all. The + deduction reaches all of these until the data separate them. Sources not + counted as income-based JSA capital are ignored. metadata: label: Income-based JSA capital sources with sale expenses period: year @@ -14,8 +21,12 @@ metadata: reference: - title: Jobseeker's Allowance Regulations 1996 reg. 111(a) href: https://www.legislation.gov.uk/uksi/1996/207/regulation/111 + - title: Jobseeker's Allowance Regulations (Northern Ireland) 1996 reg. 111(a), as substituted by S.R. 2007/396 reg. 7(11) + href: https://www.legislation.gov.uk/nisr/2007/396/regulation/7 - title: Decision Makers' Guide chapter 29, paras. 29620-29623 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=124 + - title: Decision Makers' Guide chapter 29, para. 29671 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=137 - title: Decision Makers' Guide chapter 29, paras. 29681 and 29685 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=139 values: diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml index f496742f77..45b58092df 100644 --- a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml @@ -1,8 +1,11 @@ description: > Share of the current market or surrender value deducted from Housing Benefit - capital where there would be expenses attributable to sale. The deduction - is a flat 10% whatever the actual costs, taken before any encumbrance - secured on the asset. + capital where there would be expenses attributable to sale. It is a flat 10% + whatever the actual costs, taken from the gross value before any encumbrance + secured on the asset is deducted. Before 1 October 2007 the same deduction + sat in reg. 47(a)(i) (reg. 45(a)(i) at pension age) alongside a separate + valuation for National Savings Certificates; SI 2007/2618 substituted the + regulation in its current form. values: 2006-04-10: 0.1 metadata: @@ -14,3 +17,11 @@ metadata: href: https://www.legislation.gov.uk/uksi/2006/213/regulation/47 - title: The Housing Benefit (Persons who have attained the qualifying age for state pension credit) Regulations 2006 reg. 45(a) href: https://www.legislation.gov.uk/uksi/2006/214/regulation/45 + - title: The Housing Benefit Regulations (Northern Ireland) 2006 reg. 44(a) + href: https://www.legislation.gov.uk/nisr/2006/405/regulation/44 + - title: The Housing Benefit (Persons who have attained the qualifying age for state pension credit) Regulations (Northern Ireland) 2006 reg. 43(a) + href: https://www.legislation.gov.uk/nisr/2006/406/regulation/43 + - title: Housing Benefit Guidance Manual BW1, para. W1.430 + href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=36 + - title: MH v London Borough of Waltham Forest (HB) [2016] UKUT 161 (AAC), para. 43 + href: https://www.gov.uk/administrative-appeals-tribunal-decisions/mh-v-london-borough-of-waltham-forest-hb-2016-ukut-161-aac diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml index cb504ed3c4..ad9b7d587c 100644 --- a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml @@ -1,12 +1,19 @@ description: > Capital sources whose sale would incur expenses, so that Housing Benefit - values them at 90% of market value. Land and property always have costs of - sale. Shares are sold through a broker, so `corporate_wealth` is listed; it - also holds unit trusts, which have no costs of sale, but the dataset does - not separate them. `savings` is not listed because a bank or building - society account is valued at its balance and withdrawing money is not a sale - (HBGM W1.430, W1.530-W1.531, P1.430 and P1.530-P1.531). Sources not counted - as Housing Benefit capital are ignored. + values them at 90% of market value. Costs of sale normally arise where an + agent, broker, auctioneer, solicitor or accountant is needed, and real + property always has them (HBGM W1.430), so `owned_land`, + `other_residential_property_value` and `non_residential_property_value` are + listed. `savings` is not listed: a bank or building society account is + valued at its balance, and the costs of withdrawing money are not costs of + sale (HBGM BW1 Annex F and BP1 F2.03). `corporate_wealth` is listed because + shares are valued less 10% for the costs of selling them (HBGM W1.513). It + is a mixed variable, though: it also holds unit trusts, which have no costs + of sale (HBGM W1.530-W1.531), stocks and shares ISAs and employee share + options, and datasets built before private pension wealth was split out also + fold non-defined-benefit pension wealth into it, which is not capital at + all. The deduction reaches all of these until the data separate them. + Sources not counted as Housing Benefit capital are ignored. metadata: label: Housing Benefit capital sources with sale expenses period: year @@ -16,10 +23,24 @@ metadata: href: https://www.legislation.gov.uk/uksi/2006/213/regulation/47 - title: The Housing Benefit (Persons who have attained the qualifying age for state pension credit) Regulations 2006 reg. 45(a) href: https://www.legislation.gov.uk/uksi/2006/214/regulation/45 - - title: Housing Benefit Guidance Manual BW1, paras. W1.430 and W1.530-W1.531 + - title: The Housing Benefit Regulations (Northern Ireland) 2006 reg. 44(a) + href: https://www.legislation.gov.uk/nisr/2006/405/regulation/44 + - title: The Housing Benefit (Persons who have attained the qualifying age for state pension credit) Regulations (Northern Ireland) 2006 reg. 43(a) + href: https://www.legislation.gov.uk/nisr/2006/406/regulation/43 + - title: Housing Benefit Guidance Manual BW1, para. W1.430 href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=36 - - title: Housing Benefit Guidance Manual BP1, paras. P1.430 and P1.530-P1.531 + - title: Housing Benefit Guidance Manual BP1, para. P1.430 href: https://assets.publishing.service.gov.uk/media/5a7ec5d840f0b6230268b71f/hbgm-bp1-assessment-of-capital.pdf#page=31 + - title: Housing Benefit Guidance Manual BW1, para. W1.513 + href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=43 + - title: Housing Benefit Guidance Manual BW1, paras. W1.530-W1.531 + href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=43 + - title: Housing Benefit Guidance Manual BP1, paras. P1.513 and P1.530-P1.531 + href: https://assets.publishing.service.gov.uk/media/5a7ec5d840f0b6230268b71f/hbgm-bp1-assessment-of-capital.pdf#page=38 + - title: Housing Benefit Guidance Manual BW1, Annex F + href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=93 + - title: Housing Benefit Guidance Manual BP1, paras. F2.00-F2.03 + href: https://assets.publishing.service.gov.uk/media/5a7ec5d840f0b6230268b71f/hbgm-bp1-assessment-of-capital.pdf#page=83 values: 2006-04-10: - owned_land diff --git a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml index 7cb86fe853..dd572337df 100644 --- a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml @@ -1,8 +1,10 @@ description: > Share of the current market or surrender value deducted from Income Support - capital where there would be expenses attributable to sale. The deduction - is a flat 10% whatever the actual costs, taken before any incumbrance - secured on the asset. + capital where there would be expenses attributable to sale. It is a flat 10% + whatever the actual costs, taken from the gross value before any encumbrance + secured on the asset is deducted. Before 1 October 2007 the same deduction + sat in reg. 49(a)(i) alongside a separate valuation for National Savings + Certificates; SI 2007/2618 substituted the regulation in its current form. values: 2010-01-01: 0.1 metadata: @@ -12,3 +14,7 @@ metadata: reference: - title: Income Support (General) Regulations 1987 reg. 49(a) href: https://www.legislation.gov.uk/uksi/1987/1967/regulation/49 + - title: Income Support (General) Regulations (Northern Ireland) 1987 reg. 49(a), as substituted by S.R. 2007/396 reg. 4(10) + href: https://www.legislation.gov.uk/nisr/2007/396/regulation/4 + - title: Decision Makers' Guide chapter 29, para. 29624 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=125 diff --git a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml index 0af0f836b0..baa3504bda 100644 --- a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml @@ -1,12 +1,19 @@ description: > Capital sources whose sale would incur expenses, so that Income Support - values them at 90% of market value. Land and property always have costs of - sale. Shares are sold through a broker, so `corporate_wealth` is listed; it - also holds unit trusts, which have no costs of sale, but the dataset does - not separate them. `savings` is not listed because a bank or building - society account is valued at its balance and withdrawing money is not a sale - (DMG 29620-29623, 29681 and 29685). Sources not counted as Income Support - capital are ignored. + values them at 90% of market value. Costs of sale normally arise where an + agent, broker, auctioneer, solicitor or accountant is needed, and real + property always has them (DMG 29622), so `owned_land`, + `other_residential_property_value` and `non_residential_property_value` are + listed. `savings` is not listed: a bank or building society account is + valued at its balance, and the costs of withdrawing money are not costs of + sale (DMG 29620-29623 and 29685). `corporate_wealth` is listed because + shares are valued less 10% for the costs of selling them (DMG 29671). It is + a mixed variable, though: it also holds unit trusts, which have no costs of + sale (DMG 29681), stocks and shares ISAs and employee share options, and + datasets built before private pension wealth was split out also fold non- + defined-benefit pension wealth into it, which is not capital at all. The + deduction reaches all of these until the data separate them. Sources not + counted as Income Support capital are ignored. metadata: label: Income Support capital sources with sale expenses period: year @@ -14,8 +21,12 @@ metadata: reference: - title: Income Support (General) Regulations 1987 reg. 49(a) href: https://www.legislation.gov.uk/uksi/1987/1967/regulation/49 + - title: Income Support (General) Regulations (Northern Ireland) 1987 reg. 49(a), as substituted by S.R. 2007/396 reg. 4(10) + href: https://www.legislation.gov.uk/nisr/2007/396/regulation/4 - title: Decision Makers' Guide chapter 29, paras. 29620-29623 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=124 + - title: Decision Makers' Guide chapter 29, para. 29671 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=137 - title: Decision Makers' Guide chapter 29, paras. 29681 and 29685 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=139 values: diff --git a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml index b344e9dcf2..09c5550767 100644 --- a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml @@ -1,8 +1,10 @@ description: > Share of the current market or surrender value deducted from Pension Credit - capital where there would be expenses attributable to sale. The deduction - is a flat 10% whatever the actual costs, taken before any encumbrance - secured on the asset. + capital where there would be expenses attributable to sale. It is a flat 10% + whatever the actual costs, taken from the gross value before any encumbrance + secured on the asset is deducted. Before 1 October 2007 the same deduction + sat in reg. 19(a)(i) alongside a separate valuation for National Savings + Certificates; SI 2007/2618 substituted the regulation in its current form. values: 2003-10-06: 0.1 metadata: @@ -12,3 +14,7 @@ metadata: reference: - title: State Pension Credit Regulations 2002 reg. 19(a) href: https://www.legislation.gov.uk/uksi/2002/1792/regulation/19 + - title: State Pension Credit Regulations (Northern Ireland) 2003 reg. 19(a) + href: https://www.legislation.gov.uk/nisr/2003/28/regulation/19 + - title: Decision Makers' Guide chapter 84, paras. 84712-84716 + href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=99 diff --git a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml index da4dae9ae1..1dbbd6816f 100644 --- a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml @@ -1,12 +1,19 @@ description: > Capital sources whose sale would incur expenses, so that Pension Credit - values them at 90% of market value. Land and property always have costs of - sale. Shares are sold through a broker, so `corporate_wealth` is listed; it - also holds unit trusts, which have no costs of sale, but the dataset does - not separate them. `savings` is not listed because a bank or building - society account is valued at its balance and withdrawing money is not a sale - (DMG 84712-84716, 84731 and 84772). Sources not counted as Pension Credit - capital are ignored. + values them at 90% of market value. Costs of sale normally arise where an + agent, broker, auctioneer, solicitor or accountant is needed, and real + property always has them (DMG 84714), so `owned_land`, + `other_residential_property_value` and `non_residential_property_value` are + listed. `savings` is not listed: a bank or building society account is + valued at its balance, and the costs of withdrawing money are not costs of + sale (DMG 84712-84715 and 84731). `corporate_wealth` is listed because + shares are valued less 10% for the costs of selling them (DMG 84763). It is + a mixed variable, though: it also holds unit trusts, which have no costs of + sale (DMG 84772), stocks and shares ISAs and employee share options, and + datasets built before private pension wealth was split out also fold non- + defined-benefit pension wealth into it, which is not capital at all. The + deduction reaches all of these until the data separate them. Sources not + counted as Pension Credit capital are ignored. metadata: label: Pension Credit capital sources with sale expenses period: year @@ -14,10 +21,16 @@ metadata: reference: - title: State Pension Credit Regulations 2002 reg. 19(a) href: https://www.legislation.gov.uk/uksi/2002/1792/regulation/19 - - title: Decision Makers' Guide chapter 84, paras. 84712-84716 + - title: State Pension Credit Regulations (Northern Ireland) 2003 reg. 19(a) + href: https://www.legislation.gov.uk/nisr/2003/28/regulation/19 + - title: Decision Makers' Guide chapter 84, paras. 84712-84715 href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=99 - - title: Decision Makers' Guide chapter 84, paras. 84731 and 84772 + - title: Decision Makers' Guide chapter 84, para. 84731 href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=102 + - title: Decision Makers' Guide chapter 84, para. 84763 + href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=107 + - title: Decision Makers' Guide chapter 84, para. 84772 + href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=109 values: 2003-10-06: - owned_land diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml index 150561614f..fe3a72ab6b 100644 --- a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml @@ -1,8 +1,8 @@ description: > Share of the current market or surrender value deducted from Universal - Credit capital where there would be expenses attributable to sale. The - deduction is a flat 10% whatever the actual costs, taken before any - encumbrance secured on the asset. + Credit capital where there would be expenses attributable to sale. It is a + flat 10% whatever the actual costs, taken from the gross value before any + encumbrance secured on the asset is deducted. values: 2013-04-29: 0.1 metadata: @@ -12,5 +12,7 @@ metadata: reference: - title: The Universal Credit Regulations 2013 reg. 49(1)(a) href: https://www.legislation.gov.uk/uksi/2013/376/regulation/49 + - title: The Universal Credit Regulations (Northern Ireland) 2016 reg. 49(1)(a) + href: https://www.legislation.gov.uk/nisr/2016/216/regulation/49 - title: Advice for Decision Making chapter H1, paras. H1602-H1608 href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=44 diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml index 969e9ac619..fe25cbe7d8 100644 --- a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml @@ -1,17 +1,19 @@ description: > Capital sources whose sale would incur expenses, so that Universal Credit - values them at 90% of market value. Real property always has costs of sale - (ADM H1606, citing R(IS) 21/93), so `owned_land`, + values them at 90% of market value. Costs of sale normally arise where an + agent, broker, auctioneer, solicitor or accountant is needed, and real + property always has them (ADM H1606), so `owned_land`, `other_residential_property_value` and `non_residential_property_value` are - listed. `savings` is not listed: the 10% applies only where selling needs - an agent, broker, solicitor or accountant (ADM H1604-H1605), the costs of - withdrawing money from a building society are not costs of sale (H1607), - and an account is valued at its balance (H1675). `corporate_wealth` is - listed because quoted shares are valued less 10% for costs of sale (H1665). - It also holds unit trusts, which have no costs of sale (H1674), and stocks - and shares ISAs, which the guidance values at their withdrawal value - (H1656); the dataset does not separate these, so the deduction also - reaches them. Sources not counted as Universal Credit capital are ignored. + listed. `savings` is not listed: a bank or building society account is + valued at its balance, and the costs of withdrawing money are not costs of + sale (ADM H1604-H1607 and H1675). `corporate_wealth` is listed because + shares are valued less 10% for the costs of selling them (ADM H1665). It is + a mixed variable, though: it also holds unit trusts, which have no costs of + sale (ADM H1674), stocks and shares ISAs and employee share options, and + datasets built before private pension wealth was split out also fold non- + defined-benefit pension wealth into it, which is not capital at all. The + deduction reaches all of these until the data separate them. Sources not + counted as Universal Credit capital are ignored. metadata: label: Universal Credit capital sources with sale expenses period: year @@ -19,10 +21,16 @@ metadata: reference: - title: The Universal Credit Regulations 2013 reg. 49(1)(a) href: https://www.legislation.gov.uk/uksi/2013/376/regulation/49 + - title: The Universal Credit Regulations (Northern Ireland) 2016 reg. 49(1)(a) + href: https://www.legislation.gov.uk/nisr/2016/216/regulation/49 - title: Advice for Decision Making chapter H1, paras. H1604-H1607 href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=44 - - title: Advice for Decision Making chapter H1, paras. H1665 and H1673-H1675 + - title: Advice for Decision Making chapter H1, para. H1656 + href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=55 + - title: Advice for Decision Making chapter H1, para. H1665 href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=57 + - title: Advice for Decision Making chapter H1, paras. H1673-H1675 + href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=59 values: 2013-04-29: - owned_land diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/esa_income/esa_income_capital.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/esa_income/esa_income_capital.yaml index abe48a7b5d..106352bad5 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/esa_income/esa_income_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/esa_income/esa_income_capital.yaml @@ -212,6 +212,6 @@ corporate_wealth: 2_000 private_pension_wealth: 150_000 output: - # Savings at face value; land, shares and property less 10% for the - # expenses of sale (ESA Regs 2008 reg. 113(a)): 1,000 + 90% of 2,000. + # Savings at face value; shares less 10% for the expenses of sale + # (ESA Regs 2008 reg. 113(a)): 1,000 + 90% of 2,000. esa_income_assessable_capital: 2_800 diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/income_support/income_support_capital.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/income_support/income_support_capital.yaml index f90e5f1a9d..85f0ecfb12 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/income_support/income_support_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/income_support/income_support_capital.yaml @@ -235,6 +235,6 @@ corporate_wealth: 2000 private_pension_wealth: 150000 output: - # Savings at face value; land, shares and property less 10% for the - # expenses of sale (IS Regs 1987 reg. 49(a)): 1,000 + 90% of 2,000. + # Savings at face value; shares less 10% for the expenses of sale + # (IS Regs 1987 reg. 49(a)): 1,000 + 90% of 2,000. income_support_assessable_capital: 2800 diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/jsa_income/jsa_income_capital.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/jsa_income/jsa_income_capital.yaml index bc50925503..ffea263934 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/jsa_income/jsa_income_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/jsa_income/jsa_income_capital.yaml @@ -186,6 +186,6 @@ corporate_wealth: 2_000 private_pension_wealth: 150_000 output: - # Savings at face value; land, shares and property less 10% for the - # expenses of sale (JSA Regs 1996 reg. 111(a)): 1,000 + 90% of 2,000. + # Savings at face value; shares less 10% for the expenses of sale + # (JSA Regs 1996 reg. 111(a)): 1,000 + 90% of 2,000. jsa_income_assessable_capital: 2_800 diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml index 840b084ec1..1b4870b502 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -1,8 +1,9 @@ # Capital is valued at market value less 10% where a sale would incur # expenses, and less any encumbrance secured on it: UC Regs 2013 reg. 49(1); # HB Regs 2006 reg. 47; IS Regs 1987 reg. 49; JSA Regs 1996 reg. 111; ESA Regs -# 2008 reg. 113; SPC Regs 2002 reg. 19. Savings in a bank or building society -# have no sale expenses; land, property and shares do (ADM H1604-H1607). +# 2008 reg. 113; SPC Regs 2002 reg. 19. A bank or building society account is +# valued at its balance (ADM H1604-H1607, H1675); land and property always have +# costs of sale (H1606) and shares are valued less 10% (H1665). # Expected values are worked by hand from those provisions. - name: UC values a mortgaged holiday home as in ADM H1602 @@ -216,3 +217,79 @@ pension_credit_assessable_capital: 19_000 # 18 steps of 500 above 10,000 at 1 a week: 18 * 52. pension_credit_deemed_income: 936 + +- name: UC floors each encumbered source at nil on its own + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # The second home is in negative equity (90,000 - 150,000), so it is + # valued at nil; the business premises keep 90% of 10,000. Netting the + # debts across both would wrongly give nil. + other_residential_property_value: 100_000 + other_residential_property_secured_debt: 150_000 + non_residential_property_value: 10_000 + output: + uc_assessable_capital: 9_000 + +- name: Housing Benefit values mortgaged second homes and premises less sale expenses + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + in_social_housing: true + housing_benefit_reported: 1 + benunits: + benunit: + members: person + would_claim_uc: false + households: + household: + members: person + # 1,000 + (90% of 50,000 - 30,000) + max(0, 90% of 20,000 - 25,000) + # = 1,000 + 15,000 + 0 = 16,000, at the limit (HB Regs 2006 reg. 47). + savings: 1_000 + other_residential_property_value: 50_000 + other_residential_property_secured_debt: 30_000 + non_residential_property_value: 20_000 + non_residential_property_secured_debt: 25_000 + output: + housing_benefit_assessable_capital: 16_000 + # 40 steps of 250 above 6,000 at 1 a week: 40 * 52. + housing_benefit_tariff_income: 2_080 + housing_benefit_eligible: true + +- name: Pension-age Housing Benefit values encumbered land less sale expenses + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 70 + benunits: + benunit: + members: person + households: + household: + members: person + # 90% of 200,000 - 50,000 = 130,000 (HB (SPC) Regs 2006 reg. 45). Its + # Pension Credit deemed income, 240 steps of 500 above 10,000 at 1 a + # week (12,480 a year), exceeds the 12,376 guarantee, so there is no + # guarantee credit to disregard the capital. + owned_land: 200_000 + owned_land_secured_debt: 50_000 + output: + pension_credit_assessable_capital: 130_000 + pension_credit_deemed_income: 12_480 + guarantee_credit: 0 + housing_benefit_assessable_capital: 130_000 diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 76a7aa5d1d..3ccf6d7eb3 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -5,8 +5,9 @@ be expenses attributable to sale, and less any encumbrance secured on it (UC Regs 2013 reg. 49(1); HB Regs 2006 reg. 47; HB (SPC) Regs 2006 reg. 45; IS Regs 1987 reg. 49; JSA Regs 1996 reg. 111; ESA Regs 2008 reg. 113; SPC Regs -2002 reg. 19). Savings in a bank or building society incur no sale expenses; -land, property and shares do. +2002 reg. 19). A bank or building society account is valued at its balance +(ADM H1675); land and property always have costs of sale (H1606) and shares +are valued less 10% (H1665). Invariants, for any generated population of single-adult households: @@ -15,11 +16,15 @@ 2. Cash only: a household holding only savings has the same capital with the deduction on or off. 3. Differential: capital equals a direct implementation of the regulation, - savings + sum over sources of max(0, 90% of value - secured debt). + savings + sum over sources of max(0, 90% of value - secured debt), where + the test itself fixes which assets take the 10% (land, property and + shares, not cash), so a wrong parameter list fails it. 4. Monotone: a higher sale-expense rate, or more secured debt, never raises capital. -5. Isolation: debt secured on one asset never takes capital below the value - of the household's other assets, and capital is never negative. +5. Isolation: debt secured on one source never takes capital below the value + of the household's unencumbered sources, and capital is never negative. + (Isolation between two encumbered sources is pinned by the differential and + by a YAML case.) """ from functools import reduce @@ -38,9 +43,10 @@ suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large], ) # Assessable capital variable -> parameter node holding its sources and -# sale-expense rule. Pension Credit counts only pension-age adults; the -# others are tested on working-age adults (pension-age Housing Benefit -# disregards all capital for Guarantee Credit recipients). +# sale-expense rule. Pension Credit counts only pension-age adults; Housing +# Benefit is checked at both ages, disregarding all capital for pension-age +# Guarantee Credit recipients (HB (SPC) Regs 2006 reg. 26); the others are +# checked on working-age adults. PROGRAMMES = { "uc_assessable_capital": "gov.dwp.universal_credit.means_test.capital", "housing_benefit_assessable_capital": "gov.dwp.housing_benefit.means_test.capital", @@ -50,6 +56,16 @@ "pension_credit_assessable_capital": "gov.dwp.pension_credit.income.capital", } PENSION_AGE_ONLY = {"pension_credit_assessable_capital"} +# The assets whose sale incurs expenses, fixed here from the law rather than +# read from the parameters: real property always (ADM H1606), shares (H1665); +# never a bank or building society balance (H1675). +SALE_EXPENSE_ASSETS = { + "owned_land", + "other_residential_property_value", + "non_residential_property_value", + "corporate_wealth", +} +LEGAL_RATE = 0.1 ASSETS = [ "savings", "owned_land", @@ -99,14 +115,18 @@ def calculate(units, rate=None, debt_scale=1.0): situation=situation(units, debt_scale), reform=None if rate is None else rate_reform(rate), ) - return sim, {v: np.asarray(sim.calculate(v, YEAR), dtype=float) for v in PROGRAMMES} + values = {v: np.asarray(sim.calculate(v, YEAR), dtype=float) for v in PROGRAMMES} + values["guarantee_credit"] = np.asarray(sim.calculate("guarantee_credit", YEAR)) + return sim, values def parameter_node(sim, path): return reduce(getattr, path.split("."), sim.tax_benefit_system.parameters(YEAR)) -def applies(variable, unit): +def applies(variable, unit, guarantee_credit=0.0): + if variable == "housing_benefit_assessable_capital": + return unit["age"] < 67 or guarantee_credit <= 0 return (unit["age"] >= 67) == (variable in PENSION_AGE_ONLY) @@ -115,8 +135,8 @@ def expected_capital(unit, node): total = 0.0 for source in node.sources: value = unit["assets"][source] - if source in node.sale_expenses.sources: - value *= 1 - node.sale_expenses.rate + if source in SALE_EXPENSE_ASSETS: + value *= 1 - LEGAL_RATE if source in DEBTS: value = max(0.0, value - unit["debts"][DEBTS[source]]) total += value @@ -128,25 +148,31 @@ def close(a, b): @PROPERTY_SETTINGS -@given(st.lists(households(), min_size=1, max_size=30)) +@given(st.lists(households(), min_size=20, max_size=200)) def test_valuation_matches_the_regulation_and_never_adds_capital(units): sim, valued = calculate(units) _, full = calculate(units, rate=0.0, debt_scale=0.0) for variable, path in PROGRAMMES.items(): node = parameter_node(sim, path) - assert node.sale_expenses.rate == 0.1 + assert node.sale_expenses.rate == LEGAL_RATE assert "savings" in node.sources - assert "savings" not in node.sale_expenses.sources + counted = set(node.sources) + assert set(node.sale_expenses.sources) & counted == ( + SALE_EXPENSE_ASSETS & counted + ), variable for i, unit in enumerate(units): + gc = valued["guarantee_credit"][i] assert valued[variable][i] >= 0, (variable, unit) assert valued[variable][i] <= full[variable][i] + 0.01, (variable, unit) - if applies(variable, unit): + if variable == "housing_benefit_assessable_capital" and unit["age"] >= 67: + if gc > 0: + assert valued[variable][i] == 0, unit + if applies(variable, unit, gc): expected = expected_capital(unit, node) assert close(valued[variable][i], expected), (variable, unit) # Debt secured on property never reaches the other assets. floor = sum( - unit["assets"][s] - * (1 - node.sale_expenses.rate * (s in node.sale_expenses.sources)) + unit["assets"][s] * (1 - LEGAL_RATE * (s in SALE_EXPENSE_ASSETS)) for s in node.sources if s not in DEBTS ) @@ -154,20 +180,20 @@ def test_valuation_matches_the_regulation_and_never_adds_capital(units): @PROPERTY_SETTINGS -@given(st.lists(households(cash_only=True), min_size=1, max_size=30)) +@given(st.lists(households(cash_only=True), min_size=20, max_size=200)) def test_cash_only_households_have_no_deduction(units): _, valued = calculate(units) _, full = calculate(units, rate=0.0) for variable in PROGRAMMES: assert np.allclose(valued[variable], full[variable]), variable for i, unit in enumerate(units): - if applies(variable, unit): + if applies(variable, unit, valued["guarantee_credit"][i]): assert close(valued[variable][i], unit["assets"]["savings"]), variable @PROPERTY_SETTINGS @given( - st.lists(households(), min_size=1, max_size=30), + st.lists(households(), min_size=20, max_size=200), st.floats(0, 0.5), st.floats(0, 0.5), st.floats(0, 2), diff --git a/policyengine_uk/tests/test_stock_capital_periods.py b/policyengine_uk/tests/test_stock_capital_periods.py index e694045d13..eead7689d9 100644 --- a/policyengine_uk/tests/test_stock_capital_periods.py +++ b/policyengine_uk/tests/test_stock_capital_periods.py @@ -15,6 +15,7 @@ def test_uc_capital_stocks_are_not_prorated_in_monthly_calculations(): "members": ["person"], "savings": {"2026": 12_000}, "other_residential_property_value": {"2026": 12_000}, + "other_residential_property_secured_debt": {"2026": 5_000}, "corporate_wealth": {"2026": 12_000}, } }, @@ -23,9 +24,14 @@ def test_uc_capital_stocks_are_not_prorated_in_monthly_calculations(): assert simulation.calculate("savings", "2026-01")[0] == 12_000 assert simulation.calculate("corporate_wealth", "2026-01")[0] == 12_000 + assert ( + simulation.calculate("other_residential_property_secured_debt", "2026-01")[0] + == 5_000 + ) # Savings at face value; property and shares less 10% for the expenses - # of sale (UC Regs 2013 reg. 49(1)(a)): 12,000 + 2 * 10,800. - assert simulation.calculate("uc_assessable_capital", "2026-01")[0] == 33_600 + # of sale, and the property less its mortgage (UC Regs 2013 reg. 49(1)): + # 12,000 + (10,800 - 5,000) + 10,800. + assert simulation.calculate("uc_assessable_capital", "2026-01")[0] == 28_600 assert not simulation.calculate("is_uc_eligible", "2026-01")[0] diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index 2e70896a1a..8c76af629d 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -1,19 +1,22 @@ """Value means-tested capital as the capital-valuation regulations require. -Universal Credit and each legacy means test value capital in the United -Kingdom "at its current market or surrender value less (a) where there would -be expenses attributable to sale, 10% [...]; and (b) the amount of any -encumbrances secured on it" (UC Regs 2013 reg. 49(1) and its legacy -equivalents). Each programme sets its own rate and the capital sources whose -sale would incur expenses in a ``capital.sale_expenses`` parameter node. +Universal Credit calculates capital "at its current market value or surrender +value less— (a) where there would be expenses attributable to sale, 10%; and +(b) the amount of any encumbrances secured on it" (UC Regs 2013 reg. 49(1)). +The legacy means tests have equivalent rules (HB Regs 2006 reg. 47, IS Regs +1987 reg. 49, JSA Regs 1996 reg. 111, ESA Regs 2008 reg. 113, SPC Regs 2002 +reg. 19). Each programme sets its own rate and the capital sources whose sale +would incur expenses in a ``capital.sale_expenses`` parameter node. """ from policyengine_core.model_api import max_ -# Household inputs holding the debts secured on each capital source, such as -# a mortgage on a second property. The encumbrance is deducted only from the -# asset it is secured on, so negative equity in one asset never reduces the -# value of another (ADM H1615-H1616). +# Household inputs holding the debt secured on each capital source, such as a +# mortgage on a second property. The debt is deducted from the source it is +# secured on and that source is floored at nil, so negative equity in one +# source never reduces another (ADM H1615-H1616). Each source is a category +# summed over the household's assets, so within a category the debts on one +# asset still offset equity in another. SECURED_DEBT = { "other_residential_property_value": "other_residential_property_secured_debt", "non_residential_property_value": "non_residential_property_secured_debt", @@ -25,9 +28,9 @@ def valued_capital(value_of, sources, sale_expenses): """Sum ``sources`` at market value less sale expenses and secured debt. ``value_of(variable)`` returns that household variable on the entity the - caller is working with. The sale-expense deduction comes first and the - encumbrance second (ADM H1608), and an encumbered asset is never valued - below nil. + caller is working with. The sale-expense deduction is taken from the gross + value before the encumbrance (ADM H1608), and a source carrying secured + debt is never valued below nil. """ total = 0 for source in sources: diff --git a/policyengine_uk/variables/input/non_residential_property_secured_debt.py b/policyengine_uk/variables/input/non_residential_property_secured_debt.py index 3dc39a2996..f5da202655 100644 --- a/policyengine_uk/variables/input/non_residential_property_secured_debt.py +++ b/policyengine_uk/variables/input/non_residential_property_secured_debt.py @@ -6,8 +6,10 @@ class non_residential_property_secured_debt(Variable): documentation = ( "Amount owed on mortgages and other charges secured on non-residential " "property the household owns. Means tests deduct it from that " - "property's value (UC Regs 2013 reg. 49(1)(b) and its legacy " - "equivalents)." + "property's value after the 10% for sale expenses, flooring the " + "property at nil (UC Regs 2013 reg. 49(1)(b) and its legacy " + "equivalents). The value and the debt are household totals across all " + "such properties, so debt on one property offsets equity in another." ) entity = Household definition_period = YEAR diff --git a/policyengine_uk/variables/input/other_residential_property_secured_debt.py b/policyengine_uk/variables/input/other_residential_property_secured_debt.py index 50ec795c0d..340e8842fd 100644 --- a/policyengine_uk/variables/input/other_residential_property_secured_debt.py +++ b/policyengine_uk/variables/input/other_residential_property_secured_debt.py @@ -7,7 +7,10 @@ class other_residential_property_secured_debt(Variable): "Amount owed on mortgages and other charges secured on residential " "property the household owns other than the main residence, such as a " "buy-to-let mortgage. Means tests deduct it from that property's value " - "(UC Regs 2013 reg. 49(1)(b) and its legacy equivalents)." + "after the 10% for sale expenses, flooring the property at nil (UC Regs " + "2013 reg. 49(1)(b) and its legacy equivalents). The value and the debt " + "are household totals across all such properties, so debt on one " + "property offsets equity in another." ) entity = Household definition_period = YEAR diff --git a/policyengine_uk/variables/input/owned_land_secured_debt.py b/policyengine_uk/variables/input/owned_land_secured_debt.py index b58b570051..5f8380682c 100644 --- a/policyengine_uk/variables/input/owned_land_secured_debt.py +++ b/policyengine_uk/variables/input/owned_land_secured_debt.py @@ -5,8 +5,11 @@ class owned_land_secured_debt(Variable): label = "debt secured on owned land" documentation = ( "Amount owed on mortgages and other charges secured on land-only plots " - "the household owns. Means tests deduct it from that land's value (UC " - "Regs 2013 reg. 49(1)(b) and its legacy equivalents)." + "the household owns. Means tests deduct it from that land's value after " + "the 10% for sale expenses, flooring the land at nil (UC Regs 2013 reg. " + "49(1)(b) and its legacy equivalents). The value and the debt are " + "household totals across all plots, so debt on one plot offsets equity " + "in another." ) entity = Household definition_period = YEAR From e51391f3c4e756a289f2a5e02b89fee57698c26c Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 30 Sep 2026 22:18:21 -0400 Subject: [PATCH 03/48] Cite R(IS) 21/93 for real property in the HB sale-expense sources HBGM W1.430 states only the general 10% rule; the rule that real property always has costs of sale comes from R(IS) 21/93, as DMG 29622 applies it. Co-Authored-By: Claude Opus 5.5 --- .../means_test/capital/sale_expenses/sources.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml index ad9b7d587c..f57c9f5bd7 100644 --- a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml @@ -2,7 +2,8 @@ description: > Capital sources whose sale would incur expenses, so that Housing Benefit values them at 90% of market value. Costs of sale normally arise where an agent, broker, auctioneer, solicitor or accountant is needed, and real - property always has them (HBGM W1.430), so `owned_land`, + property always has them (R(IS) 21/93, as DMG 29622 applies it; HBGM W1.430 + states the general 10% rule), so `owned_land`, `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of @@ -31,6 +32,8 @@ metadata: href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=36 - title: Housing Benefit Guidance Manual BP1, para. P1.430 href: https://assets.publishing.service.gov.uk/media/5a7ec5d840f0b6230268b71f/hbgm-bp1-assessment-of-capital.pdf#page=31 + - title: Decision Makers' Guide chapter 29, para. 29622 (real property, R(IS) 21/93) + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=124 - title: Housing Benefit Guidance Manual BW1, para. W1.513 href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=43 - title: Housing Benefit Guidance Manual BW1, paras. W1.530-W1.531 From 22274cad14581256419fc2c445cb5b6a6df6d5ba Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 3 Oct 2026 22:05:05 -0400 Subject: [PATCH 04/48] Value capital under reg 19 in two Pension Credit tests from main Two tests main added after this branch's earlier base assumed full-value capital: - The CTR savings-credit-only case holds savings 10,000 and a 7,000 second property: capital is 10,000 + 90% of 7,000 = 16,300 (SPC Regs 2002 reg. 19(a)), still over the 16,000 limit, so CTR stays nil. Deemed income is 13 steps x 52 = 676, Pension Credit income 13,314 + 676 = 13,990, and savings credit 60% of (12,376 - 208.07 x 52) less 40% of (13,990 - 12,376) = 288.22. - The reported-capital property test's proxy oracle now values land, property and shares at 90% and savings at face value. Co-Authored-By: Claude Opus 5.5 --- .../council_tax_reduction_pension_credit.yaml | 10 +++++++--- ...t_pension_credit_reported_capital_properties.py | 14 ++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_pension_credit.yaml b/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_pension_credit.yaml index 6e52f66d3d..146a5a399e 100644 --- a/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_pension_credit.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_pension_credit.yaml @@ -466,12 +466,16 @@ savings: 10_000 other_residential_property_value: 7_000 output: - savings_credit: 267.42 + # Capital 10,000 + 90% of 7,000 = 16,300 (SPC Regs 2002 reg. 19(a)), so + # deemed income is 13 steps x 52 = 676 and Pension Credit income is + # 13,314 + 676 = 13,990. Savings credit: 60% of (12,376 - 208.07 x 52) + # = 933.82, less 40% of (13,990 - 12,376) = 645.60, leaves 288.22. + savings_credit: 288.22 in_receipt_of_savings_credit_only: true # Pension Credit counts the second property as capital; household # savings alone (10,000) are under the limit. Before: CTR 1,999.60. - pension_credit_assessable_capital: 17_000 - council_tax_reduction_assessable_capital: 17_000 + pension_credit_assessable_capital: 16_300 + council_tax_reduction_assessable_capital: 16_300 council_tax_reduction: 0 - name: The same pensioner not claiming Pension Credit is tested on household savings only diff --git a/policyengine_uk/tests/test_pension_credit_reported_capital_properties.py b/policyengine_uk/tests/test_pension_credit_reported_capital_properties.py index cf5fef6f30..d3a1a9b2ca 100644 --- a/policyengine_uk/tests/test_pension_credit_reported_capital_properties.py +++ b/policyengine_uk/tests/test_pension_credit_reported_capital_properties.py @@ -11,9 +11,11 @@ 1. Override identity: a pension-age unit with reported capital R >= 0 has assessable capital R, whatever the household holds. 2. Default differential: with nothing reported, assessable capital equals the - household proxy recomputed here from the inputs (household sources times - the unit's share of the household's pension-age adults, plus person-level - sources of the claimant or partner), the formula before this change. + household proxy recomputed here from the inputs (household sources, valued + under SPC Regs 2002 reg. 19 with savings at face value and the others at + 90%, times the unit's share of the household's pension-age adults, plus + person-level sources of the claimant or partner), the formula before this + change. 3. Locality: reporting capital for one unit never changes another unit's assessable capital. 4. Bounds: assessable capital is never negative, and is 0 for a unit with no @@ -102,7 +104,11 @@ def proxy(people, units, household, index): "non_residential_property_value", "corporate_wealth", ] - household_capital = sum(household.get(s, 0) for s in sources) + # SPC Regs 2002 reg. 19(a): sources whose sale would incur expenses (land, + # property, shares) are valued at 90%; savings at face value. + household_capital = sum( + household.get(s, 0) * (1 if s == "savings" else 0.9) for s in sources + ) sp_age = {name: p["age"] >= 66 for name, p in people.items()} unit = units[index]["members"] unit_sp = sum(sp_age[n] for n in unit) From b1a660045033bafd67a6f45ef8a5d7e17e798bbb Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 4 Oct 2026 06:57:09 -0400 Subject: [PATCH 05/48] Exempt unit trusts and stocks and shares ISAs from the sale-expense deduction corporate_wealth is now itemised in the capital sources lists (#1974), so the sale-expense lists name directly_held_shares, which DWP values less 10% for costs of sale (ADM H1665; DMG 29671/52671/84763; HBGM W1.513), and unitemised_corporate_wealth, which keeps the previous flat treatment on datasets that do not itemise. Unit trusts have no costs of sale even when sold through a broker (ADM H1673-H1674; DMG 29680-29681, 52680-52681, 84771-84772; HBGM W1.530-W1.531), and an ISA is valued at what the holder would get by withdrawing it, with no paragraph applying the 10% (ADM H1656-H1658; DMG 29662-29664, 52662, 84748-84750). The survey bucket of unit and investment trusts is treated as having no costs of sale; investment trusts were 8.2% and 6.9% of the pooled funds in stocks and shares ISAs at 5 April 2022 and 2025 (HMRC ISA Table 9.6). The property tests keep their own legal asset set and assert each programme's list against it, and gain the split invariants: the residual, backward compatibility with every component nil, conservation at a zero rate, split effect = rate x (trusts + ISA), and no double counting. #1974's itemising-invariance test no longer holds by design and is replaced by them. Co-Authored-By: Claude Opus 5.5 --- changelog.d/sale-expense-share-split.fixed.md | 1 + .../income/capital/sale_expenses/sources.yaml | 37 ++- .../income/capital/sale_expenses/sources.yaml | 36 ++- .../capital/sale_expenses/sources.yaml | 36 ++- .../capital/sale_expenses/sources.yaml | 36 ++- .../income/capital/sale_expenses/sources.yaml | 38 ++- .../capital/sale_expenses/sources.yaml | 34 ++- .../dwp/capital_valuation_share_split.yaml | 260 ++++++++++++++++ .../tests/test_capital_share_components.py | 34 +-- .../test_capital_valuation_properties.py | 287 +++++++++++++++--- .../tests/test_stock_capital_periods.py | 36 +++ 11 files changed, 710 insertions(+), 125 deletions(-) create mode 100644 changelog.d/sale-expense-share-split.fixed.md create mode 100644 policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml diff --git a/changelog.d/sale-expense-share-split.fixed.md b/changelog.d/sale-expense-share-split.fixed.md new file mode 100644 index 0000000000..1060d7977b --- /dev/null +++ b/changelog.d/sale-expense-share-split.fixed.md @@ -0,0 +1 @@ +- Apply the 10% sale-expense deduction to directly held shares only, so unit and investment trusts (ADM H1673-H1674) and stocks and shares ISAs (ADM H1656) count at full value in every means test; datasets that do not itemise `corporate_wealth` keep its previous treatment. diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml index 40f6f3fb9a..0f05cea7e0 100644 --- a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml @@ -6,14 +6,28 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (DMG 52620-52623 and 52685). `corporate_wealth` is listed because + sale (DMG 52620-52623 and 52685). `directly_held_shares` is listed because shares are valued less 10% for the costs of selling them (DMG 52671). - It is a mixed variable, though: it also holds unit trusts, which have no - costs of sale (DMG 52681), stocks and shares ISAs and employee share - options, and datasets built before private pension wealth was split out also - fold non-defined-benefit pension wealth into it, which is not capital at - all. The deduction reaches all of these until the data separate them. - Sources not counted as income-related ESA capital are ignored. + `unit_and_investment_trusts` is deliberately not listed: a unit trust is + valued at its bid price and has no costs of sale, because the person + withdraws from the manager, even if they use a stockbroker (DMG + 52680-52681). Investment trusts are not named in the guidance and, as listed + company shares, arguably take the 10%, but the Wealth and Assets Survey asks + about unit and investment trusts in one question, so the whole bucket is + treated as having no costs of sale. That approximation counts investment + trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts + at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April + 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed + either: an ISA is valued at what the person would get by withdrawing it, and + no ISA paragraph applies the 10% (DMG 52662-52664). + `unitemised_corporate_wealth` is listed so that datasets which do not + itemise `corporate_wealth` keep its previous flat treatment: there it equals + `corporate_wealth`, which mixes shares with unit trusts, stocks and shares + ISAs and employee share options, and, on datasets built before private + pension wealth was split out, non-defined-benefit pension wealth, which is + not capital at all. The deduction reaches all of these until the data + separate them. Sources not counted as income-related ESA capital are + ignored. metadata: label: Income-related ESA capital sources with sale expenses period: year @@ -27,13 +41,16 @@ metadata: href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=115 - title: Decision Makers' Guide chapter 52, para. 52623 href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=116 + - title: Decision Makers' Guide chapter 52, paras. 52662-52664 + href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=124 - title: Decision Makers' Guide chapter 52, para. 52671 href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=126 - - title: Decision Makers' Guide chapter 52, paras. 52681 and 52685 - href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=128 + - title: Decision Makers' Guide chapter 52, paras. 52680-52681 and 52685 + href: https://assets.publishing.service.gov.uk/media/69d8f30ad3e08b8871b665ac/dmg-Ch-52.pdf#page=127 values: 2008-10-27: - owned_land - other_residential_property_value - non_residential_property_value - - corporate_wealth + - directly_held_shares + - unitemised_corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml index 538833841b..db4d9e0322 100644 --- a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml @@ -6,14 +6,27 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (DMG 29620-29623 and 29685). `corporate_wealth` is listed because - shares are valued less 10% for the costs of selling them (DMG 29671). It is - a mixed variable, though: it also holds unit trusts, which have no costs of - sale (DMG 29681), stocks and shares ISAs and employee share options, and - datasets built before private pension wealth was split out also fold non- - defined-benefit pension wealth into it, which is not capital at all. The - deduction reaches all of these until the data separate them. Sources not - counted as income-based JSA capital are ignored. + sale (DMG 29620-29623 and 29685). `directly_held_shares` is listed because + shares are valued less 10% for the costs of selling them (DMG 29671). + `unit_and_investment_trusts` is deliberately not listed: a unit trust is + valued at its bid price and has no costs of sale, because the person + withdraws from the manager, even if they use a stockbroker (DMG + 29680-29681). Investment trusts are not named in the guidance and, as listed + company shares, arguably take the 10%, but the Wealth and Assets Survey asks + about unit and investment trusts in one question, so the whole bucket is + treated as having no costs of sale. That approximation counts investment + trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts + at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April + 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed + either: an ISA is valued at what the person would get by withdrawing it, and + no ISA paragraph applies the 10% (DMG 29662-29664). + `unitemised_corporate_wealth` is listed so that datasets which do not + itemise `corporate_wealth` keep its previous flat treatment: there it equals + `corporate_wealth`, which mixes shares with unit trusts, stocks and shares + ISAs and employee share options, and, on datasets built before private + pension wealth was split out, non-defined-benefit pension wealth, which is + not capital at all. The deduction reaches all of these until the data + separate them. Sources not counted as income-based JSA capital are ignored. metadata: label: Income-based JSA capital sources with sale expenses period: year @@ -25,13 +38,16 @@ metadata: href: https://www.legislation.gov.uk/nisr/2007/396/regulation/7 - title: Decision Makers' Guide chapter 29, paras. 29620-29623 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=124 + - title: Decision Makers' Guide chapter 29, paras. 29662-29664 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=135 - title: Decision Makers' Guide chapter 29, para. 29671 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=137 - - title: Decision Makers' Guide chapter 29, paras. 29681 and 29685 + - title: Decision Makers' Guide chapter 29, paras. 29680-29681 and 29685 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=139 values: 1996-10-07: - owned_land - other_residential_property_value - non_residential_property_value - - corporate_wealth + - directly_held_shares + - unitemised_corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml index f57c9f5bd7..84284223d9 100644 --- a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml @@ -7,14 +7,29 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (HBGM BW1 Annex F and BP1 F2.03). `corporate_wealth` is listed because - shares are valued less 10% for the costs of selling them (HBGM W1.513). It - is a mixed variable, though: it also holds unit trusts, which have no costs - of sale (HBGM W1.530-W1.531), stocks and shares ISAs and employee share - options, and datasets built before private pension wealth was split out also - fold non-defined-benefit pension wealth into it, which is not capital at - all. The deduction reaches all of these until the data separate them. - Sources not counted as Housing Benefit capital are ignored. + sale (HBGM BW1 Annex F and BP1 F2.03). `directly_held_shares` is listed + because shares are valued less 10% for selling costs (HBGM W1.513 and + P1.513). `unit_and_investment_trusts` is deliberately not listed: unit trust + holdings are valued at the bid price, which already takes account of the + selling expenses, and the 10% is not deducted even if they could be sold + through a bank or stockbroker (HBGM W1.530-W1.531 and P1.530-P1.531). + Investment trusts are not named in the guidance and, as listed company + shares, arguably take the 10%, but the Wealth and Assets Survey asks about + unit and investment trusts in one question, so the whole bucket is treated + as having no costs of sale. That approximation counts investment trusts at + full value; HMRC ISA statistics (table 9.6) put investment trusts at about 7% + to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April + 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed either: the HB + guidance manual has no ISA paragraph, and the DWP guidance on the parallel + Income Support and JSA rule values an ISA at what the person would get by + withdrawing it, with no ISA paragraph applying the 10% (DMG 29662-29664). + `unitemised_corporate_wealth` is listed so that datasets which do not + itemise `corporate_wealth` keep its previous flat treatment: there it equals + `corporate_wealth`, which mixes shares with unit trusts, stocks and shares + ISAs and employee share options, and, on datasets built before private + pension wealth was split out, non-defined-benefit pension wealth, which is + not capital at all. The deduction reaches all of these until the data + separate them. Sources not counted as Housing Benefit capital are ignored. metadata: label: Housing Benefit capital sources with sale expenses period: year @@ -40,6 +55,8 @@ metadata: href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=43 - title: Housing Benefit Guidance Manual BP1, paras. P1.513 and P1.530-P1.531 href: https://assets.publishing.service.gov.uk/media/5a7ec5d840f0b6230268b71f/hbgm-bp1-assessment-of-capital.pdf#page=38 + - title: Decision Makers' Guide chapter 29, paras. 29662-29664 (ISAs, parallel IS and JSA guidance) + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=135 - title: Housing Benefit Guidance Manual BW1, Annex F href: https://assets.publishing.service.gov.uk/media/5a749328ed915d0e8e3994c0/hbgm-bw1-assessment-of-capital.pdf#page=93 - title: Housing Benefit Guidance Manual BP1, paras. F2.00-F2.03 @@ -49,4 +66,5 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - corporate_wealth + - directly_held_shares + - unitemised_corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml index baa3504bda..06188a12fd 100644 --- a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml @@ -6,14 +6,27 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (DMG 29620-29623 and 29685). `corporate_wealth` is listed because - shares are valued less 10% for the costs of selling them (DMG 29671). It is - a mixed variable, though: it also holds unit trusts, which have no costs of - sale (DMG 29681), stocks and shares ISAs and employee share options, and - datasets built before private pension wealth was split out also fold non- - defined-benefit pension wealth into it, which is not capital at all. The - deduction reaches all of these until the data separate them. Sources not - counted as Income Support capital are ignored. + sale (DMG 29620-29623 and 29685). `directly_held_shares` is listed because + shares are valued less 10% for the costs of selling them (DMG 29671). + `unit_and_investment_trusts` is deliberately not listed: a unit trust is + valued at its bid price and has no costs of sale, because the person + withdraws from the manager, even if they use a stockbroker (DMG + 29680-29681). Investment trusts are not named in the guidance and, as listed + company shares, arguably take the 10%, but the Wealth and Assets Survey asks + about unit and investment trusts in one question, so the whole bucket is + treated as having no costs of sale. That approximation counts investment + trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts + at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April + 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed + either: an ISA is valued at what the person would get by withdrawing it, and + no ISA paragraph applies the 10% (DMG 29662-29664). + `unitemised_corporate_wealth` is listed so that datasets which do not + itemise `corporate_wealth` keep its previous flat treatment: there it equals + `corporate_wealth`, which mixes shares with unit trusts, stocks and shares + ISAs and employee share options, and, on datasets built before private + pension wealth was split out, non-defined-benefit pension wealth, which is + not capital at all. The deduction reaches all of these until the data + separate them. Sources not counted as Income Support capital are ignored. metadata: label: Income Support capital sources with sale expenses period: year @@ -25,13 +38,16 @@ metadata: href: https://www.legislation.gov.uk/nisr/2007/396/regulation/4 - title: Decision Makers' Guide chapter 29, paras. 29620-29623 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=124 + - title: Decision Makers' Guide chapter 29, paras. 29662-29664 + href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=135 - title: Decision Makers' Guide chapter 29, para. 29671 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=137 - - title: Decision Makers' Guide chapter 29, paras. 29681 and 29685 + - title: Decision Makers' Guide chapter 29, paras. 29680-29681 and 29685 href: https://assets.publishing.service.gov.uk/media/69d8f3a496c86b751317022c/dmg-Ch-29.pdf#page=139 values: 2010-01-01: - owned_land - other_residential_property_value - non_residential_property_value - - corporate_wealth + - directly_held_shares + - unitemised_corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml index 1dbbd6816f..dae92445b4 100644 --- a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml @@ -6,14 +6,27 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (DMG 84712-84715 and 84731). `corporate_wealth` is listed because - shares are valued less 10% for the costs of selling them (DMG 84763). It is - a mixed variable, though: it also holds unit trusts, which have no costs of - sale (DMG 84772), stocks and shares ISAs and employee share options, and - datasets built before private pension wealth was split out also fold non- - defined-benefit pension wealth into it, which is not capital at all. The - deduction reaches all of these until the data separate them. Sources not - counted as Pension Credit capital are ignored. + sale (DMG 84712-84715 and 84731). `directly_held_shares` is listed because + shares are valued less 10% for the costs of selling them (DMG 84763). + `unit_and_investment_trusts` is deliberately not listed: a unit trust is + valued at its bid price and has no costs of sale, because the person + withdraws from the manager, even if they use a stockbroker (DMG + 84771-84772). Investment trusts are not named in the guidance and, as listed + company shares, arguably take the 10%, but the Wealth and Assets Survey asks + about unit and investment trusts in one question, so the whole bucket is + treated as having no costs of sale. That approximation counts investment + trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts + at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April + 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed + either: an ISA is valued at what the person would get by withdrawing it, and + no ISA paragraph applies the 10% (DMG 84748-84750). + `unitemised_corporate_wealth` is listed so that datasets which do not + itemise `corporate_wealth` keep its previous flat treatment: there it equals + `corporate_wealth`, which mixes shares with unit trusts, stocks and shares + ISAs and employee share options, and, on datasets built before private + pension wealth was split out, non-defined-benefit pension wealth, which is + not capital at all. The deduction reaches all of these until the data + separate them. Sources not counted as Pension Credit capital are ignored. metadata: label: Pension Credit capital sources with sale expenses period: year @@ -27,13 +40,16 @@ metadata: href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=99 - title: Decision Makers' Guide chapter 84, para. 84731 href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=102 + - title: Decision Makers' Guide chapter 84, paras. 84748-84750 + href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=105 - title: Decision Makers' Guide chapter 84, para. 84763 href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=107 - - title: Decision Makers' Guide chapter 84, para. 84772 - href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=109 + - title: Decision Makers' Guide chapter 84, paras. 84771-84772 + href: https://assets.publishing.service.gov.uk/media/6a5e38bb8b7e4fa537e693d5/dmg-ch84.pdf#page=108 values: 2003-10-06: - owned_land - other_residential_property_value - non_residential_property_value - - corporate_wealth + - directly_held_shares + - unitemised_corporate_wealth diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml index fe25cbe7d8..f7a760beb9 100644 --- a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml @@ -6,14 +6,27 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (ADM H1604-H1607 and H1675). `corporate_wealth` is listed because - shares are valued less 10% for the costs of selling them (ADM H1665). It is - a mixed variable, though: it also holds unit trusts, which have no costs of - sale (ADM H1674), stocks and shares ISAs and employee share options, and - datasets built before private pension wealth was split out also fold non- - defined-benefit pension wealth into it, which is not capital at all. The - deduction reaches all of these until the data separate them. Sources not - counted as Universal Credit capital are ignored. + sale (ADM H1604-H1607 and H1675). `directly_held_shares` is listed because + shares are valued less 10% for the costs of selling them (ADM H1665). + `unit_and_investment_trusts` is deliberately not listed: a unit trust is + valued at its bid price and has no costs of sale, because the person + withdraws from the manager, even if they use a stockbroker (ADM + H1673-H1674). Investment trusts are not named in the guidance and, as listed + company shares, arguably take the 10%, but the Wealth and Assets Survey asks + about unit and investment trusts in one question, so the whole bucket is + treated as having no costs of sale. That approximation counts investment + trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts + at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April + 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed + either: an ISA is valued at what the person would get by withdrawing it, and + no ISA paragraph applies the 10% (ADM H1656-H1658). + `unitemised_corporate_wealth` is listed so that datasets which do not + itemise `corporate_wealth` keep its previous flat treatment: there it equals + `corporate_wealth`, which mixes shares with unit trusts, stocks and shares + ISAs and employee share options, and, on datasets built before private + pension wealth was split out, non-defined-benefit pension wealth, which is + not capital at all. The deduction reaches all of these until the data + separate them. Sources not counted as Universal Credit capital are ignored. metadata: label: Universal Credit capital sources with sale expenses period: year @@ -25,7 +38,7 @@ metadata: href: https://www.legislation.gov.uk/nisr/2016/216/regulation/49 - title: Advice for Decision Making chapter H1, paras. H1604-H1607 href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=44 - - title: Advice for Decision Making chapter H1, para. H1656 + - title: Advice for Decision Making chapter H1, paras. H1656-H1658 href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=55 - title: Advice for Decision Making chapter H1, para. H1665 href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=57 @@ -36,4 +49,5 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - corporate_wealth + - directly_held_shares + - unitemised_corporate_wealth diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml new file mode 100644 index 0000000000..d1c1a17514 --- /dev/null +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml @@ -0,0 +1,260 @@ +# corporate_wealth itemised into directly_held_shares, unit_and_investment_trusts +# and stocks_and_shares_isa, with unitemised_corporate_wealth carrying whatever +# is not itemised (max(0, corporate_wealth - the three components)). +# Capital is valued at market value less 10% where a sale would incur expenses +# (UC Regs 2013 reg. 49(1); HB Regs 2006 reg. 47; IS Regs 1987 reg. 49; JSA +# Regs 1996 reg. 111; ESA Regs 2008 reg. 113; SPC Regs 2002 reg. 19). Shares +# take the 10% (ADM H1665; DMG 29671, 52671, 84763; HBGM W1.513). Unit trusts +# have no costs of sale (ADM H1673-H1674; DMG 29680-29681, 52680-52681, +# 84771-84772; HBGM W1.530-W1.531), and the survey bucket of unit and +# investment trusts is treated the same. An ISA is valued at what the person +# would get by withdrawing it, with no 10% (ADM H1656; DMG 29662, 52662, +# 84748). Expected values are worked by hand from those rules. + +- name: UC unsplit corporate_wealth keeps the flat 10% treatment + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # No components, so the residual is all 12,000 of corporate_wealth: + # 5,000 + 90% of 12,000 = 15,800, the same as before the split. + savings: 5_000 + corporate_wealth: 12_000 + output: + unitemised_corporate_wealth: 12_000 + uc_assessable_capital: 15_800 + is_uc_eligible: true + # 9,800 above 6,000 is 40 steps of 250 (rounded up): 40 * 4.35 * 12. + uc_tariff_income: 2_088 + +- name: UC split of the same total exempts trusts and ISAs and crosses the limit + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # Residual max(0, 12,000 - (4,000 + 3,000 + 5,000)) = 0. Capital is + # 5,000 + 90% of 4,000 + 3,000 + 5,000 = 16,600, above the 16,000 + # limit; unsplit, the same household held 15,800 and qualified. + savings: 5_000 + corporate_wealth: 12_000 + directly_held_shares: 4_000 + unit_and_investment_trusts: 3_000 + stocks_and_shares_isa: 5_000 + output: + unitemised_corporate_wealth: 0 + uc_assessable_capital: 16_600 + is_uc_eligible: false + +- name: UC counts the components when corporate_wealth is not given + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # Residual max(0, 0 - 15,600) = 0. Capital is + # 1,000 + 90% of 10,000 + 2,600 + 3,000 = 15,600. + savings: 1_000 + directly_held_shares: 10_000 + unit_and_investment_trusts: 2_600 + stocks_and_shares_isa: 3_000 + output: + unitemised_corporate_wealth: 0 + uc_assessable_capital: 15_600 + is_uc_eligible: true + # 9,600 above 6,000 is 39 steps of 250 (38.4 rounded up): 39 * 4.35 * 12. + uc_tariff_income: 2_035.8 + +- name: UC partial split values the unitemised residual less 10% + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # Only the ISA is itemised: residual 12,000 - 5,000 = 7,000. Share-like + # capital is 90% of 7,000 + 5,000 = 11,300; with savings 15,300 + # (unsplit it would be 4,000 + 10,800 = 14,800). + savings: 4_000 + corporate_wealth: 12_000 + stocks_and_shares_isa: 5_000 + output: + unitemised_corporate_wealth: 7_000 + uc_assessable_capital: 15_300 + # 9,300 above 6,000 is 38 steps of 250 (37.2 rounded up): 38 * 4.35 * 12. + uc_tariff_income: 1_983.6 + +- name: UC components exceeding corporate_wealth leave a nil residual + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # The components (7,000) exceed corporate_wealth (5,000), so the + # residual is max(0, -2,000) = 0, not a negative offset. Capital is + # 1,000 + 90% of 4,000 + 3,000 = 7,600. + savings: 1_000 + corporate_wealth: 5_000 + directly_held_shares: 4_000 + unit_and_investment_trusts: 3_000 + output: + unitemised_corporate_wealth: 0 + uc_assessable_capital: 7_600 + # 1,600 above 6,000 is 7 steps of 250 (6.4 rounded up): 7 * 4.35 * 12. + uc_tariff_income: 365.4 + +- name: Housing Benefit split exempts trusts and ISAs + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + in_social_housing: true + housing_benefit_reported: 1 + benunits: + benunit: + members: person + would_claim_uc: false + households: + household: + members: person + # Residual 0. 1,100 + 90% of 5,000 + 4,000 + 6,000 = 15,600 (HBGM + # W1.513, W1.530); unsplit it would be 1,100 + 13,500 = 14,600. + savings: 1_100 + corporate_wealth: 15_000 + directly_held_shares: 5_000 + unit_and_investment_trusts: 4_000 + stocks_and_shares_isa: 6_000 + output: + unitemised_corporate_wealth: 0 + housing_benefit_assessable_capital: 15_600 + # 9,600 above 6,000 is 39 steps of 250 (38.4 rounded up) at 1 a week. + housing_benefit_tariff_income: 2_028 + housing_benefit_eligible: true + +- name: Income Support split exempts unit trusts + period: 2021 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # Residual 0. 90% of 6,000 + 4,000 = 9,400 (DMG 29671, 29681); + # unsplit it would be 9,000. + corporate_wealth: 10_000 + directly_held_shares: 6_000 + unit_and_investment_trusts: 4_000 + output: + income_support_assessable_capital: 9_400 + +- name: Income-based JSA split exempts stocks and shares ISAs + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # Residual 0. 2,000 + 90% of 3,000 + 6,000 = 10,700 (DMG 29662, + # 29671); unsplit it would be 2,000 + 8,100 = 10,100. + savings: 2_000 + corporate_wealth: 9_000 + directly_held_shares: 3_000 + stocks_and_shares_isa: 6_000 + output: + jsa_income_assessable_capital: 10_700 + +- name: Income-related ESA split exempts trusts and ISAs + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 40 + benunits: + benunit: + members: person + households: + household: + members: person + # Residual 0. 3,000 + 90% of 2,000 + 3,000 + 5,000 = 12,800 (DMG + # 52662, 52671, 52681); unsplit it would be 3,000 + 9,000 = 12,000. + savings: 3_000 + corporate_wealth: 10_000 + directly_held_shares: 2_000 + unit_and_investment_trusts: 3_000 + stocks_and_shares_isa: 5_000 + output: + esa_income_assessable_capital: 12_800 + +- name: Pension Credit split exempts trusts and ISAs + period: 2026 + absolute_error_margin: 0.01 + input: + people: + person: + age: 70 + benunits: + benunit: + members: person + households: + household: + members: person + # Residual 0. 2,100 + 90% of 10,000 + 8,000 + 12,000 = 31,100 (DMG + # 84748, 84763, 84772); unsplit it would be 2,100 + 27,000 = 29,100. + savings: 2_100 + corporate_wealth: 30_000 + directly_held_shares: 10_000 + unit_and_investment_trusts: 8_000 + stocks_and_shares_isa: 12_000 + output: + pension_credit_assessable_capital: 31_100 + # 21,100 above 10,000 is 43 steps of 500 (42.2 rounded up) at 1 a week. + pension_credit_deemed_income: 2_236 diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 8d4a5201ce..885d66333f 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -1,10 +1,10 @@ -"""Itemising corporate_wealth never changes a household's capital total. +"""The means-test capital sources itemise corporate_wealth. -The means-test capital sources list corporate_wealth's components and -unitemised_corporate_wealth (the part a dataset does not itemise) instead of -corporate_wealth. With no valuation rule that tells the components apart, every -programme's assessable capital must equal what it is when the same holdings are -entered as one unitemised corporate_wealth. +The lists name corporate_wealth's components and unitemised_corporate_wealth +(the part a dataset does not itemise) instead of corporate_wealth. Since the +sale-expense lists tell the components apart, itemising changes capital by +exactly rate x (trusts + ISA): that, conservation at a zero rate and the other +valuation invariants are in test_capital_valuation_properties.py. """ import pytest @@ -86,25 +86,3 @@ def test_unitemised_corporate_wealth_is_the_floored_remainder( "unitemised_corporate_wealth", YEAR )[0] assert residual == max(0, corporate_wealth - sum(components)) - - -@pytest.mark.parametrize("variable", SOURCE_LISTS) -@settings(max_examples=15, deadline=None) -@given( - savings=amount, - corporate_wealth=amount, - components=st.tuples(amount, amount, amount), -) -def test_itemising_never_changes_capital( - variable, savings, corporate_wealth, components -): - """Split holdings count exactly as max(corporate_wealth, their sum) does.""" - itemised = {"savings": savings, "corporate_wealth": corporate_wealth} - itemised.update(dict(zip(COMPONENTS, components))) - unitemised = { - "savings": savings, - "corporate_wealth": max(corporate_wealth, sum(components)), - } - assert _capital(variable, itemised) == pytest.approx( - _capital(variable, unitemised), abs=1e-2 - ) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 3ccf6d7eb3..4e77f884b9 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -7,9 +7,19 @@ Regs 1987 reg. 49; JSA Regs 1996 reg. 111; ESA Regs 2008 reg. 113; SPC Regs 2002 reg. 19). A bank or building society account is valued at its balance (ADM H1675); land and property always have costs of sale (H1606) and shares -are valued less 10% (H1665). +are valued less 10% (H1665). Unit trusts have no costs of sale (H1673-H1674) +and an ISA is valued at what the person would get by withdrawing it (H1656). -Invariants, for any generated population of single-adult households: +corporate_wealth may be itemised into directly_held_shares, +unit_and_investment_trusts and stocks_and_shares_isa; unitemised_corporate_wealth +carries whatever is not itemised, so it is all of corporate_wealth on datasets +without the components and about nil on datasets that build corporate_wealth as +their exact sum. The survey bucket of unit and investment trusts is treated as +having no costs of sale, an approximation for its investment-trust part. + +Invariants, for any generated population of single-adult households, whose +share-like holdings are unsplit, split consistently (corporate_wealth equal to +the components' sum), partly split, given as components only, or drawn freely: 1. Non-increasing: every programme's assessable capital is at most the same household's capital with the deduction switched off (rate 0, no debt). @@ -17,14 +27,27 @@ deduction on or off. 3. Differential: capital equals a direct implementation of the regulation, savings + sum over sources of max(0, 90% of value - secured debt), where - the test itself fixes which assets take the 10% (land, property and - shares, not cash), so a wrong parameter list fails it. + the test itself fixes which assets count and which take the 10% (land, + property, directly held shares and unitemised corporate wealth; not cash, + trusts or ISAs), so a wrong parameter list fails it. 4. Monotone: a higher sale-expense rate, or more secured debt, never raises capital. 5. Isolation: debt secured on one source never takes capital below the value of the household's unencumbered sources, and capital is never negative. (Isolation between two encumbered sources is pinned by the differential and by a YAML case.) +6. Residual: unitemised_corporate_wealth is never negative and equals + max(0, corporate_wealth - sum of components). +7. Backward compatibility: with every component nil, every programme's capital + is bit-for-bit the capital under a reform restoring the source lists used + before the split. +8. Conservation: at rate 0, a consistent split leaves capital unchanged. +9. Split effect: a consistent split less the unsplit household is rate x + (trusts + ISA), which lies in [0, rate x corporate_wealth]. +10. No double counting: capital is at most the other assets plus + max(corporate_wealth, sum of components). +11. Aggregates: total_wealth, net_wealth and corporate_sector_wealth do not + change with the component inputs. """ from functools import reduce @@ -33,7 +56,7 @@ from hypothesis import HealthCheck, given, settings from hypothesis import strategies as st -from policyengine_uk import Simulation +from policyengine_uk import CountryTaxBenefitSystem, Simulation YEAR = 2026 PROPERTY_SETTINGS = settings( @@ -56,45 +79,105 @@ "pension_credit_assessable_capital": "gov.dwp.pension_credit.income.capital", } PENSION_AGE_ONLY = {"pension_credit_assessable_capital"} +COMPONENTS = ( + "directly_held_shares", + "unit_and_investment_trusts", + "stocks_and_shares_isa", +) +RESIDUAL = "unitemised_corporate_wealth" +SHARE_LIKE = (*COMPONENTS, RESIDUAL) +PROPERTY = ("other_residential_property_value", "non_residential_property_value") +# The assets each programme counts, fixed here rather than read from the +# parameters. Universal Credit's list has never included owned_land; that +# predates the capital-valuation work and is outside these properties. +LEGACY_COUNTED = {"savings", "owned_land", *PROPERTY, *SHARE_LIKE} +COUNTED = { + variable: LEGACY_COUNTED + for variable in PROGRAMMES + if variable != "uc_assessable_capital" +} | {"uc_assessable_capital": {"savings", *PROPERTY, *SHARE_LIKE}} # The assets whose sale incurs expenses, fixed here from the law rather than -# read from the parameters: real property always (ADM H1606), shares (H1665); -# never a bank or building society balance (H1675). +# read from the parameters: real property always (ADM H1606) and shares +# (H1665); never a bank or building society balance (H1675), a unit trust +# (H1673-H1674) or an ISA (H1656). The unitemised residual keeps the flat +# treatment corporate_wealth had before it was itemised. SALE_EXPENSE_ASSETS = { "owned_land", - "other_residential_property_value", - "non_residential_property_value", - "corporate_wealth", + *PROPERTY, + "directly_held_shares", + RESIDUAL, } LEGAL_RATE = 0.1 -ASSETS = [ +# The source lists in force before corporate_wealth was itemised, for the +# backward-compatibility differential. +PRE_SPLIT_LEGACY_SOURCES = [ "savings", "owned_land", "corporate_wealth", - "other_residential_property_value", - "non_residential_property_value", + *PROPERTY, ] +PRE_SPLIT_SOURCES = { + "gov.dwp.universal_credit.means_test.capital": [ + "savings", + *PROPERTY, + "corporate_wealth", + ], + "gov.dwp.housing_benefit.means_test.capital": PRE_SPLIT_LEGACY_SOURCES, + "gov.dwp.income_support.means_test.capital": PRE_SPLIT_LEGACY_SOURCES, + "gov.dwp.JSA.income.capital": PRE_SPLIT_LEGACY_SOURCES, + "gov.dwp.ESA.income.capital": PRE_SPLIT_LEGACY_SOURCES, + "gov.dwp.pension_credit.income.capital": [ + "savings", + "owned_land", + *PROPERTY, + "corporate_wealth", + ], +} +PRE_SPLIT_SALE_EXPENSE_SOURCES = ["owned_land", *PROPERTY, "corporate_wealth"] +BASE_ASSETS = ["savings", "owned_land", "corporate_wealth", *PROPERTY] DEBTS = { "owned_land": "owned_land_secured_debt", "other_residential_property_value": "other_residential_property_secured_debt", "non_residential_property_value": "non_residential_property_secured_debt", } +SPLIT_MODES = ("unsplit", "consistent", "partial", "components_only", "free") amount = st.one_of(st.just(0.0), st.floats(0, 400_000, allow_nan=False)) @st.composite -def households(draw, cash_only=False): - assets = {asset: draw(amount) for asset in ASSETS} +def households(draw, mode=None, cash_only=False, dividends=False): + mode = mode or draw(st.sampled_from(SPLIT_MODES)) + assets = {asset: draw(amount) for asset in BASE_ASSETS} + components = {component: draw(amount) for component in COMPONENTS} + if mode == "unsplit": + components = {component: 0.0 for component in COMPONENTS} + elif mode == "consistent": + assets["corporate_wealth"] = sum(components.values()) + elif mode == "partial": + components = { + component: value if draw(st.booleans()) else 0.0 + for component, value in components.items() + } + assets["corporate_wealth"] = sum(components.values()) + draw(amount) + elif mode == "components_only": + assets["corporate_wealth"] = 0.0 + assets |= components debts = {debt: draw(amount) for debt in DEBTS.values()} if cash_only: - assets = {asset: 0.0 for asset in ASSETS} | {"savings": assets["savings"]} + assets = {asset: 0.0 for asset in assets} | {"savings": assets["savings"]} debts = {debt: 0.0 for debt in debts} - return dict(age=draw(st.sampled_from([30, 70])), assets=assets, debts=debts) + unit = dict(age=draw(st.sampled_from([30, 70])), assets=assets, debts=debts) + if dividends: + unit["dividend_income"] = draw(st.floats(0, 50_000, allow_nan=False)) + return unit -def situation(units, debt_scale=1.0): +def situation(units, debt_scale=1.0, dividends=True): people, benunits, homes = {}, {}, {} for i, unit in enumerate(units): people[f"p{i}"] = {"age": {YEAR: unit["age"]}} + if dividends and "dividend_income" in unit: + people[f"p{i}"]["dividend_income"] = {YEAR: unit["dividend_income"]} benunits[f"b{i}"] = {"members": [f"p{i}"]} homes[f"h{i}"] = { "members": [f"p{i}"], @@ -110,16 +193,46 @@ def rate_reform(rate): } -def calculate(units, rate=None, debt_scale=1.0): +PRE_SPLIT_REFORM = { + f"{node}.{parameter}": {str(YEAR): value} + for node, sources in PRE_SPLIT_SOURCES.items() + for parameter, value in ( + ("sources", sources), + ("sale_expenses.sources", PRE_SPLIT_SALE_EXPENSE_SOURCES), + ) +} +EXTRA_OUTPUTS = ( + "guarantee_credit", + RESIDUAL, + "uc_tariff_income", + "uc_unearned_income", + "pension_credit_deemed_income", + "total_wealth", + "net_wealth", + "corporate_sector_wealth", +) + + +def calculate(units, rate=None, debt_scale=1.0, reform=None, dividends=True): + if rate is not None: + reform = (reform or {}) | rate_reform(rate) sim = Simulation( - situation=situation(units, debt_scale), - reform=None if rate is None else rate_reform(rate), + situation=situation(units, debt_scale, dividends), + reform=reform, ) - values = {v: np.asarray(sim.calculate(v, YEAR), dtype=float) for v in PROGRAMMES} - values["guarantee_credit"] = np.asarray(sim.calculate("guarantee_credit", YEAR)) + values = { + v: np.asarray(sim.calculate(v, YEAR), dtype=float) + for v in (*PROGRAMMES, *EXTRA_OUTPUTS) + } return sim, values +def without_components(unit): + """The same household with corporate_wealth left unitemised.""" + assets = unit["assets"] | {component: 0.0 for component in COMPONENTS} + return unit | {"assets": assets} + + def parameter_node(sim, path): return reduce(getattr, path.split("."), sim.tax_benefit_system.parameters(YEAR)) @@ -130,21 +243,43 @@ def applies(variable, unit, guarantee_credit=0.0): return (unit["age"] >= 67) == (variable in PENSION_AGE_ONLY) -def expected_capital(unit, node): +def residual(unit): + assets = unit["assets"] + return max(0.0, assets["corporate_wealth"] - sum(assets[c] for c in COMPONENTS)) + + +def share_like_total(unit): + """max(corporate_wealth, sum of components): the share-like holdings once.""" + return sum(unit["assets"][c] for c in COMPONENTS) + residual(unit) + + +def expected_capital(unit, variable, rate=LEGAL_RATE): """Reg. 49(1) applied source by source, independently of the model.""" + values = unit["assets"] | {RESIDUAL: residual(unit)} total = 0.0 - for source in node.sources: - value = unit["assets"][source] + for source in COUNTED[variable]: + value = values[source] if source in SALE_EXPENSE_ASSETS: - value *= 1 - LEGAL_RATE + value *= 1 - rate if source in DEBTS: value = max(0.0, value - unit["debts"][DEBTS[source]]) total += value return total -def close(a, b): - return abs(a - b) <= 1 + 1e-6 * abs(b) +def close(a, b, scale=0.0): + """Equal up to float32 rounding of totals as large as ``b`` or ``scale``.""" + return abs(a - b) <= 1 + 1e-6 * max(abs(b), abs(scale)) + + +def test_source_lists_match_the_legal_asset_sets(): + parameters = CountryTaxBenefitSystem().parameters(YEAR) + for variable, path in PROGRAMMES.items(): + node = reduce(getattr, path.split("."), parameters) + assert set(node.sources) == COUNTED[variable], variable + assert set(node.sale_expenses.sources) == SALE_EXPENSE_ASSETS, variable + assert "corporate_wealth" not in node.sources, variable + assert node.sale_expenses.rate == LEGAL_RATE, variable @PROPERTY_SETTINGS @@ -155,11 +290,7 @@ def test_valuation_matches_the_regulation_and_never_adds_capital(units): for variable, path in PROGRAMMES.items(): node = parameter_node(sim, path) assert node.sale_expenses.rate == LEGAL_RATE - assert "savings" in node.sources - counted = set(node.sources) - assert set(node.sale_expenses.sources) & counted == ( - SALE_EXPENSE_ASSETS & counted - ), variable + assert set(node.sale_expenses.sources) == SALE_EXPENSE_ASSETS, variable for i, unit in enumerate(units): gc = valued["guarantee_credit"][i] assert valued[variable][i] >= 0, (variable, unit) @@ -168,15 +299,97 @@ def test_valuation_matches_the_regulation_and_never_adds_capital(units): if gc > 0: assert valued[variable][i] == 0, unit if applies(variable, unit, gc): - expected = expected_capital(unit, node) + expected = expected_capital(unit, variable) assert close(valued[variable][i], expected), (variable, unit) # Debt secured on property never reaches the other assets. + values = unit["assets"] | {RESIDUAL: residual(unit)} floor = sum( - unit["assets"][s] * (1 - LEGAL_RATE * (s in SALE_EXPENSE_ASSETS)) - for s in node.sources + values[s] * (1 - LEGAL_RATE * (s in SALE_EXPENSE_ASSETS)) + for s in COUNTED[variable] if s not in DEBTS ) assert valued[variable][i] >= floor - 1, (variable, unit) + # Each share-like holding is counted at most once. + other = sum( + unit["assets"][s] for s in COUNTED[variable] if s not in SHARE_LIKE + ) + ceiling = other + share_like_total(unit) + assert valued[variable][i] <= ceiling + 1 + 1e-6 * ceiling, ( + variable, + unit, + ) + + +@PROPERTY_SETTINGS +@given(st.lists(households(), min_size=20, max_size=200)) +def test_residual_is_corporate_wealth_less_its_components_floored_at_nil(units): + _, valued = calculate(units) + for i, unit in enumerate(units): + assert valued[RESIDUAL][i] >= 0, unit + assert close(valued[RESIDUAL][i], residual(unit)), unit + if all(unit["assets"][c] == 0 for c in COMPONENTS): + assert valued[RESIDUAL][i] == np.float32(unit["assets"]["corporate_wealth"]) + + +@PROPERTY_SETTINGS +@given(st.lists(households(mode="unsplit"), min_size=20, max_size=200)) +def test_unsplit_datasets_match_the_pre_split_source_lists_exactly(units): + _, split_lists = calculate(units) + _, pre_split = calculate(units, reform=PRE_SPLIT_REFORM) + for variable in ( + *PROGRAMMES, + "guarantee_credit", + "uc_tariff_income", + "uc_unearned_income", + "pension_credit_deemed_income", + ): + assert np.array_equal(split_lists[variable], pre_split[variable]), variable + + +@PROPERTY_SETTINGS +@given( + st.lists(households(mode="consistent"), min_size=20, max_size=200), + st.one_of(st.just(LEGAL_RATE), st.floats(0, 0.5)), +) +def test_a_consistent_split_moves_capital_only_by_the_exempt_holdings(units, rate): + unsplit_units = [without_components(unit) for unit in units] + _, split0 = calculate(units, rate=0.0) + _, unsplit0 = calculate(unsplit_units, rate=0.0) + _, split = calculate(units, rate=rate) + _, unsplit = calculate(unsplit_units, rate=rate) + for variable in PROGRAMMES: + for i, unit in enumerate(units): + if not ( + applies(variable, unit, split0["guarantee_credit"][i]) + and applies(variable, unit, unsplit0["guarantee_credit"][i]) + ): + continue + # At rate 0 itemising corporate_wealth conserves capital. + assert close(split0[variable][i], unsplit0[variable][i]), (variable, unit) + if not ( + applies(variable, unit, split["guarantee_credit"][i]) + and applies(variable, unit, unsplit["guarantee_credit"][i]) + ): + continue + exempt = ( + unit["assets"]["unit_and_investment_trusts"] + + unit["assets"]["stocks_and_shares_isa"] + ) + difference = split[variable][i] - unsplit[variable][i] + scale = max(split[variable][i], unsplit[variable][i]) + assert close(difference, rate * exempt, scale), (variable, unit, rate) + cap = rate * unit["assets"]["corporate_wealth"] + slack = 1 + 1e-6 * scale + assert -slack <= difference <= cap + slack, (variable, unit, rate) + + +@PROPERTY_SETTINGS +@given(st.lists(households(), min_size=20, max_size=200)) +def test_wealth_aggregates_ignore_the_components(units): + _, itemised = calculate(units) + _, unitemised = calculate([without_components(unit) for unit in units]) + for variable in ("total_wealth", "net_wealth", "corporate_sector_wealth"): + assert np.array_equal(itemised[variable], unitemised[variable]), variable @PROPERTY_SETTINGS diff --git a/policyengine_uk/tests/test_stock_capital_periods.py b/policyengine_uk/tests/test_stock_capital_periods.py index eead7689d9..fe6f440ddf 100644 --- a/policyengine_uk/tests/test_stock_capital_periods.py +++ b/policyengine_uk/tests/test_stock_capital_periods.py @@ -57,3 +57,39 @@ def test_pension_credit_capital_stocks_are_not_prorated_monthly(): simulation.calculate("pension_credit_assessable_capital", "2026-01")[0] == 33_600 ) + + +def test_itemised_share_like_stocks_are_not_prorated_monthly(): + stocks = { + "savings": 1_000, + "corporate_wealth": 12_000, + "directly_held_shares": 4_000, + "unit_and_investment_trusts": 3_000, + "stocks_and_shares_isa": 2_000, + } + for age, capital in ( + (30, "uc_assessable_capital"), + (70, "pension_credit_assessable_capital"), + ): + situation = { + "people": {"person": {"age": {"2026": age}}}, + "benunits": {"benunit": {"members": ["person"]}}, + "households": { + "household": { + "members": ["person"], + **{name: {"2026": value} for name, value in stocks.items()}, + } + }, + } + simulation = Simulation(situation=situation) + + for name, value in stocks.items(): + assert simulation.calculate(name, "2026-01")[0] == value, name + # 12,000 less the 9,000 itemised. + assert simulation.calculate("unitemised_corporate_wealth", "2026-01")[0] == ( + 3_000 + ) + # Shares and the unitemised residual less 10% for the expenses of + # sale; unit trusts and the ISA at their withdrawal value: + # 1,000 + 3,600 + 3,000 + 2,000 + 2,700. + assert simulation.calculate(capital, "2026-01")[0] == 12_300, capital From f3929c1918b4d75bd1e2d0306b6019f4ebaf3c59 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 11 Oct 2026 20:56:28 -0400 Subject: [PATCH 06/48] Value capital under reg 19 in the corporate_wealth CTR case from main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit £20,000 of shares is £18,000 of Pension Credit capital (SPC Regs 2002 reg. 19(a)), still over the CTR limit: deemed income 16 x 52 = 832, Pension Credit income 14,146, savings credit 933.816 - 0.4 x 1,770 = 225.82. Co-Authored-By: Claude Opus 5.5 --- .../council_tax_reduction_pension_credit.yaml | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_pension_credit.yaml b/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_pension_credit.yaml index e745af108f..5a29964d97 100644 --- a/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_pension_credit.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_pension_credit.yaml @@ -659,20 +659,21 @@ savings: 0 corporate_wealth: 20_000 output: - # (12,000 + 1,500 - 12,570) x 0.2 = 186. (20,000 - 10,000) / 500 = 20 - # steps of £1 a week; 20 x 52 = 1,040 of deemed income. - pension_credit_assessable_capital: 20_000 - pension_credit_deemed_income: 1_040 - # 13,500 - 186 + 1,040 = 14,354, above the minimum guarantee of 12,376. - pension_credit_income: 14_354 + # (12,000 + 1,500 - 12,570) x 0.2 = 186. Shares are valued at 90% for the + # expenses of sale (SPC Regs 2002 reg. 19(a)): 18,000. (18,000 - 10,000) / + # 500 = 16 steps of £1 a week; 16 x 52 = 832 of deemed income. + pension_credit_assessable_capital: 18_000 + pension_credit_deemed_income: 832 + # 13,500 - 186 + 832 = 14,146, above the minimum guarantee of 12,376. + pension_credit_income: 14_146 guarantee_credit: 0 - # 933.816 - 0.4 x (14,354 - 12,376) = 933.816 - 791.20 = 142.616. - savings_credit: 142.62 + # 933.816 - 0.4 x (14,146 - 12,376) = 933.816 - 708 = 225.816. + savings_credit: 225.82 in_receipt_of_savings_credit_only: true - # The Pension Credit capital is 20,000, over 16,000, with nil savings in + # The Pension Credit capital is 18,000, over 16,000, with nil savings in # the household. The same pensioner with 20,000 of private_pension_wealth # keeps CTR in the next case. - council_tax_reduction_assessable_capital: 20_000 + council_tax_reduction_assessable_capital: 18_000 council_tax_reduction: 0 - name: Savings credit only, private_pension_wealth is not Pension Credit capital, so it does not take the pensioner over the CTR capital limit From 54ed063b1bd93821dfb90373d12842c2918d1da9 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 12 Oct 2026 10:48:18 -0400 Subject: [PATCH 07/48] Skip passported families in the HB valuation property Main's Housing Benefit passport (#1927 and the Universal Credit limb) gives a family on a passporting benefit nil HB capital, so the property's independent reg 47 valuation applies only to non-passported families. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_capital_valuation_properties.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 3ccf6d7eb3..4bafb0c51d 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -117,6 +117,9 @@ def calculate(units, rate=None, debt_scale=1.0): ) values = {v: np.asarray(sim.calculate(v, YEAR), dtype=float) for v in PROGRAMMES} values["guarantee_credit"] = np.asarray(sim.calculate("guarantee_credit", YEAR)) + values["hb_passported"] = np.asarray( + sim.calculate("housing_benefit_on_passporting_benefit", YEAR) + ) return sim, values @@ -124,8 +127,12 @@ def parameter_node(sim, path): return reduce(getattr, path.split("."), sim.tax_benefit_system.parameters(YEAR)) -def applies(variable, unit, guarantee_credit=0.0): +def applies(variable, unit, guarantee_credit=0.0, hb_passported=False): if variable == "housing_benefit_assessable_capital": + # A family on a passporting benefit has nil HB capital + # (housing_benefit_on_passporting_benefit, on main since #1927). + if hb_passported: + return False return unit["age"] < 67 or guarantee_credit <= 0 return (unit["age"] >= 67) == (variable in PENSION_AGE_ONLY) @@ -167,7 +174,7 @@ def test_valuation_matches_the_regulation_and_never_adds_capital(units): if variable == "housing_benefit_assessable_capital" and unit["age"] >= 67: if gc > 0: assert valued[variable][i] == 0, unit - if applies(variable, unit, gc): + if applies(variable, unit, gc, valued["hb_passported"][i]): expected = expected_capital(unit, node) assert close(valued[variable][i], expected), (variable, unit) # Debt secured on property never reaches the other assets. @@ -187,7 +194,12 @@ def test_cash_only_households_have_no_deduction(units): for variable in PROGRAMMES: assert np.allclose(valued[variable], full[variable]), variable for i, unit in enumerate(units): - if applies(variable, unit, valued["guarantee_credit"][i]): + if applies( + variable, + unit, + valued["guarantee_credit"][i], + valued["hb_passported"][i], + ): assert close(valued[variable][i], unit["assets"]["savings"]), variable From b7e6bc5c54feeb35fe8bcf979943f491be64e627 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 12 Oct 2026 11:32:57 -0400 Subject: [PATCH 08/48] Split share-like capital by expenses of sale on #1974's block design #1974 replaced the components-plus-residual design with one share_like_capital block that keeps the supplied corporate_wealth exactly. This follow-up now splits that block in two: - share_like_capital_with_sale_expenses: share_like_capital less the itemised holdings in gov.dwp.share_like_capital.without_sale_expenses (unit and investment trusts, stocks and shares ISAs), floored at nil; all of it when nothing is itemised. - share_like_capital_without_sale_expenses: the rest, exactly nil when nothing is itemised. The six capital lists name both parts and the six sale-expense lists the first, so datasets that carry only corporate_wealth keep #1969's flat 10% exactly (differential test, annual and monthly, against the lists before itemising, including negative aggregates and a value whose 90% is a fraction of a penny over the limit). The exempt holdings are a parameter list, so the methodology call on investment trusts and ISAs (d1396) is a one-line change. Merged the refreshed #1969 (54ed063b1) and #1974 (7784193a). #1969's property oracle reads the share-like sources from an unitemised household's corporate_wealth; the split invariants (definition of both parts, the unitemised differential, split effect = 10% of trusts plus ISAs on UC capital, components-only valuation) are in test_capital_share_components. Dropping the nothing-itemised branch from the formula fails the differential. Co-Authored-By: Claude Opus 5.5 --- changelog.d/sale-expense-share-split.fixed.md | 2 +- docs/book/assumptions/growthfactors.md | 2 +- policyengine_uk/data/uprating_indices.yaml | 2 + .../income/capital/sale_expenses/sources.yaml | 34 +-- .../gov/dwp/ESA/income/capital/sources.yaml | 5 +- .../income/capital/sale_expenses/sources.yaml | 33 +-- .../gov/dwp/JSA/income/capital/sources.yaml | 5 +- .../capital/sale_expenses/sources.yaml | 36 +--- .../means_test/capital/sources.yaml | 5 +- .../capital/sale_expenses/sources.yaml | 33 +-- .../means_test/capital/sources.yaml | 5 +- .../income/capital/sale_expenses/sources.yaml | 33 +-- .../income/capital/sources.yaml | 3 +- .../without_sale_expenses.yaml | 29 +++ .../capital/sale_expenses/sources.yaml | 33 +-- .../means_test/capital/sources.yaml | 5 +- .../dwp/capital_valuation_share_split.yaml | 19 +- .../tests/test_capital_share_components.py | 197 ++++++++++-------- .../test_capital_valuation_properties.py | 29 ++- .../tests/test_stock_capital_periods.py | 13 +- .../share_like_capital_with_sale_expenses.py | 35 ++++ ...hare_like_capital_without_sale_expenses.py | 20 ++ 22 files changed, 320 insertions(+), 258 deletions(-) create mode 100644 policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml create mode 100644 policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py create mode 100644 policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py diff --git a/changelog.d/sale-expense-share-split.fixed.md b/changelog.d/sale-expense-share-split.fixed.md index 1060d7977b..014f38dd95 100644 --- a/changelog.d/sale-expense-share-split.fixed.md +++ b/changelog.d/sale-expense-share-split.fixed.md @@ -1 +1 @@ -- Apply the 10% sale-expense deduction to directly held shares only, so unit and investment trusts (ADM H1673-H1674) and stocks and shares ISAs (ADM H1656) count at full value in every means test; datasets that do not itemise `corporate_wealth` keep its previous treatment. +- Value share-like capital by asset type in every means test: directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction; unit trusts (ADM H1673-H1674) and stocks and shares ISAs (ADM H1656) count at full value, as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. diff --git a/docs/book/assumptions/growthfactors.md b/docs/book/assumptions/growthfactors.md index f58b658b7d..f75004a01f 100644 --- a/docs/book/assumptions/growthfactors.md +++ b/docs/book/assumptions/growthfactors.md @@ -62,7 +62,7 @@ We derive these rates from OBR GDP growth and ONS population projections. |-------------|------|------|------|------|------|------|------|------| | Growth rate | 9.2% | 5.0% | 3.8% | 2.8% | 2.8% | 3.1% | 3.3% | 3.3% | -We use per capita GDP for these variables: `benunit_reported_capital`, `capital_gains`, `capital_gains_badr`, `capital_gains_before_response`, `capital_gains_carried_interest`, `capital_gains_residential_property`, `cash_isa`, `corporate_wealth`, `dividend_income`, `gross_financial_wealth`, `household_lifetime_isa_balance`, `lifetime_isa_balance`, `lump_sum_income`, `main_residence_value`, `maintenance_income`, `miscellaneous_income`, `mortgage_capital_repayment`, `net_financial_wealth`, `non_residential_property_secured_debt`, `non_residential_property_value`, `other_investment_income`, `other_residential_property_secured_debt`, `other_residential_property_value`, `owned_land`, `owned_land_secured_debt`, `pension_credit_reported_capital`, `pension_income`, `private_pension_wealth`, `private_transfer_income`, `property_income`, `property_rental_income`, `savings`, `savings_interest_income`, `sublet_income`, `uc_reported_capital`, `unit_and_investment_trusts` +We use per capita GDP for these variables: `benunit_reported_capital`, `capital_gains`, `capital_gains_badr`, `capital_gains_before_response`, `capital_gains_carried_interest`, `capital_gains_residential_property`, `cash_isa`, `corporate_wealth`, `directly_held_shares`, `dividend_income`, `gross_financial_wealth`, `household_lifetime_isa_balance`, `lifetime_isa_balance`, `lump_sum_income`, `main_residence_value`, `maintenance_income`, `miscellaneous_income`, `mortgage_capital_repayment`, `net_financial_wealth`, `non_residential_property_secured_debt`, `non_residential_property_value`, `other_investment_income`, `other_residential_property_secured_debt`, `other_residential_property_value`, `owned_land`, `owned_land_secured_debt`, `pension_credit_reported_capital`, `pension_income`, `private_pension_wealth`, `private_transfer_income`, `property_income`, `property_rental_income`, `savings`, `savings_interest_income`, `stocks_and_shares_isa`, `sublet_income`, `uc_reported_capital`, `unit_and_investment_trusts` ## Council tax diff --git a/policyengine_uk/data/uprating_indices.yaml b/policyengine_uk/data/uprating_indices.yaml index c3eb624a68..699e3958f4 100644 --- a/policyengine_uk/data/uprating_indices.yaml +++ b/policyengine_uk/data/uprating_indices.yaml @@ -95,6 +95,7 @@ gov.economic_assumptions.yoy_growth.obr.per_capita.gdp: - benunit_reported_capital - cash_isa - corporate_wealth +- directly_held_shares - dividend_income - gross_financial_wealth - household_lifetime_isa_balance @@ -122,6 +123,7 @@ gov.economic_assumptions.yoy_growth.obr.per_capita.gdp: - property_rental_income - savings - savings_interest_income +- stocks_and_shares_isa - sublet_income # A formula of benunit_reported_capital; listed so a dataset that stores it # directly is uprated like the input. diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml index 0f05cea7e0..384cd7d7db 100644 --- a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml @@ -6,28 +6,15 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (DMG 52620-52623 and 52685). `directly_held_shares` is listed because - shares are valued less 10% for the costs of selling them (DMG 52671). - `unit_and_investment_trusts` is deliberately not listed: a unit trust is - valued at its bid price and has no costs of sale, because the person - withdraws from the manager, even if they use a stockbroker (DMG - 52680-52681). Investment trusts are not named in the guidance and, as listed - company shares, arguably take the 10%, but the Wealth and Assets Survey asks - about unit and investment trusts in one question, so the whole bucket is - treated as having no costs of sale. That approximation counts investment - trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts - at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April - 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed - either: an ISA is valued at what the person would get by withdrawing it, and - no ISA paragraph applies the 10% (DMG 52662-52664). - `unitemised_corporate_wealth` is listed so that datasets which do not - itemise `corporate_wealth` keep its previous flat treatment: there it equals - `corporate_wealth`, which mixes shares with unit trusts, stocks and shares - ISAs and employee share options, and, on datasets built before private - pension wealth was split out, non-defined-benefit pension wealth, which is - not capital at all. The deduction reaches all of these until the data - separate them. Sources not counted as income-related ESA capital are - ignored. + sale (DMG 52620-52623 and 52685). `share_like_capital_with_sale_expenses` is + listed: the part of share-like capital whose sale incurs expenses, namely + directly held shares, valued less 10% for selling costs (DMG 52671), and all + of `corporate_wealth` on datasets that do not itemise it. Unit and + investment trusts and stocks and shares ISAs are valued without the + deduction; `gov.dwp.share_like_capital.without_sale_expenses` lists them, + with the guidance and the approximation for investment trusts, which the + survey cannot separate from unit trusts. Sources not counted as + income-related ESA capital are ignored. metadata: label: Income-related ESA capital sources with sale expenses period: year @@ -52,5 +39,4 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - directly_held_shares - - unitemised_corporate_wealth + - share_like_capital_with_sale_expenses diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sources.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sources.yaml index a5de71cb3e..6f75bf1b1e 100644 --- a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sources.yaml @@ -6,7 +6,7 @@ description: > held directly, the share-like sources, `other_residential_property_value` for residential property other than the home, and `non_residential_property_value` for other land and premises. - `share_like_capital` is `corporate_wealth` as supplied, or the sum of its + `share_like_capital_with_sale_expenses` and `share_like_capital_without_sale_expenses` split `share_like_capital`, which is `corporate_wealth` as supplied, or the sum of its itemised components (`directly_held_shares`, `unit_and_investment_trusts`, `stocks_and_shares_isa`) where that is larger, so a household given only the components has them counted and no holding counts twice. @@ -37,6 +37,7 @@ values: 2008-10-27: - savings - owned_land - - share_like_capital + - share_like_capital_with_sale_expenses + - share_like_capital_without_sale_expenses - other_residential_property_value - non_residential_property_value diff --git a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml index db4d9e0322..78f4811cb3 100644 --- a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml @@ -6,27 +6,15 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (DMG 29620-29623 and 29685). `directly_held_shares` is listed because - shares are valued less 10% for the costs of selling them (DMG 29671). - `unit_and_investment_trusts` is deliberately not listed: a unit trust is - valued at its bid price and has no costs of sale, because the person - withdraws from the manager, even if they use a stockbroker (DMG - 29680-29681). Investment trusts are not named in the guidance and, as listed - company shares, arguably take the 10%, but the Wealth and Assets Survey asks - about unit and investment trusts in one question, so the whole bucket is - treated as having no costs of sale. That approximation counts investment - trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts - at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April - 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed - either: an ISA is valued at what the person would get by withdrawing it, and - no ISA paragraph applies the 10% (DMG 29662-29664). - `unitemised_corporate_wealth` is listed so that datasets which do not - itemise `corporate_wealth` keep its previous flat treatment: there it equals - `corporate_wealth`, which mixes shares with unit trusts, stocks and shares - ISAs and employee share options, and, on datasets built before private - pension wealth was split out, non-defined-benefit pension wealth, which is - not capital at all. The deduction reaches all of these until the data - separate them. Sources not counted as income-based JSA capital are ignored. + sale (DMG 29620-29623 and 29685). `share_like_capital_with_sale_expenses` is + listed: the part of share-like capital whose sale incurs expenses, namely + directly held shares, valued less 10% for selling costs (DMG 29671), and all + of `corporate_wealth` on datasets that do not itemise it. Unit and + investment trusts and stocks and shares ISAs are valued without the + deduction; `gov.dwp.share_like_capital.without_sale_expenses` lists them, + with the guidance and the approximation for investment trusts, which the + survey cannot separate from unit trusts. Sources not counted as income-based + JSA capital are ignored. metadata: label: Income-based JSA capital sources with sale expenses period: year @@ -49,5 +37,4 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - directly_held_shares - - unitemised_corporate_wealth + - share_like_capital_with_sale_expenses diff --git a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sources.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sources.yaml index 7c5262e767..0c0504f4b6 100644 --- a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sources.yaml @@ -6,7 +6,7 @@ description: > directly, the share-like sources, `other_residential_property_value` for residential property other than the home, and `non_residential_property_value` for other land and premises. - `share_like_capital` is `corporate_wealth` as supplied, or the sum of its + `share_like_capital_with_sale_expenses` and `share_like_capital_without_sale_expenses` split `share_like_capital`, which is `corporate_wealth` as supplied, or the sum of its itemised components (`directly_held_shares`, `unit_and_investment_trusts`, `stocks_and_shares_isa`) where that is larger, so a household given only the components has them counted and no holding counts twice. @@ -38,6 +38,7 @@ values: 1996-10-07: - savings - owned_land - - share_like_capital + - share_like_capital_with_sale_expenses + - share_like_capital_without_sale_expenses - other_residential_property_value - non_residential_property_value diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml index 84284223d9..3c48fff910 100644 --- a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml @@ -7,29 +7,16 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (HBGM BW1 Annex F and BP1 F2.03). `directly_held_shares` is listed - because shares are valued less 10% for selling costs (HBGM W1.513 and - P1.513). `unit_and_investment_trusts` is deliberately not listed: unit trust - holdings are valued at the bid price, which already takes account of the - selling expenses, and the 10% is not deducted even if they could be sold - through a bank or stockbroker (HBGM W1.530-W1.531 and P1.530-P1.531). - Investment trusts are not named in the guidance and, as listed company - shares, arguably take the 10%, but the Wealth and Assets Survey asks about - unit and investment trusts in one question, so the whole bucket is treated - as having no costs of sale. That approximation counts investment trusts at - full value; HMRC ISA statistics (table 9.6) put investment trusts at about 7% - to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April - 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed either: the HB - guidance manual has no ISA paragraph, and the DWP guidance on the parallel - Income Support and JSA rule values an ISA at what the person would get by - withdrawing it, with no ISA paragraph applying the 10% (DMG 29662-29664). - `unitemised_corporate_wealth` is listed so that datasets which do not - itemise `corporate_wealth` keep its previous flat treatment: there it equals - `corporate_wealth`, which mixes shares with unit trusts, stocks and shares - ISAs and employee share options, and, on datasets built before private - pension wealth was split out, non-defined-benefit pension wealth, which is - not capital at all. The deduction reaches all of these until the data - separate them. Sources not counted as Housing Benefit capital are ignored. + sale (HBGM BW1 Annex F and BP1 F2.03). + `share_like_capital_with_sale_expenses` is listed: the part of share-like + capital whose sale incurs expenses, namely directly held shares, valued less + 10% for selling costs (HBGM W1.513 and P1.513), and all of + `corporate_wealth` on datasets that do not itemise it. Unit and investment + trusts and stocks and shares ISAs are valued without the deduction; + `gov.dwp.share_like_capital.without_sale_expenses` lists them, with the + guidance and the approximation for investment trusts, which the survey + cannot separate from unit trusts. Sources not counted as Housing Benefit + capital are ignored. metadata: label: Housing Benefit capital sources with sale expenses period: year @@ -66,5 +53,4 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - directly_held_shares - - unitemised_corporate_wealth + - share_like_capital_with_sale_expenses diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sources.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sources.yaml index dbf6a86c0b..b7178bf360 100644 --- a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sources.yaml @@ -5,7 +5,7 @@ description: > are `savings` for liquid capital, `owned_land` for land held directly, the share-like sources, `other_residential_property_value` for residential property other than the home, and `non_residential_property_value` for other - land and premises. `share_like_capital` is `corporate_wealth` as supplied, + land and premises. `share_like_capital_with_sale_expenses` and `share_like_capital_without_sale_expenses` split `share_like_capital`, which is `corporate_wealth` as supplied, or the sum of its itemised components (`directly_held_shares`, `unit_and_investment_trusts`, `stocks_and_shares_isa`) where that is larger, so a household given only the components has them counted and no holding @@ -45,6 +45,7 @@ values: 2006-04-10: - savings - owned_land - - share_like_capital + - share_like_capital_with_sale_expenses + - share_like_capital_without_sale_expenses - other_residential_property_value - non_residential_property_value diff --git a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml index 06188a12fd..ef18e218f9 100644 --- a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml @@ -6,27 +6,15 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (DMG 29620-29623 and 29685). `directly_held_shares` is listed because - shares are valued less 10% for the costs of selling them (DMG 29671). - `unit_and_investment_trusts` is deliberately not listed: a unit trust is - valued at its bid price and has no costs of sale, because the person - withdraws from the manager, even if they use a stockbroker (DMG - 29680-29681). Investment trusts are not named in the guidance and, as listed - company shares, arguably take the 10%, but the Wealth and Assets Survey asks - about unit and investment trusts in one question, so the whole bucket is - treated as having no costs of sale. That approximation counts investment - trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts - at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April - 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed - either: an ISA is valued at what the person would get by withdrawing it, and - no ISA paragraph applies the 10% (DMG 29662-29664). - `unitemised_corporate_wealth` is listed so that datasets which do not - itemise `corporate_wealth` keep its previous flat treatment: there it equals - `corporate_wealth`, which mixes shares with unit trusts, stocks and shares - ISAs and employee share options, and, on datasets built before private - pension wealth was split out, non-defined-benefit pension wealth, which is - not capital at all. The deduction reaches all of these until the data - separate them. Sources not counted as Income Support capital are ignored. + sale (DMG 29620-29623 and 29685). `share_like_capital_with_sale_expenses` is + listed: the part of share-like capital whose sale incurs expenses, namely + directly held shares, valued less 10% for selling costs (DMG 29671), and all + of `corporate_wealth` on datasets that do not itemise it. Unit and + investment trusts and stocks and shares ISAs are valued without the + deduction; `gov.dwp.share_like_capital.without_sale_expenses` lists them, + with the guidance and the approximation for investment trusts, which the + survey cannot separate from unit trusts. Sources not counted as Income + Support capital are ignored. metadata: label: Income Support capital sources with sale expenses period: year @@ -49,5 +37,4 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - directly_held_shares - - unitemised_corporate_wealth + - share_like_capital_with_sale_expenses diff --git a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sources.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sources.yaml index 971341aa06..e5e83161db 100644 --- a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sources.yaml @@ -3,7 +3,7 @@ description: > `private_pension_wealth` is excluded because Schedule 10 paragraphs 23 and 23A disregard the value of the right to receive an occupational or personal pension and the value of funds held under a personal pension scheme. - `share_like_capital` is `corporate_wealth` as supplied, or the sum of its + `share_like_capital_with_sale_expenses` and `share_like_capital_without_sale_expenses` split `share_like_capital`, which is `corporate_wealth` as supplied, or the sum of its itemised components (`directly_held_shares`, `unit_and_investment_trusts`, `stocks_and_shares_isa`) where that is larger, so a household given only the components has them counted and no holding counts twice. @@ -26,6 +26,7 @@ values: 2010-01-01: - savings - owned_land - - share_like_capital + - share_like_capital_with_sale_expenses + - share_like_capital_without_sale_expenses - other_residential_property_value - non_residential_property_value diff --git a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml index dae92445b4..dd312c18b8 100644 --- a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml @@ -6,27 +6,15 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (DMG 84712-84715 and 84731). `directly_held_shares` is listed because - shares are valued less 10% for the costs of selling them (DMG 84763). - `unit_and_investment_trusts` is deliberately not listed: a unit trust is - valued at its bid price and has no costs of sale, because the person - withdraws from the manager, even if they use a stockbroker (DMG - 84771-84772). Investment trusts are not named in the guidance and, as listed - company shares, arguably take the 10%, but the Wealth and Assets Survey asks - about unit and investment trusts in one question, so the whole bucket is - treated as having no costs of sale. That approximation counts investment - trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts - at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April - 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed - either: an ISA is valued at what the person would get by withdrawing it, and - no ISA paragraph applies the 10% (DMG 84748-84750). - `unitemised_corporate_wealth` is listed so that datasets which do not - itemise `corporate_wealth` keep its previous flat treatment: there it equals - `corporate_wealth`, which mixes shares with unit trusts, stocks and shares - ISAs and employee share options, and, on datasets built before private - pension wealth was split out, non-defined-benefit pension wealth, which is - not capital at all. The deduction reaches all of these until the data - separate them. Sources not counted as Pension Credit capital are ignored. + sale (DMG 84712-84715 and 84731). `share_like_capital_with_sale_expenses` is + listed: the part of share-like capital whose sale incurs expenses, namely + directly held shares, valued less 10% for selling costs (DMG 84763), and all + of `corporate_wealth` on datasets that do not itemise it. Unit and + investment trusts and stocks and shares ISAs are valued without the + deduction; `gov.dwp.share_like_capital.without_sale_expenses` lists them, + with the guidance and the approximation for investment trusts, which the + survey cannot separate from unit trusts. Sources not counted as Pension + Credit capital are ignored. metadata: label: Pension Credit capital sources with sale expenses period: year @@ -51,5 +39,4 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - directly_held_shares - - unitemised_corporate_wealth + - share_like_capital_with_sale_expenses diff --git a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sources.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sources.yaml index b567570949..9e80b09f52 100644 --- a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sources.yaml @@ -29,4 +29,5 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - share_like_capital + - share_like_capital_with_sale_expenses + - share_like_capital_without_sale_expenses diff --git a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml new file mode 100644 index 0000000000..086d7d849c --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml @@ -0,0 +1,29 @@ +description: > + Itemised share-like holdings valued for every means test without the + deduction for expenses of sale. Unit trusts are valued at the bid price, + which the manager pays on withdrawal, with no costs of sale even when sold + through a broker (ADM H1673-H1674; DMG 29680-29681, 52680-52681, + 84771-84772; HBGM W1.530-W1.531). The Wealth and Assets Survey asks about + unit and investment trusts in one question, so the whole bucket is listed; + investment trusts are quoted shares, which take the deduction (ADM H1665), + and were 8.2% of the pooled funds held in stocks and shares ISAs at 5 April + 2022 and 6.9% at 5 April 2025 (HMRC ISA Table 9.6). An ISA is valued at + what the holder would get by withdrawing it, and no ISA paragraph applies + the deduction (ADM H1656-H1658; DMG 29662-29664, 52662, 84748-84750). + Everything else in share_like_capital takes the deduction: directly held + shares, and on datasets that do not itemise it, all of corporate_wealth. +metadata: + label: Share-like holdings without expenses of sale + period: year + unit: list + reference: + - title: Advice for Decision Making chapter H1, paras. H1656-H1658 + href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=55 + - title: Advice for Decision Making chapter H1, paras. H1673-H1674 + href: https://assets.publishing.service.gov.uk/media/6a5e0ac7a2662d4563fe39e0/adm-ch-h1.pdf#page=59 + - title: HMRC Annual savings statistics 2026, ISA Table 9.6 + href: https://www.gov.uk/government/statistics/annual-savings-statistics-2026 +values: + 2013-04-29: + - unit_and_investment_trusts + - stocks_and_shares_isa diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml index f7a760beb9..0194852eb6 100644 --- a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml @@ -6,27 +6,15 @@ description: > `other_residential_property_value` and `non_residential_property_value` are listed. `savings` is not listed: a bank or building society account is valued at its balance, and the costs of withdrawing money are not costs of - sale (ADM H1604-H1607 and H1675). `directly_held_shares` is listed because - shares are valued less 10% for the costs of selling them (ADM H1665). - `unit_and_investment_trusts` is deliberately not listed: a unit trust is - valued at its bid price and has no costs of sale, because the person - withdraws from the manager, even if they use a stockbroker (ADM - H1673-H1674). Investment trusts are not named in the guidance and, as listed - company shares, arguably take the 10%, but the Wealth and Assets Survey asks - about unit and investment trusts in one question, so the whole bucket is - treated as having no costs of sale. That approximation counts investment - trusts at full value; HMRC ISA statistics (table 9.6) put investment trusts - at about 7% to 8% of the pooled funds held in stocks and shares ISAs (8.2% at 5 April - 2022, 6.9% at 5 April 2025). `stocks_and_shares_isa` is deliberately not listed - either: an ISA is valued at what the person would get by withdrawing it, and - no ISA paragraph applies the 10% (ADM H1656-H1658). - `unitemised_corporate_wealth` is listed so that datasets which do not - itemise `corporate_wealth` keep its previous flat treatment: there it equals - `corporate_wealth`, which mixes shares with unit trusts, stocks and shares - ISAs and employee share options, and, on datasets built before private - pension wealth was split out, non-defined-benefit pension wealth, which is - not capital at all. The deduction reaches all of these until the data - separate them. Sources not counted as Universal Credit capital are ignored. + sale (ADM H1604-H1607 and H1675). `share_like_capital_with_sale_expenses` is + listed: the part of share-like capital whose sale incurs expenses, namely + directly held shares, valued less 10% for selling costs (ADM H1665), and all + of `corporate_wealth` on datasets that do not itemise it. Unit and + investment trusts and stocks and shares ISAs are valued without the + deduction; `gov.dwp.share_like_capital.without_sale_expenses` lists them, + with the guidance and the approximation for investment trusts, which the + survey cannot separate from unit trusts. Sources not counted as Universal + Credit capital are ignored. metadata: label: Universal Credit capital sources with sale expenses period: year @@ -49,5 +37,4 @@ values: - owned_land - other_residential_property_value - non_residential_property_value - - directly_held_shares - - unitemised_corporate_wealth + - share_like_capital_with_sale_expenses diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sources.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sources.yaml index c4615ccf9c..d982144dba 100644 --- a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sources.yaml @@ -5,7 +5,7 @@ description: > current mappings are `savings` for liquid capital, `other_residential_property_value` for residential property other than the home, `non_residential_property_value` for other land and premises, and the - share-like sources. `share_like_capital` is `corporate_wealth` as supplied, + share-like sources. `share_like_capital_with_sale_expenses` and `share_like_capital_without_sale_expenses` split `share_like_capital`, which is `corporate_wealth` as supplied, or the sum of its itemised components (`directly_held_shares`, `unit_and_investment_trusts`, `stocks_and_shares_isa`) where that is larger, so a household given only the components has them counted and no holding @@ -52,4 +52,5 @@ values: - savings - other_residential_property_value - non_residential_property_value - - share_like_capital + - share_like_capital_with_sale_expenses + - share_like_capital_without_sale_expenses diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml index d1c1a17514..1563961bed 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml @@ -1,6 +1,7 @@ # corporate_wealth itemised into directly_held_shares, unit_and_investment_trusts -# and stocks_and_shares_isa, with unitemised_corporate_wealth carrying whatever -# is not itemised (max(0, corporate_wealth - the three components)). +# and stocks_and_shares_isa. share_like_capital_with_sale_expenses is the part +# valued less 10%: directly held shares plus anything not itemised (all of +# corporate_wealth when nothing is itemised). # Capital is valued at market value less 10% where a sale would incur expenses # (UC Regs 2013 reg. 49(1); HB Regs 2006 reg. 47; IS Regs 1987 reg. 49; JSA # Regs 1996 reg. 111; ESA Regs 2008 reg. 113; SPC Regs 2002 reg. 19). Shares @@ -29,7 +30,7 @@ savings: 5_000 corporate_wealth: 12_000 output: - unitemised_corporate_wealth: 12_000 + share_like_capital_with_sale_expenses: 12_000 uc_assessable_capital: 15_800 is_uc_eligible: true # 9,800 above 6,000 is 40 steps of 250 (rounded up): 40 * 4.35 * 12. @@ -57,7 +58,7 @@ unit_and_investment_trusts: 3_000 stocks_and_shares_isa: 5_000 output: - unitemised_corporate_wealth: 0 + share_like_capital_with_sale_expenses: 4_000 uc_assessable_capital: 16_600 is_uc_eligible: false @@ -81,13 +82,13 @@ unit_and_investment_trusts: 2_600 stocks_and_shares_isa: 3_000 output: - unitemised_corporate_wealth: 0 + share_like_capital_with_sale_expenses: 10_000 uc_assessable_capital: 15_600 is_uc_eligible: true # 9,600 above 6,000 is 39 steps of 250 (38.4 rounded up): 39 * 4.35 * 12. uc_tariff_income: 2_035.8 -- name: UC partial split values the unitemised residual less 10% +- name: UC partial split values the part not itemised less 10% period: 2026 absolute_error_margin: 0.01 input: @@ -107,7 +108,7 @@ corporate_wealth: 12_000 stocks_and_shares_isa: 5_000 output: - unitemised_corporate_wealth: 7_000 + share_like_capital_with_sale_expenses: 7_000 uc_assessable_capital: 15_300 # 9,300 above 6,000 is 38 steps of 250 (37.2 rounded up): 38 * 4.35 * 12. uc_tariff_income: 1_983.6 @@ -133,7 +134,7 @@ directly_held_shares: 4_000 unit_and_investment_trusts: 3_000 output: - unitemised_corporate_wealth: 0 + share_like_capital_with_sale_expenses: 4_000 uc_assessable_capital: 7_600 # 1,600 above 6,000 is 7 steps of 250 (6.4 rounded up): 7 * 4.35 * 12. uc_tariff_income: 365.4 @@ -162,7 +163,7 @@ unit_and_investment_trusts: 4_000 stocks_and_shares_isa: 6_000 output: - unitemised_corporate_wealth: 0 + share_like_capital_with_sale_expenses: 5_000 housing_benefit_assessable_capital: 15_600 # 9,600 above 6,000 is 39 steps of 250 (38.4 rounded up) at 1 a week. housing_benefit_tariff_income: 2_028 diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 3194e95198..c66ba2dba1 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -1,14 +1,24 @@ -"""share_like_capital replaces corporate_wealth in the means-test capital lists. +"""Share-like capital in the means tests, itemised and valued by asset type. + +The capital lists name share_like_capital's two parts: +share_like_capital_with_sale_expenses (directly held shares, and all of an +unitemised corporate_wealth), which the sale-expense lists value less 10%, and +share_like_capital_without_sale_expenses (unit and investment trusts, stocks +and shares ISAs), valued in full. Invariants: 1. share_like_capital is corporate_wealth as supplied (any sign, any fraction) - unless the itemised components add up to more than it by more than the - rounding tolerance, in which case it is their sum. -2. Differential: for identical inputs that carry no components, or components - consistent with corporate_wealth, every programme's assessable capital and - eligibility equal those under the original lists (corporate_wealth), - exactly, annually and monthly. -3. A household given only the components has them counted. + unless the itemised components exceed it beyond the rounding tolerance, in + which case it is their sum. +2. With no itemised holdings, the part with sale expenses is all of + share_like_capital and the other part is exactly nil; otherwise the part + with sale expenses is share_like_capital less trusts and ISAs, floored at + nil, and the two parts add up to share_like_capital. +3. Differential: for identical unitemised inputs, every programme's assessable + capital and UC eligibility equal those under the lists before itemising + (corporate_wealth valued less 10%), exactly, annually and monthly. +4. Split effect: a consistent split raises a working-age single adult's UC + capital by 10% of trusts plus ISAs, against the unitemised lists. """ import numpy as np @@ -27,13 +37,18 @@ "unit_and_investment_trusts", "stocks_and_shares_isa", ) -SOURCE_LISTS = { - "uc_assessable_capital": "gov.dwp.universal_credit.means_test.capital.sources", - "housing_benefit_assessable_capital": "gov.dwp.housing_benefit.means_test.capital.sources", - "income_support_assessable_capital": "gov.dwp.income_support.means_test.capital.sources", - "jsa_income_assessable_capital": "gov.dwp.JSA.income.capital.sources", - "esa_income_assessable_capital": "gov.dwp.ESA.income.capital.sources", - "pension_credit_assessable_capital": "gov.dwp.pension_credit.income.capital.sources", +WITH, WITHOUT = ( + "share_like_capital_with_sale_expenses", + "share_like_capital_without_sale_expenses", +) +LEGAL_RATE = 0.1 +NODES = { + "uc_assessable_capital": "gov.dwp.universal_credit.means_test.capital", + "housing_benefit_assessable_capital": "gov.dwp.housing_benefit.means_test.capital", + "income_support_assessable_capital": "gov.dwp.income_support.means_test.capital", + "jsa_income_assessable_capital": "gov.dwp.JSA.income.capital", + "esa_income_assessable_capital": "gov.dwp.ESA.income.capital", + "pension_credit_assessable_capital": "gov.dwp.pension_credit.income.capital", } YEAR = 2026 SETTINGS = settings( @@ -52,26 +67,30 @@ def _parameter(path): return node(f"{YEAR}-01-01") -ORIGINAL_LISTS = { - path: [ - "corporate_wealth" if source == "share_like_capital" else source - for source in _parameter(path) - ] - for path in SOURCE_LISTS.values() -} -ORIGINAL_REFORM = { - path: {str(YEAR): sources} for path, sources in ORIGINAL_LISTS.items() +def _unitemised(sources): + """The list before itemising: corporate_wealth where the share parts are.""" + out = [] + for source in sources: + if source == WITHOUT: + continue + out.append("corporate_wealth" if source == WITH else source) + return out + + +UNITEMISED_REFORM = { + f"{node}.{name}": {str(YEAR): _unitemised(_parameter(f"{node}.{name}"))} + for node in NODES.values() + for name in ("sources", "sale_expenses.sources") } money = st.floats(min_value=0, max_value=200_000, allow_nan=False, width=32) signed_money = st.floats(min_value=-5_000, max_value=200_000, allow_nan=False, width=32) -def _situation(households): - """One single-adult household per entry; ages alternate 30 and 70.""" +def _situation(households, age=None): people, benunits, hhs = {}, {}, {} for i, assets in enumerate(households): - people[f"p{i}"] = {"age": {YEAR: 70 if i % 2 else 30}} + people[f"p{i}"] = {"age": {YEAR: age or (70 if i % 2 else 30)}} benunits[f"b{i}"] = {"members": [f"p{i}"], "would_claim_uc": {YEAR: True}} hhs[f"h{i}"] = { "members": [f"p{i}"], @@ -80,28 +99,25 @@ def _situation(households): return {"people": people, "benunits": benunits, "households": hhs} -def _results(households, reform=None, period=YEAR): - sim = Simulation(situation=_situation(households), reform=reform) - out = {v: sim.calculate(v, period) for v in SOURCE_LISTS} +def _results(households, reform=None, period=YEAR, age=None): + sim = Simulation(situation=_situation(households, age), reform=reform) + out = {v: sim.calculate(v, period) for v in NODES} out["is_uc_eligible"] = sim.calculate("is_uc_eligible", period) - out["share_like_capital"] = sim.calculate("share_like_capital", YEAR) + for v in ("share_like_capital", WITH, WITHOUT): + out[v] = sim.calculate(v, YEAR) return out -def _assert_same_as_original(households): - for period in (YEAR, f"{YEAR}-01"): - new = _results(households, period=period) - old = _results(households, reform=ORIGINAL_REFORM, period=period) - for variable in (*SOURCE_LISTS, "is_uc_eligible"): - assert np.array_equal(new[variable], old[variable]), (variable, period) - - -@pytest.mark.parametrize("variable", SOURCE_LISTS) -def test_lists_name_share_like_capital_only(variable): - sources = list(_parameter(SOURCE_LISTS[variable])) - assert "share_like_capital" in sources - assert "corporate_wealth" not in sources - assert not set(COMPONENTS) & set(sources) +@pytest.mark.parametrize("variable", NODES) +def test_lists_name_the_two_parts(variable): + sources = list(_parameter(f"{NODES[variable]}.sources")) + sale = list(_parameter(f"{NODES[variable]}.sale_expenses.sources")) + assert WITH in sources and WITHOUT in sources + assert not {"corporate_wealth", "share_like_capital", *COMPONENTS} & set(sources) + assert WITH in sale and WITHOUT not in sale + assert not {"corporate_wealth", *COMPONENTS} & set(sale) + without = set(_parameter("gov.dwp.share_like_capital.without_sale_expenses")) + assert without == {"unit_and_investment_trusts", "stocks_and_shares_isa"} @SETTINGS @@ -112,62 +128,75 @@ def test_lists_name_share_like_capital_only(variable): max_size=40, ) ) -def test_share_like_capital_keeps_the_supplied_aggregate(rows): +def test_share_like_capital_and_its_parts(rows): households = [] for corporate_wealth, components, itemise in rows: assets = {"corporate_wealth": corporate_wealth} if itemise: assets |= dict(zip(COMPONENTS, components)) households.append(assets) - got = _results(households)["share_like_capital"] - for value, assets in zip(got, households): + got = _results(households) + for i, assets in enumerate(households): cw = np.float32(assets["corporate_wealth"]) - itemised = np.float32(sum(np.float32(assets.get(c, 0)) for c in COMPONENTS)) + values = [np.float32(assets.get(c, 0)) for c in COMPONENTS] + itemised = np.float32(sum(values)) tolerance = RELATIVE_TOLERANCE * abs(cw) + ABSOLUTE_TOLERANCE - expected = itemised if itemised > 0 and itemised > cw + tolerance else cw - assert value == pytest.approx(expected, rel=1e-6, abs=1e-3) - if not (itemised > 0 and itemised > cw + tolerance): - assert value == cw # exactly the supplied aggregate + exceeds = itemised > 0 and itemised > cw + tolerance + share_like = got["share_like_capital"][i] + if exceeds: + assert share_like == pytest.approx(itemised, rel=1e-6, abs=1e-3) + else: + assert share_like == cw + if itemised == 0: + assert got[WITH][i] == share_like and got[WITHOUT][i] == 0 + else: + expected = max(0.0, share_like - values[1] - values[2]) + assert got[WITH][i] == pytest.approx(expected, rel=1e-6, abs=1e-2) + assert got[WITH][i] + got[WITHOUT][i] == pytest.approx( + share_like, rel=1e-6, abs=1e-2 + ) @SETTINGS @given( - st.lists( - st.tuples(money, signed_money, st.tuples(money, money, money), st.booleans()), - min_size=1, - max_size=30, - ) + st.lists(st.tuples(money, signed_money), min_size=1, max_size=30), ) -def test_capital_matches_the_original_lists(rows): - """Unsplit, or split consistently: identical to listing corporate_wealth.""" - households = [] - for savings, corporate_wealth, components, split in rows: - assets = {"savings": savings, "corporate_wealth": corporate_wealth} - if split: - assets |= dict(zip(COMPONENTS, components)) - assets["corporate_wealth"] = float(sum(components)) - households.append(assets) - _assert_same_as_original(households) +def test_unitemised_inputs_match_the_lists_before_itemising(rows): + households = [{"savings": s, "corporate_wealth": cw} for s, cw in rows] + households += [ + {"savings": 6_001, "corporate_wealth": -2}, + {"savings": 0, "corporate_wealth": 17_777.78}, # 90% is £16,000.002 + ] + for period in (YEAR, f"{YEAR}-01"): + new = _results(households, period=period) + old = _results(households, reform=UNITEMISED_REFORM, period=period) + for variable in (*NODES, "is_uc_eligible"): + assert np.array_equal(new[variable], old[variable]), (variable, period) -def test_float32_rounding_at_the_limit_keeps_eligibility(): - """Components whose float32 sum overshoots £16,000 by a fraction of a penny.""" +@SETTINGS +@given( + st.lists(st.tuples(money, st.tuples(money, money, money)), min_size=1, max_size=30) +) +def test_a_consistent_split_exempts_trusts_and_isas(rows): households = [ { - "savings": 0, - "corporate_wealth": 16_000, - "directly_held_shares": 6_744.81, - "unit_and_investment_trusts": 6_581.24, - "stocks_and_shares_isa": 2_673.95, - }, - {"savings": 6_001, "corporate_wealth": -2}, - {"savings": 15_999.99, "corporate_wealth": 0.01}, + "savings": savings, + "corporate_wealth": float(sum(components)), + **dict(zip(COMPONENTS, components)), + } + for savings, components in rows ] - _assert_same_as_original(households) - assert _results(households)["share_like_capital"][0] == 16_000 + new = _results(households, age=30) + old = _results(households, reform=UNITEMISED_REFORM, age=30) + for i, (_, (_, trusts, isa)) in enumerate(rows): + exempt = np.float32(trusts) + np.float32(isa) + assert new["uc_assessable_capital"][i] - old["uc_assessable_capital"][ + i + ] == pytest.approx(LEGAL_RATE * exempt, rel=1e-5, abs=0.05) -def test_components_alone_are_counted(): +def test_components_alone_are_valued_by_type(): households = [ { "savings": 1_000, @@ -176,6 +205,8 @@ def test_components_alone_are_counted(): "stocks_and_shares_isa": 5_000, } ] - got = _results(households) + got = _results(households, age=30) assert got["share_like_capital"][0] == 12_000 - assert got["uc_assessable_capital"][0] == 13_000 + assert got[WITH][0] == 4_000 and got[WITHOUT][0] == 8_000 + # £1,000 + 90% of £4,000 + £3,000 + £5,000. + assert got["uc_assessable_capital"][0] == pytest.approx(12_600) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 4bafb0c51d..0517d3181d 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -7,7 +7,9 @@ Regs 1987 reg. 49; JSA Regs 1996 reg. 111; ESA Regs 2008 reg. 113; SPC Regs 2002 reg. 19). A bank or building society account is valued at its balance (ADM H1675); land and property always have costs of sale (H1606) and shares -are valued less 10% (H1665). +are valued less 10% (H1665). The households here hold share-like wealth only +as unitemised corporate_wealth, which all takes the 10%; itemised holdings +(unit trusts and ISAs without it) are tested in test_capital_share_components. Invariants, for any generated population of single-adult households: @@ -57,14 +59,29 @@ } PENSION_AGE_ONLY = {"pension_credit_assessable_capital"} # The assets whose sale incurs expenses, fixed here from the law rather than -# read from the parameters: real property always (ADM H1606), shares (H1665); -# never a bank or building society balance (H1675). +# read from the parameters: real property always (ADM H1606), shares (H1665), +# and unitemised corporate wealth with them; never a bank or building society +# balance (H1675). SALE_EXPENSE_ASSETS = { "owned_land", "other_residential_property_value", "non_residential_property_value", - "corporate_wealth", + "share_like_capital_with_sale_expenses", +} +# How each capital source reads an unitemised household's inputs: all of its +# corporate_wealth has expenses of sale, none is without. +SHARE_LIKE_SOURCES = { + "share_like_capital_with_sale_expenses": lambda assets: assets["corporate_wealth"], + "share_like_capital_without_sale_expenses": lambda assets: 0.0, } + + +def asset_value(unit, source): + if source in SHARE_LIKE_SOURCES: + return SHARE_LIKE_SOURCES[source](unit["assets"]) + return unit["assets"][source] + + LEGAL_RATE = 0.1 ASSETS = [ "savings", @@ -141,7 +158,7 @@ def expected_capital(unit, node): """Reg. 49(1) applied source by source, independently of the model.""" total = 0.0 for source in node.sources: - value = unit["assets"][source] + value = asset_value(unit, source) if source in SALE_EXPENSE_ASSETS: value *= 1 - LEGAL_RATE if source in DEBTS: @@ -179,7 +196,7 @@ def test_valuation_matches_the_regulation_and_never_adds_capital(units): assert close(valued[variable][i], expected), (variable, unit) # Debt secured on property never reaches the other assets. floor = sum( - unit["assets"][s] * (1 - LEGAL_RATE * (s in SALE_EXPENSE_ASSETS)) + asset_value(unit, s) * (1 - LEGAL_RATE * (s in SALE_EXPENSE_ASSETS)) for s in node.sources if s not in DEBTS ) diff --git a/policyengine_uk/tests/test_stock_capital_periods.py b/policyengine_uk/tests/test_stock_capital_periods.py index fe6f440ddf..92d4d82100 100644 --- a/policyengine_uk/tests/test_stock_capital_periods.py +++ b/policyengine_uk/tests/test_stock_capital_periods.py @@ -85,11 +85,12 @@ def test_itemised_share_like_stocks_are_not_prorated_monthly(): for name, value in stocks.items(): assert simulation.calculate(name, "2026-01")[0] == value, name - # 12,000 less the 9,000 itemised. - assert simulation.calculate("unitemised_corporate_wealth", "2026-01")[0] == ( - 3_000 - ) - # Shares and the unitemised residual less 10% for the expenses of + # 12,000 less the unit trusts and ISA (5,000): the 4,000 of shares + # and the 3,000 not itemised. + assert simulation.calculate("share_like_capital_with_sale_expenses", "2026-01")[ + 0 + ] == (7_000) + # Shares and the part not itemised less 10% for the expenses of # sale; unit trusts and the ISA at their withdrawal value: - # 1,000 + 3,600 + 3,000 + 2,000 + 2,700. + # 1,000 + 90% of 7,000 + 3,000 + 2,000 = 1,000 + 6,300 + 5,000. assert simulation.calculate(capital, "2026-01")[0] == 12_300, capital diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py new file mode 100644 index 0000000000..596008d993 --- /dev/null +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -0,0 +1,35 @@ +from policyengine_uk.model_api import * + +COMPONENTS = [ + "directly_held_shares", + "unit_and_investment_trusts", + "stocks_and_shares_isa", +] + + +class share_like_capital_with_sale_expenses(Variable): + label = "share-like capital with expenses of sale" + documentation = ( + "The part of share_like_capital whose sale would incur expenses, so " + "that the means tests value it less 10%: share_like_capital less the " + "itemised holdings listed in gov.dwp.share_like_capital." + "without_sale_expenses (unit and investment trusts, stocks and shares " + "ISAs), floored at nil. A household with no itemised holdings has all " + "of its share-like capital here, so datasets that carry only " + "corporate_wealth keep the flat 10% on it." + ) + entity = Household + definition_period = YEAR + value_type = float + unit = GBP + quantity_type = STOCK + + def formula(household, period, parameters): + share_like = household("share_like_capital", period) + itemised = add(household, period, COMPONENTS) + without = add( + household, + period, + parameters(period).gov.dwp.share_like_capital.without_sale_expenses, + ) + return where(itemised > 0, max_(0, share_like - without), share_like) diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py new file mode 100644 index 0000000000..ad777f2f0b --- /dev/null +++ b/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py @@ -0,0 +1,20 @@ +from policyengine_uk.model_api import * + + +class share_like_capital_without_sale_expenses(Variable): + label = "share-like capital without expenses of sale" + documentation = ( + "The part of share_like_capital the means tests value at full value: " + "share_like_capital less share_like_capital_with_sale_expenses. Nil " + "for a household with no itemised holdings." + ) + entity = Household + definition_period = YEAR + value_type = float + unit = GBP + quantity_type = STOCK + + def formula(household, period, parameters): + return household("share_like_capital", period) - household( + "share_like_capital_with_sale_expenses", period + ) From 3abaf166b0275ea86816330d1d7332be48088e4c Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 13 Oct 2026 08:35:35 -0400 Subject: [PATCH 09/48] Assert nil HB capital for passported units and keep non-passported cover Review of 54ed063b1: half the generated units now decline Universal Credit, so the Housing Benefit passport cannot remove every working-age unit from the reg 47 differential, and a passported unit's HB capital is asserted to be nil rather than skipped. Co-Authored-By: Claude Opus 5.5 --- .../test_capital_valuation_properties.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 4bafb0c51d..a78368ba5e 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -88,14 +88,25 @@ def households(draw, cash_only=False): if cash_only: assets = {asset: 0.0 for asset in ASSETS} | {"savings": assets["savings"]} debts = {debt: 0.0 for debt in debts} - return dict(age=draw(st.sampled_from([30, 70])), assets=assets, debts=debts) + # About half the units do not claim Universal Credit, so the Housing + # Benefit passport cannot remove every working-age unit from the + # differential below. + return dict( + age=draw(st.sampled_from([30, 70])), + claims_uc=draw(st.booleans()), + assets=assets, + debts=debts, + ) def situation(units, debt_scale=1.0): people, benunits, homes = {}, {}, {} for i, unit in enumerate(units): people[f"p{i}"] = {"age": {YEAR: unit["age"]}} - benunits[f"b{i}"] = {"members": [f"p{i}"]} + benunits[f"b{i}"] = { + "members": [f"p{i}"], + "would_claim_uc": {YEAR: unit["claims_uc"]}, + } homes[f"h{i}"] = { "members": [f"p{i}"], **{k: {YEAR: v} for k, v in unit["assets"].items()}, @@ -171,8 +182,8 @@ def test_valuation_matches_the_regulation_and_never_adds_capital(units): gc = valued["guarantee_credit"][i] assert valued[variable][i] >= 0, (variable, unit) assert valued[variable][i] <= full[variable][i] + 0.01, (variable, unit) - if variable == "housing_benefit_assessable_capital" and unit["age"] >= 67: - if gc > 0: + if variable == "housing_benefit_assessable_capital": + if valued["hb_passported"][i] or (unit["age"] >= 67 and gc > 0): assert valued[variable][i] == 0, unit if applies(variable, unit, gc, valued["hb_passported"][i]): expected = expected_capital(unit, node) From 10c54a5962176f3fb5befa757793d121ce459077 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 13 Oct 2026 08:50:32 -0400 Subject: [PATCH 10/48] Start the exempt list in 1996, sum it from zero, and test float32 grouping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review of b7e6bc5c5: - gov.dwp.share_like_capital.without_sale_expenses started in 2013, after the legacy capital lists (JSA from 1996-10-07), so a 2012 simulation with unitemised corporate_wealth raised ParameterNotFoundError; it now starts at 1996-10-07, and Income Support and JSA capital in 2012 are tested (both fail with the 2013 start). - An empty exempt list made add() return None; the exempt holdings are now summed from a numeric zero, and an empty-list reform (every share-like holding less 10%) is tested. - The property oracle now follows the engine's float32 grouping (components left to right, exempt holdings summed before subtraction) and compares exactly; the reviewer's example (trusts £200,000, ISA £199,999.984375) is pinned. Co-Authored-By: Claude Opus 5.5 --- .../without_sale_expenses.yaml | 2 +- .../tests/test_capital_share_components.py | 67 ++++++++++++++++--- .../share_like_capital_with_sale_expenses.py | 12 ++-- 3 files changed, 64 insertions(+), 17 deletions(-) diff --git a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml index 086d7d849c..fa06ccc205 100644 --- a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml +++ b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml @@ -24,6 +24,6 @@ metadata: - title: HMRC Annual savings statistics 2026, ISA Table 9.6 href: https://www.gov.uk/government/statistics/annual-savings-statistics-2026 values: - 2013-04-29: + 1996-10-07: - unit_and_investment_trusts - stocks_and_shares_isa diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index c66ba2dba1..c848efc0a8 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -28,7 +28,6 @@ from policyengine_uk import CountryTaxBenefitSystem, Simulation from policyengine_uk.variables.household.wealth.share_like_capital import ( - ABSOLUTE_TOLERANCE, RELATIVE_TOLERANCE, ) @@ -139,22 +138,68 @@ def test_share_like_capital_and_its_parts(rows): for i, assets in enumerate(households): cw = np.float32(assets["corporate_wealth"]) values = [np.float32(assets.get(c, 0)) for c in COMPONENTS] - itemised = np.float32(sum(values)) - tolerance = RELATIVE_TOLERANCE * abs(cw) + ABSOLUTE_TOLERANCE - exceeds = itemised > 0 and itemised > cw + tolerance + # The engine's float32 grouping: components added left to right, the + # exempt holdings summed before they are subtracted. + itemised = np.float32(np.float32(values[0] + values[1]) + values[2]) + exempt = np.float32(values[1] + values[2]) + tolerance = RELATIVE_TOLERANCE * max(abs(cw), itemised) share_like = got["share_like_capital"][i] - if exceeds: - assert share_like == pytest.approx(itemised, rel=1e-6, abs=1e-3) + if itemised > 0 and itemised > cw + tolerance: + assert share_like == itemised else: assert share_like == cw if itemised == 0: assert got[WITH][i] == share_like and got[WITHOUT][i] == 0 else: - expected = max(0.0, share_like - values[1] - values[2]) - assert got[WITH][i] == pytest.approx(expected, rel=1e-6, abs=1e-2) - assert got[WITH][i] + got[WITHOUT][i] == pytest.approx( - share_like, rel=1e-6, abs=1e-2 - ) + assert got[WITH][i] == max(np.float32(0), np.float32(share_like - exempt)) + assert got[WITHOUT][i] == np.float32(share_like - got[WITH][i]) + + +def test_float32_grouping_of_the_exempt_holdings(): + """Trusts and ISA summed first: £400,000 less £399,999.98 rounds to nil.""" + households = [ + { + "corporate_wealth": 399_999.984375, + "unit_and_investment_trusts": 200_000, + "stocks_and_shares_isa": 199_999.984375, + } + ] + got = _results(households) + assert got[WITH][0] == 0 + + +def test_an_empty_exempt_list_values_everything_less_10_percent(): + """A ruling that every share-like holding takes the 10% is a parameter edit.""" + reform = {"gov.dwp.share_like_capital.without_sale_expenses": {str(YEAR): []}} + households = [ + {"savings": 1_000, "corporate_wealth": 12_000}, + { + "savings": 1_000, + "directly_held_shares": 4_000, + "unit_and_investment_trusts": 3_000, + "stocks_and_shares_isa": 5_000, + }, + ] + got = _results(households, reform=reform, age=30) + assert list(got[WITH]) == [12_000, 12_000] + assert list(got[WITHOUT]) == [0, 0] + # £1,000 + 90% of £12,000 either way. + assert got["uc_assessable_capital"] == pytest.approx([11_800, 11_800]) + + +@pytest.mark.parametrize( + "variable", ["income_support_assessable_capital", "jsa_income_assessable_capital"] +) +def test_legacy_capital_before_universal_credit(variable): + """2012: the legacy lists apply, and so does the exempt list (from 1996).""" + situation = _situation([{"savings": 1_000, "corporate_wealth": 12_000}], age=30) + for entity in situation.values(): + for name, values in entity.items(): + for key, by_year in list(values.items()): + if isinstance(by_year, dict) and YEAR in by_year: + values[key] = {2012: by_year[YEAR]} + capital = Simulation(situation=situation).calculate(variable, 2012)[0] + assert capital == pytest.approx(11_800) @SETTINGS diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py index 596008d993..d5136dd2b3 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -27,9 +27,11 @@ class share_like_capital_with_sale_expenses(Variable): def formula(household, period, parameters): share_like = household("share_like_capital", period) itemised = add(household, period, COMPONENTS) - without = add( - household, - period, - parameters(period).gov.dwp.share_like_capital.without_sale_expenses, - ) + # Summed from a numeric zero so that an empty list (every holding + # taking the deduction) still works. + without = 0 * share_like + for variable in parameters( + period + ).gov.dwp.share_like_capital.without_sale_expenses: + without = without + household(variable, period) return where(itemised > 0, max_(0, share_like - without), share_like) From 1efee62b697588f2fbc8f48db3709c5d526d86c0 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 13 Oct 2026 09:22:18 -0400 Subject: [PATCH 11/48] Guarantee both Housing Benefit branches are exercised MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delta review of b54167756 (F1): coverage of the HB passport-nil assertion and the working-age reg 47 differential depended on Hypothesis draws. The checks move into check_valuation(), which counts the branches it ran, and a fixed test asserts both run: a UC claimant with £5,000 of savings (passported, nil HB capital) and a non-claimant with a mortgaged second home (valued under reg 47). Co-Authored-By: Claude Opus 5.5 --- .../test_capital_valuation_properties.py | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index a78368ba5e..ad3e253d7e 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -165,11 +165,11 @@ def close(a, b): return abs(a - b) <= 1 + 1e-6 * abs(b) -@PROPERTY_SETTINGS -@given(st.lists(households(), min_size=20, max_size=200)) -def test_valuation_matches_the_regulation_and_never_adds_capital(units): +def check_valuation(units): + """Assert the valuation invariants; count which Housing Benefit branches ran.""" sim, valued = calculate(units) _, full = calculate(units, rate=0.0, debt_scale=0.0) + hb_checked = {"passported_nil": 0, "working_age_differential": 0} for variable, path in PROGRAMMES.items(): node = parameter_node(sim, path) assert node.sale_expenses.rate == LEGAL_RATE @@ -178,16 +178,21 @@ def test_valuation_matches_the_regulation_and_never_adds_capital(units): assert set(node.sale_expenses.sources) & counted == ( SALE_EXPENSE_ASSETS & counted ), variable + hb = variable == "housing_benefit_assessable_capital" for i, unit in enumerate(units): gc = valued["guarantee_credit"][i] assert valued[variable][i] >= 0, (variable, unit) assert valued[variable][i] <= full[variable][i] + 0.01, (variable, unit) - if variable == "housing_benefit_assessable_capital": - if valued["hb_passported"][i] or (unit["age"] >= 67 and gc > 0): - assert valued[variable][i] == 0, unit + if hb and valued["hb_passported"][i]: + assert valued[variable][i] == 0, unit + hb_checked["passported_nil"] += 1 + if hb and unit["age"] >= 67 and gc > 0: + assert valued[variable][i] == 0, unit if applies(variable, unit, gc, valued["hb_passported"][i]): expected = expected_capital(unit, node) assert close(valued[variable][i], expected), (variable, unit) + if hb and unit["age"] < 67 and expected > 0: + hb_checked["working_age_differential"] += 1 # Debt secured on property never reaches the other assets. floor = sum( unit["assets"][s] * (1 - LEGAL_RATE * (s in SALE_EXPENSE_ASSETS)) @@ -195,6 +200,38 @@ def test_valuation_matches_the_regulation_and_never_adds_capital(units): if s not in DEBTS ) assert valued[variable][i] >= floor - 1, (variable, unit) + return hb_checked + + +@PROPERTY_SETTINGS +@given(st.lists(households(), min_size=20, max_size=200)) +def test_valuation_matches_the_regulation_and_never_adds_capital(units): + check_valuation(units) + + +def test_housing_benefit_branches_are_both_exercised(): + """Fixed units that a passport cannot hide: one claims UC with £5,000 of + savings (UC passports it to nil HB capital), one declines UC and holds a + mortgaged second home (its HB capital is checked against reg 47).""" + no_debt = {debt: 0.0 for debt in DEBTS.values()} + units = [ + dict( + age=30, + claims_uc=True, + assets={asset: 0.0 for asset in ASSETS} | {"savings": 5_000.0}, + debts=no_debt, + ), + dict( + age=30, + claims_uc=False, + assets={asset: 0.0 for asset in ASSETS} + | {"savings": 2_000.0, "other_residential_property_value": 100_000.0}, + debts=no_debt | {"other_residential_property_secured_debt": 60_000.0}, + ), + ] + hb_checked = check_valuation(units) + assert hb_checked["passported_nil"] >= 1 + assert hb_checked["working_age_differential"] >= 1 @PROPERTY_SETTINGS From 2eb4e526e4a87cfc66a861b896dd94ba04389eb5 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 19 Oct 2026 15:53:00 -0400 Subject: [PATCH 12/48] Value the savings-credit-only capital test under reg 19 Savings 12,000 plus a 5,000 property is 12,000 + 4,500 = 16,500 of Pension Credit capital (SPC Regs 2002 reg. 19(a)), still over the 16,000 CTR limit. Deemed income is 13 a week, so the savings credit is 0.6 x 29.93 - 0.4 x 15 = 11.958 a week (621.82). Co-Authored-By: Claude Opus 5.5 --- ...st_savings_credit_only_receipt_properties.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/policyengine_uk/tests/test_savings_credit_only_receipt_properties.py b/policyengine_uk/tests/test_savings_credit_only_receipt_properties.py index 98133c2046..c7bfaf6e8f 100644 --- a/policyengine_uk/tests/test_savings_credit_only_receipt_properties.py +++ b/policyengine_uk/tests/test_savings_credit_only_receipt_properties.py @@ -396,7 +396,8 @@ def test_known_families_detect_main(): ) assert not np.any(fix[FLAG]) # Main keeps the Pension Credit assessment. The owner with capital is - # tested on 17,000 against the 16,000 limit and gets no council tax + # tested on 16,500 (12,000 of savings and 90% of the 5,000 property, + # SPC Regs 2002 reg. 19(a)) against the 16,000 limit and gets no council tax # reduction, where the scheme's own rules give 2,000 on savings of # 12,000. The tenant has no Housing Benefit tariff income, where # Housing Benefit's own rules count 4 a week on savings of 12,000 @@ -499,16 +500,18 @@ def read(simulation, variable): def test_stopping_pension_credit_payments_ends_the_pension_credit_capital_test(): # Savings of 12,000 and other property worth 5,000. The Pension Credit - # assessment of capital counts both (17,000), above the 16,000 limit, so - # the savings-credit-only award leaves no council tax reduction. Deemed - # income is 1 a week for each 500 over 10,000: 14 a week, so the savings - # credit is 0.6 x 29.93 - 0.4 x (254.00 - 238.00) = 11.558 a week (601.02). + # assessment of capital counts both, the property less 10% for the + # expenses of sale (SPC Regs 2002 reg. 19(a)): 12,000 + 4,500 = 16,500, + # above the 16,000 limit, so the savings-credit-only award leaves no + # council tax reduction. Deemed income is 1 a week for each 500 or part + # over 10,000: 13 a week, so the savings credit is 0.6 x 29.93 - 0.4 x + # (253.00 - 238.00) = 11.958 a week (621.82). data = single_pensioner(savings=12_000.0, other_property=5_000.0) unreformed = Simulation(situation=data) - assert abs(unreformed.calculate("savings_credit", YEAR)[0] - 601.02) < 0.01 + assert abs(unreformed.calculate("savings_credit", YEAR)[0] - 621.82) < 0.01 assert unreformed.calculate(FLAG, YEAR).tolist() == [True] capital = "council_tax_reduction_assessable_capital" - assert unreformed.calculate(capital, YEAR)[0] == 17_000 + assert unreformed.calculate(capital, YEAR)[0] == 16_500 assert unreformed.calculate("council_tax_reduction", YEAR)[0] == 0 # With Pension Credit not paid the scheme's own capital rule applies, for From ce8493d7bba8e2c704374dc422891115ca7b4114 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 20 Oct 2026 18:32:36 -0400 Subject: [PATCH 13/48] Consume a recorded total's holding at its counted value; round to the penny MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the GPT-6.1 Sol review of a7d8988e5: - A recorded benunit_reported_capital total holds its owner's reg. 77 holding at full value, while the pool counts that holding at 90%. The report now consumes its known holding part at the counted 90% (household_uc_reported_financial_capital), so it can no longer eat another unit's savings; the owner's own assessment still takes the full holding off the report. The company-override conservation oracle consumes the same way, and a YAML regression pins the reviewer's case: £16,500 of savings and a £10,000 report that is all holding give [0, 16,500]. - valued_capital rounds the 90% value down to the penny in the claimant's favour (ADM H1665), in float64 with a guard against binary noise. A YAML regression puts £1,000 of savings and £16,666.67 of shares at exactly £16,000.00, which passes the limit (WRA 2012 s. 5(1)(a), UC reg. 18(1)). Co-Authored-By: Claude Opus 5.5 --- .../baseline/gov/dwp/capital_valuation.yaml | 23 +++++++++++ .../universal_credit/uc_property_capital.yaml | 40 +++++++++++++++++++ .../test_uc_company_override_properties.py | 31 ++++++++++---- policyengine_uk/utils/capital_valuation.py | 18 +++++++-- ...household_uc_reported_financial_capital.py | 20 +++++++--- 5 files changed, 116 insertions(+), 16 deletions(-) diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml index 1b4870b502..a68465995c 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -293,3 +293,26 @@ pension_credit_deemed_income: 12_480 guarantee_credit: 0 housing_benefit_assessable_capital: 130_000 + +- name: UC rounds the share valuation down to the penny, at the capital limit + period: 2026 + absolute_error_margin: 0 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # 90% of 16,666.67 is 15,000.003, rounded down to the penny in the + # claimant's favour (ADM H1665): 15,000.00. With 1,000 of savings the + # capital is exactly the 16,000 limit, which does not exceed it (WRA + # 2012 s. 5(1)(a)). + savings: 1_000 + corporate_wealth: 16_666.67 + output: + uc_assessable_capital: 16_000 + is_uc_eligible: true diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/universal_credit/uc_property_capital.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/universal_credit/uc_property_capital.yaml index 13e0bc9255..7d94546a62 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/universal_credit/uc_property_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/universal_credit/uc_property_capital.yaml @@ -127,3 +127,43 @@ # 19,000 for the other claimant. uc_assessable_capital: [1_000, 19_000] universal_credit: [5_098.80, 0] + +- name: A recorded financial total consumes its owner's company holding at its counted value + period: 2026 + input: + people: + owner: + age: 30 + is_claimant_or_partner: true + stands_as_sole_owner_or_partner_of_company: true + owned_company_carries_on_property_business: true + owned_company_holding_value: 10_000 + owned_company_capital: 0 + other_claimant: + age: 30 + is_claimant_or_partner: true + benunits: + reporting: + members: [owner] + would_claim_uc: true + benunit_reported_capital: 10_000 + missing: + members: [other_claimant] + would_claim_uc: true + households: + household: + members: [owner, other_claimant] + savings: 16_500 + corporate_wealth: 10_000 + output: + # The pool counts the 10,000 of shares at 90% (reg. 49(1)(a)): 16,500 + + # 9,000 = 25,500. The recorded total holds the holding at full value, so + # its holding part is consumed at the counted 9,000, not 10,000: the + # report consumes 10,000 - 1,000 = 9,000. The owner's own assessment takes + # the full holding off the report (10,000 - 10,000 = 0), and the other + # claimant keeps all 16,500 of savings, over the 16,000 limit. The total + # reconciles: 0 + 16,500 + the 9,000 disregarded holding = 25,500. + household_uc_reported_financial_capital: 9_000 + household_uc_pool_company_holdings: 0 + uc_assessable_capital: [0, 16_500] + universal_credit: [5_098.80, 0] diff --git a/policyengine_uk/tests/test_uc_company_override_properties.py b/policyengine_uk/tests/test_uc_company_override_properties.py index ec9fd1731b..c6b426f401 100644 --- a/policyengine_uk/tests/test_uc_company_override_properties.py +++ b/policyengine_uk/tests/test_uc_company_override_properties.py @@ -144,7 +144,6 @@ def test_company_overrides_conserve_capital_and_keep_holdings_out_of_other_units explicit = [ spec.get("override", max(0, spec.get("financial", -1))) for spec in specs ] - explicit_consumption = sum(explicit) # Invalid holdings are bounded per person, before grouping into units. # Allocate one budget by those ownership shares; never recap a route. bounded_holdings = [ @@ -155,9 +154,19 @@ def test_company_overrides_conserve_capital_and_keep_holdings_out_of_other_units total_holdings = sum(bounded_holdings) + bounded_dependants budget = min(corporate, total_holdings) scale = budget / total_holdings if total_holdings else 0 - effective_holdings = [ - SHARE_VALUE * holding * scale for holding in bounded_holdings - ] + market_holdings = [holding * scale for holding in bounded_holdings] + effective_holdings = [SHARE_VALUE * holding for holding in market_holdings] + # A recorded financial total holds its owners' holdings at full value; + # the pool counts them at 90%, so its known holding part is consumed at + # 90% (reg. 49(1)(a)) and the rest of the report in full. + explicit_consumption = sum( + spec["override"] + if "override" in spec + else max(0, spec["financial"] - (1 - SHARE_VALUE) * market) + if spec.get("financial", -1) >= 0 + else 0 + for spec, market in zip(specs, market_holdings) + ) extra_holding_draw = SHARE_VALUE * bounded_dependants * scale + sum( holding if absent @@ -189,11 +198,17 @@ def test_company_overrides_conserve_capital_and_keep_holdings_out_of_other_units # owners, without scaling that substitution. This identity also # covers inconsistent observations and exhausted residual pools. # A complete override is a countable figure, so the holding comes off - # it at 90%; a recorded financial total is used unvalued, so in full. + # it at 90%. A recorded financial total is used unvalued, so the owner + # loses the holding in full while the pool gives up only its 90% + # value: what the report removes from the pool beyond the owner's own + # remaining capital is its consumption less that capital. owner_substitution = sum( - min(SHARE_VALUE * holding if "override" in spec else holding, reported) - for holding, reported, absent, spec in zip( - holdings, explicit, missing, specs + min(SHARE_VALUE * holding, reported) + if "override" in spec + else max(0, reported - (1 - SHARE_VALUE) * market) + - max(0, reported - holding) + for holding, market, reported, absent, spec in zip( + holdings, market_holdings, explicit, missing, specs ) if not absent ) diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index 7851ca440f..a1293d2d87 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -9,6 +9,7 @@ would incur expenses in a ``capital.sale_expenses`` parameter node. """ +import numpy as np from policyengine_core.model_api import max_ # Household inputs holding the debt secured on each capital source, such as a @@ -29,14 +30,15 @@ def valued_capital(value_of, sources, sale_expenses): ``value_of(variable)`` returns that household variable on the entity the caller is working with. The sale-expense deduction is taken from the gross - value before the encumbrance (ADM H1608), and a source carrying secured - debt is never valued below nil. + value before the encumbrance (ADM H1608) and the result rounded down to the + penny in the claimant's favour, as ADM H1665 does for quoted shares. A + source carrying secured debt is never valued below nil. """ total = 0 for source in sources: value = value_of(source) if source in sale_expenses.sources: - value = value * (1 - sale_expenses.rate) + value = penny_floor(value * (1 - sale_expenses.rate)) if source in SECURED_DEBT: value = max_(0, value - value_of(SECURED_DEBT[source])) total = total + value @@ -47,3 +49,13 @@ def counted_share(sale_expenses, source): """Share of a source's market value counted as capital: 90% where its sale would incur expenses (reg. 49(1)(a)), otherwise all of it.""" return 1 - sale_expenses.rate if source in sale_expenses.sources else 1 + + +def penny_floor(amount): + """Round down to the penny, in the claimant's favour (ADM H1665). + + Computed in float64, and rounded to a millionth of a penny first, so binary + noise just under a whole penny (10,799.9999999 for 90% of 12,000) does not + lose a penny.""" + pence = np.round(np.asarray(amount, dtype=np.float64) * 100, 6) + return np.floor(pence) / 100 diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py index 8ec4160847..6daf295adc 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py @@ -52,14 +52,24 @@ def formula(household, period, parameters): ).astype(holding.dtype) * person.household( "household_uc_company_holding_pool_scale", period ) - # A complete override is a countable figure, so the holdings it must at - # least cover are counted at the reg. 49(1) value of corporate_wealth. + # The pool counts corporate_wealth, and the holdings in it, at the reg. + # 49(1) value. A complete override is a countable figure, so the + # holdings it must at least cover are counted at that value. A recorded + # financial total is used unvalued and holds the holdings at full value, + # so its known holding part is consumed at the counted value too; the + # owner's own assessment still takes the full holding off the report. p = parameters(period).gov.dwp.universal_credit.means_test.capital - own_holdings = own_holdings * counted_share(p.sale_expenses, "corporate_wealth") + valued_holdings = own_holdings * counted_share( + p.sale_expenses, "corporate_wealth" + ) consumed_capital = where( complete_override >= 0, - max_(complete_override, own_holdings), - financial_capital, + max_(complete_override, valued_holdings), + where( + financial_capital >= 0, + max_(0, financial_capital - (own_holdings - valued_holdings)), + financial_capital, + ), ) return household.sum( max_(0, consumed_capital) * person("is_benunit_head", period) From 57f93709861f8dc0ea6c14bcbaec157d885c32b6 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 20 Oct 2026 19:24:17 -0400 Subject: [PATCH 14/48] Value capital less sale expenses in float64, to the penny MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inputs are float32, so 90% of £16,001 came to £14,400.8994 and the penny floor gave £14,400.89 (the HB £16,001 case failed). less_sale_expenses takes the value to the penny in float64 before the 10% deduction and rounds down to the penny (ADM H1665). The UC property path now uses it too, so every reg. 49(1)(a) valuation rounds the same way. Adds a Hypothesis property checking 90% of every whole-penny float32 input up to £131,071.99 against integer pence, and a UC YAML case. Co-Authored-By: Claude Opus 5.5 --- .../baseline/gov/dwp/capital_valuation.yaml | 22 +++++++++++++++++++ .../test_capital_valuation_properties.py | 19 +++++++++++++++- policyengine_uk/utils/capital_valuation.py | 13 ++++++++++- .../uc_non_residential_property_capital.py | 3 ++- .../uc_other_residential_property_capital.py | 3 ++- 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml index a68465995c..9f34ce7187 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -316,3 +316,25 @@ output: uc_assessable_capital: 16_000 is_uc_eligible: true + +- name: UC values property and shares less sale expenses to the penny + period: 2026 + absolute_error_margin: 0.005 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # 90% of 16,001 is 14,400.90 and 90% of 1,000.10 is 900.09, each + # rounded down to the penny (ADM H1665): 15,300.99. Float32 arithmetic + # would give 14,400.89 and 900.08. + other_residential_property_value: 16_001 + corporate_wealth: 1_000.10 + output: + uc_assessable_capital: 15_300.99 + is_uc_eligible: true diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index e0d8775155..430628cb2f 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -25,15 +25,19 @@ of the household's unencumbered sources, and capital is never negative. (Isolation between two encumbered sources is pinned by the differential and by a YAML case.) +6. Pennies: 90% of any whole-penny value stored as a float32 input is the + exact figure rounded down to the penny (ADM H1665), checked in integer + pence up to 131,071.99, the largest value float32 holds to the penny. """ from functools import reduce import numpy as np -from hypothesis import HealthCheck, given, settings +from hypothesis import HealthCheck, example, given, settings from hypothesis import strategies as st from policyengine_uk import Simulation +from policyengine_uk.utils.capital_valuation import less_sale_expenses YEAR = 2026 PROPERTY_SETTINGS = settings( @@ -278,3 +282,16 @@ def test_capital_is_non_increasing_in_rate_and_secured_debt(units, r1, r2, scale for variable in PROGRAMMES: assert np.all(at_high[variable] <= at_low[variable] + 0.01), variable assert np.all(more_debt[variable] <= at_low[variable] + 0.01), variable + + +@settings(max_examples=200, deadline=None, derandomize=True) +@given(st.lists(st.integers(0, 13_107_199), min_size=1, max_size=1_000)) +# 16,001 is 14,400.8994 after a float32 multiplication; 1,000.10 is stored as +# 1,000.0999756; 12,000 is 10,799.9999999 in binary. +@example([1_600_100, 100_010, 1_200_000]) +def test_sale_expenses_round_down_to_the_penny(pence): + stored = np.asarray(pence, dtype=np.int64).astype(np.float32) / np.float32(100) + valued = less_sale_expenses(stored, LEGAL_RATE) + assert valued.dtype == np.float64 + exact = [9 * amount // 10 for amount in pence] + assert np.round(valued * 100).astype(np.int64).tolist() == exact diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index a1293d2d87..cd9cb0035c 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -38,7 +38,7 @@ def valued_capital(value_of, sources, sale_expenses): for source in sources: value = value_of(source) if source in sale_expenses.sources: - value = penny_floor(value * (1 - sale_expenses.rate)) + value = less_sale_expenses(value, sale_expenses.rate) if source in SECURED_DEBT: value = max_(0, value - value_of(SECURED_DEBT[source])) total = total + value @@ -51,6 +51,17 @@ def counted_share(sale_expenses, source): return 1 - sale_expenses.rate if source in sale_expenses.sources else 1 +def less_sale_expenses(value, rate): + """Market value less the sale-expense ``rate`` (reg. 49(1)(a)), rounded + down to the penny in the claimant's favour (ADM H1665). + + Inputs are stored in float32, and a float32 product loses pennies: 90% of + 16,001 is 14,400.8994 in float32 rather than 14,400.90. So the value is + taken to the penny in float64 before the deduction.""" + pounds = np.round(np.asarray(value, dtype=np.float64), 2) + return penny_floor(pounds * (1 - np.asarray(rate, dtype=np.float64))) + + def penny_floor(amount): """Round down to the penny, in the claimant's favour (ADM H1665). diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_non_residential_property_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_non_residential_property_capital.py index 0de636f749..2d804975a6 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_non_residential_property_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_non_residential_property_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import less_sale_expenses class uc_non_residential_property_capital(Variable): @@ -21,4 +22,4 @@ def formula(household, period, parameters): p = parameters(period).gov.dwp.universal_credit.means_test.capital market_value = max_(0, household("non_residential_property_value", period)) debt = max_(0, household("non_residential_property_secured_debt", period)) - return max_(0, market_value * (1 - p.sale_expenses.rate) - debt) + return max_(0, less_sale_expenses(market_value, p.sale_expenses.rate) - debt) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_other_residential_property_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_other_residential_property_capital.py index 974b5f6825..ed969cb52e 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_other_residential_property_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_other_residential_property_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import less_sale_expenses class uc_other_residential_property_capital(Variable): @@ -21,4 +22,4 @@ def formula(household, period, parameters): p = parameters(period).gov.dwp.universal_credit.means_test.capital market_value = max_(0, household("other_residential_property_value", period)) debt = max_(0, household("other_residential_property_secured_debt", period)) - return max_(0, market_value * (1 - p.sale_expenses.rate) - debt) + return max_(0, less_sale_expenses(market_value, p.sale_expenses.rate) - debt) From b3f6f608b0aca9165b8182bc324d4139818e50cf Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 20 Oct 2026 21:50:35 -0400 Subject: [PATCH 15/48] Round capital to the penny as each programme's regulations require Sol review v4b found that rounding the input to the penny first could round up (the ADM H1665 example gave 930.94, not 930.93), that nothing was rounded at the last stage, and that UC rounds to the nearest penny. - capital.round_down per programme: false for UC (UC Regs 2013 reg 6(1); NI reg 7(1)) and HB (HB Regs 2006 reg 80; HB (SPC) reg 61(6); NI 78(8), 59(7)); true for IS (reg 27), JSA (reg 92), ESA (reg 3(a)) and Pension Credit (reg 24A), which count a fraction only to the claimant's advantage. - exact_amount removes float32 storage error only where a value is the stored form of a whole penny; other values are kept exactly. - Each valuation, each UC holding and property share, and each programme's assessed capital (the last stage) is rounded by that rule. - A recorded financial total below its owner's holding now consumes the holding at its counted value, as an override does, so no part of the holding is left for another unit. Tests: the H1665 example (930.93 / 930.94), whole-penny properties for both rules, a never-wrong-way bound for any float32 input, UC half-penny, 16,000.00 after a holding, a three-way split, IS shared-capital rounding, and reports below the holding in the reg 77 conservation grid. Co-Authored-By: Claude Opus 5.5 --- changelog.d/uc-capital-sale-expenses.fixed.md | 2 +- .../dwp/ESA/income/capital/round_down.yaml | 17 +++ .../dwp/JSA/income/capital/round_down.yaml | 17 +++ .../means_test/capital/round_down.yaml | 22 ++++ .../means_test/capital/round_down.yaml | 18 +++ .../income/capital/round_down.yaml | 17 +++ .../means_test/capital/round_down.yaml | 19 +++ .../baseline/gov/dwp/capital_valuation.yaml | 113 ++++++++++++++++-- .../universal_credit/uc_property_capital.yaml | 111 +++++++++++++++++ .../test_capital_valuation_properties.py | 69 +++++++++-- .../test_uc_company_override_properties.py | 15 ++- policyengine_uk/utils/capital_valuation.py | 84 +++++++++---- .../gov/dwp/esa_income_assessable_capital.py | 15 ++- .../housing_benefit_assessable_capital.py | 21 ++-- .../dwp/income_support_assessable_capital.py | 17 ++- .../gov/dwp/jsa_income_assessable_capital.py | 15 ++- .../pension_credit_assessable_capital.py | 19 ++- .../household_uc_pool_company_holdings.py | 17 ++- ...household_uc_reported_financial_capital.py | 50 +++++--- .../universal_credit/uc_assessable_capital.py | 42 +++++-- .../uc_non_residential_property_capital.py | 8 +- .../uc_other_residential_property_capital.py | 8 +- .../universal_credit/uc_property_capital.py | 9 +- 23 files changed, 603 insertions(+), 122 deletions(-) create mode 100644 policyengine_uk/parameters/gov/dwp/ESA/income/capital/round_down.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/JSA/income/capital/round_down.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/round_down.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/round_down.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/round_down.yaml create mode 100644 policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/round_down.yaml diff --git a/changelog.d/uc-capital-sale-expenses.fixed.md b/changelog.d/uc-capital-sale-expenses.fixed.md index 6b926ace41..b71561b5b9 100644 --- a/changelog.d/uc-capital-sale-expenses.fixed.md +++ b/changelog.d/uc-capital-sale-expenses.fixed.md @@ -1 +1 @@ -Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and corporate_wealth, not to cash savings; corporate_wealth also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land. +Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and corporate_wealth, not to cash savings; corporate_wealth also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/round_down.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/round_down.yaml new file mode 100644 index 0000000000..2a17ce9a84 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/round_down.yaml @@ -0,0 +1,17 @@ +description: > + Whether a fraction of a penny in an income-related Employment and Support + Allowance capital calculation is disregarded (true) rather than rounded to + the nearest penny (false). A fraction of a penny is treated as a penny + only where that is to the claimant's advantage, and is otherwise + disregarded; for capital that means rounding down. +values: + 2008-10-27: true +metadata: + label: Income-related ESA capital rounded down to the penny + period: year + unit: bool + reference: + - title: The Employment and Support Allowance Regulations 2008 reg. 3(a) + href: https://www.legislation.gov.uk/uksi/2008/794/regulation/3 + - title: The Employment and Support Allowance Regulations (Northern Ireland) 2008 reg. 3(a) + href: https://www.legislation.gov.uk/nisr/2008/280/regulation/3 diff --git a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/round_down.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/round_down.yaml new file mode 100644 index 0000000000..262e1207b7 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/round_down.yaml @@ -0,0 +1,17 @@ +description: > + Whether a fraction of a penny in an income-based Jobseeker's Allowance + capital calculation is disregarded (true) rather than rounded to the + nearest penny (false). A fraction of a penny is treated as a penny only + where that is to the claimant's advantage, and is otherwise disregarded; + for capital that means rounding down. +values: + 1996-10-07: true +metadata: + label: Income-based JSA capital rounded down to the penny + period: year + unit: bool + reference: + - title: The Jobseeker's Allowance Regulations 1996 reg. 92 + href: https://www.legislation.gov.uk/uksi/1996/207/regulation/92 + - title: The Jobseeker's Allowance Regulations (Northern Ireland) 1996 reg. 92 + href: https://www.legislation.gov.uk/nisr/1996/198/regulation/92 diff --git a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/round_down.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/round_down.yaml new file mode 100644 index 0000000000..30153e66fb --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/round_down.yaml @@ -0,0 +1,22 @@ +description: > + Whether a fraction of a penny in a Housing Benefit capital calculation is + disregarded (true) rather than rounded to the nearest penny (false). Any + amount determined under the regulations may, if appropriate, be rounded to + the nearest whole penny, disregarding less than half a penny and treating + half a penny or more as a penny. That is the regulations' only rounding + rule, and the model applies it. +values: + 2006-04-10: false +metadata: + label: Housing Benefit capital rounded down to the penny + period: year + unit: bool + reference: + - title: The Housing Benefit Regulations 2006 reg. 80 + href: https://www.legislation.gov.uk/uksi/2006/213/regulation/80 + - title: The Housing Benefit (Persons who have attained the qualifying age for state pension credit) Regulations 2006 reg. 61(6) + href: https://www.legislation.gov.uk/uksi/2006/214/regulation/61 + - title: The Housing Benefit Regulations (Northern Ireland) 2006 reg. 78(8) + href: https://www.legislation.gov.uk/nisr/2006/405/regulation/78 + - title: The Housing Benefit (Persons who have attained the qualifying age for state pension credit) Regulations (Northern Ireland) 2006 reg. 59(7) + href: https://www.legislation.gov.uk/nisr/2006/406/regulation/59 diff --git a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/round_down.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/round_down.yaml new file mode 100644 index 0000000000..b628746c46 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/round_down.yaml @@ -0,0 +1,18 @@ +description: > + Whether a fraction of a penny in an Income Support capital calculation is + disregarded (true) rather than rounded to the nearest penny (false). A + fraction of a penny is treated as a penny only where that is to the + claimant's advantage, and is otherwise disregarded; for capital that means + rounding down. The Northern Ireland regulation disregards any fraction of + a penny in capital. +values: + 2010-01-01: true +metadata: + label: Income Support capital rounded down to the penny + period: year + unit: bool + reference: + - title: The Income Support (General) Regulations 1987 reg. 27 + href: https://www.legislation.gov.uk/uksi/1987/1967/regulation/27 + - title: The Income Support (General) Regulations (Northern Ireland) 1987 reg. 27 + href: https://www.legislation.gov.uk/nisr/1987/459/regulation/27 diff --git a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/round_down.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/round_down.yaml new file mode 100644 index 0000000000..4170770dd6 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/round_down.yaml @@ -0,0 +1,17 @@ +description: > + Whether a fraction of a penny in a Pension Credit capital calculation is + disregarded (true) rather than rounded to the nearest penny (false). A + fraction of a penny is treated as a penny only where that is to the + claimant's advantage, and is otherwise disregarded; for capital that means + rounding down. DMG 84763 values shares the same way. +values: + 2003-10-06: true +metadata: + label: Pension Credit capital rounded down to the penny + period: year + unit: bool + reference: + - title: State Pension Credit Regulations 2002 reg. 24A + href: https://www.legislation.gov.uk/uksi/2002/1792/regulation/24A + - title: State Pension Credit Regulations (Northern Ireland) 2003 reg. 24A + href: https://www.legislation.gov.uk/nisr/2003/28/regulation/24A diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/round_down.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/round_down.yaml new file mode 100644 index 0000000000..6b34443074 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/round_down.yaml @@ -0,0 +1,19 @@ +description: > + Whether a fraction of a penny in a Universal Credit capital calculation is + disregarded (true) rather than rounded to the nearest penny (false). + Regulation 6(1) disregards a fraction of less than half a penny and treats + any other fraction as a penny, for every amount calculated under the + regulations, including the reg. 49 valuation and the capital tested + against the limit. ADM H1665 rounds a share valuation down in the + claimant's favour, but the regulation governs. +values: + 2013-04-29: false +metadata: + label: Universal Credit capital rounded down to the penny + period: year + unit: bool + reference: + - title: The Universal Credit Regulations 2013 reg. 6(1) + href: https://www.legislation.gov.uk/uksi/2013/376/regulation/6 + - title: The Universal Credit Regulations (Northern Ireland) 2016 reg. 7(1) + href: https://www.legislation.gov.uk/nisr/2016/216/regulation/7 diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml index 9f34ce7187..6984634c9f 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -294,7 +294,7 @@ guarantee_credit: 0 housing_benefit_assessable_capital: 130_000 -- name: UC rounds the share valuation down to the penny, at the capital limit +- name: UC rounds the share valuation to the nearest penny, at the capital limit period: 2026 absolute_error_margin: 0 input: @@ -307,10 +307,10 @@ households: household: members: person - # 90% of 16,666.67 is 15,000.003, rounded down to the penny in the - # claimant's favour (ADM H1665): 15,000.00. With 1,000 of savings the - # capital is exactly the 16,000 limit, which does not exceed it (WRA - # 2012 s. 5(1)(a)). + # 90% of 16,666.67 is 15,000.003, rounded to the nearest penny (UC Regs + # 2013 reg. 6(1)): 15,000.00. With 1,000 of savings the capital is + # exactly the 16,000 limit, which does not exceed it (WRA 2012 s. + # 5(1)(a)). savings: 1_000 corporate_wealth: 16_666.67 output: @@ -330,11 +330,108 @@ households: household: members: person - # 90% of 16,001 is 14,400.90 and 90% of 1,000.10 is 900.09, each - # rounded down to the penny (ADM H1665): 15,300.99. Float32 arithmetic - # would give 14,400.89 and 900.08. + # 90% of 16,001 is 14,400.90 and 90% of 1,000.10 is 900.09, exactly: + # 15,300.99. Float32 arithmetic would give 14,400.8994 and 900.0899. other_residential_property_value: 16_001 corporate_wealth: 1_000.10 output: uc_assessable_capital: 15_300.99 is_uc_eligible: true + +- name: UC rounds half a penny up, so the capital is a penny over the limit + period: 2026 + absolute_error_margin: 0 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # 90% of 16,666.65 is 14,999.985. UC Regs 2013 reg. 6(1) treats a + # fraction of half a penny or more as a penny: 14,999.99, so the capital + # is 1,000.02 + 14,999.99 = 16,000.01, over the 16,000 limit. Rounding + # down, as ADM H1665 does, would give exactly 16,000.00; the regulation + # governs the guidance. + savings: 1_000.02 + corporate_wealth: 16_666.65 + output: + uc_assessable_capital: 16_000.01 + is_uc_eligible: false + +- name: Pension Credit values shares as in the ADM and DMG worked example + period: 2026 + absolute_error_margin: 0.001 + input: + people: + person: + age: 70 + benunits: + benunit: + members: person + households: + household: + members: person + # 250 shares at 4.1375 are 1,034.375 (ADM H1665; DMG 84763). Less 10% + # for the expenses of sale that is 930.9375, and the fraction of a + # penny is disregarded because counting it would not be to the + # claimant's advantage (SPC Regs 2002 reg. 24A): 930.93. + corporate_wealth: 1_034.375 + output: + pension_credit_assessable_capital: 930.93 + +- name: UC values the worked-example shares to the nearest penny + period: 2026 + absolute_error_margin: 0.001 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # The same 930.9375 is 930.94 to the nearest penny (UC Regs 2013 reg. + # 6(1)), where ADM H1665 gives 930.93. + corporate_wealth: 1_034.375 + output: + uc_assessable_capital: 930.94 + +- name: Income Support rounds a shared capital down to the penny + period: 2021 + absolute_error_margin: 0.001 + input: + people: + first: + age: 30 + is_claimant_or_partner: true + second: + age: 30 + is_claimant_or_partner: true + third: + age: 30 + is_claimant_or_partner: true + benunits: + first_unit: + members: [first] + would_claim_IS: false + second_unit: + members: [second] + would_claim_IS: false + third_unit: + members: [third] + would_claim_IS: false + households: + household: + members: [first, second, third] + # With no Income Support claim in the household, 10,000.01 of savings + # is shared by the three adults: 3,333.3366 each, rounded down at the + # last stage (IS Regs 1987 reg. 27): 3,333.33. + savings: 10_000.01 + output: + income_support_assessable_capital: [3_333.33, 3_333.33, 3_333.33] diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/universal_credit/uc_property_capital.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/universal_credit/uc_property_capital.yaml index 7d94546a62..f522fcb351 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/universal_credit/uc_property_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/universal_credit/uc_property_capital.yaml @@ -167,3 +167,114 @@ household_uc_pool_company_holdings: 0 uc_assessable_capital: [0, 16_500] universal_credit: [5_098.80, 0] + +- name: A capital of exactly 16,000.00 after a company holding leaves the pool is within the limit + period: 2026 + absolute_error_margin: 0 + input: + people: + owner: + age: 30 + is_claimant_or_partner: true + stands_as_sole_owner_or_partner_of_company: true + owned_company_carries_on_property_business: true + owned_company_holding_value: 10_000.01 + owned_company_capital: 0 + other_claimant: + age: 30 + is_claimant_or_partner: true + benunits: + reporting: + members: [owner] + would_claim_uc: true + uc_reported_capital: 0 + missing: + members: [other_claimant] + would_claim_uc: true + households: + household: + members: [owner, other_claimant] + savings: 7_000.01 + corporate_wealth: 20_000 + output: + # The pool is 7,000.01 + 90% of 20,000 = 25,000.01. The owner's holding + # leaves it at 90% of 10,000.01 = 9,000.009, which is 9,000.01 to the + # nearest penny (UC Regs 2013 reg. 6(1)), so the other claimant has + # 16,000.00, which does not exceed the 16,000 limit. Unrounded, the + # 16,000.001 would fail it. + household_uc_reported_financial_capital: 9_000.01 + uc_assessable_capital: [0, 16_000] + is_uc_eligible: [true, true] + +- name: A capital pool shared three ways is rounded to the nearest penny at the last stage + period: 2026 + absolute_error_margin: 0 + input: + people: + first: + age: 30 + is_claimant_or_partner: true + second: + age: 30 + is_claimant_or_partner: true + third: + age: 30 + is_claimant_or_partner: true + benunits: + first_unit: + members: [first] + would_claim_uc: true + second_unit: + members: [second] + would_claim_uc: true + third_unit: + members: [third] + would_claim_uc: true + households: + household: + members: [first, second, third] + savings: 48_000.01 + output: + # A third of 48,000.01 is 16,000.0033, which is 16,000.00 to the nearest + # penny (reg. 6(1)), within the limit for each unit. + uc_assessable_capital: [16_000, 16_000, 16_000] + is_uc_eligible: [true, true, true] + +- name: A recorded financial total below its owner's company holding still consumes the holding + period: 2026 + input: + people: + owner: + age: 30 + is_claimant_or_partner: true + stands_as_sole_owner_or_partner_of_company: true + owned_company_carries_on_property_business: true + owned_company_holding_value: 10_000 + owned_company_capital: 0 + other_claimant: + age: 30 + is_claimant_or_partner: true + benunits: + reporting: + members: [owner] + would_claim_uc: true + benunit_reported_capital: 4_000 + missing: + members: [other_claimant] + would_claim_uc: true + households: + household: + members: [owner, other_claimant] + savings: 10_000 + corporate_wealth: 10_000 + output: + # All 10,000 of shares are the owner's holding, which the pool counts at + # 9,000 (reg. 49(1)(a)). The recorded 4,000 is below the holding, so it + # has no part beyond it and consumes the holding at its counted 9,000, + # as an override would. The other claimant keeps only the 10,000 of + # savings: none of the holding is left for them to count. The owner's + # own assessment takes the full holding off the report: max(0, 4,000 - + # 10,000) = 0. + household_uc_reported_financial_capital: 9_000 + household_uc_pool_company_holdings: 0 + uc_assessable_capital: [0, 10_000] diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 430628cb2f..855a88c59c 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -26,10 +26,15 @@ (Isolation between two encumbered sources is pinned by the differential and by a YAML case.) 6. Pennies: 90% of any whole-penny value stored as a float32 input is the - exact figure rounded down to the penny (ADM H1665), checked in integer - pence up to 131,071.99, the largest value float32 holds to the penny. + exact figure rounded down (the legacy benefits) or to the nearest penny + (Universal Credit and Housing Benefit), checked in integer pence up to + 131,071.99, the largest value float32 holds to the penny. +7. Never rounds the wrong way: for any stored value, whole penny or not, the + result is within a penny below 90% of the exact stored value when rounding + down, and within half a penny of it when rounding to the nearest penny. """ +from fractions import Fraction from functools import reduce import numpy as np @@ -37,7 +42,7 @@ from hypothesis import strategies as st from policyengine_uk import Simulation -from policyengine_uk.utils.capital_valuation import less_sale_expenses +from policyengine_uk.utils.capital_valuation import exact_amount, less_sale_expenses YEAR = 2026 PROPERTY_SETTINGS = settings( @@ -287,11 +292,55 @@ def test_capital_is_non_increasing_in_rate_and_secured_debt(units, r1, r2, scale @settings(max_examples=200, deadline=None, derandomize=True) @given(st.lists(st.integers(0, 13_107_199), min_size=1, max_size=1_000)) # 16,001 is 14,400.8994 after a float32 multiplication; 1,000.10 is stored as -# 1,000.0999756; 12,000 is 10,799.9999999 in binary. -@example([1_600_100, 100_010, 1_200_000]) -def test_sale_expenses_round_down_to_the_penny(pence): +# 1,000.0999756; 90% of 2.30 is 206.99999999999997 pence in float64; 90% of +# 16,666.65 is 14,999.985, a half penny. +@example([1_600_100, 100_010, 230, 1_666_665]) +def test_sale_expenses_round_to_the_penny(pence): stored = np.asarray(pence, dtype=np.int64).astype(np.float32) / np.float32(100) - valued = less_sale_expenses(stored, LEGAL_RATE) - assert valued.dtype == np.float64 - exact = [9 * amount // 10 for amount in pence] - assert np.round(valued * 100).astype(np.int64).tolist() == exact + down = less_sale_expenses(stored, LEGAL_RATE, True) + nearest = less_sale_expenses(stored, LEGAL_RATE, False) + assert down.dtype == nearest.dtype == np.float64 + assert np.round(down * 100).astype(np.int64).tolist() == [ + 9 * amount // 10 for amount in pence + ] + assert np.round(nearest * 100).astype(np.int64).tolist() == [ + (9 * amount + 5) // 10 for amount in pence + ] + + +def test_share_valuation_matches_the_adm_worked_example(): + # ADM H1665 and DMG 84763: 250 shares at 4.1375 are 1,034.375, and less + # 10% for the expenses of sale that is 930.9375: 930.93 rounded down, as + # the legacy benefits do, or 930.94 to the nearest penny, as Universal + # Credit does (UC Regs 2013 reg. 6(1)). + for stored in (1034.375, np.float32(1034.375)): + assert less_sale_expenses(stored, LEGAL_RATE, True) == 930.93 + assert less_sale_expenses(stored, LEGAL_RATE, False) == 930.94 + + +@settings(max_examples=200, deadline=None, derandomize=True) +@given( + st.lists( + st.floats(0, 1_000_000, allow_nan=False, width=32), min_size=1, max_size=500 + ) +) +@example([1034.375, 10352.055, 0.005, 999_999.875]) +def test_sale_expenses_never_round_the_wrong_way(values): + stored = np.asarray(values, dtype=np.float32) + exact = exact_amount(stored) + # Storage error is removed only within half a unit of the stored value's + # own precision, so a value is never moved to a penny it was not stored + # from. + assert np.all( + np.abs(exact - stored.astype(np.float64)) + <= np.spacing(np.abs(stored)).astype(np.float64) / 2 + ) + down = less_sale_expenses(stored, LEGAL_RATE, True) + nearest = less_sale_expenses(stored, LEGAL_RATE, False) + for value, low, near in zip(exact.tolist(), down.tolist(), nearest.tolist()): + # Exact rational arithmetic on the value the helper works from, with + # the helper's millionth-of-a-penny allowance for binary noise. + target = Fraction(value) * Fraction(9, 10) + noise = Fraction(1, 100_000_000) + assert target - Fraction(1, 100) - noise < Fraction(low) <= target + noise + assert abs(Fraction(near) - target) <= Fraction(1, 200) + noise diff --git a/policyengine_uk/tests/test_uc_company_override_properties.py b/policyengine_uk/tests/test_uc_company_override_properties.py index c6b426f401..1fac837bf1 100644 --- a/policyengine_uk/tests/test_uc_company_override_properties.py +++ b/policyengine_uk/tests/test_uc_company_override_properties.py @@ -56,7 +56,7 @@ def _company_person(holding=0, dependant=False): def _grid(layout): - """Combine 960 independent three-unit households in one simulation.""" + """Combine 1,280 independent three-unit households in one simulation.""" people, units, households, cases = {}, {}, {}, [] first_holdings, dependant_holdings, second_holdings = LAYOUTS[layout] claimant_holdings = (sum(first_holdings), sum(second_holdings), 0) @@ -70,7 +70,7 @@ def _grid(layout): ) in enumerate( product( (0, 4_000, 10_000, 20_000), - (None, -1, 10_000), + (None, -1, 4_000, 10_000), (0, 4_000, 10_000, 20_000), (6_000, 20_000), OTHER_REPORTS, @@ -157,12 +157,14 @@ def test_company_overrides_conserve_capital_and_keep_holdings_out_of_other_units market_holdings = [holding * scale for holding in bounded_holdings] effective_holdings = [SHARE_VALUE * holding for holding in market_holdings] # A recorded financial total holds its owners' holdings at full value; - # the pool counts them at 90%, so its known holding part is consumed at - # 90% (reg. 49(1)(a)) and the rest of the report in full. + # the pool counts them at 90% (reg. 49(1)(a)), so the report consumes + # its part beyond the holdings in full and the holdings at 90%. Like an + # override, a report below the holdings still consumes them: a report + # of 4,000 against a 10,000 holding consumes 9,000. explicit_consumption = sum( spec["override"] if "override" in spec - else max(0, spec["financial"] - (1 - SHARE_VALUE) * market) + else max(0, spec["financial"] - market) + SHARE_VALUE * market if spec.get("financial", -1) >= 0 else 0 for spec, market in zip(specs, market_holdings) @@ -205,7 +207,8 @@ def test_company_overrides_conserve_capital_and_keep_holdings_out_of_other_units owner_substitution = sum( min(SHARE_VALUE * holding, reported) if "override" in spec - else max(0, reported - (1 - SHARE_VALUE) * market) + else max(0, reported - market) + + SHARE_VALUE * market - max(0, reported - holding) for holding, market, reported, absent, spec in zip( holdings, market_holdings, explicit, missing, specs diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index cd9cb0035c..10396761dc 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -6,7 +6,9 @@ The legacy means tests have equivalent rules (HB Regs 2006 reg. 47, IS Regs 1987 reg. 49, JSA Regs 1996 reg. 111, ESA Regs 2008 reg. 113, SPC Regs 2002 reg. 19). Each programme sets its own rate and the capital sources whose sale -would incur expenses in a ``capital.sale_expenses`` parameter node. +would incur expenses in a ``capital.sale_expenses`` parameter node, and how it +rounds a fraction of a penny in ``capital.round_down``: to the nearest penny +for Universal Credit and Housing Benefit, down for the others. """ import numpy as np @@ -25,22 +27,26 @@ } -def valued_capital(value_of, sources, sale_expenses): - """Sum ``sources`` at market value less sale expenses and secured debt. +def valued_capital(value_of, capital): + """Sum ``capital.sources`` at market value less sale expenses and secured debt. ``value_of(variable)`` returns that household variable on the entity the - caller is working with. The sale-expense deduction is taken from the gross - value before the encumbrance (ADM H1608) and the result rounded down to the - penny in the claimant's favour, as ADM H1665 does for quoted shares. A - source carrying secured debt is never valued below nil. + caller is working with, and ``capital`` is the programme's capital + parameter node. The sale-expense deduction is taken from the gross value + before the encumbrance (ADM H1608), and each valuation is rounded to the + penny under the programme's rule. A source carrying secured debt is never + valued below nil. The total is in float64, unrounded: the caller rounds + the capital it assesses at the last stage (``round_to_penny``). """ total = 0 - for source in sources: - value = value_of(source) - if source in sale_expenses.sources: - value = less_sale_expenses(value, sale_expenses.rate) + for source in capital.sources: + value = exact_amount(value_of(source)) + if source in capital.sale_expenses.sources: + value = less_sale_expenses( + value, capital.sale_expenses.rate, capital.round_down + ) if source in SECURED_DEBT: - value = max_(0, value - value_of(SECURED_DEBT[source])) + value = max_(0, value - exact_amount(value_of(SECURED_DEBT[source]))) total = total + value return total @@ -51,22 +57,50 @@ def counted_share(sale_expenses, source): return 1 - sale_expenses.rate if source in sale_expenses.sources else 1 -def less_sale_expenses(value, rate): - """Market value less the sale-expense ``rate`` (reg. 49(1)(a)), rounded - down to the penny in the claimant's favour (ADM H1665). +def less_sale_expenses(value, rate, round_down): + """Market value less the sale-expense ``rate`` (reg. 49(1)(a)), rounded to + the penny under the programme's rule. - Inputs are stored in float32, and a float32 product loses pennies: 90% of - 16,001 is 14,400.8994 in float32 rather than 14,400.90. So the value is - taken to the penny in float64 before the deduction.""" - pounds = np.round(np.asarray(value, dtype=np.float64), 2) - return penny_floor(pounds * (1 - np.asarray(rate, dtype=np.float64))) + The deduction is worked on the exact stored value: 250 shares at £4.1375 + are £1,034.375, and less 10% that is £930.9375, so £930.93 rounded down + (ADM H1665) or £930.94 to the nearest penny (UC Regs 2013 reg. 6(1)).""" + return round_to_penny( + exact_amount(value) * (1 - np.asarray(rate, dtype=np.float64)), round_down + ) -def penny_floor(amount): - """Round down to the penny, in the claimant's favour (ADM H1665). +def exact_amount(amount): + """``amount`` in float64, with float32 storage error removed. + + Inputs are stored in float32, which holds £1,000.10 as 1,000.0999756 and + 90% of £16,001 as 14,400.8994. A value is taken to be a whole penny when + that penny is within half a unit of the value's own precision, so it is + the penny the value was stored from; any other value (a share price to + four decimal places, say) is kept exactly as stored. Above £131,072 + float32 cannot hold every penny, so a penny lost in storage there cannot + be recovered.""" + stored = np.asarray(amount) + wide = stored.astype(np.float64) + pennies = np.round(wide, 2) + # An infinite amount has no precision to compare against and passes through. + with np.errstate(over="ignore", invalid="ignore"): + stored_from_penny = np.abs(pennies - wide) <= np.spacing(np.abs(stored)) / 2 + return np.where(stored_from_penny, pennies, wide) + + +def round_to_penny(amount, round_down): + """Round ``amount`` to the penny: down where ``round_down``, otherwise to + the nearest penny with half a penny rounded up. + + Universal Credit treats a fraction of half a penny or more as a penny and + disregards a smaller one (UC Regs 2013 reg. 6(1)), and Housing Benefit may + do the same (HB Regs 2006 reg. 80). The legacy benefits treat a fraction + as a penny only where that is to the claimant's advantage (IS Regs 1987 + reg. 27, JSA Regs 1996 reg. 92, ESA Regs 2008 reg. 3(a), SPC Regs 2002 + reg. 24A), which for capital means rounding down. Computed in float64, and rounded to a millionth of a penny first, so binary - noise just under a whole penny (10,799.9999999 for 90% of 12,000) does not - lose a penny.""" + noise next to a whole or half penny (206.99999999999997 pence for 90% of + £2.30) does not move it.""" pence = np.round(np.asarray(amount, dtype=np.float64) * 100, 6) - return np.floor(pence) / 100 + return np.where(round_down, np.floor(pence), np.floor(pence + 0.5)) / 100 diff --git a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py index 1d760dfb38..fd66242987 100644 --- a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py @@ -1,5 +1,9 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import valued_capital +from policyengine_uk.utils.capital_valuation import ( + exact_amount, + round_to_penny, + valued_capital, +) class esa_income_assessable_capital(Variable): @@ -27,14 +31,12 @@ class esa_income_assessable_capital(Variable): def formula(benunit, period, parameters): ESA = parameters(period).gov.dwp.ESA.income - sources = ESA.capital.sources person = benunit.members claiming_esa_income = add(benunit, period, ["esa_income_reported"]) > 0 household_capital = valued_capital( lambda variable: benunit.max(person.household(variable, period)), - sources, - ESA.capital.sale_expenses, + ESA.capital, ) # Regulation 83(2) excludes children's and young persons' capital. # The claimant/partner weights approximate otherwise unobserved ownership. @@ -54,10 +56,11 @@ def formula(benunit, period, parameters): ) claimant_or_partner = person("is_claimant_or_partner", period) person_capital = sum( - benunit.sum(person(source, period) * claimant_or_partner) + benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) for source in ESA.capital.person_sources ) household_share = where( household_reporting_claimants > 0, claiming_proxy, fallback_proxy ) - return household_share + person_capital + # A fraction of a penny is disregarded at the last stage (reg. 3(a)). + return round_to_penny(household_share + person_capital, ESA.capital.round_down) diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py index ce0b138b81..44c381268e 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py @@ -1,5 +1,9 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import valued_capital +from policyengine_uk.utils.capital_valuation import ( + exact_amount, + round_to_penny, + valued_capital, +) class housing_benefit_assessable_capital(Variable): @@ -47,11 +51,11 @@ def formula(benunit, period, parameters): ) p = parameters(period).gov.dwp.housing_benefit.means_test.capital household_capital = valued_capital( - lambda variable: household(variable, period), p.sources, p.sale_expenses + lambda variable: household(variable, period), p ) claimant_or_partner = person("is_claimant_or_partner", period) person_capital = sum( - benunit.sum(person(source, period) * claimant_or_partner) + benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) for source in p.person_sources ) benunit_claimants_and_partners = add( @@ -80,7 +84,7 @@ def formula(benunit, period, parameters): ) capital = where( savings_credit_only, - benunit("pension_credit_assessable_capital", period), + exact_amount(benunit("pension_credit_assessable_capital", period)), household_capital_proxy + person_capital, ) # Guarantee Credit passport: SI 2006/214 reg 26 (NI: SR 2006/406 @@ -102,8 +106,9 @@ def formula(benunit, period, parameters): on_passporting_benefit = benunit( "housing_benefit_on_passporting_benefit", period ) - return where( - passported | on_passporting_benefit, - 0, - max_(0, capital), + # Rounded to the nearest penny at the last stage (reg. 80; HB (SPC) + # Regs 2006 reg. 61(6)). + return round_to_penny( + where(passported | on_passporting_benefit, 0, max_(0, capital)), + p.round_down, ) diff --git a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py index e382b938f1..33df6b0840 100644 --- a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py @@ -1,5 +1,9 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import valued_capital +from policyengine_uk.utils.capital_valuation import ( + exact_amount, + round_to_penny, + valued_capital, +) class income_support_assessable_capital(Variable): @@ -26,7 +30,6 @@ class income_support_assessable_capital(Variable): def formula(benunit, period, parameters): IS = parameters(period).gov.dwp.income_support - sources = IS.means_test.capital.sources person = benunit.members would_claim_is = benunit("would_claim_IS", period) @@ -38,8 +41,7 @@ def formula(benunit, period, parameters): # the household allocation itself is a modelling convention. household_capital = valued_capital( lambda variable: benunit.max(person.household(variable, period)), - sources, - IS.means_test.capital.sale_expenses, + IS.means_test.capital, ) benunit_claimants_and_partners = add( benunit, period, ["is_claimant_or_partner"] @@ -60,10 +62,13 @@ def formula(benunit, period, parameters): ) claimant_or_partner = person("is_claimant_or_partner", period) person_capital = sum( - benunit.sum(person(source, period) * claimant_or_partner) + benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) for source in IS.means_test.capital.person_sources ) household_share = where( household_claiming_members > 0, claiming_proxy, fallback_proxy ) - return household_share + person_capital + # A fraction of a penny is disregarded at the last stage (reg. 27). + return round_to_penny( + household_share + person_capital, IS.means_test.capital.round_down + ) diff --git a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py index c83148a1b4..1cf104940a 100644 --- a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py @@ -1,5 +1,9 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import valued_capital +from policyengine_uk.utils.capital_valuation import ( + exact_amount, + round_to_penny, + valued_capital, +) class jsa_income_assessable_capital(Variable): @@ -27,14 +31,12 @@ class jsa_income_assessable_capital(Variable): def formula(benunit, period, parameters): JSA = parameters(period).gov.dwp.JSA.income - sources = JSA.capital.sources person = benunit.members claiming_jsa_income = add(benunit, period, ["jsa_income_reported"]) > 0 household_capital = valued_capital( lambda variable: benunit.max(person.household(variable, period)), - sources, - JSA.capital.sale_expenses, + JSA.capital, ) # Regulation 88(2) excludes children's and young persons' capital. # The claimant/partner weights approximate otherwise unobserved ownership. @@ -54,10 +56,11 @@ def formula(benunit, period, parameters): ) claimant_or_partner = person("is_claimant_or_partner", period) person_capital = sum( - benunit.sum(person(source, period) * claimant_or_partner) + benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) for source in JSA.capital.person_sources ) household_share = where( household_reporting_claimants > 0, claiming_proxy, fallback_proxy ) - return household_share + person_capital + # A fraction of a penny is disregarded at the last stage (reg. 92). + return round_to_penny(household_share + person_capital, JSA.capital.round_down) diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py index 3e3914d5be..bf33736ef9 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py @@ -1,5 +1,9 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import valued_capital +from policyengine_uk.utils.capital_valuation import ( + exact_amount, + round_to_penny, + valued_capital, +) class pension_credit_assessable_capital(Variable): @@ -31,11 +35,11 @@ def formula(benunit, period, parameters): person = benunit.members p = parameters(period).gov.dwp.pension_credit.income.capital household_capital = valued_capital( - lambda variable: household(variable, period), p.sources, p.sale_expenses + lambda variable: household(variable, period), p ) claimant_or_partner = person("is_claimant_or_partner", period) person_capital = sum( - benunit.sum(person(source, period) * claimant_or_partner) + benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) for source in p.person_sources ) any_pension_age = benunit.any( @@ -55,10 +59,15 @@ def formula(benunit, period, parameters): household_capital_proxy = ( household_capital * benunit_pension_age_adults / adult_divisor ) - reported_capital = benunit("pension_credit_reported_capital", period) + reported_capital = exact_amount( + benunit("pension_credit_reported_capital", period) + ) assessed_capital = where( reported_capital >= 0, reported_capital, household_capital_proxy + person_capital, ) - return where(any_pension_age, max_(0, assessed_capital), 0) + # A fraction of a penny is disregarded at the last stage (reg. 24A). + return round_to_penny( + where(any_pension_age, max_(0, assessed_capital), 0), p.round_down + ) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py index 622b04a944..c4d6236d29 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py @@ -1,5 +1,9 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import counted_share +from policyengine_uk.utils.capital_valuation import ( + counted_share, + exact_amount, + round_to_penny, +) class household_uc_pool_company_holdings(Variable): @@ -54,8 +58,10 @@ def formula(household, period, parameters): off_reported_capital = ( has_financial_report | has_complete_override ) & claimant_or_partner - holding = person("uc_company_holding_disregard", period) - upper_bound = max_(0, person.household("corporate_wealth", period)) + holding = exact_amount(person("uc_company_holding_disregard", period)) + upper_bound = max_( + 0, exact_amount(person.household("corporate_wealth", period)) + ) finite_holding = np.where( np.isfinite(holding), holding, np.where(holding > 0, upper_bound, 0) ) @@ -67,4 +73,7 @@ def formula(household, period, parameters): # The holdings sit in corporate_wealth, which the pool counts at the # reg. 49(1) value, so they leave it at that value. p = parameters(period).gov.dwp.universal_credit.means_test.capital - return holdings * counted_share(p.sale_expenses, "corporate_wealth") + return round_to_penny( + holdings * counted_share(p.sale_expenses, "corporate_wealth"), + p.round_down, + ) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py index 6daf295adc..0a09bcfec1 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py @@ -1,5 +1,9 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import counted_share +from policyengine_uk.utils.capital_valuation import ( + counted_share, + exact_amount, + round_to_penny, +) class household_uc_reported_financial_capital(Variable): @@ -30,7 +34,12 @@ class household_uc_reported_financial_capital(Variable): "holding leaves the pool separately in household_uc_pool_company_holdings. " "Subtracting complete overrides retains the inherited residual-pool " "convention. The scale changes only deductions from the household " - "pool, not regulation 77 substitution in the owner's own assessment." + "pool, not regulation 77 substitution in the owner's own assessment. " + "A recorded financial total is unvalued, so it consumes its part " + "beyond its claimants' holdings in full and the holdings at their " + "counted value. Like an override, a total below the holdings still " + "consumes them, so no part of an owner's holding is left in the pool " + "for another unit to count." ) definition_period = YEAR unit = GBP @@ -38,36 +47,41 @@ class household_uc_reported_financial_capital(Variable): def formula(household, period, parameters): person = household.members - financial_capital = person.benunit("benunit_reported_capital", period) - complete_override = person.benunit("uc_reported_capital", period) - holding = person("uc_company_holding_disregard", period) - upper_bound = max_(0, person.household("corporate_wealth", period)) + financial_capital = exact_amount( + person.benunit("benunit_reported_capital", period) + ) + complete_override = exact_amount(person.benunit("uc_reported_capital", period)) + holding = exact_amount(person("uc_company_holding_disregard", period)) + upper_bound = max_( + 0, exact_amount(person.household("corporate_wealth", period)) + ) finite_holding = np.where( np.isfinite(holding), holding, np.where(holding > 0, upper_bound, 0) ) bounded_holdings = np.clip(finite_holding, 0, upper_bound) - # Match the claimant holding variable's storage precision before scaling. own_holdings = person.benunit.sum( bounded_holdings * person("is_uc_claimant", period) - ).astype(holding.dtype) * person.household( - "household_uc_company_holding_pool_scale", period - ) + ) * person.household("household_uc_company_holding_pool_scale", period) # The pool counts corporate_wealth, and the holdings in it, at the reg. - # 49(1) value. A complete override is a countable figure, so the - # holdings it must at least cover are counted at that value. A recorded - # financial total is used unvalued and holds the holdings at full value, - # so its known holding part is consumed at the counted value too; the - # owner's own assessment still takes the full holding off the report. + # 49(1) value, rounded to the nearest penny (reg. 6(1)). A complete + # override is a countable figure, so the holdings it must at least + # cover are counted at that value. A recorded financial total is used + # unvalued and holds the holdings at full value, so it consumes its + # part beyond the holdings in full and the holdings at their counted + # value; a total below the holdings still consumes them, so no part of + # an owner's holding is left for another unit. The owner's own + # assessment still takes the full holding off the report. p = parameters(period).gov.dwp.universal_credit.means_test.capital - valued_holdings = own_holdings * counted_share( - p.sale_expenses, "corporate_wealth" + valued_holdings = round_to_penny( + own_holdings * counted_share(p.sale_expenses, "corporate_wealth"), + p.round_down, ) consumed_capital = where( complete_override >= 0, max_(complete_override, valued_holdings), where( financial_capital >= 0, - max_(0, financial_capital - (own_holdings - valued_holdings)), + max_(0, financial_capital - own_holdings) + valued_holdings, financial_capital, ), ) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py index 86883504da..dbee1c5ab3 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py @@ -1,5 +1,10 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import counted_share, valued_capital +from policyengine_uk.utils.capital_valuation import ( + counted_share, + exact_amount, + round_to_penny, + valued_capital, +) class uc_assessable_capital(Variable): @@ -33,7 +38,9 @@ class uc_assessable_capital(Variable): "disregarded holding comes off at the value at which it was counted: " "90% in the pool and in a complete override, which is a countable " "figure, and in full from a recorded financial total, which is used " - "without valuation." + "without valuation. Every amount calculated is rounded to the nearest " + "penny (regulation 6(1)), including this capital, which is tested " + "against the limit." ) definition_period = YEAR unit = GBP @@ -49,7 +56,7 @@ def formula(benunit, period, parameters): household = benunit.household p = parameters(period).gov.dwp.universal_credit.means_test.capital household_financial_capital = valued_capital( - lambda variable: household(variable, period), p.sources, p.sale_expenses + lambda variable: household(variable, period), p ) # A reg. 77 holding sits in corporate_wealth, so it is counted at the # same 90% as the shares around it wherever they are valued. @@ -57,19 +64,21 @@ def formula(benunit, period, parameters): claimant_or_partner = benunit.members("is_uc_claimant", period) benunit_claimants = benunit.sum(claimant_or_partner) person_capital = sum( - benunit.sum(benunit.members(source, period) * claimant_or_partner) + benunit.sum( + exact_amount(benunit.members(source, period)) * claimant_or_partner + ) for source in p.person_sources ) - financial_report = benunit("benunit_reported_capital", period) - complete_override = benunit("uc_reported_capital", period) + financial_report = exact_amount(benunit("benunit_reported_capital", period)) + complete_override = exact_amount(benunit("uc_reported_capital", period)) unreported_claimants = household("household_uc_unreported_claimants", period) # Each unit consumes its complete override, otherwise its financial # report, from the financial pool under the inherited convention. residual_financial_capital = max_( 0, household_financial_capital - - household("household_uc_reported_financial_capital", period) - - household("household_uc_pool_company_holdings", period), + - exact_amount(household("household_uc_reported_financial_capital", period)) + - exact_amount(household("household_uc_pool_company_holdings", period)), ) financial_proxy = where( unreported_claimants > 0, @@ -79,7 +88,7 @@ def formula(benunit, period, parameters): 0, ) own_holdings = benunit.sum( - benunit.members("uc_company_holding_disregard", period) + exact_amount(benunit.members("uc_company_holding_disregard", period)) * claimant_or_partner ) financial_capital = where( @@ -89,10 +98,17 @@ def formula(benunit, period, parameters): ) assessed_capital = where( complete_override >= 0, - max_(0, complete_override - own_holdings * holding_value), - financial_capital + benunit("uc_property_capital", period), + max_( + 0, + complete_override + - round_to_penny(own_holdings * holding_value, p.round_down), + ), + financial_capital + exact_amount(benunit("uc_property_capital", period)), ) company_capital = benunit.sum( - benunit.members("uc_company_capital", period) * claimant_or_partner + exact_amount(benunit.members("uc_company_capital", period)) + * claimant_or_partner ) - return max_(0, assessed_capital) + company_capital + # Every amount is rounded to the nearest penny (reg. 6(1)), the + # capital tested against the limit included. + return round_to_penny(max_(0, assessed_capital) + company_capital, p.round_down) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_non_residential_property_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_non_residential_property_capital.py index 2d804975a6..4574f8ad39 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_non_residential_property_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_non_residential_property_capital.py @@ -1,5 +1,5 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import less_sale_expenses +from policyengine_uk.utils.capital_valuation import exact_amount, less_sale_expenses class uc_non_residential_property_capital(Variable): @@ -22,4 +22,8 @@ def formula(household, period, parameters): p = parameters(period).gov.dwp.universal_credit.means_test.capital market_value = max_(0, household("non_residential_property_value", period)) debt = max_(0, household("non_residential_property_secured_debt", period)) - return max_(0, less_sale_expenses(market_value, p.sale_expenses.rate) - debt) + return max_( + 0, + less_sale_expenses(market_value, p.sale_expenses.rate, p.round_down) + - exact_amount(debt), + ) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_other_residential_property_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_other_residential_property_capital.py index ed969cb52e..fec4d08457 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_other_residential_property_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_other_residential_property_capital.py @@ -1,5 +1,5 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import less_sale_expenses +from policyengine_uk.utils.capital_valuation import exact_amount, less_sale_expenses class uc_other_residential_property_capital(Variable): @@ -22,4 +22,8 @@ def formula(household, period, parameters): p = parameters(period).gov.dwp.universal_credit.means_test.capital market_value = max_(0, household("other_residential_property_value", period)) debt = max_(0, household("other_residential_property_secured_debt", period)) - return max_(0, less_sale_expenses(market_value, p.sale_expenses.rate) - debt) + return max_( + 0, + less_sale_expenses(market_value, p.sale_expenses.rate, p.round_down) + - exact_amount(debt), + ) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_property_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_property_capital.py index 7ae4bbb10e..2a673af312 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_property_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_property_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import exact_amount, round_to_penny class uc_property_capital(Variable): @@ -28,11 +29,15 @@ class uc_property_capital(Variable): def formula(benunit, period, parameters): p = parameters(period).gov.dwp.universal_credit.means_test.capital household_property = sum( - benunit.household(source, period) for source in p.property_sources + exact_amount(benunit.household(source, period)) + for source in p.property_sources ) person = benunit.members household_claimants = benunit.max( person.household.sum(person.household.members("is_uc_claimant", period)) ) benunit_claimants = benunit.sum(person("is_uc_claimant", period)) - return household_property * benunit_claimants / max_(1, household_claimants) + return round_to_penny( + household_property * benunit_claimants / max_(1, household_claimants), + p.round_down, + ) From 9b9ef669ac7169c9e7719bcf953f0e68205425ed Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 21 Oct 2026 23:52:09 -0400 Subject: [PATCH 16/48] Keep stored whole pennies through float64 paths; fix the CI failures Sol review v5 at b3f6f608b: - exact_amount raised an underflow warning on zero inputs, failing test_warning_filters. Errors are now ignored inside np.errstate, and twice the gap is compared with the spacing. - IS, JSA and ESA read household values through benunit.max, which is float64, so exact_amount used float64 spacing and never removed float32 storage error: 16,000.01 of savings floored to 16,000.00, at the limit. A value equal to its float32 is now judged at float32 spacing. - From 131,072 float32 cannot hold every penny, so no penny is identified and the stored value is kept; rounding down then never goes against the claimant. - The Lifetime ISA's 75% and UC company capital are worked in float64 from the stored amounts; company capital is rounded under reg. 6(1). - test_uc_capital_allocation expected exact conservation; each share is now its own nearest-penny amount (1.00 three ways is 0.33 each). - Docstrings: the guard's intended tolerance; no report leaves a holding in the pool. Tests: a model-level property that every programme counts whole-penny savings, shares and Lifetime ISA balances to the penny; widened-input and above-131,072 helper checks; YAML for 16,000.01 of savings under IS, JSA and ESA and a 1,000.04 Lifetime ISA. Co-Authored-By: Claude Opus 5.5 --- .../test_uc_capital_allocation.py | 37 +++++- .../baseline/gov/dwp/capital_valuation.yaml | 44 +++++++ .../test_capital_valuation_properties.py | 120 ++++++++++++++++-- policyengine_uk/utils/capital_valuation.py | 36 ++++-- .../gov/dwp/lifetime_isa_countable_capital.py | 5 +- .../company/uc_company_capital.py | 13 +- .../household_uc_pool_company_holdings.py | 6 +- 7 files changed, 229 insertions(+), 32 deletions(-) diff --git a/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/test_uc_capital_allocation.py b/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/test_uc_capital_allocation.py index fe82f6aa46..bfc742c641 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/test_uc_capital_allocation.py +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/test_uc_capital_allocation.py @@ -1,8 +1,16 @@ -"""The financial proxy conserves residual capital after financial observations.""" +"""The financial proxy conserves residual capital after financial observations. + +Each unreported unit's share of the residual is its own amount, rounded to the +nearest penny with half a penny rounded up (UC Regs 2013 reg. 6(1)), so the +shares add up to the residual to within half a penny per unit: 1.00 shared +three ways is 0.33 each. +""" + +from decimal import ROUND_HALF_UP, Decimal import numpy as np import pytest -from hypothesis import HealthCheck, given, settings, strategies as st +from hypothesis import HealthCheck, example, given, settings, strategies as st from policyengine_core.simulations import Simulation from policyengine_uk.system import system @@ -29,6 +37,10 @@ def household_capital_situations(draw): max_size=3, ) ) + return build_situation(household_specs) + + +def build_situation(household_specs): people, benunits, households, expected = {}, {}, {}, [] for household_index, (capital, unit_specs) in enumerate(household_specs): household_members = [] @@ -56,7 +68,7 @@ def household_capital_situations(draw): if has_reported: reported_values[len(benunits)] = reported_capital else: - unreported_indices.append(len(benunits)) + unreported_indices.append((len(benunits), claimant_count)) benunits[unit_id] = { "members": members, "benunit_reported_capital": { @@ -78,6 +90,10 @@ def household_capital_situations(draw): return {"people": people, "benunits": benunits, "households": households}, expected +def nearest_penny(amount): + return float(amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)) + + # Test conservation independently of machine-dependent generation timings. @settings( max_examples=30, @@ -85,6 +101,8 @@ def household_capital_situations(draw): suppress_health_check=[HealthCheck.too_slow], ) @given(household_capital_situations()) +# 1.00 of savings shared by three single claimants is 0.33 each, 0.99 in all. +@example(build_situation([(1, [(1, 0, False, 0)] * 3)])) def test_unreported_capital_shares_sum_to_each_households_residual(case): situation, expected = case # Reuse baseline rules; each example still gets fresh people and inputs. @@ -92,7 +110,16 @@ def test_unreported_capital_shares_sum_to_each_households_residual(case): assessed_capital = simulation.calculate("uc_assessable_capital", 2025) assert np.isfinite(assessed_capital).all() - for unreported_indices, reported_values, residual in expected: - assert assessed_capital[unreported_indices].sum() == pytest.approx(residual) + for unreported_units, reported_values, residual in expected: + claimants = sum(count for _, count in unreported_units) + for index, count in unreported_units: + share = Decimal(residual) * count / claimants + assert assessed_capital[index] == pytest.approx( + nearest_penny(share), abs=0.001 + ) + indices = [index for index, _ in unreported_units] + assert assessed_capital[indices].sum() == pytest.approx( + residual, abs=0.005 * len(indices) + 0.001 + ) for index, reported_capital in reported_values.items(): assert assessed_capital[index] == pytest.approx(reported_capital) diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml index 6984634c9f..b3b2efe488 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -435,3 +435,47 @@ savings: 10_000.01 output: income_support_assessable_capital: [3_333.33, 3_333.33, 3_333.33] + +- name: Legacy benefits count 16,000.01 of savings in full, over the limit + period: 2026 + absolute_error_margin: 0.004 + input: + people: + person: + age: 30 + benunits: + benunit: + members: person + households: + household: + members: person + # Stored in float32 as 16,000.0098, which is the penny 16,000.01: + # rounding down at the last stage (IS Regs 1987 reg. 27; JSA Regs 1996 + # reg. 92; ESA Regs 2008 reg. 3(a)) must not turn the storage error + # into a lost penny, which would put the capital at the 16,000 limit. + savings: 16_000.01 + output: + income_support_assessable_capital: 16_000.01 + jsa_income_assessable_capital: 16_000.01 + esa_income_assessable_capital: 16_000.01 + +- name: A Lifetime ISA counts at 75% of its balance to the penny + period: 2026 + absolute_error_margin: 0.004 + input: + people: + person: + age: 30 + lifetime_isa_balance: 1_000.04 + benunits: + benunit: + members: person + households: + household: + members: person + output: + # 75% of 1,000.04 is 750.03, its surrender value below age 60. + lifetime_isa_countable_capital: 750.03 + income_support_assessable_capital: 750.03 + esa_income_assessable_capital: 750.03 + uc_assessable_capital: 750.03 diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 855a88c59c..2af8e32aa2 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -32,6 +32,12 @@ 7. Never rounds the wrong way: for any stored value, whole penny or not, the result is within a penny below 90% of the exact stored value when rounding down, and within half a penny of it when rounding to the nearest penny. + The same holds for a float32 value widened to float64, as a benefit unit's + maximum over its household's values is. +8. Whole pennies through the model: every programme counts whole-penny + savings, shares and Lifetime ISA balances to the penny: savings in full, + shares at 90% rounded by the programme's rule, and a Lifetime ISA at 75% + below its charge-free age. """ from fractions import Fraction @@ -297,15 +303,18 @@ def test_capital_is_non_increasing_in_rate_and_secured_debt(units, r1, r2, scale @example([1_600_100, 100_010, 230, 1_666_665]) def test_sale_expenses_round_to_the_penny(pence): stored = np.asarray(pence, dtype=np.int64).astype(np.float32) / np.float32(100) - down = less_sale_expenses(stored, LEGAL_RATE, True) - nearest = less_sale_expenses(stored, LEGAL_RATE, False) - assert down.dtype == nearest.dtype == np.float64 - assert np.round(down * 100).astype(np.int64).tolist() == [ - 9 * amount // 10 for amount in pence - ] - assert np.round(nearest * 100).astype(np.int64).tolist() == [ - (9 * amount + 5) // 10 for amount in pence - ] + # A benefit unit's maximum over its household's float32 values is float64. + for value in (stored, stored.astype(np.float64)): + assert np.round(exact_amount(value) * 100).astype(np.int64).tolist() == pence + down = less_sale_expenses(value, LEGAL_RATE, True) + nearest = less_sale_expenses(value, LEGAL_RATE, False) + assert down.dtype == nearest.dtype == np.float64 + assert np.round(down * 100).astype(np.int64).tolist() == [ + 9 * amount // 10 for amount in pence + ] + assert np.round(nearest * 100).astype(np.int64).tolist() == [ + (9 * amount + 5) // 10 for amount in pence + ] def test_share_valuation_matches_the_adm_worked_example(): @@ -324,10 +333,16 @@ def test_share_valuation_matches_the_adm_worked_example(): st.floats(0, 1_000_000, allow_nan=False, width=32), min_size=1, max_size=500 ) ) -@example([1034.375, 10352.055, 0.005, 999_999.875]) +@example([1034.375, 10352.055, 0.005, 999_999.875, 140_000.015625]) def test_sale_expenses_never_round_the_wrong_way(values): stored = np.asarray(values, dtype=np.float32) exact = exact_amount(stored) + assert np.array_equal(exact, exact_amount(stored.astype(np.float64))) + # From 131,072 float32 cannot hold every penny, so no penny is identified + # and the value is kept as stored: 140,000.01 and 140,000.02 are both + # stored as 140,000.015625, which rounds down to 140,000.01. + large = stored >= 131_072 + assert np.array_equal(exact[large], stored[large].astype(np.float64)) # Storage error is removed only within half a unit of the stored value's # own precision, so a value is never moved to a penny it was not stored # from. @@ -344,3 +359,88 @@ def test_sale_expenses_never_round_the_wrong_way(values): noise = Fraction(1, 100_000_000) assert target - Fraction(1, 100) - noise < Fraction(low) <= target + noise assert abs(Fraction(near) - target) <= Fraction(1, 200) + noise + + +ROUNDS_DOWN = { + "uc_assessable_capital": False, + "housing_benefit_assessable_capital": False, + "income_support_assessable_capital": True, + "jsa_income_assessable_capital": True, + "esa_income_assessable_capital": True, + "pension_credit_assessable_capital": True, +} + + +def whole_penny_situation(rows): + people, benunits, homes = {}, {}, {} + for i, (savings, shares, lisa_quarters, age) in enumerate(rows): + people[f"p{i}"] = { + "age": {YEAR: age}, + "lifetime_isa_balance": {YEAR: 4 * lisa_quarters / 100}, + } + benunits[f"b{i}"] = {"members": [f"p{i}"]} + homes[f"h{i}"] = { + "members": [f"p{i}"], + "savings": {YEAR: savings / 100}, + "corporate_wealth": {YEAR: shares / 100}, + } + return {"people": people, "benunits": benunits, "households": homes} + + +@PROPERTY_SETTINGS +@given( + st.lists( + st.tuples( + st.integers(0, 6_000_000), + st.integers(0, 6_000_000), + st.integers(0, 375_000), + st.sampled_from([30, 70]), + ), + min_size=20, + max_size=100, + ) +) +# 16,000.01 of savings is over every 16,000 limit; 1,000.10 and 12,345.67 +# lose a penny if float32 storage error reaches a floor; a Lifetime ISA of +# 0.24 or 1,000.04 counts 0.18 or 750.03 under 60. +@example( + [ + (1_600_001, 0, 0, 30), + (100_010, 0, 0, 30), + (1_234_567, 0, 0, 70), + (159_992, 1_600_010, 0, 30), + (0, 0, 6, 30), + (0, 0, 25_001, 30), + ] + * 4 +) +def test_whole_pennies_are_counted_to_the_penny(rows): + sim = Simulation(situation=whole_penny_situation(rows)) + values = {v: np.asarray(sim.calculate(v, YEAR), dtype=float) for v in PROGRAMMES} + gc = np.asarray(sim.calculate("guarantee_credit", YEAR)) + passported = np.asarray( + sim.calculate("housing_benefit_on_passporting_benefit", YEAR) + ) + savings_credit_only = np.asarray( + sim.calculate("in_receipt_of_savings_credit_only", YEAR) + ) + for variable, round_down in ROUNDS_DOWN.items(): + for i, (savings, shares, lisa_quarters, age) in enumerate(rows): + if not applies(variable, {"age": age}, gc[i], passported[i]): + continue + # Housing Benefit takes Pension Credit's capital for a savings + # credit only award (HB (SPC) Regs 2006 reg. 27(6)). + down = round_down or ( + variable == "housing_benefit_assessable_capital" + and savings_credit_only[i] + ) + share_pence = (9 * shares + (0 if down else 5)) // 10 + lisa_pence = 4 * lisa_quarters if age >= 60 else 3 * lisa_quarters + expected = (savings + share_pence + lisa_pence) / 100 + # The model stores float32, which holds every penny below 131,072. + assert abs(values[variable][i] - expected) < 0.004, ( + variable, + rows[i], + values[variable][i], + expected, + ) diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index 10396761dc..8b601731cd 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -73,18 +73,28 @@ def exact_amount(amount): """``amount`` in float64, with float32 storage error removed. Inputs are stored in float32, which holds £1,000.10 as 1,000.0999756 and - 90% of £16,001 as 14,400.8994. A value is taken to be a whole penny when - that penny is within half a unit of the value's own precision, so it is - the penny the value was stored from; any other value (a share price to - four decimal places, say) is kept exactly as stored. Above £131,072 - float32 cannot hold every penny, so a penny lost in storage there cannot - be recovered.""" - stored = np.asarray(amount) - wide = stored.astype(np.float64) + 90% of £16,001 as 14,400.8994. A float32 value, or one widened from + float32 to float64, is taken to be a whole penny when that penny is within + half its float32 spacing: it is then the penny the value was stored from. + Below £131,072 float32 holds every penny, so at most one penny is that + close. From £131,072 its spacing is wider than a penny, the penny cannot + be identified, and the value is kept as stored, so rounding it down + never goes against the claimant. Any other value (a share price to four + decimal places, or a float64 that is not a float32) is kept exactly.""" + wide = np.asarray(amount).astype(np.float64) + narrow = wide.astype(np.float32) pennies = np.round(wide, 2) - # An infinite amount has no precision to compare against and passes through. - with np.errstate(over="ignore", invalid="ignore"): - stored_from_penny = np.abs(pennies - wide) <= np.spacing(np.abs(stored)) / 2 + # Zero and subnormal values underflow in np.spacing, and an infinite one + # overflows; neither is a penny that needs recovering. + with np.errstate(over="ignore", under="ignore", invalid="ignore"): + precision = np.where( + narrow == wide, + np.spacing(np.abs(narrow)).astype(np.float64), + np.spacing(np.abs(wide)), + ) + stored_from_penny = (2 * np.abs(pennies - wide) <= precision) & ( + precision < 0.01 + ) return np.where(stored_from_penny, pennies, wide) @@ -101,6 +111,8 @@ def round_to_penny(amount, round_down): Computed in float64, and rounded to a millionth of a penny first, so binary noise next to a whole or half penny (206.99999999999997 pence for 90% of - £2.30) does not move it.""" + £2.30) does not move it. That tolerance is intended: an amount within a + millionth of a penny below a whole penny, which only a value that is not + a whole penny can produce, rounds to that penny.""" pence = np.round(np.asarray(amount, dtype=np.float64) * 100, 6) return np.where(round_down, np.floor(pence), np.floor(pence + 0.5)) / 100 diff --git a/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py index 6daf2817c3..ef088bbe9f 100644 --- a/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import exact_amount class lifetime_isa_countable_capital(Variable): @@ -25,6 +26,8 @@ class lifetime_isa_countable_capital(Variable): def formula(person, period, parameters): p = parameters(period).gov.hmrc.isa.lifetime - balance = person("lifetime_isa_balance", period) + # Worked in float64 from the stored balance, so 75% of a balance in + # whole pennies keeps its pennies (75% of 1,000.04 is 750.03). + balance = exact_amount(person("lifetime_isa_balance", period)) charge_free = person("age", period) >= p.charge_free_age return where(charge_free, balance, balance * (1 - p.withdrawal_charge)) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/company/uc_company_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/company/uc_company_capital.py index 541e637805..006a5f46b7 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/company/uc_company_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/company/uc_company_capital.py @@ -1,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import exact_amount, round_to_penny class uc_company_capital(Variable): @@ -47,5 +48,13 @@ def formula(person, period, parameters): person("owned_company_trade_assets", period), 0, ) - capital = max_(0, person("owned_company_capital", period) - disregarded) - return where(applies, capital, 0) + # Worked in float64 from the stored amounts and rounded to the nearest + # penny (UC Regs 2013 reg. 6(1)): a float32 difference of two large + # amounts can be most of a penny out. + capital = max_( + 0, + exact_amount(person("owned_company_capital", period)) + - exact_amount(disregarded), + ) + p = parameters(period).gov.dwp.universal_credit.means_test.capital + return where(applies, round_to_penny(capital, p.round_down), 0) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py index c4d6236d29..81d6463ecc 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py @@ -28,8 +28,10 @@ class household_uc_pool_company_holdings(Variable): "All other holdings leave the pool here, including a dependant's " "holding even when their benunit supplies a report or override. " "When financial reports and holdings are compatible, no benunit counts " - "any part of a disregarded holding. An inconsistent financial report " - "that omits a known holding can leave it in the residual pool. A holding " + "any part of a disregarded holding. A financial report below its " + "holder's known holding still consumes the holding at its counted " + "value (household_uc_reported_financial_capital), so no report leaves " + "a holding in the residual pool. A holding " "is shares, held within the household's corporate_wealth. Each " "person's holding is first clipped to [0, max(0, corporate_wealth)], " "with positive infinity mapped to the upper bound and negative infinity " From 81235408518f1d8722166dcdba200f436c93206a Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 24 Oct 2026 03:32:11 -0400 Subject: [PATCH 17/48] Value each Lifetime ISA to the penny in float64 under each programme's rule The engine stores lifetime_isa_countable_capital as float32, so 75% of a whole-penny balance that ends in half a penny (75% of 0.26 is 0.195) was read back just below it and rounded the wrong way under UC and HB: 0.26 of LISA and 15,999.81 of savings gave UC capital of 16,000.00, eligible, instead of 16,000.01. valued_person_capital now works a LISA's surrender value out in float64 from the balance and rounds each person's to the penny under the programme's rule, like any other valuation, in all six means tests. The whole-penny property draws any whole-penny balance, with the half-penny cases as examples, and two YAML cases pin the limit case and per-partner rounding. exact_amount's docstring no longer claims that rounding down never goes against the claimant above 131,072: a figure built from a stored value there can be a penny either way. The float32 cast moves inside errstate. Co-Authored-By: Claude Opus 5.5 --- changelog.d/uc-capital-sale-expenses.fixed.md | 2 +- .../baseline/gov/dwp/capital_valuation.yaml | 56 +++++++++++++++++ .../test_capital_valuation_properties.py | 33 ++++++---- policyengine_uk/utils/capital_valuation.py | 61 +++++++++++++++++-- .../gov/dwp/esa_income_assessable_capital.py | 7 +-- .../housing_benefit_assessable_capital.py | 6 +- .../dwp/income_support_assessable_capital.py | 7 +-- .../gov/dwp/jsa_income_assessable_capital.py | 7 +-- .../gov/dwp/lifetime_isa_countable_capital.py | 12 ++-- .../pension_credit_assessable_capital.py | 6 +- .../universal_credit/uc_assessable_capital.py | 8 +-- 11 files changed, 155 insertions(+), 50 deletions(-) diff --git a/changelog.d/uc-capital-sale-expenses.fixed.md b/changelog.d/uc-capital-sale-expenses.fixed.md index b71561b5b9..5193d8d2f3 100644 --- a/changelog.d/uc-capital-sale-expenses.fixed.md +++ b/changelog.d/uc-capital-sale-expenses.fixed.md @@ -1 +1 @@ -Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and corporate_wealth, not to cash savings; corporate_wealth also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. +Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and share-like capital (share_like_capital), not to cash savings; share-like capital also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. A Lifetime ISA's surrender value is worked out from its balance and rounded under the same rule. diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml index b3b2efe488..521397a82b 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -479,3 +479,59 @@ income_support_assessable_capital: 750.03 esa_income_assessable_capital: 750.03 uc_assessable_capital: 750.03 + +- name: UC rounds a Lifetime ISA's half penny up, a penny over the limit + period: 2026 + absolute_error_margin: 0.004 + input: + people: + person: + age: 30 + # Below age 60 the surrender value is 75% of the balance: 0.195, half + # a penny, which float32 would store as 0.19499999. UC Regs 2013 reg. + # 6(1) treats it as a penny, so the capital is 15,999.81 + 0.20 = + # 16,000.01, over the 16,000 limit. The legacy benefits disregard it + # (IS Regs 1987 reg. 27; JSA Regs 1996 reg. 92; ESA Regs 2008 reg. + # 3(a)): 15,999.81 + 0.19 = 16,000.00. + lifetime_isa_balance: 0.26 + benunits: + benunit: + members: person + households: + household: + members: person + savings: 15_999.81 + output: + uc_assessable_capital: 16_000.01 + is_uc_eligible: false + income_support_assessable_capital: 16_000 + jsa_income_assessable_capital: 16_000 + esa_income_assessable_capital: 16_000 + +- name: Each partner's Lifetime ISA is valued to the penny on its own + period: 2026 + absolute_error_margin: 0.004 + input: + people: + first: + age: 30 + lifetime_isa_balance: 0.26 + second: + age: 30 + lifetime_isa_balance: 0.26 + benunits: + benunit: + members: [first, second] + households: + household: + members: [first, second] + # Each surrender value is 0.195, a calculation of its own: 0.20 to the + # nearest penny (UC Regs 2013 reg. 6(1)), so 15,999.62 + 0.40 = + # 16,000.02; 0.19 rounded down (IS Regs 1987 reg. 27; JSA Regs 1996 + # reg. 92; ESA Regs 2008 reg. 3(a)), so 15,999.62 + 0.38 = 16,000.00. + savings: 15_999.62 + output: + uc_assessable_capital: 16_000.02 + income_support_assessable_capital: 16_000 + jsa_income_assessable_capital: 16_000 + esa_income_assessable_capital: 16_000 diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 19b97ffa1b..2f7be49d89 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -36,8 +36,8 @@ maximum over its household's values is. 8. Whole pennies through the model: every programme counts whole-penny savings, shares and Lifetime ISA balances to the penny: savings in full, - shares at 90% rounded by the programme's rule, and a Lifetime ISA at 75% - below its charge-free age. + shares at 90% and a Lifetime ISA at 75% below its charge-free age, each + rounded by the programme's rule, and a Lifetime ISA in full from that age. """ from fractions import Fraction @@ -347,8 +347,10 @@ def test_sale_expenses_never_round_the_wrong_way(values): exact = exact_amount(stored) assert np.array_equal(exact, exact_amount(stored.astype(np.float64))) # From 131,072 float32 cannot hold every penny, so no penny is identified - # and the value is kept as stored: 140,000.01 and 140,000.02 are both - # stored as 140,000.015625, which rounds down to 140,000.01. + # and the value is kept as stored. The result is then within a penny of + # the stored value's figure, not of every penny it could have been stored + # from: 140,000.01 and 140,000.02 are both stored as 140,000.015625, and + # 90% of that rounds down to 126,000.01, a penny above 140,000.01's. large = stored >= 131_072 assert np.array_equal(exact[large], stored[large].astype(np.float64)) # Storage error is removed only within half a unit of the stored value's @@ -381,10 +383,10 @@ def test_sale_expenses_never_round_the_wrong_way(values): def whole_penny_situation(rows): people, benunits, homes = {}, {}, {} - for i, (savings, shares, lisa_quarters, age) in enumerate(rows): + for i, (savings, shares, lisa, age) in enumerate(rows): people[f"p{i}"] = { "age": {YEAR: age}, - "lifetime_isa_balance": {YEAR: 4 * lisa_quarters / 100}, + "lifetime_isa_balance": {YEAR: lisa / 100}, } benunits[f"b{i}"] = {"members": [f"p{i}"]} homes[f"h{i}"] = { @@ -401,7 +403,7 @@ def whole_penny_situation(rows): st.tuples( st.integers(0, 6_000_000), st.integers(0, 6_000_000), - st.integers(0, 375_000), + st.integers(0, 1_500_000), st.sampled_from([30, 70]), ), min_size=20, @@ -410,17 +412,22 @@ def whole_penny_situation(rows): ) # 16,000.01 of savings is over every 16,000 limit; 1,000.10 and 12,345.67 # lose a penny if float32 storage error reaches a floor; a Lifetime ISA of -# 0.24 or 1,000.04 counts 0.18 or 750.03 under 60. +# 0.24 or 1,000.04 counts 0.18 or 750.03 under 60. 75% of a 0.26 balance is +# 0.195 and of 1,000.30 is 750.225, half pennies, which float32 stores just +# below: with 15,999.81 or 15,249.77 of savings the capital is 16,000.01 or +# 16,000.00 to the nearest penny, and 16,000.00 or 15,999.99 rounded down. @example( [ (1_600_001, 0, 0, 30), (100_010, 0, 0, 30), (1_234_567, 0, 0, 70), (159_992, 1_600_010, 0, 30), - (0, 0, 6, 30), - (0, 0, 25_001, 30), + (0, 0, 24, 30), + (0, 0, 100_004, 30), + (1_599_981, 0, 26, 30), + (1_524_977, 0, 100_030, 30), ] - * 4 + * 3 ) def test_whole_pennies_are_counted_to_the_penny(rows): sim = Simulation(situation=whole_penny_situation(rows)) @@ -433,7 +440,7 @@ def test_whole_pennies_are_counted_to_the_penny(rows): sim.calculate("in_receipt_of_savings_credit_only", YEAR) ) for variable, round_down in ROUNDS_DOWN.items(): - for i, (savings, shares, lisa_quarters, age) in enumerate(rows): + for i, (savings, shares, lisa, age) in enumerate(rows): if not applies(variable, {"age": age}, gc[i], passported[i]): continue # Housing Benefit takes Pension Credit's capital for a savings @@ -443,7 +450,7 @@ def test_whole_pennies_are_counted_to_the_penny(rows): and savings_credit_only[i] ) share_pence = (9 * shares + (0 if down else 5)) // 10 - lisa_pence = 4 * lisa_quarters if age >= 60 else 3 * lisa_quarters + lisa_pence = lisa if age >= 60 else (3 * lisa + (0 if down else 2)) // 4 expected = (savings + share_pence + lisa_pence) / 100 # The model stores float32, which holds every penny below 131,072. assert abs(values[variable][i] - expected) < 0.004, ( diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index 8b601731cd..2b7a6911da 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -51,6 +51,49 @@ def valued_capital(value_of, capital): return total +def valued_person_capital(benunit, period, parameters, capital, counted): + """Sum ``capital.person_sources`` over the benefit unit's members for whom + ``counted`` is true (its claimant and partner), in float64. + + A source the engine would store with a fraction of a penny is worked out + here from its inputs (``CALCULATED_PERSON_SOURCES``) and rounded to the + penny under the programme's rule, like any other valuation, rather than + read back from float32. Any other source is a stored amount.""" + person = benunit.members + total = 0 + for source in capital.person_sources: + if source in CALCULATED_PERSON_SOURCES: + value = round_to_penny( + CALCULATED_PERSON_SOURCES[source](person, period, parameters), + capital.round_down, + ) + else: + value = exact_amount(person(source, period)) + total = total + benunit.sum(value * counted) + return total + + +def lifetime_isa_surrender_value(person, period, parameters): + """Surrender value of each person's Lifetime ISAs, in float64: the balance + less the withdrawal charge below the charge-free age, and the whole balance + from that age. + + 75% of a whole-penny balance can end in a quarter or half penny (75% of + £0.26 is £0.195), which float32 would store as 0.19499999 and so move a + nearest-penny rounding; 75% of £1,000.04 is £750.03.""" + p = parameters(period).gov.hmrc.isa.lifetime + balance = exact_amount(person("lifetime_isa_balance", period)) + charge_free = person("age", period) >= p.charge_free_age + return np.where(charge_free, balance, balance * (1 - p.withdrawal_charge)) + + +# Person-level capital sources the means tests value from their inputs, each +# mapped to the float64 calculation of its value. +CALCULATED_PERSON_SOURCES = { + "lifetime_isa_countable_capital": lifetime_isa_surrender_value, +} + + def counted_share(sale_expenses, source): """Share of a source's market value counted as capital: 90% where its sale would incur expenses (reg. 49(1)(a)), otherwise all of it.""" @@ -78,15 +121,21 @@ def exact_amount(amount): half its float32 spacing: it is then the penny the value was stored from. Below £131,072 float32 holds every penny, so at most one penny is that close. From £131,072 its spacing is wider than a penny, the penny cannot - be identified, and the value is kept as stored, so rounding it down - never goes against the claimant. Any other value (a share price to four - decimal places, or a float64 that is not a float32) is kept exactly.""" + be identified, and the value is kept as stored. A capital figure built + from it can then be a penny either way: £140,000.01 and £140,000.02 are + both stored as 140,000.015625, and 90% of that rounds down to + £126,000.01, a penny above the £126,000.00 that £140,000.01 gives. The + same holds for any stored value from £262,144, where the spacing exceeds + two pennies. A value in whole pounds below £16,777,216 is stored exactly + and is unaffected. Any other value (a share price to four decimal places, + or a float64 that is not a float32) is kept exactly.""" wide = np.asarray(amount).astype(np.float64) - narrow = wide.astype(np.float32) pennies = np.round(wide, 2) - # Zero and subnormal values underflow in np.spacing, and an infinite one - # overflows; neither is a penny that needs recovering. + # Zero and subnormal values underflow in np.spacing and in the cast to + # float32, and an infinite one overflows; neither is a penny that needs + # recovering. with np.errstate(over="ignore", under="ignore", invalid="ignore"): + narrow = wide.astype(np.float32) precision = np.where( narrow == wide, np.spacing(np.abs(narrow)).astype(np.float64), diff --git a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py index fd66242987..77624ac1fb 100644 --- a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py @@ -1,8 +1,8 @@ from policyengine_uk.model_api import * from policyengine_uk.utils.capital_valuation import ( - exact_amount, round_to_penny, valued_capital, + valued_person_capital, ) @@ -55,9 +55,8 @@ def formula(benunit, period, parameters): household_capital * benunit_claimants_and_partners / fallback_divisor ) claimant_or_partner = person("is_claimant_or_partner", period) - person_capital = sum( - benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) - for source in ESA.capital.person_sources + person_capital = valued_person_capital( + benunit, period, parameters, ESA.capital, claimant_or_partner ) household_share = where( household_reporting_claimants > 0, claiming_proxy, fallback_proxy diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py index 44c381268e..3dc5d6b60d 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py @@ -3,6 +3,7 @@ exact_amount, round_to_penny, valued_capital, + valued_person_capital, ) @@ -54,9 +55,8 @@ def formula(benunit, period, parameters): lambda variable: household(variable, period), p ) claimant_or_partner = person("is_claimant_or_partner", period) - person_capital = sum( - benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) - for source in p.person_sources + person_capital = valued_person_capital( + benunit, period, parameters, p, claimant_or_partner ) benunit_claimants_and_partners = add( benunit, period, ["is_claimant_or_partner"] diff --git a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py index 33df6b0840..aa38b2279b 100644 --- a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py @@ -1,8 +1,8 @@ from policyengine_uk.model_api import * from policyengine_uk.utils.capital_valuation import ( - exact_amount, round_to_penny, valued_capital, + valued_person_capital, ) @@ -61,9 +61,8 @@ def formula(benunit, period, parameters): household_capital * benunit_claimants_and_partners / fallback_divisor ) claimant_or_partner = person("is_claimant_or_partner", period) - person_capital = sum( - benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) - for source in IS.means_test.capital.person_sources + person_capital = valued_person_capital( + benunit, period, parameters, IS.means_test.capital, claimant_or_partner ) household_share = where( household_claiming_members > 0, claiming_proxy, fallback_proxy diff --git a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py index 1cf104940a..3ca5804c58 100644 --- a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py @@ -1,8 +1,8 @@ from policyengine_uk.model_api import * from policyengine_uk.utils.capital_valuation import ( - exact_amount, round_to_penny, valued_capital, + valued_person_capital, ) @@ -55,9 +55,8 @@ def formula(benunit, period, parameters): household_capital * benunit_claimants_and_partners / fallback_divisor ) claimant_or_partner = person("is_claimant_or_partner", period) - person_capital = sum( - benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) - for source in JSA.capital.person_sources + person_capital = valued_person_capital( + benunit, period, parameters, JSA.capital, claimant_or_partner ) household_share = where( household_reporting_claimants > 0, claiming_proxy, fallback_proxy diff --git a/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py index ef088bbe9f..4f5d1e6271 100644 --- a/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py @@ -1,5 +1,5 @@ from policyengine_uk.model_api import * -from policyengine_uk.utils.capital_valuation import exact_amount +from policyengine_uk.utils.capital_valuation import lifetime_isa_surrender_value class lifetime_isa_countable_capital(Variable): @@ -25,9 +25,7 @@ class lifetime_isa_countable_capital(Variable): ] def formula(person, period, parameters): - p = parameters(period).gov.hmrc.isa.lifetime - # Worked in float64 from the stored balance, so 75% of a balance in - # whole pennies keeps its pennies (75% of 1,000.04 is 750.03). - balance = exact_amount(person("lifetime_isa_balance", period)) - charge_free = person("age", period) >= p.charge_free_age - return where(charge_free, balance, balance * (1 - p.withdrawal_charge)) + # Stored as float32. The means tests work the value out in float64 + # from the balance instead, and round it under each programme's rule + # (capital_valuation.valued_person_capital). + return lifetime_isa_surrender_value(person, period, parameters) diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py index bf33736ef9..adf8ac35de 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py @@ -3,6 +3,7 @@ exact_amount, round_to_penny, valued_capital, + valued_person_capital, ) @@ -38,9 +39,8 @@ def formula(benunit, period, parameters): lambda variable: household(variable, period), p ) claimant_or_partner = person("is_claimant_or_partner", period) - person_capital = sum( - benunit.sum(exact_amount(person(source, period)) * claimant_or_partner) - for source in p.person_sources + person_capital = valued_person_capital( + benunit, period, parameters, p, claimant_or_partner ) any_pension_age = benunit.any( person("has_attained_state_pension_credit_qualifying_age", period) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py index 712650f0ab..e7ece46cdd 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py @@ -4,6 +4,7 @@ exact_amount, round_to_penny, valued_capital, + valued_person_capital, ) from policyengine_uk.variables.gov.dwp.universal_credit.household_uc_company_holding_pool_scale import ( HOLDINGS_SOURCE, @@ -66,11 +67,8 @@ def formula(benunit, period, parameters): holding_value = counted_share(p.sale_expenses, HOLDINGS_SOURCE) claimant_or_partner = benunit.members("is_uc_claimant", period) benunit_claimants = benunit.sum(claimant_or_partner) - person_capital = sum( - benunit.sum( - exact_amount(benunit.members(source, period)) * claimant_or_partner - ) - for source in p.person_sources + person_capital = valued_person_capital( + benunit, period, parameters, p, claimant_or_partner ) financial_report = exact_amount(benunit("benunit_reported_capital", period)) complete_override = exact_amount(benunit("uc_reported_capital", period)) From a677cb348c219393bdf22ee90a687093568e7d8f Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 28 Oct 2026 14:52:59 -0400 Subject: [PATCH 18/48] Preserve supplied and reformed Lifetime ISA capital values Reconstruct the baseline surrender value in float64 only when the active formula is the baseline function and no input was supplied for this period and visible branch. Numeric equality with a float32 formula result cannot establish provenance: it can discard a supplied whole penny. Read the active variable from the tax-benefit system, since an existing holder can retain a definition from before a reform. Reuse supplied-input tracking and cover explicit inputs, float32 collisions, replacement and parameter reforms, late inputs, periods and branches. Reuse the existing independent-clone test fixture for the capital property suite. Co-Authored-By: Claude Opus 5.5 --- changelog.d/uc-capital-sale-expenses.fixed.md | 2 +- .../baseline/gov/dwp/capital_valuation.yaml | 71 +++++++++++++++++ .../test_capital_valuation_properties.py | 76 +++++++++++++++++++ policyengine_uk/utils/capital_valuation.py | 31 +++++--- policyengine_uk/utils/supplied_inputs.py | 1 + .../gov/dwp/lifetime_isa_countable_capital.py | 10 +-- 6 files changed, 175 insertions(+), 16 deletions(-) diff --git a/changelog.d/uc-capital-sale-expenses.fixed.md b/changelog.d/uc-capital-sale-expenses.fixed.md index 5193d8d2f3..0a6ffc7c9a 100644 --- a/changelog.d/uc-capital-sale-expenses.fixed.md +++ b/changelog.d/uc-capital-sale-expenses.fixed.md @@ -1 +1 @@ -Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and share-like capital (share_like_capital), not to cash savings; share-like capital also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. A Lifetime ISA's surrender value is worked out from its balance and rounded under the same rule. +Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and share-like capital (share_like_capital), not to cash savings; share-like capital also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. A Lifetime ISA's surrender value is worked out from its balance and rounded under the same rule. Explicit Lifetime ISA capital inputs and reformed valuation formulas are preserved. diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml index 521397a82b..503df382a8 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -535,3 +535,74 @@ income_support_assessable_capital: 16_000 jsa_income_assessable_capital: 16_000 esa_income_assessable_capital: 16_000 + +- name: A Lifetime ISA value given as an input is counted as given + period: 2026 + absolute_error_margin: 0.004 + input: + people: + person: + age: 30 + # The balance's surrender value would be 0.195, but the value counted + # as capital is given directly, so every means test counts that 0.20: + # 15,999.81 + 0.20 = 16,000.01. + lifetime_isa_balance: 0.26 + lifetime_isa_countable_capital: 0.20 + benunits: + benunit: + members: person + households: + household: + members: person + savings: 15_999.81 + output: + uc_assessable_capital: 16_000.01 + is_uc_eligible: false + income_support_assessable_capital: 16_000.01 + jsa_income_assessable_capital: 16_000.01 + esa_income_assessable_capital: 16_000.01 + +- name: A Lifetime ISA input is preserved when its float32 value matches the formula + period: 2026 + absolute_error_margin: 0.004 + input: + people: + person: + age: 30 + # The formula gives 65,536.005. That and the explicit whole-penny + # value 65,536.01 both store as 65,536.0078125, so equality cannot + # tell a formula result from an input. Counting the input as given + # preserves 65,536.01 even under a programme that rounds down. + lifetime_isa_balance: 87_381.34 + lifetime_isa_countable_capital: 65_536.01 + benunits: + benunit: + members: person + housing_benefit_on_passporting_benefit: false + households: + household: + members: person + output: + uc_assessable_capital: 65_536.01 + housing_benefit_assessable_capital: 65_536.01 + income_support_assessable_capital: 65_536.01 + jsa_income_assessable_capital: 65_536.01 + esa_income_assessable_capital: 65_536.01 + +- name: Pension Credit preserves an explicit Lifetime ISA value + period: 2026 + absolute_error_margin: 0.004 + input: + people: + person: + age: 70 + lifetime_isa_balance: 0.26 + lifetime_isa_countable_capital: 0.20 + benunits: + benunit: + members: person + households: + household: + members: person + output: + pension_credit_assessable_capital: 0.20 diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 2f7be49d89..47dcd3348e 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -44,12 +44,18 @@ from functools import reduce import numpy as np +import pytest from hypothesis import HealthCheck, example, given, settings from hypothesis import strategies as st +from policyengine_core.reforms import Reform from policyengine_uk import Simulation +from policyengine_uk.model_api import Person, Variable +from policyengine_uk.model_api import YEAR as YEAR_PERIOD from policyengine_uk.utils.capital_valuation import exact_amount, less_sale_expenses +pytestmark = pytest.mark.usefixtures("cloned_uk_tax_benefit_system") + YEAR = 2026 PROPERTY_SETTINGS = settings( max_examples=5, @@ -459,3 +465,73 @@ def test_whole_pennies_are_counted_to_the_penny(rows): values[variable][i], expected, ) + + +def test_lifetime_isa_reformed_value_is_kept_as_stored(): + # This reform's value and the baseline's 0.195 are the same float32, + # but the reform deliberately values the ISA below the half penny. + class lifetime_isa_countable_capital(Variable): + value_type = float + entity = Person + definition_period = YEAR_PERIOD + + def formula(person, period, parameters): + return person.filled_array(0.19499999) + + class ReplaceLifetimeISA(Reform): + def apply(self): + self.update_variable(lifetime_isa_countable_capital) + + sim = Simulation( + situation=whole_penny_situation([(0, 0, 26, 30)]), + reform=ReplaceLifetimeISA, + ) + assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - 0.19) < 0.004 + + +def test_lifetime_isa_baseline_formula_uses_reformed_parameters(): + sim = Simulation( + situation=whole_penny_situation([(0, 0, 26, 30)]), + reform={"gov.hmrc.isa.lifetime.withdrawal_charge": {str(YEAR): 0.5}}, + ) + assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - 0.13) < 0.004 + + +@pytest.mark.parametrize("via_holder", [False, True]) +def test_lifetime_isa_input_set_after_construction_is_preserved(via_holder): + sim = Simulation(situation=whole_penny_situation([(0, 0, 26, 30)])) + # Cache the formula first: a later equal-valued input still has input + # provenance, including when the caller uses Holder.set_input directly. + sim.calculate("lifetime_isa_countable_capital", YEAR) + if via_holder: + from policyengine_core import periods + + sim.get_holder("lifetime_isa_countable_capital").set_input( + periods.period(YEAR), np.array([0.195]) + ) + else: + sim.set_input("lifetime_isa_countable_capital", YEAR, np.array([0.195])) + assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - 0.19) < 0.004 + + +def test_lifetime_isa_input_for_another_period_does_not_replace_the_formula(): + situation = whole_penny_situation([(0, 0, 26, 30)]) + situation["people"]["p0"]["lifetime_isa_countable_capital"] = {YEAR - 1: 0.195} + sim = Simulation(situation=situation) + # The previous year's supplied value cannot suppress this year's exact + # baseline valuation of 75% of 0.26, rounded nearest to 0.20. + assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - 0.20) < 0.004 + + +@pytest.mark.parametrize("inherited", [False, True]) +def test_lifetime_isa_input_is_preserved_on_its_visible_branch(inherited): + situation = whole_penny_situation([(0, 0, 26, 30)]) + if inherited: + situation["people"]["p0"]["lifetime_isa_countable_capital"] = {YEAR: 0.195} + sim = Simulation(situation=situation) + branch = sim.get_branch("entered_lisa") + if not inherited: + branch.set_input("lifetime_isa_countable_capital", YEAR, np.array([0.195])) + assert abs(branch.calculate("uc_assessable_capital", YEAR)[0] - 0.19) < 0.004 + expected_main = 0.19 if inherited else 0.20 + assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - expected_main) < 0.004 diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index 2b7a6911da..6a8ee61e62 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -14,6 +14,8 @@ import numpy as np from policyengine_core.model_api import max_ +from policyengine_uk.utils.supplied_inputs import supplied_input + # Household inputs holding the debt secured on each capital source, such as a # mortgage on a second property. The debt is deducted from the source it is # secured on and that source is floored at nil, so negative equity in one @@ -55,20 +57,29 @@ def valued_person_capital(benunit, period, parameters, capital, counted): """Sum ``capital.person_sources`` over the benefit unit's members for whom ``counted`` is true (its claimant and partner), in float64. - A source the engine would store with a fraction of a penny is worked out - here from its inputs (``CALCULATED_PERSON_SOURCES``) and rounded to the - penny under the programme's rule, like any other valuation, rather than - read back from float32. Any other source is a stored amount.""" + A source whose formula can give a fraction of a penny + (``CALCULATED_PERSON_SOURCES``) is valued to the penny under the + programme's rule, like any other valuation. The baseline formula is + worked again in float64, so float32 cannot move the rounding. Explicit + inputs for this period and branch, and values from a reformed formula, + are kept as stored: matching a baseline value in float32 does not prove + where a value came from. Any other source is a stored amount.""" person = benunit.members total = 0 for source in capital.person_sources: + stored = person(source, period) + value = exact_amount(stored) if source in CALCULATED_PERSON_SOURCES: - value = round_to_penny( - CALCULATED_PERSON_SOURCES[source](person, period, parameters), - capital.round_down, - ) - else: - value = exact_amount(person(source, period)) + calculate = CALCULATED_PERSON_SOURCES[source] + # A holder can predate a reform; the system owns the active formula. + variable = person.simulation.tax_benefit_system.get_variable(source) + if ( + not variable.is_neutralized + and variable.get_formula(period) is calculate + and supplied_input(person, source, period) is None + ): + value = calculate(person, period, parameters) + value = round_to_penny(value, capital.round_down) total = total + benunit.sum(value * counted) return total diff --git a/policyengine_uk/utils/supplied_inputs.py b/policyengine_uk/utils/supplied_inputs.py index 58bc6f0cef..33499206a8 100644 --- a/policyengine_uk/utils/supplied_inputs.py +++ b/policyengine_uk/utils/supplied_inputs.py @@ -51,6 +51,7 @@ "pip_m_points", "local_bus_trips", "local_bus_uncapped_single_fare", + "lifetime_isa_countable_capital", "ni_class_4_losses_brought_forward", "ni_class_4_trading_loss", "tenure_type", diff --git a/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py index 4f5d1e6271..83ce5d8dea 100644 --- a/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py @@ -24,8 +24,8 @@ class lifetime_isa_countable_capital(Variable): "https://www.legislation.gov.uk/uksi/1998/1870/schedule", ] - def formula(person, period, parameters): - # Stored as float32. The means tests work the value out in float64 - # from the balance instead, and round it under each programme's rule - # (capital_valuation.valued_person_capital). - return lifetime_isa_surrender_value(person, period, parameters) + # The shared function's identity lets the means tests distinguish this + # baseline formula from a reform. They work it again in float64 before + # rounding, while preserving explicit inputs and reformed values + # (capital_valuation.valued_person_capital). + formula = lifetime_isa_surrender_value From d5c2a57e81dda7a55a24369f222e5ff666cb12d3 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 28 Oct 2026 14:58:50 -0400 Subject: [PATCH 19/48] Fix the company capital conservation penny-rounding oracle Port of #2688's 1193614a6. Model stored-input precision, the raw holdings budget scale, separately rounded share and holding valuations, each owner's company capital and each benefit unit's final capital. Sum the rounded benefit units for the household expectation under UC regulation 6(1). Pin the original CI witness and the holdings-budget precision boundary, while preserving main's explicit claimant and partner roles. Production calculations and comparison tolerances are unchanged by this port. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_uc_company_owner_properties.py | 99 ++++++++++++++++--- 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/policyengine_uk/tests/test_uc_company_owner_properties.py b/policyengine_uk/tests/test_uc_company_owner_properties.py index 64d158e3dc..85eb2e3818 100644 --- a/policyengine_uk/tests/test_uc_company_owner_properties.py +++ b/policyengine_uk/tests/test_uc_company_owner_properties.py @@ -27,8 +27,9 @@ not report their capital, the household's capital less every owner's holding (up to its corporate wealth) is shared between the units in proportion to their claimants, and each unit adds its own claimants' - company capital; so the units' capital sums to that pool plus the owners' - company capital. + company capital. Each valuation, owner's company capital and unit's final + capital is rounded to the nearest penny, and the household total sums the + rounded units (reg. 6(1)). 4. Earnings identity: earned income before the floor is pay less the person's own income tax and NI on the employment, plus the trading total floored at zero, less their relievable pension contributions, floored at @@ -66,11 +67,17 @@ holding, whatever the generated examples reach. """ +from decimal import Decimal, ROUND_HALF_UP + import numpy as np +import pytest from hypothesis import HealthCheck, example, given, settings from hypothesis import strategies as st from policyengine_uk import Simulation +from policyengine_uk.utils.capital_valuation import exact_amount + +pytestmark = pytest.mark.usefixtures("cloned_uk_tax_benefit_system") YEAR = 2026 # corporate_wealth (shares) is valued at 90% for the expenses of sale (UC Regs @@ -124,6 +131,20 @@ def close(a, b): return abs(a - b) <= 1e-2 + 1e-6 * abs(b) +def stored_amount(value): + """Use the same float32 input precision as the simulation.""" + return float(exact_amount(np.float32(value))) + + +def penny(value): + # UC Regs 2013 reg. 6(1): half a penny is rounded up, for every amount + # calculated (https://www.legislation.gov.uk/uksi/2013/376/regulation/6). + # Remove binary arithmetic noise below a millionth of a penny before + # applying the legal rule, independently of the model rounding helper. + amount = Decimal(str(value)).quantize(Decimal("0.00000001"), rounding=ROUND_HALF_UP) + return float(amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)) + + @st.composite def companies(draw): company_capital = draw(st.one_of(st.just(0.0), st.floats(0, 12_000))) @@ -268,17 +289,19 @@ def applies(company): def company_capital_of(company): - """Capital treated as possessed under reg. 77(2), net of 77(3)(a).""" + """Reg. 77(2) capital, net of 77(3)(a), rounded per person (reg. 6(1)).""" engaged = ( company["is_engaged_in_owned_company_trade"] or company["owned_company_is_main_employment"] ) disregarded = ( - company["owned_company_trade_assets"] + stored_amount(company["owned_company_trade_assets"]) if company["owned_company_carries_on_trade"] and engaged else 0.0 ) - return max(0.0, company["owned_company_capital"] - disregarded) + return penny( + max(0.0, stored_amount(company["owned_company_capital"]) - disregarded) + ) def pinned_company(**facts): @@ -615,6 +638,34 @@ def test_property_company_gives_no_earnings(unit_list, share): ) ] ) +@example( + [ + ( + pinned_unit( + pinned_adult(), + pinned_adult(), + corporate_wealth=6392.862111833667, + ), + pinned_unit( + pinned_adult( + pinned_company(owned_company_holding_value=6336.697665836761) + ), + pinned_adult(), + ), + ) + ] +) +@example( + [ + ( + pinned_unit( + pinned_adult(pinned_company(owned_company_holding_value=0.40)), + corporate_wealth=0.65, + ), + pinned_unit(pinned_adult(pinned_company(owned_company_holding_value=0.40))), + ) + ] +) def test_household_capital_is_allocated_and_conserved_across_benefit_units(pairs): # Each household holds two benefit units: the first unit's adults and the # second's, with the first unit's savings and corporate wealth. No unit @@ -624,7 +675,7 @@ def test_household_capital_is_allocated_and_conserved_across_benefit_units(pairs people, benunits, households = {}, {}, {} expected_units, expected_households = [], [] for h, (first, second) in enumerate(pairs): - names, holdings, unit_company_capital = [], 0.0, [] + names, holdings, unit_company_capital = [], [], [] for b, unit in enumerate((first, second)): members, company_capital = [], 0.0 for j, adult in enumerate(unit["adults"]): @@ -637,7 +688,7 @@ def test_household_capital_is_allocated_and_conserved_across_benefit_units(pairs **{k: {YEAR: v} for k, v in c.items()}, } if applies(c): - holdings += c["owned_company_holding_value"] + holdings.append(c["owned_company_holding_value"]) company_capital += company_capital_of(c) members.append(name) benunits[f"h{h}_b{b}"] = {"members": members} @@ -648,14 +699,38 @@ def test_household_capital_is_allocated_and_conserved_across_benefit_units(pairs "savings": {YEAR: first["savings"]}, "corporate_wealth": {YEAR: first["corporate_wealth"]}, } - disregarded = min(holdings, first["corporate_wealth"]) - pool = first["savings"] + SHARE_VALUE * ( - first["corporate_wealth"] - disregarded + shares = stored_amount(first["corporate_wealth"]) + # The holdings budget uses raw stored inputs and stores its scale as + # float32. Apply that scale to the recovered monetary amounts before + # valuation; an ideal min(total holdings, shares) loses this rounding + # boundary when holdings exceed the budget. + raw_shares = np.float32(first["corporate_wealth"]) + raw_holdings = sum( + float(np.clip(np.float32(holding), np.float32(0), raw_shares)) + for holding in holdings + ) + scale = float( + np.float32(min(1.0, float(raw_shares) / raw_holdings)) + if raw_holdings > 0 + else np.float32(1.0) + ) + disregarded = sum( + min(stored_amount(holding), shares) * scale for holding in holdings + ) + # Reg. 49(1)(a) values the shares and the removed holdings separately; + # reg. 6(1) rounds each valuation, then each unit's final capital. + pool = max( + 0.0, + stored_amount(first["savings"]) + + penny(SHARE_VALUE * shares) + - penny(SHARE_VALUE * disregarded), ) claimants = [len(first["adults"]), len(second["adults"])] for n, company_capital in zip(claimants, unit_company_capital): - expected_units.append(pool * n / sum(claimants) + company_capital) - expected_households.append(pool + sum(unit_company_capital)) + expected_units.append(penny(pool * n / sum(claimants) + company_capital)) + # Allocation rounding belongs to each benefit unit. Summing the + # unrounded household pool would lose up to half a penny per unit. + expected_households.append(sum(expected_units[-2:])) sim = Simulation( situation={"people": people, "benunits": benunits, "households": households} ) From b168dc509d8d92be485f3664b8c55f9294adb839 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 28 Oct 2026 17:11:52 -0400 Subject: [PATCH 20/48] Give the capital property households a cash ISA Main's ISA fix (feb50e440, merged here in 646743859) added cash_isa to every means test's capital sources. The property file's households had no cash_isa input, so the differential and the fixed Housing Benefit units raised KeyError: 'cash_isa' when they read each source. Households now draw a cash ISA balance. The cash-only property holds savings and a cash ISA, both deposit balances (ADM H1675), and checks each programme counts the two in full, so a source list that drops cash_isa fails it. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_capital_valuation_properties.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 47dcd3348e..65837ebc3f 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -13,8 +13,8 @@ 1. Non-increasing: every programme's assessable capital is at most the same household's capital with the deduction switched off (rate 0, no debt). -2. Cash only: a household holding only savings has the same capital with the - deduction on or off. +2. Cash only: a household holding only savings and a cash ISA has the same + capital with the deduction on or off, equal to the two balances. 3. Differential: capital equals a direct implementation of the regulation, savings + sum over sources of max(0, 90% of value - secured debt), where the test itself fixes which assets take the 10% (land, property and @@ -89,11 +89,14 @@ LEGAL_RATE = 0.1 ASSETS = [ "savings", + "cash_isa", "owned_land", "corporate_wealth", "other_residential_property_value", "non_residential_property_value", ] +# Ordinary savings and a cash ISA are both deposit balances, counted in full. +CASH_ASSETS = ("savings", "cash_isa") # The capital sources count shares as share_like_capital, which is the # corporate_wealth these households are given. INPUT_OF = {"share_like_capital": "corporate_wealth"} @@ -116,7 +119,9 @@ def households(draw, cash_only=False): assets = {asset: draw(amount) for asset in ASSETS} debts = {debt: draw(amount) for debt in DEBTS.values()} if cash_only: - assets = {asset: 0.0 for asset in ASSETS} | {"savings": assets["savings"]} + assets = {asset: 0.0 for asset in ASSETS} | { + cash: assets[cash] for cash in CASH_ASSETS + } debts = {debt: 0.0 for debt in debts} # About half the units do not claim Universal Credit, so the Housing # Benefit passport cannot remove every working-age unit from the @@ -289,7 +294,8 @@ def test_cash_only_households_have_no_deduction(units): valued["guarantee_credit"][i], valued["hb_passported"][i], ): - assert close(valued[variable][i], unit["assets"]["savings"]), variable + cash = sum(unit["assets"][asset] for asset in CASH_ASSETS) + assert close(valued[variable][i], cash), variable @PROPERTY_SETTINGS From 696ae34ad8ac46278f5bca7468a9d587344a211c Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 29 Oct 2026 00:19:40 -0400 Subject: [PATCH 21/48] Keep Core's defined_for mask in the exact Lifetime ISA valuation The float64 recompute called the baseline LISA formula directly, so a reform that only adds a defined_for mask (keeping the baseline formula) still counted the ISA where Core stores the default. A masked 0.26 ISA then added 0.20 to Universal Credit capital, and with 15,999.81 of savings made the claimant ineligible (v7 review, P2-1). Apply the mask the way Core does: where the defined_for variable, mapped to the person, is above zero, keep the float64 value; elsewhere keep the stored value, which is Core's default. New tests cover a mixed masked/counted pair across the six means tests and the UC eligibility case at the limit; both fail on the previous helper. Co-Authored-By: Claude Opus 5.5 --- .../test_capital_valuation_properties.py | 62 +++++++++++++++++++ policyengine_uk/utils/capital_valuation.py | 24 +++++-- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 65837ebc3f..6942fd9748 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -541,3 +541,65 @@ def test_lifetime_isa_input_is_preserved_on_its_visible_branch(inherited): assert abs(branch.calculate("uc_assessable_capital", YEAR)[0] - 0.19) < 0.004 expected_main = 0.19 if inherited else 0.20 assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - expected_main) < 0.004 + + +def lisa_mask_reform(): + """A reform that keeps the baseline LISA formula and only adds a + ``defined_for`` mask, so the formula identity check still passes.""" + + class lisa_is_counted(Variable): + value_type = bool + entity = Person + definition_period = YEAR_PERIOD + default_value = False + label = "Lifetime ISA counted as capital" + + class lifetime_isa_countable_capital(Variable): + defined_for = "lisa_is_counted" + + class MaskLifetimeISA(Reform): + def apply(self): + self.add_variable(lisa_is_counted) + self.update_variable(lifetime_isa_countable_capital) + + return MaskLifetimeISA + + +def test_lifetime_isa_exact_valuation_respects_a_defined_for_mask(): + # Two units hold 0.26 each. Only p1's ISA is counted: Core stores 0 for + # p0, so p0 must have no capital, and p1 must be valued as without the + # mask (0.195, to the penny under each programme's rule). + situation = whole_penny_situation([(0, 0, 26, 30), (0, 0, 26, 30)]) + unmasked = Simulation(situation=situation) + masked = Simulation(situation=situation, reform=lisa_mask_reform()) + # The reform adds the mask, so the shared situation can't supply it. + masked.set_input("lisa_is_counted", YEAR, np.array([False, True])) + assert list(masked.calculate("lifetime_isa_countable_capital", YEAR)) == [ + 0, + pytest.approx(0.195), + ] + assert abs(unmasked.calculate("uc_assessable_capital", YEAR)[0] - 0.20) < 0.004 + for variable in PROGRAMMES: + before = np.asarray(unmasked.calculate(variable, YEAR), dtype=float) + after = np.asarray(masked.calculate(variable, YEAR), dtype=float) + assert abs(after[0]) < 0.004, (variable, after) + assert abs(after[1] - before[1]) < 0.004, (variable, before, after) + + +def test_a_masked_lifetime_isa_leaves_universal_credit_eligibility(): + # 15,999.81 of savings is within the 16,000 limit. A counted 0.26 ISA + # (0.195, rounded to 0.20) would take it to 16,000.01; masked, it adds + # nothing. + sim = Simulation( + situation=whole_penny_situation([(1_599_981, 0, 26, 30)]), + reform=lisa_mask_reform(), + ) + assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - 15_999.81) < 0.004 + assert sim.calculate("is_uc_eligible", YEAR)[0] + sim = Simulation( + situation=whole_penny_situation([(1_599_981, 0, 26, 30)]), + reform=lisa_mask_reform(), + ) + sim.set_input("lisa_is_counted", YEAR, np.array([True])) + assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - 16_000.01) < 0.004 + assert not sim.calculate("is_uc_eligible", YEAR)[0] diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index 6a8ee61e62..c1e5097bd4 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -60,10 +60,12 @@ def valued_person_capital(benunit, period, parameters, capital, counted): A source whose formula can give a fraction of a penny (``CALCULATED_PERSON_SOURCES``) is valued to the penny under the programme's rule, like any other valuation. The baseline formula is - worked again in float64, so float32 cannot move the rounding. Explicit - inputs for this period and branch, and values from a reformed formula, - are kept as stored: matching a baseline value in float32 does not prove - where a value came from. Any other source is a stored amount.""" + worked again in float64, so float32 cannot move the rounding, and only + where the variable's ``defined_for`` mask applies it, as Core does. + Explicit inputs for this period and branch, and values from a reformed + formula, are kept as stored: matching a baseline value in float32 does + not prove where a value came from. Any other source is a stored + amount.""" person = benunit.members total = 0 for source in capital.person_sources: @@ -78,7 +80,19 @@ def valued_person_capital(benunit, period, parameters, capital, counted): and variable.get_formula(period) is calculate and supplied_input(person, source, period) is None ): - value = calculate(person, period, parameters) + exact = calculate(person, period, parameters) + if variable.defined_for is not None: + # Core keeps the formula's result only where the + # defined_for variable is above zero and stores the + # default elsewhere; keep that stored default. + applicable = ( + person.simulation.calculate( + variable.defined_for, period, map_to=variable.entity.key + ) + > 0 + ) + exact = np.where(applicable, exact, value) + value = exact value = round_to_penny(value, capital.round_down) total = total + benunit.sum(value * counted) return total From dbc0c587f2f05681008e42567e5636ca1179d528 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 29 Oct 2026 01:27:46 -0400 Subject: [PATCH 22/48] Run no Lifetime ISA formula when its defined_for mask applies to nobody Core computes a variable's defined_for mask first and, when it applies to nobody, stores the default without running the formula. The exact float64 valuation ran the formula before masking, so under a reform that masks everyone it calculated dependencies Core never needs, and could fail where Core returns zero. It now works out the mask first and skips the formula when nobody is applicable. A regression gives the balance a formula that raises and checks every programme's capital. Co-Authored-By: Claude Opus 5.5 --- .../test_capital_valuation_properties.py | 27 +++++++++++++++++++ policyengine_uk/utils/capital_valuation.py | 15 +++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 6942fd9748..ed2dfec1c7 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -586,6 +586,33 @@ def test_lifetime_isa_exact_valuation_respects_a_defined_for_mask(): assert abs(after[1] - before[1]) < 0.004, (variable, before, after) +def test_a_lifetime_isa_masked_for_everyone_runs_no_formula(): + # Core runs no formula when the mask applies to nobody, so a dependency + # only applicable people need is never calculated. A balance formula + # that raises shows whether the exact valuation calculates it anyway. + class lifetime_isa_balance(Variable): + def formula(person, period, parameters): + raise AssertionError("A masked Lifetime ISA balance was calculated") + + mask = lisa_mask_reform() + + class MaskWithUnavailableBalance(Reform): + def apply(self): + mask.apply(self) + self.update_variable(lifetime_isa_balance) + + without_lisa = Simulation(situation=whole_penny_situation([(1_599_981, 0, 0, 30)])) + situation = whole_penny_situation([(1_599_981, 0, 0, 30)]) + del situation["people"]["p0"]["lifetime_isa_balance"] + sim = Simulation(situation=situation, reform=MaskWithUnavailableBalance) + assert list(sim.calculate("lifetime_isa_countable_capital", YEAR)) == [0] + for variable in PROGRAMMES: + before = without_lisa.calculate(variable, YEAR)[0] + after = sim.calculate(variable, YEAR)[0] + assert abs(after - before) < 0.004, (variable, before, after) + assert abs(sim.calculate("uc_assessable_capital", YEAR)[0] - 15_999.81) < 0.004 + + def test_a_masked_lifetime_isa_leaves_universal_credit_eligibility(): # 15,999.81 of savings is within the 16,000 limit. A counted 0.26 ISA # (0.195, rounded to 0.20) would take it to 16,000.01; masked, it adds diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index c1e5097bd4..23c3d326c7 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -61,7 +61,8 @@ def valued_person_capital(benunit, period, parameters, capital, counted): (``CALCULATED_PERSON_SOURCES``) is valued to the penny under the programme's rule, like any other valuation. The baseline formula is worked again in float64, so float32 cannot move the rounding, and only - where the variable's ``defined_for`` mask applies it, as Core does. + where the variable's ``defined_for`` mask applies it, as Core does. Like + Core, it runs no formula when the mask applies to nobody. Explicit inputs for this period and branch, and values from a reformed formula, are kept as stored: matching a baseline value in float32 does not prove where a value came from. Any other source is a stored @@ -80,19 +81,23 @@ def valued_person_capital(benunit, period, parameters, capital, counted): and variable.get_formula(period) is calculate and supplied_input(person, source, period) is None ): - exact = calculate(person, period, parameters) + applicable = None if variable.defined_for is not None: # Core keeps the formula's result only where the # defined_for variable is above zero and stores the - # default elsewhere; keep that stored default. + # default elsewhere, and runs no formula when it is + # above zero for nobody; do the same. applicable = ( person.simulation.calculate( variable.defined_for, period, map_to=variable.entity.key ) > 0 ) - exact = np.where(applicable, exact, value) - value = exact + if applicable is None or applicable.any(): + exact = calculate(person, period, parameters) + if applicable is not None: + exact = np.where(applicable, exact, value) + value = exact value = round_to_penny(value, capital.round_down) total = total + benunit.sum(value * counted) return total From fc066bd318f2e059623ab30df56985e3605e24d0 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 29 Oct 2026 02:41:13 -0400 Subject: [PATCH 23/48] Expect the sale-expense deduction on a stocks-and-shares ISA in UC capital MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Main's test_isa_balances expected Universal Credit capital to count a stored stocks-and-shares ISA at its full projected value. This branch values share_like_capital, which carries that ISA, less UC's 10% sale-expense rate until the data separate ISAs from shares (see the sale_expenses.sources description), so the merged test failed with £6,218.99 against £6,433.44: £5,800 rather than £6,000 times growth. The test now reads the rate from the parameters. Co-Authored-By: Claude Opus 5.5 --- policyengine_uk/tests/test_isa_balances.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/policyengine_uk/tests/test_isa_balances.py b/policyengine_uk/tests/test_isa_balances.py index a38b6cc2f4..e5a28362aa 100644 --- a/policyengine_uk/tests/test_isa_balances.py +++ b/policyengine_uk/tests/test_isa_balances.py @@ -59,10 +59,16 @@ def test_stored_household_totals_without_person_balances_project_with_savings(): shares = simulation.calculate("stocks_and_shares_isa", 2027).values[0] assert cash == pytest.approx(3_000.0 * growth) assert shares == pytest.approx(2_000.0 * growth) - # Savings, the cash ISA and the stocks-and-shares ISA (through - # share_like_capital) all reach the capital pool. + # Savings and the cash ISA reach the capital pool at their value. The + # stocks-and-shares ISA reaches it through share_like_capital, which + # Universal Credit values less its sale-expense rate until the data + # separate ISAs from shares. + rate = simulation.tax_benefit_system.parameters( + "2027-04-06" + ).gov.dwp.universal_credit.means_test.capital.sale_expenses.rate capital = simulation.calculate("uc_assessable_capital", 2027).values[0] - assert capital == pytest.approx(6_000.0 * growth, rel=1e-5) + expected = (1_000.0 + 3_000.0 + 2_000.0 * (1 - rate)) * growth + assert capital == pytest.approx(expected, rel=1e-5) def test_household_totals_sum_the_person_balances_in_every_year(): From 3a3241cf6a324f318f4a8cce750a39f9bbdabf4a Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 31 Oct 2026 08:58:37 -0400 Subject: [PATCH 24/48] Say which means tests deduct land debt UC lists no land among its capital sources, so the land-debt input changes the five legacy means tests only. Co-Authored-By: Claude Opus 5.5 --- .../variables/input/owned_land_secured_debt.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/policyengine_uk/variables/input/owned_land_secured_debt.py b/policyengine_uk/variables/input/owned_land_secured_debt.py index e3a890ef82..18d93d7c0b 100644 --- a/policyengine_uk/variables/input/owned_land_secured_debt.py +++ b/policyengine_uk/variables/input/owned_land_secured_debt.py @@ -9,10 +9,11 @@ class owned_land_secured_debt(Variable): "Outstanding encumbrances secured specifically on the household's " "land-only plots. Excludes main-home mortgage debt and unsecured debt. " "Deducted after the 10% for sale expenses in the capital valuation of " - "UC regulation 49(1) and its legacy equivalents (HB, IS, JSA, ESA and " - "Pension Credit), flooring the asset class at nil. The value and the " - "debt are household totals across the class, so debt on one asset " - "offsets equity in another. The survey lacks reliable property-specific " + "the legacy means tests (HB, IS, JSA, ESA and Pension Credit), " + "flooring the asset class at nil. UC counts no land, so this input " + "leaves UC capital unchanged. The value and the debt are household " + "totals across the class, so debt on one asset offsets equity in " + "another. The survey lacks reliable property-specific " "debt flags, so the default zero is a modelling approximation unless " "supplied explicitly." ) From 90e52b48ae98a74f3ac2c0e22e758ae6eb129af7 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 31 Oct 2026 12:04:51 -0400 Subject: [PATCH 25/48] Count an itemised stocks-and-shares ISA in full in every means test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #1969's fc066bd31 made main's test_isa_balances.py expect UC's 10% on a stored stocks-and-shares ISA total, because the ISA then reached capital through share_like_capital, which #1969 values less 10%. With the split, an itemised ISA sits in share_like_capital_without_sale_expenses and counts at its withdrawal value (ADM H1656), so UC capital is (1,000 + 3,000 + 2,000) x growth: 6,000 x 1.07224 = 6,433.44 in 2027. A new parametrised test pins the person-balance route in all six means tests: a £1,000 saver with a £3,000 cash ISA and a £2,000 stocks-and-shares ISA has £6,000 of capital, the ISA wholly in the part without sale expenses. The changelog fragment loses its leading list marker, which towncrier would render as a double bullet. Co-Authored-By: Claude Opus 5.5 --- changelog.d/sale-expense-share-split.fixed.md | 2 +- policyengine_uk/tests/test_isa_balances.py | 78 ++++++++++++++++--- 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/changelog.d/sale-expense-share-split.fixed.md b/changelog.d/sale-expense-share-split.fixed.md index 014f38dd95..70a719b327 100644 --- a/changelog.d/sale-expense-share-split.fixed.md +++ b/changelog.d/sale-expense-share-split.fixed.md @@ -1 +1 @@ -- Value share-like capital by asset type in every means test: directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction; unit trusts (ADM H1673-H1674) and stocks and shares ISAs (ADM H1656) count at full value, as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. +Value share-like capital by asset type in every means test: directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction; unit trusts (ADM H1673-H1674) and stocks and shares ISAs (ADM H1656) count at full value, as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. diff --git a/policyengine_uk/tests/test_isa_balances.py b/policyengine_uk/tests/test_isa_balances.py index e5a28362aa..588d221b6c 100644 --- a/policyengine_uk/tests/test_isa_balances.py +++ b/policyengine_uk/tests/test_isa_balances.py @@ -3,12 +3,14 @@ Datasets built before the per-person balances existed store only the household totals. Those totals must keep their stored values, projected with savings, rather than fall to the sum of balances the dataset does not have. +Every means test counts both kinds of ISA at their withdrawal value, without +the 10% for expenses of sale. """ import pandas as pd import pytest -from policyengine_uk import Microsimulation +from policyengine_uk import Microsimulation, Simulation from policyengine_uk.data.dataset_schema import UKSingleYearDataset @@ -59,15 +61,17 @@ def test_stored_household_totals_without_person_balances_project_with_savings(): shares = simulation.calculate("stocks_and_shares_isa", 2027).values[0] assert cash == pytest.approx(3_000.0 * growth) assert shares == pytest.approx(2_000.0 * growth) - # Savings and the cash ISA reach the capital pool at their value. The - # stocks-and-shares ISA reaches it through share_like_capital, which - # Universal Credit values less its sale-expense rate until the data - # separate ISAs from shares. - rate = simulation.tax_benefit_system.parameters( - "2027-04-06" - ).gov.dwp.universal_credit.means_test.capital.sale_expenses.rate + # Savings, the cash ISA and the stocks-and-shares ISA all reach the + # capital pool at their value: an ISA is valued at what its holder would + # get by withdrawing it, with no deduction for expenses of sale (ADM + # H1656), so the itemised ISA sits in the part of share_like_capital + # without them. + without = simulation.calculate("share_like_capital_without_sale_expenses", 2027) + with_expenses = simulation.calculate("share_like_capital_with_sale_expenses", 2027) + assert without.values[0] == pytest.approx(2_000.0 * growth) + assert with_expenses.values[0] == 0 capital = simulation.calculate("uc_assessable_capital", 2027).values[0] - expected = (1_000.0 + 3_000.0 + 2_000.0 * (1 - rate)) * growth + expected = (1_000.0 + 3_000.0 + 2_000.0) * growth assert capital == pytest.approx(expected, rel=1e-5) @@ -91,3 +95,59 @@ def test_household_totals_sum_the_person_balances_in_every_year(): household_shares = simulation.calculate("stocks_and_shares_isa", year) assert household_cash == pytest.approx(cash.sum()) assert household_shares.values[0] == pytest.approx(shares.sum()) + + +def _isa_situation(age, period, **person): + """One adult with £1,000 of savings and the given person-level balances.""" + return { + "people": { + "person": { + "age": {period: age}, + **{name: {period: value} for name, value in person.items()}, + } + }, + "benunits": { + "benunit": {"members": ["person"], "would_claim_uc": {period: False}} + }, + "households": { + "household": {"members": ["person"], "savings": {period: 1_000.0}} + }, + } + + +@pytest.mark.parametrize( + "variable, age, period", + [ + ("uc_assessable_capital", 30, 2026), + ("housing_benefit_assessable_capital", 30, 2026), + # Income Support's capital list applies to a working-age claimant + # before Universal Credit replaced it. + ("income_support_assessable_capital", 30, 2021), + ("jsa_income_assessable_capital", 30, 2026), + ("esa_income_assessable_capital", 40, 2026), + ("pension_credit_assessable_capital", 70, 2026), + ], +) +def test_person_isa_balances_count_in_full_in_every_means_test(variable, age, period): + """Neither a cash ISA nor a stocks-and-shares ISA takes the 10% for + expenses of sale: each is valued at its withdrawal value (ADM H1656; DMG + 29662, 52662, 84748). £1,000 + £3,000 + £2,000 = £6,000, where the 10% + on the stocks-and-shares ISA would give £5,800.""" + simulation = Simulation( + situation=_isa_situation( + age, + period, + cash_isa_balance=3_000.0, + stocks_and_shares_isa_balance=2_000.0, + ) + ) + assert simulation.calculate("stocks_and_shares_isa", period)[0] == 2_000 + assert simulation.calculate("share_like_capital_without_sale_expenses", period)[ + 0 + ] == pytest.approx(2_000) + assert simulation.calculate("share_like_capital_with_sale_expenses", period)[0] == 0 + if variable == "housing_benefit_assessable_capital": + assert not simulation.calculate( + "housing_benefit_on_passporting_benefit", period + )[0] + assert simulation.calculate(variable, period)[0] == pytest.approx(6_000, abs=0.01) From ce360946a084d90579535d29b02bd260edcfa8c2 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 31 Oct 2026 12:21:04 -0400 Subject: [PATCH 26/48] Test that every means test values itemised holdings by type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Hypothesis property gives single adults only itemised holdings, with the ISAs as their own person-level balances, and checks all six means tests against the law: savings, cash ISAs, unit trusts and stocks and shares ISAs in full, directly held shares less 10%, each rounded by the programme's rule, to within a penny of float32 noise. A pinned example gives £15,600. The list test also asserts that each capital list names cash_isa and that no sale-expense list names savings or cash_isa. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_capital_share_components.py | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 35b018ccb3..80f68c4853 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -23,6 +23,10 @@ from the part with sale expenses, whether it was entered within corporate_wealth or as directly held shares. 6. The exempt list exists from the first date any capital list does. +7. Valuation by type: given only itemised holdings, with the ISAs held as the + person's own balances, all six means tests count savings, cash ISAs, unit + trusts and stocks and shares ISAs in full and directly held shares less + 10%, rounded by each programme's rule, to within a penny. """ import numpy as np @@ -127,6 +131,8 @@ def test_lists_name_the_two_parts(variable): assert not {"corporate_wealth", "share_like_capital", *COMPONENTS} & set(sources) assert WITH in sale and WITHOUT not in sale assert not {"corporate_wealth", *COMPONENTS} & set(sale) + # Deposit balances have no costs of sale (ADM H1607, H1675). + assert "cash_isa" in sources and not {"savings", "cash_isa"} & set(sale) without = set(_parameter("gov.dwp.share_like_capital.without_sale_expenses")) assert without == {"unit_and_investment_trusts", "stocks_and_shares_isa"} @@ -403,3 +409,81 @@ def test_a_disregarded_company_holding_leaves_the_part_with_sale_expenses(): # The pool counts the shares at 90%, and the holding leaves it at that. assert sim.calculate("household_uc_pool_company_holdings", YEAR)[0] == 27_000 assert list(sim.calculate("uc_assessable_capital", YEAR)) == [5_000, 5_000] + + +ROUNDS_DOWN = { + "uc_assessable_capital": False, + "housing_benefit_assessable_capital": False, + "income_support_assessable_capital": True, + "jsa_income_assessable_capital": True, + "esa_income_assessable_capital": True, + "pension_credit_assessable_capital": True, +} +pennies = st.integers(min_value=0, max_value=2_000_000) + + +@settings( + max_examples=10, + deadline=None, + derandomize=True, + suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large], +) +@given( + st.lists( + st.tuples( + pennies, + pennies, + pennies, + pennies, + pennies, + st.sampled_from([30, 70]), + st.booleans(), + ), + min_size=1, + max_size=20, + ) +) +# £1,000 of savings, £3,000 in a cash ISA, £3,000 of unit trusts and a £5,000 +# stocks-and-shares ISA in full, and 90% of £4,000 of shares: £15,600. +@example([(100_000, 300_000, 400_000, 300_000, 500_000, 30, False)]) +def test_itemised_holdings_are_valued_by_type_in_every_means_test(rows): + """Given only itemised holdings, with the ISAs held as the person's own + balances, every means test counts savings, a cash ISA, unit trusts and a + stocks-and-shares ISA in full and directly held shares less 10%, rounded + by the programme's rule. The engine adds the holdings in float32, which + can move the shares' value by a fraction of a penny before valuation, so + each total is checked to within a penny.""" + people, benunits, homes = {}, {}, {} + for i, (savings, cash_isa, shares, trusts, isa, age, claims_uc) in enumerate(rows): + people[f"p{i}"] = { + "age": {YEAR: age}, + "cash_isa_balance": {YEAR: cash_isa / 100}, + "stocks_and_shares_isa_balance": {YEAR: isa / 100}, + } + benunits[f"b{i}"] = { + "members": [f"p{i}"], + "would_claim_uc": {YEAR: claims_uc}, + } + homes[f"h{i}"] = { + "members": [f"p{i}"], + "savings": {YEAR: savings / 100}, + "directly_held_shares": {YEAR: shares / 100}, + "unit_and_investment_trusts": {YEAR: trusts / 100}, + } + sim = Simulation( + situation={"people": people, "benunits": benunits, "households": homes} + ) + passported = sim.calculate("housing_benefit_on_passporting_benefit", YEAR) + for variable, round_down in ROUNDS_DOWN.items(): + values = sim.calculate(variable, YEAR) + for i, (savings, cash_isa, shares, trusts, isa, age, _) in enumerate(rows): + if variable == "pension_credit_assessable_capital": + if age < 67: + continue + elif age >= 67 or ( + variable == "housing_benefit_assessable_capital" and passported[i] + ): + continue + share_pence = (9 * shares + (0 if round_down else 5)) // 10 + expected = (savings + cash_isa + trusts + isa + share_pence) / 100 + assert abs(values[i] - expected) <= 0.011, (variable, rows[i], values[i]) From 2f1051e9fd6340bcfd2a6eb81fdfc616f283bb38 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 31 Oct 2026 12:36:47 -0400 Subject: [PATCH 27/48] Rename the shard-duration lines for the share-components tests this PR renamed test_ci_test_shards.py fails on any shard_durations.toml entry that names a missing test. Main's table lists three tests that this PR replaced with its split versions: - test_capital_matches_the_original_lists became test_unitemised_inputs_match_the_lists_before_itemising, the same four-period differential on the unitemised households; - test_share_like_capital_keeps_the_supplied_aggregate became test_share_like_capital_and_its_parts; - test_float32_rounding_at_the_limit_keeps_eligibility became test_float32_rounding_at_the_limit_keeps_the_aggregate. Each line keeps its measured duration, as the table's header asks of a renaming pull request, until the table is regenerated. Every one of the 566 entries now names a test that exists. Co-Authored-By: Claude Opus 5.5 --- policyengine_uk/tests/shard_durations.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/policyengine_uk/tests/shard_durations.toml b/policyengine_uk/tests/shard_durations.toml index 2c52eb6701..907d405416 100644 --- a/policyengine_uk/tests/shard_durations.toml +++ b/policyengine_uk/tests/shard_durations.toml @@ -13,7 +13,7 @@ # rename or delete its line here. Regenerate when a shard drifts well above # the others. [seconds] -"policyengine_uk/tests/test_capital_share_components.py::test_capital_matches_the_original_lists" = 1299 +"policyengine_uk/tests/test_capital_share_components.py::test_unitemised_inputs_match_the_lists_before_itemising" = 1299 "policyengine_uk/tests/test_statutory_pension_edges.py::test_nics_cap_preserves_aa_inputs_and_charge_with_fixed_ordinary_tax[2029]" = 761 "policyengine_uk/tests/test_statutory_pension_edges.py::test_nics_cap_preserves_aa_inputs_and_charge_with_fixed_ordinary_tax[2030]" = 753 "policyengine_uk/tests/test_mixed_age_couple_properties.py::test_mixed_age_couple_invariants" = 498 @@ -129,7 +129,7 @@ "policyengine_uk/tests/test_disable_simulated_benefits_benefit_cap.py::test_the_benefit_cap_matches_the_replaced_readers_with_the_reform_off" = 108 "policyengine_uk/tests/test_income_support_gate_reads_claimant_or_partner_awards.py::test_the_switched_gate_matches_the_replaced_code" = 107 "policyengine_uk/tests/test_dataframe_dataset.py::test_a_frame_over_several_years_exports_the_same_frame_again" = 107 -"policyengine_uk/tests/test_capital_share_components.py::test_share_like_capital_keeps_the_supplied_aggregate" = 107 +"policyengine_uk/tests/test_capital_share_components.py::test_share_like_capital_and_its_parts" = 107 "policyengine_uk/tests/test_uc_unearned_benefits_properties.py::test_carer_support_payment_counts_like_capped_private_pension" = 107 "policyengine_uk/tests/test_uc_single_claim_properties.py::test_maximum_amount_is_the_solo_claimants" = 107 "policyengine_uk/tests/test_uc_earnings_deductions_properties.py::test_unearned_income_never_changes_earned_income" = 107 @@ -329,7 +329,7 @@ "policyengine_uk/tests/test_uc_earned_income_before_work_allowance_properties.py::test_award_earned_income_is_before_work_allowance_less_the_allowance" = 55 "policyengine_uk/tests/test_capital_share_components.py::test_one_unit_of_float32_rounding_above_a_power_of_two_keeps_the_aggregate" = 55 "policyengine_uk/tests/test_housing_benefit_savings_credit_only_properties.py::test_net_income_does_not_fall_where_savings_credit_ends" = 54 -"policyengine_uk/tests/test_capital_share_components.py::test_float32_rounding_at_the_limit_keeps_eligibility" = 54 +"policyengine_uk/tests/test_capital_share_components.py::test_float32_rounding_at_the_limit_keeps_the_aggregate" = 54 "policyengine_uk/tests/test_housing_benefit_specified_accommodation_disregard_properties.py::test_differential_against_the_statutory_reference" = 54 "policyengine_uk/tests/test_hbai_negative_income_properties.py::test_reset_income_and_its_measures" = 54 "policyengine_uk/tests/test_benunit_reported_capital_properties.py::test_programme_variable_set_directly_wins_for_that_programme" = 53 From 6a0d26d618e018d673e23adaaf777cbd2a498d35 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 31 Oct 2026 17:53:49 -0400 Subject: [PATCH 28/48] Test that the part with sale expenses stops at nil MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When trusts and an ISA exceed corporate_wealth only by float32 rounding, share_like_capital keeps corporate_wealth and subtracting the exempt holdings goes below nil. £16,000 of corporate_wealth with £8,000.01 of trusts and an £8,000 ISA leaves -£0.009765625 without the floor. No fixed case reached the floor before: the grouping case lands at exactly nil either way. A fixed test and a matching @example on the property pin it. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_capital_share_components.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 80f68c4853..e91475b2c9 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -147,6 +147,8 @@ def test_lists_name_the_two_parts(variable): ) # Subtracting trusts and ISA one at a time leaves £0.015625 here; grouped, nil. @example([(399_999.984375, (0.0, 200_000.0, 199_999.984375), True)]) +# Trusts and ISA exceed corporate_wealth by float32 rounding: floored at nil. +@example([(16_000.0, (0.0, 8_000.01, 8_000.0), True)]) def test_share_like_capital_and_its_parts(rows): households = [] for corporate_wealth, components, itemise in rows: @@ -191,6 +193,24 @@ def test_float32_grouping_of_the_exempt_holdings(): assert got[WITH][0] == 0 +def test_exempt_holdings_above_the_aggregate_by_rounding_leave_nil_with_expenses(): + """£8,000.01 of trusts and an £8,000 ISA add up in float32 to + £16,000.009765625, above £16,000 of corporate_wealth by less than a + millionth, so share_like_capital keeps the £16,000. Subtracting the exempt + holdings would leave -£0.009765625; the part with sale expenses stops at + nil, and the part without holds all £16,000.""" + households = [ + { + "corporate_wealth": 16_000, + "unit_and_investment_trusts": 8_000.01, + "stocks_and_shares_isa": 8_000, + } + ] + got = _results(households) + assert got["share_like_capital"][0] == 16_000 + assert got[WITH][0] == 0 and got[WITHOUT][0] == 16_000 + + def test_an_empty_exempt_list_values_everything_less_10_percent(): """A ruling that every share-like holding takes the 10% is a parameter edit.""" reform = {"gov.dwp.share_like_capital.without_sale_expenses": {str(YEAR): []}} From c11d7c1d92faeab80bf37a3019463f0b4ecbc103 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 20:33:16 +0000 Subject: [PATCH 29/48] Value the stocks-and-shares ISA less sale expenses in the stored-totals test The household's stocks-and-shares ISA reaches Universal Credit capital through share_like_capital, which UC values less its sale-expense rate (UC Regulations 2013 reg. 49(1)(a)). Build the expected capital from savings, the cash ISA and the ISA less that rate, read from the parameters, and keep the check that capital keeps one ratio to savings. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LwQq6Kxyq1frfihPSQorLM --- .../tests/test_stored_household_totals.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/policyengine_uk/tests/test_stored_household_totals.py b/policyengine_uk/tests/test_stored_household_totals.py index 468ff7c971..52c1ea99e6 100644 --- a/policyengine_uk/tests/test_stored_household_totals.py +++ b/policyengine_uk/tests/test_stored_household_totals.py @@ -216,10 +216,26 @@ def test_stored_household_totals_grow_past_the_projection_horizon(): assert totals[year][0] == pytest.approx( totals[PROJECTION_END_YEAR][0] * growth, rel=1e-6 ) - # Savings, the cash ISA and the stocks-and-shares ISA (through - # share_like_capital) make up the capital, each grown alike. + # Savings, the cash ISA and the stocks-and-shares ISA make up the capital. + # Savings and the cash ISA count at their value. The stocks-and-shares ISA + # reaches the capital through share_like_capital, which Universal Credit + # values less its sale-expense rate (Universal Credit Regulations 2013 + # reg. 49(1)(a)). The parts grow alike, so capital keeps the same ratio to + # savings in every year: 5.8 for this household. + cash_isa = _values(simulation, "cash_isa") + shares_isa = _values(simulation, "stocks_and_shares_isa") + ratio = capital[DATA_YEAR][0] / savings[DATA_YEAR][0] for year in YEARS: - assert capital[year][0] == pytest.approx(6 * savings[year][0], rel=1e-5) + rate = simulation.tax_benefit_system.parameters( + period(year).start + ).gov.dwp.universal_credit.means_test.capital.sale_expenses.rate + expected = ( + savings[year][0] + cash_isa[year][0] + shares_isa[year][0] * (1 - rate) + ) + assert capital[year][0] == pytest.approx(expected, rel=1e-5), year + face_value = savings[year][0] + cash_isa[year][0] + shares_isa[year][0] + assert capital[year][0] < face_value - 0.01, year + assert capital[year][0] == pytest.approx(ratio * savings[year][0], rel=1e-5) @pytest.mark.parametrize( From ce91e92ea9d2d7c7025d932ba613438bf4a70a8d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 07:43:08 +0000 Subject: [PATCH 30/48] Expect the stocks-and-shares ISA at face value in the stored-totals test Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LwQq6JPpGLuS9js3RjsmWH --- .../tests/test_stored_household_totals.py | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/policyengine_uk/tests/test_stored_household_totals.py b/policyengine_uk/tests/test_stored_household_totals.py index 52c1ea99e6..5d92adb523 100644 --- a/policyengine_uk/tests/test_stored_household_totals.py +++ b/policyengine_uk/tests/test_stored_household_totals.py @@ -216,25 +216,20 @@ def test_stored_household_totals_grow_past_the_projection_horizon(): assert totals[year][0] == pytest.approx( totals[PROJECTION_END_YEAR][0] * growth, rel=1e-6 ) - # Savings, the cash ISA and the stocks-and-shares ISA make up the capital. - # Savings and the cash ISA count at their value. The stocks-and-shares ISA - # reaches the capital through share_like_capital, which Universal Credit - # values less its sale-expense rate (Universal Credit Regulations 2013 - # reg. 49(1)(a)). The parts grow alike, so capital keeps the same ratio to - # savings in every year: 5.8 for this household. + # Savings, the cash ISA and the stocks-and-shares ISA make up the capital, + # each at its value. A decision maker values an ISA at what its holder + # would get by withdrawing it, with no deduction for expenses of sale (ADM + # H1656), so the stored stocks-and-shares ISA reaches the capital through + # share_like_capital_without_sale_expenses. The parts grow alike, so + # capital keeps the same ratio to savings in every year: 6 for this + # household. cash_isa = _values(simulation, "cash_isa") shares_isa = _values(simulation, "stocks_and_shares_isa") ratio = capital[DATA_YEAR][0] / savings[DATA_YEAR][0] for year in YEARS: - rate = simulation.tax_benefit_system.parameters( - period(year).start - ).gov.dwp.universal_credit.means_test.capital.sale_expenses.rate - expected = ( - savings[year][0] + cash_isa[year][0] + shares_isa[year][0] * (1 - rate) - ) - assert capital[year][0] == pytest.approx(expected, rel=1e-5), year face_value = savings[year][0] + cash_isa[year][0] + shares_isa[year][0] - assert capital[year][0] < face_value - 0.01, year + assert capital[year][0] == pytest.approx(face_value, rel=1e-5), year + assert capital[year][0] == pytest.approx(6 * savings[year][0], rel=1e-5), year assert capital[year][0] == pytest.approx(ratio * savings[year][0], rel=1e-5) From 76242a05bba75b73c007226f348d96293e15f795 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 14:43:12 +0000 Subject: [PATCH 31/48] Count main's person ISA oracles at each programme's sale-expense share The pound-counts-once and worked-example checks in test_person_isa_capital.py now value share_like_capital, and each stocks and shares ISA balance moved out of it, less the programme's sale-expense rate, and allow for each unit's penny rounding. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LwQq6K8DguS6nS1jwFZ8Zi --- policyengine_uk/tests/test_person_isa_capital.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/policyengine_uk/tests/test_person_isa_capital.py b/policyengine_uk/tests/test_person_isa_capital.py index 053c6c4f25..5ab33ba7e3 100644 --- a/policyengine_uk/tests/test_person_isa_capital.py +++ b/policyengine_uk/tests/test_person_isa_capital.py @@ -433,12 +433,15 @@ def test_both_forms_in_one_dataset_add_up_to_the_stored_total(): uc = simulation.calculate("uc_assessable_capital", year) hb = simulation.calculate("housing_benefit_assessable_capital", year) for capital in (uc, hb): + # UC and Housing Benefit round each unit's capital to the nearest + # penny, so the household's two units can come to a penny over: + # savings of 1,268.69 in 2032 give each 634.345, which rounds up. by_household = np.bincount(benunit_household, weights=capital) - assert by_household == pytest.approx(holdings, rel=1e-6), year + assert by_household == pytest.approx(holdings, rel=1e-6, abs=0.011), year # The lodger counts their own balance on top of a third of the pool. pool = holdings[0] - counted[2] - assert uc[1] == pytest.approx(pool / 3 + counted[2], rel=1e-6), year - assert uc[0] == pytest.approx(2 * pool / 3, rel=1e-6), year + assert uc[1] == pytest.approx(pool / 3 + counted[2], rel=1e-6, abs=0.006), year + assert uc[0] == pytest.approx(2 * pool / 3, rel=1e-6, abs=0.006), year # #2781 keeps the stored 15,000, so the formula allocates savings of 4,000 # and the unexplained 5,000 as 6,000 and 3,000. The second household's # pool holds only its savings. From 3dbdb00276578089c68949b31658239386af9420 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 03:45:14 +0000 Subject: [PATCH 32/48] List owned_land_secured_debt among the per capita GDP variables uprating_indices.yaml grows owned_land_secured_debt with per capita GDP, but the growth factors page left it out of that list. The page's list now matches the index file's per capita GDP entry. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01H3DAwvyhPgY7sU1r3AiycF --- docs/book/assumptions/growthfactors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book/assumptions/growthfactors.md b/docs/book/assumptions/growthfactors.md index 501dd5c9e2..2be060c349 100644 --- a/docs/book/assumptions/growthfactors.md +++ b/docs/book/assumptions/growthfactors.md @@ -106,7 +106,7 @@ We derive these rates as calendar-year nominal GDP growth from the OBR's October |-------------|------|------|------|------|------|------|------|------|------|------| | Growth rate | 10.0% | 5.2% | 4.0% | 4.6% | 4.0% | 3.1% | 3.4% | 3.6% | 3.4% | 3.3% | -We use per capita GDP for these variables: `benunit_reported_capital`, `cash_isa`, `cash_isa_balance`, `consumer_debt`, `corporate_wealth`, `directly_held_shares`, `dividend_income`, `gross_financial_wealth`, `household_lifetime_isa_balance`, `income_not_otherwise_charged`, `individual_savings_account_dividend_income`, `lifetime_isa_balance`, `lump_sum_income`, `maintenance_income`, `miscellaneous_income`, `mortgage_capital_repayment`, `mortgage_debt`, `net_financial_wealth`, `non_residential_property_purchased`, `non_residential_property_secured_debt`, `non_residential_property_value`, `other_residential_property_secured_debt`, `owned_company_capital`, `owned_company_holding_value`, `owned_company_trade_assets`, `owned_land`, `pension_credit_reported_capital`, `pension_income`, `private_pension_wealth`, `private_transfer_income`, `property_income`, `property_rental_income`, `rent_paid_as_boarder`, `rent_paid_as_lodger`, `savings`, `spousal_maintenance_income`, `stocks_and_shares_isa`, `stocks_and_shares_isa_balance`, `sublet_income`, `uc_reported_capital`, `unit_and_investment_trusts` +We use per capita GDP for these variables: `benunit_reported_capital`, `cash_isa`, `cash_isa_balance`, `consumer_debt`, `corporate_wealth`, `directly_held_shares`, `dividend_income`, `gross_financial_wealth`, `household_lifetime_isa_balance`, `income_not_otherwise_charged`, `individual_savings_account_dividend_income`, `lifetime_isa_balance`, `lump_sum_income`, `maintenance_income`, `miscellaneous_income`, `mortgage_capital_repayment`, `mortgage_debt`, `net_financial_wealth`, `non_residential_property_purchased`, `non_residential_property_secured_debt`, `non_residential_property_value`, `other_residential_property_secured_debt`, `owned_company_capital`, `owned_company_holding_value`, `owned_company_trade_assets`, `owned_land`, `owned_land_secured_debt`, `pension_credit_reported_capital`, `pension_income`, `private_pension_wealth`, `private_transfer_income`, `property_income`, `property_rental_income`, `rent_paid_as_boarder`, `rent_paid_as_lodger`, `savings`, `spousal_maintenance_income`, `stocks_and_shares_isa`, `stocks_and_shares_isa_balance`, `sublet_income`, `uc_reported_capital`, `unit_and_investment_trusts` ## Capital gains From 59a1c4ad217b3d054bab75dfa7388186ffd89f5b Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 5 Nov 2026 02:32:16 -0500 Subject: [PATCH 33/48] Name the formula and the model in the capital changelog fragment Co-Authored-By: Claude Opus 5.5 --- changelog.d/uc-capital-sale-expenses.fixed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/uc-capital-sale-expenses.fixed.md b/changelog.d/uc-capital-sale-expenses.fixed.md index 2a9f6d49fb..02d0588143 100644 --- a/changelog.d/uc-capital-sale-expenses.fixed.md +++ b/changelog.d/uc-capital-sale-expenses.fixed.md @@ -1 +1 @@ -Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and share-like capital (share_like_capital), not to cash savings; share-like capital also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land, and council tax reduction's own household capital now deducts the debt secured on land too. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. A Lifetime ISA's surrender value is worked out from its balance and rounded under the same rule. Explicit Lifetime ISA capital inputs and reformed valuation formulas are preserved. +Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and share-like capital (share_like_capital), not to cash savings; share-like capital also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land, and the council tax reduction formula deducts the debt secured on land from the land on its own household route. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. The model works out a Lifetime ISA's surrender value from its balance and rounds it under the same rule, and keeps explicit Lifetime ISA capital inputs and reformed valuation formulas. From 65cebd3f6e58be6fa097fdf5e6b7625e6a9679a6 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 12 Nov 2026 09:27:57 -0500 Subject: [PATCH 34/48] Count person stocks and shares ISAs at face value in main's ISA tests This branch values stocks and shares ISAs without the deduction for expenses of sale (ADM H1656-H1658), and the ISA person source now comes out of share_like_capital_without_sale_expenses. Main's person ISA cases expected 90%, so each counted ISA rises by a tenth. Cases 13 to 15 test a boundary, so their inputs move to keep it: a 30,600 ISA in Case 13, and household totals of 16,000 and 6,000 in Cases 14 and 15. Co-Authored-By: Claude Opus 5.5 --- .../baseline/gov/dwp/person_isa_capital.yaml | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml index a282d3c84d..86162714b5 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml @@ -9,11 +9,14 @@ # from the household's capital, then allocates the remainder by claimant and # partner counts, between pension-age adults for Pension Credit, or wholly to # a unit on the IS, JSA or ESA claim path. Each programme values the pool's -# share_like_capital, and each stocks and shares ISA balance the formula moves -# out of it, at market value less 10% for the expenses of sale (UC Regs 2013 -# reg 49(1)(a); HB Regs 2006 reg 47; IS Regs 1987 reg 49; JSA Regs 1996 reg -# 111; ESA Regs 2008 reg 113; SPC Regs 2002 reg 19), and counts savings and -# cash ISAs at face value. +# share-like holdings with expenses of sale (directly held shares, and all of +# an unitemised corporate_wealth) at market value less 10% (UC Regs 2013 reg +# 49(1)(a); HB Regs 2006 reg 47; IS Regs 1987 reg 49; JSA Regs 1996 reg 111; +# ESA Regs 2008 reg 113; SPC Regs 2002 reg 19). It counts savings, cash ISAs +# and each stocks and shares ISA balance the formula moves out of +# share_like_capital at face value: an ISA is valued at what the holder would +# get by withdrawing it, with no deduction for expenses of sale (ADM +# H1656-H1658; DMG 29662-29664, 52662, 84748-84750). - name: Case 1, a lodger's cash ISA stays out of the main benefit unit's capital. period: 2025 @@ -75,9 +78,9 @@ # The formula subtracts the child's 6,000 from savings 9,000 plus # share_like_capital 6,000 and allocates the remaining 9,000 by claimant # counts: 6,000 to the parents and 3,000 to the child's unit, which adds - # the 6,000 ISA less 10%, 5,400. - uc_assessable_capital: [6_000, 8_400] - housing_benefit_assessable_capital: [6_000, 8_400] + # the 6,000 ISA at face value. + uc_assessable_capital: [6_000, 9_000] + housing_benefit_assessable_capital: [6_000, 9_000] - name: Case 3, an adult child's ISA inside corporate wealth stays out of the parents' capital. period: 2025 @@ -107,10 +110,10 @@ share_like_capital: 9_000 # The formula subtracts the child's 6,000 ISA from corporate wealth # 9,000, values the remaining 3,000 less 10% at 2,700 and allocates it: - # 1,800 to the parents and 900 to the child's unit, which adds the ISA - # less 10%, 5,400. - uc_assessable_capital: [1_800, 6_300] - housing_benefit_assessable_capital: [1_800, 6_300] + # 1,800 to the parents and 900 to the child's unit, which adds the 6,000 + # ISA at face value. + uc_assessable_capital: [1_800, 6_900] + housing_benefit_assessable_capital: [1_800, 6_900] - name: Case 4, a parent's Income Support claim does not count an adult child's cash ISA. period: 2025 @@ -187,8 +190,8 @@ savings: 2_000 output: # The parent's claiming unit takes the 2,000 of savings; the child's unit - # counts the ISA less 10%, 4,500. - esa_income_assessable_capital: [2_000, 4_500] + # counts the 5,000 ISA at face value. + esa_income_assessable_capital: [2_000, 5_000] - name: Case 7, a pensioner couple's Pension Credit counts their own ISAs and not a lodger's. period: 2025 @@ -217,8 +220,8 @@ # The formula subtracts all three balances from savings 4,000, cash_isa # 9,000 and share_like_capital 2,000, and allocates the remaining 4,000 # between the two pension-age adults. The couple's unit adds their own - # 3,000 cash ISA and the 2,000 stocks and shares ISA less 10%, 1,800. - pension_credit_assessable_capital: [8_800, 0] + # 3,000 cash ISA and 2,000 stocks and shares ISA at face value. + pension_credit_assessable_capital: [9_000, 0] - name: Case 8, a dependent child's junior ISA counts in no benefit unit. period: 2025 @@ -277,9 +280,9 @@ # Joint claimants' combined capital (WRA 2012 s 5(2)(a)): the formula # allocates savings of 6,000 by claimant counts, 4,000 to the couple and # 2,000 to the lodger, and the couple's unit adds their 4,000 cash ISA - # and the 3,000 stocks and shares ISA less 10%, 2,700. - uc_assessable_capital: [10_700, 2_000] - housing_benefit_assessable_capital: [10_700, 2_000] + # and the 3,000 stocks and shares ISA at face value. + uc_assessable_capital: [11_000, 2_000] + housing_benefit_assessable_capital: [11_000, 2_000] - name: Case 10, a household total above the balances keeps the rest in the pool. period: 2025 @@ -377,7 +380,7 @@ age: 30 lodger: age: 30 - stocks_and_shares_isa_balance: 34_000 + stocks_and_shares_isa_balance: 30_600 benunits: tenant_unit: members: tenant @@ -387,16 +390,15 @@ household: members: [tenant, lodger] output: - # The ISA less 10%, 30,600, exceeds reg 18's 16,000 limit. Pooling it - # would give each claimant 15,300, within the limit. The formula - # attributes it to its holder. + # The ISA of 30,600 exceeds reg 18's 16,000 limit. Pooling it would give + # each claimant 15,300, within the limit. The formula attributes it to + # its holder. uc_assessable_capital: [0, 30_600] # Cases 14 to 17: where balances exceed a household total, the model counts # exactly the total, so a holder at a capital limit or a tariff threshold -# stays on its boundary. In Cases 14 and 15 the stocks and shares total, less -# 10% and rounded to the nearest penny (UC Regs 2013 reg 6(1)), comes to the -# boundary: 90% of 17,777.78 is 16,000.002 and 90% of 6,666.67 is 6,000.003. +# stays on its boundary. In Cases 14 and 15 the stocks and shares total is the +# boundary itself, since a stocks and shares ISA counts at face value. # The model stores amounts in float32 (spacing 0.0009765625 at 16,000), and # absolute_error_margin 0 fails on one unit in the last place. @@ -426,10 +428,10 @@ cash_isa: 16_000 stocks_home: members: stocks_holder - stocks_and_shares_isa: 17_777.78 + stocks_and_shares_isa: 16_000 output: cash_isa_countable_capital: [16_000, 0] - stocks_and_shares_isa_countable_capital: [0, 17_777.78] + stocks_and_shares_isa_countable_capital: [0, 16_000] # WRA 2012 s 5(1)(a) requires capital not greater than the amount reg # 18(1)(a) prescribes, 16,000, so capital of exactly 16,000 keeps # entitlement. Reg 72(1) deems 4.35 a month for each 250 above 6,000: @@ -464,10 +466,10 @@ cash_isa: 6_000 stocks_home: members: stocks_holder - stocks_and_shares_isa: 6_666.67 + stocks_and_shares_isa: 6_000 output: cash_isa_countable_capital: [6_000, 0] - stocks_and_shares_isa_countable_capital: [0, 6_666.67] + stocks_and_shares_isa_countable_capital: [0, 6_000] # Reg 72(1) deems no income from capital of 6,000 or less. uc_assessable_capital: [6_000, 6_000] uc_tariff_income: [0, 0] @@ -578,8 +580,8 @@ share_like_capital: 100 output: stocks_and_shares_isa_countable_capital: 100 - # UC counts the 100 less 10%. - uc_assessable_capital: 90 + # UC counts the 100 at face value. + uc_assessable_capital: 100 - name: Case 19, a child's ISA counts in no unit when the parent reports the family's capital. period: 2025 From df8c1ea79ca095126723fee8b1ba7e62e62a92fa Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 12 Nov 2026 09:31:38 -0500 Subject: [PATCH 35/48] Value the share-like parts separately in main's ISA property tests Main's tests valued all of share_like_capital, and each stocks and shares ISA, at 90%. On this branch only share_like_capital_with_sale_expenses takes the deduction, and the ISA person source comes out of share_like_capital_without_sale_expenses at face value. The helpers now value each part by whether the programme's sale_expenses.sources lists it, and the hand-worked cases follow: the producer-shape households give UC capital of 10,900, 8,950, 14,000 and 11,000, and the list-reform test drops share_like_capital_without_sale_expenses, the source that holds the ISA. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_person_isa_capital.py | 134 ++++++++++-------- 1 file changed, 73 insertions(+), 61 deletions(-) diff --git a/policyengine_uk/tests/test_person_isa_capital.py b/policyengine_uk/tests/test_person_isa_capital.py index 5ab33ba7e3..669c441b9a 100644 --- a/policyengine_uk/tests/test_person_isa_capital.py +++ b/policyengine_uk/tests/test_person_isa_capital.py @@ -18,10 +18,14 @@ Credit holders outside a pension-age unit), equals savings, cash_isa and share_like_capital together, up to float32 rounding of the remainder's shares and each programme's penny rounding. Each programme values - share_like_capital, and each stocks and shares ISA it moves out of it, at - its sale-expense share (90%), and savings and cash ISAs at face value. Where balances exceed a total, the holdings sum to it exactly, so - that source leaves nothing in the remainder: an adult with no ISA counts - exactly the capital they count without the other members' ISAs. + share_like_capital_with_sale_expenses (directly held shares, and all of + an unitemised corporate_wealth) at its sale-expense share (90%), and + share_like_capital_without_sale_expenses (unit and investment trusts and + stocks and shares ISAs), each stocks and shares ISA it moves out of that + part, savings and cash ISAs at face value. Where balances exceed a total, + the holdings sum to it exactly, so that source leaves nothing in the + remainder: an adult with no ISA counts exactly the capital they count + without the other members' ISAs. 2. Where the balances' stored sum exceeds the total, the holdings sum to the total exactly, each in proportion to its balance within the step invariant 7 gives; otherwise each member counts their balance exactly. @@ -83,6 +87,10 @@ } MEANS_TEST_CAPITAL = (*CAPITAL, "council_tax_reduction_assessable_capital") ISA_SOURCES = tuple(HOUSEHOLD_SOURCE_OF) +SHARE_LIKE_PARTS = ( + "share_like_capital_with_sale_expenses", + "share_like_capital_without_sale_expenses", +) BALANCE = { "cash_isa_countable_capital": "cash_isa_balance", "stocks_and_shares_isa_countable_capital": "stocks_and_shares_isa_balance", @@ -394,12 +402,12 @@ def test_household_only_data_keep_todays_capital(): assert np.array_equal( simulation.calculate(name, year), before.calculate(name, year) ), (name, year) - # The first household's pool: savings 3,000, cash_isa 4,000 and - # corporate_wealth 5,000 (which holds the 2,000 ISA) less 10%, 4,500, - # shared by three claimants, two of them the couple. UC rounds each to - # the nearest penny. + # The first household's pool: savings 3,000, cash_isa 4,000, and + # corporate_wealth 5,000, which holds the 2,000 ISA at face value and + # 3,000 of other shares less 10%, 2,700: 11,700 shared by three + # claimants, two of them the couple. uc = simulation.calculate("uc_assessable_capital", YEAR) - assert list(uc[:2]) == pytest.approx([7_666.67, 3_833.33], abs=0.001) + assert list(uc[:2]) == pytest.approx([7_800, 3_900], abs=0.001) def test_both_forms_in_one_dataset_add_up_to_the_stored_total(): @@ -492,11 +500,20 @@ def test_both_forms_in_one_dataset_add_up_to_the_stored_total(): ] -def _household_capital(simulation, year, share=1): +def _household_capital(simulation, year, variable=None): + """Savings, cash ISAs and share-like capital, as ``variable`` values them. + + With no ``variable``, at market value. + """ + share_like = sum( + (_share_counted(variable, part) if variable else 1) + * simulation.calculate(part, year) + for part in SHARE_LIKE_PARTS + ) return ( simulation.calculate("savings", year) + simulation.calculate("cash_isa", year) - + share * simulation.calculate("share_like_capital", year) + + share_like ) @@ -522,23 +539,20 @@ def test_person_balances_without_household_totals_count_with_their_holders(): simulation.calculate("share_like_capital", year), simulation.calculate("corporate_wealth", year), ) - holdings = _household_capital( - simulation, year, _share_counted("uc_assessable_capital") - ) + holdings = _household_capital(simulation, year, "uc_assessable_capital") uc = simulation.calculate("uc_assessable_capital", year) assert np.bincount(benunit_household, weights=uc) == pytest.approx( holdings, rel=1e-6 ) - # Savings 7,000 and 2,000 of non-ISA shares less 10%, 1,800, make the - # first pool, 2,933.33 for each claimant. The couple adds a 3,000 cash ISA - # and a 2,000 stocks and shares ISA less 10% (1,800), and the other unit a - # 5,000 cash ISA and a 1,000 one less 10% (900). The second pool, savings - # 12,000 and 3,000 of trusts less 10% (2,700), gives the parents 9,800 - # and their son 4,900 in UC, to which they add 4,000 and 5,400 of ISAs; - # the pension-age parents count all 14,700 and their 4,000 in Pension - # Credit. UC rounds to the nearest penny, and the legacy programmes - # round down. - expected_uc = [10_666.67, 8_833.33, 13_800, 10_300] + # Savings 7,000, 1,500 of directly held shares less 10%, 1,350, and 500 + # of trusts at face value make the first pool, 2,950 for each claimant. + # The couple adds a 3,000 cash ISA and a 2,000 stocks and shares ISA, and + # the other unit a 5,000 cash ISA and a 1,000 stocks and shares ISA, all + # at face value. The second pool, savings 12,000 and 3,000 of trusts, + # gives the parents 10,000 and their son 5,000 in UC, to which they add + # 4,000 and 6,000 of ISAs; the pension-age parents count all 15,000 and + # their 4,000 in Pension Credit. + expected_uc = [10_900, 8_950, 14_000, 11_000] assert list(simulation.calculate("uc_assessable_capital", YEAR)) == pytest.approx( expected_uc, abs=0.001 ) @@ -548,7 +562,7 @@ def test_person_balances_without_household_totals_count_with_their_holders(): assert list(capital[:2]) == pytest.approx(expected_uc[:2], abs=0.011), name assert list( simulation.calculate("pension_credit_assessable_capital", YEAR) - ) == pytest.approx([0, 0, 18_700, 0], abs=0.001) + ) == pytest.approx([0, 0, 19_000, 0], abs=0.001) # One benefit unit each, with a child: the adults' cash and stocks and shares @@ -726,35 +740,31 @@ def _check_counted_isas(simulation): return counted -def _share_counted(variable): - """The share of share_like_capital's market value ``variable`` counts. +def _share_counted(variable, source): + """The share of household ``source``'s market value ``variable`` counts. - The programme counts share_like_capital, and each stocks and shares ISA - balance it moves out of it, less its sale-expense rate where its - ``sale_expenses.sources`` lists share_like_capital. + The programme counts ``source``, and each person ISA it moves out of it, + less its sale-expense rate where its ``sale_expenses.sources`` lists + ``source``. """ capital = _node(CAPITAL[variable]) date = f"{YEAR}-01-01" - if "share_like_capital" in capital.sale_expenses.sources(date): + if source in capital.sale_expenses.sources(date): return 1 - capital.sale_expenses.rate(date) return 1 -# The share of each ISA person source's value a programme counts, given the -# share it counts of share_like_capital. -def _isa_shares(share): +# The share of each ISA person source's value a programme counts: the share +# it counts of the household source that holds it. +def _isa_shares(variable): return { - "cash_isa_countable_capital": 1, - "stocks_and_shares_isa_countable_capital": share, + source: _share_counted(variable, HOUSEHOLD_SOURCE_OF[source]) + for source in ISA_SOURCES } -def _holdings(simulation, share=1): - return ( - simulation.calculate("savings", YEAR) - + simulation.calculate("cash_isa", YEAR) - + share * simulation.calculate("share_like_capital", YEAR) - ) +def _holdings(simulation, variable=None): + return _household_capital(simulation, YEAR, variable) @SITUATION_SETTINGS @@ -775,8 +785,7 @@ def test_a_pound_counts_once_in_working_age_means_tests(units, holdings): "jsa_income_assessable_capital", "esa_income_assessable_capital", ): - share = _share_counted(name) - weights = _isa_shares(share) + weights = _isa_shares(name) uncounted = sum( (weights[source] * amount * dependants).sum() for source, amount in counted.items() @@ -785,7 +794,7 @@ def test_a_pound_counts_once_in_working_age_means_tests(units, holdings): # Float32 shares of the remainder, and each valuation's penny # rounding, come to within a few pence. assert capital.sum() + uncounted == pytest.approx( - _holdings(simulation, share)[0], rel=1e-5, abs=0.05 + _holdings(simulation, name)[0], rel=1e-5, abs=0.05 ), name # Each unit counts at least its own claimant's and partner's ISAs. own = sum( @@ -901,8 +910,7 @@ def test_a_pound_counts_once_in_pension_credit(households): > 0 ) counts = simulation.calculate("is_claimant_or_partner", YEAR) & in_pension_unit - share = _share_counted("pension_credit_assessable_capital") - weights = _isa_shares(share) + weights = _isa_shares("pension_credit_assessable_capital") uncounted = sum( _by_household(simulation, "person", weights[source] * amount * ~counts) for source, amount in counted.items() @@ -911,7 +919,9 @@ def test_a_pound_counts_once_in_pension_credit(households): # Float32 shares of the remainder, and each valuation's penny rounding, # come to within a few pence. assert _by_household(simulation, "benunit", capital) + uncounted == pytest.approx( - _holdings(simulation, share), rel=1e-5, abs=0.05 + _holdings(simulation, "pension_credit_assessable_capital"), + rel=1e-5, + abs=0.05, ) if households is STORED_TOTALS: # The last household's ISA holdings sum exactly to its totals, so its @@ -1075,28 +1085,30 @@ def test_reforms_to_either_list_keep_each_isa_with_its_household_source(): def capital(name): return list(simulation.calculate(name, YEAR)) - # The lodger's unit counts the 10,000 cash ISA and the 4,000 stocks and - # shares ISA less 10% (3,600), and half the 2,000 of savings. - assert capital("uc_assessable_capital") == [1_000, 14_600] - assert capital("housing_benefit_assessable_capital") == [1_000, 14_600] + # The lodger's unit counts the 10,000 cash ISA, the 4,000 stocks and + # shares ISA at face value, and half the 2,000 of savings. + assert capital("uc_assessable_capital") == [1_000, 15_000] + assert capital("housing_benefit_assessable_capital") == [1_000, 15_000] sources = list(_node(uc_path + ".sources")(f"{YEAR}-01-01")) # Dropping cash_isa from UC's sources: savings 2,000 shared, and the - # lodger keeps their stocks and shares ISA less 10%. Dropping - # share_like_capital: the 10,000 cash ISA stays theirs. + # lodger keeps their stocks and shares ISA. Dropping + # share_like_capital_without_sale_expenses, which holds that ISA: the + # 10,000 cash ISA stays theirs. for dropped, expected in ( - ("cash_isa", [1_000, 4_600]), - ("share_like_capital", [1_000, 11_000]), + ("cash_isa", [1_000, 5_000]), + ("share_like_capital_without_sale_expenses", [1_000, 11_000]), ): + assert dropped in sources, dropped kept = [name for name in sources if name != dropped] with _law(simulation, uc_path + ".sources", kept): assert capital("uc_assessable_capital") == expected, dropped # Emptying UC's person_sources returns both ISAs to the pool: savings - # 2,000, the cash ISA and the stocks and shares ISA less 10%, 15,600 in - # all, shared by two claimants. Housing Benefit keeps its own lists. + # 2,000 and the two ISAs, 16,000 in all, shared by two claimants. + # Housing Benefit keeps its own lists. with _law(simulation, uc_path + ".person_sources", []): - assert capital("uc_assessable_capital") == [7_800, 7_800] - assert capital("housing_benefit_assessable_capital") == [1_000, 14_600] - assert capital("uc_assessable_capital") == [1_000, 14_600] + assert capital("uc_assessable_capital") == [8_000, 8_000] + assert capital("housing_benefit_assessable_capital") == [1_000, 15_000] + assert capital("uc_assessable_capital") == [1_000, 15_000] @pytest.mark.parametrize("variable", CAPITAL) From 3fe76ee3e62480972a5b9d57a1bd6773e8d1e1a3 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Fri, 13 Nov 2026 07:02:58 -0500 Subject: [PATCH 36/48] Allow float32's step in the itemised-holdings means-test property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test checked each total to within £0.011, and CI at df8c1ea79 failed it. The engine holds totals in float32. Its float32 sum can round a penny under the exact total, which the test's docstring allows, and it then stores that figure to float32's step, which the £0.011 bound didn't allow for above about £16,000. CI drew a household the test expects at £16,834.13: the engine gives £16,834.12, held as 16,834.119, which is £0.0109 under, and the test's own float32 subtraction read £0.0117. The check now subtracts in float64 and allows a penny plus one float32 step at the expected value. Two households are pinned: CI's, and one expected at £37,747.34 that the engine holds as 37,747.328, which is £0.0119 under and fails the old bound in float64 too. Co-Authored-By: Claude Fable 5.2 --- .../tests/test_capital_share_components.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index e91475b2c9..a6e7e57944 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -466,13 +466,22 @@ def test_a_disregarded_company_holding_leaves_the_part_with_sale_expenses(): # £1,000 of savings, £3,000 in a cash ISA, £3,000 of unit trusts and a £5,000 # stocks-and-shares ISA in full, and 90% of £4,000 of shares: £15,600. @example([(100_000, 300_000, 400_000, 300_000, 500_000, 30, False)]) +# Income Support counts £16,834.13 here. The engine gives £16,834.12, held +# in float32 as 16,834.119: £0.0109 under, or £0.0117 when the comparison +# itself runs in float32. +@example([(510_510, 1_046_019, 2_051, 437, 124_602, 30, True)]) +# Income Support counts £37,747.34 here, and the engine holds £37,747.33 as +# 37,747.328: £0.0119 under, a penny plus half of float32's step at that +# size (£0.0039). +@example([(1_813_184, 40_164, 988_571, 7_260, 1_024_413, 30, False)]) def test_itemised_holdings_are_valued_by_type_in_every_means_test(rows): """Given only itemised holdings, with the ISAs held as the person's own balances, every means test counts savings, a cash ISA, unit trusts and a stocks-and-shares ISA in full and directly held shares less 10%, rounded by the programme's rule. The engine adds the holdings in float32, which can move the shares' value by a fraction of a penny before valuation, so - each total is checked to within a penny.""" + each total is checked to within a penny plus float32's step at that + size.""" people, benunits, homes = {}, {}, {} for i, (savings, cash_isa, shares, trusts, isa, age, claims_uc) in enumerate(rows): people[f"p{i}"] = { @@ -506,4 +515,9 @@ def test_itemised_holdings_are_valued_by_type_in_every_means_test(rows): continue share_pence = (9 * shares + (0 if round_down else 5)) // 10 expected = (savings + cash_isa + trusts + isa + share_pence) / 100 - assert abs(values[i] - expected) <= 0.011, (variable, rows[i], values[i]) + tolerance = 0.01 + float(np.spacing(np.float32(expected))) + assert abs(float(values[i]) - expected) <= tolerance, ( + variable, + rows[i], + values[i], + ) From 690a562228006161e1f50c5121053b7398c52149 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 05:31:03 -0500 Subject: [PATCH 37/48] Say the full ISA value rests on ADM H1656's silence on costs of sale The without_sale_expenses description and the changelog fragment now say the model counts a stocks and shares ISA at its full withdrawal value because H1656 says nothing about costs of sale, not that a paragraph exempts it. The description also notes that employee share options, which the survey asks about with employee shares, take the deduction as an approximation. A comment on COMPONENTS says every name on the exempt list must be one of them, since the formula reads only COMPONENTS to decide whether a household itemises. Co-Authored-By: Claude Opus 5.5 --- changelog.d/sale-expense-share-split.fixed.md | 2 +- .../gov/dwp/share_like_capital/without_sale_expenses.yaml | 8 ++++++-- .../wealth/share_like_capital_with_sale_expenses.py | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/changelog.d/sale-expense-share-split.fixed.md b/changelog.d/sale-expense-share-split.fixed.md index 70a719b327..7863885269 100644 --- a/changelog.d/sale-expense-share-split.fixed.md +++ b/changelog.d/sale-expense-share-split.fixed.md @@ -1 +1 @@ -Value share-like capital by asset type in every means test: directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction; unit trusts (ADM H1673-H1674) and stocks and shares ISAs (ADM H1656) count at full value, as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. +Value share-like capital by asset type in every means test. Directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction. Unit trusts count at full value (ADM H1673-H1674), as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. Stocks and shares ISAs count at their full withdrawal value, because ADM H1656 says nothing about costs of sale. diff --git a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml index fa06ccc205..76b7c40c94 100644 --- a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml +++ b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml @@ -8,10 +8,14 @@ description: > investment trusts are quoted shares, which take the deduction (ADM H1665), and were 8.2% of the pooled funds held in stocks and shares ISAs at 5 April 2022 and 6.9% at 5 April 2025 (HMRC ISA Table 9.6). An ISA is valued at - what the holder would get by withdrawing it, and no ISA paragraph applies - the deduction (ADM H1656-H1658; DMG 29662-29664, 52662, 84748-84750). + what the holder would get by withdrawing it (ADM H1656-H1658; DMG + 29662-29664, 52662, 84748-84750). The model counts that value in full, a + reading that rests on ADM H1656 saying nothing about costs of sale. Everything else in share_like_capital takes the deduction: directly held shares, and on datasets that do not itemise it, all of corporate_wealth. + Directly held shares include employee shares and share options, which the + Wealth and Assets Survey asks about together, so share options also take + the deduction, an approximation. metadata: label: Share-like holdings without expenses of sale period: year diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py index d5136dd2b3..bbd8b72f33 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -1,5 +1,10 @@ from policyengine_uk.model_api import * +# The share-like holdings a dataset can itemise. The formula treats a +# household as itemising only when one of these is positive, so every name in +# gov.dwp.share_like_capital.without_sale_expenses must be in this list. A +# reform that adds a holding outside it would leave a household that itemises +# only that holding with all of its share-like capital under the deduction. COMPONENTS = [ "directly_held_shares", "unit_and_investment_trusts", From d6cf32529fdc7a6d6802f9bd7f55ea98a46b388c Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 05:31:03 -0500 Subject: [PATCH 38/48] Check that every sale-expense name is a counted capital source valued_capital reads only each programme's capital.sources, so a name on capital.sale_expenses.sources outside them is never valued. The property now asserts the sale list is a subset of the counted sources for all six programmes, which the intersection check alone could not see. Co-Authored-By: Claude Opus 5.5 --- policyengine_uk/tests/test_capital_valuation_properties.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 8c7a6fbaa0..3298677890 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -228,6 +228,13 @@ def check_valuation(units): assert node.sale_expenses.rate == LEGAL_RATE assert "savings" in node.sources counted = set(node.sources) + # Every name on the sale-expense list must be a counted source: + # valued_capital reads only node.sources, so a listed name outside + # them is never valued, and the intersection check below can't see it. + assert set(node.sale_expenses.sources) <= counted, ( + variable, + sorted(set(node.sale_expenses.sources) - counted), + ) assert set(node.sale_expenses.sources) & counted == ( SALE_EXPENSE_ASSETS & counted ), variable From 8f755b98176a7b1fe622457e98de593d2cd828ec Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 06:48:29 -0500 Subject: [PATCH 39/48] Describe the share split in #1969's fragment, the ISA docs and test comments #1969's changelog fragment said the 10% reached all of share_like_capital, unit trusts included, "until the data separate them". It now names what takes the deduction after the split: land, property, directly held shares and any corporate_wealth a dataset does not itemise. The ISA docs named share_like_capital as the source the stocks and shares ISA balances leave. They now name share_like_capital_without_sale_expenses, and say every means test counts that part at withdrawal value. The test comments and the parameter description say the model reads ADM H1656's silence on costs of sale as no deduction, rather than saying H1656 rules one out. The COMPONENTS comment notes that share_like_capital sums the same names, and invariant 7 allows float32's step as well as a penny. Co-Authored-By: Claude Opus 5.5 --- changelog.d/sale-expense-share-split.fixed.md | 2 +- changelog.d/uc-capital-sale-expenses.fixed.md | 2 +- .../isa-inputs-and-capital-flows.md | 40 ++++++++++--------- .../without_sale_expenses.yaml | 2 +- .../dwp/capital_valuation_share_split.yaml | 5 ++- .../baseline/gov/dwp/person_isa_capital.yaml | 5 ++- .../tests/test_capital_share_components.py | 3 +- .../test_capital_valuation_properties.py | 5 ++- policyengine_uk/tests/test_isa_balances.py | 4 +- .../tests/test_stored_household_totals.py | 4 +- .../share_like_capital_with_sale_expenses.py | 2 + 11 files changed, 41 insertions(+), 33 deletions(-) diff --git a/changelog.d/sale-expense-share-split.fixed.md b/changelog.d/sale-expense-share-split.fixed.md index 7863885269..b1b35caba9 100644 --- a/changelog.d/sale-expense-share-split.fixed.md +++ b/changelog.d/sale-expense-share-split.fixed.md @@ -1 +1 @@ -Value share-like capital by asset type in every means test. Directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction. Unit trusts count at full value (ADM H1673-H1674), as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. Stocks and shares ISAs count at their full withdrawal value, because ADM H1656 says nothing about costs of sale. +Value share-like capital by asset type in every means test. Directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction. Unit trusts count at full value (ADM H1673-H1674), as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. Stocks and shares ISAs count at their full withdrawal value, a reading that rests on ADM H1656 saying nothing about costs of sale. diff --git a/changelog.d/uc-capital-sale-expenses.fixed.md b/changelog.d/uc-capital-sale-expenses.fixed.md index 02d0588143..102b57f784 100644 --- a/changelog.d/uc-capital-sale-expenses.fixed.md +++ b/changelog.d/uc-capital-sale-expenses.fixed.md @@ -1 +1 @@ -Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property and share-like capital (share_like_capital), not to cash savings; share-like capital also holds unit trusts, which have no costs of sale, and in datasets built before the private pension split it holds pension wealth, so the deduction reaches those too until the data separate them. Adds secured-debt inputs for other residential property, non-residential property and land, and the council tax reduction formula deducts the debt secured on land from the land on its own household route. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. The model works out a Lifetime ISA's surrender value from its balance and rounds it under the same rule, and keeps explicit Lifetime ISA capital inputs and reformed valuation formulas. +Value Universal Credit, Housing Benefit, Income Support, income-based JSA, income-related ESA and Pension Credit capital at market value less 10% where a sale would incur expenses and less any debt secured on the asset, as UC Regs 2013 reg. 49(1) and its legacy equivalents require. The 10% applies to land, property, directly held shares and all of a `corporate_wealth` that the dataset does not itemise, not to cash savings. Unitemised `corporate_wealth` can still fold in unit trusts, ISAs and, on datasets built before private pension wealth was split out, non-defined-benefit pension wealth. Adds secured-debt inputs for other residential property, non-residential property and land, and the council tax reduction formula deducts the debt secured on land from the land on its own household route. Each programme rounds a fraction of a penny in its capital calculations as its regulations require: to the nearest penny for Universal Credit (UC Regs 2013 reg. 6(1)) and Housing Benefit, and down for the legacy benefits and Pension Credit. The model works out a Lifetime ISA's surrender value from its balance and rounds it under the same rule, and keeps explicit Lifetime ISA capital inputs and reformed valuation formulas. diff --git a/docs/book/assumptions/isa-inputs-and-capital-flows.md b/docs/book/assumptions/isa-inputs-and-capital-flows.md index c6e0836479..c926b8cba1 100644 --- a/docs/book/assumptions/isa-inputs-and-capital-flows.md +++ b/docs/book/assumptions/isa-inputs-and-capital-flows.md @@ -114,21 +114,22 @@ shares ISA balances in their own benefit unit, through `cash_isa_countable_capital` and `stocks_and_shares_isa_countable_capital` in its `person_sources`, and excludes a dependant's balance, a child's junior ISA among them. The formulas subtract a household's counted balances from `cash_isa` -and `share_like_capital` before they allocate the remainder between benefit -units. Where the balances sum to less than the total the model holds for the -year, the remainder stays in the pool. Where their stored sum exceeds the total, -the model scales them to sum to the total exactly: it rounds each proportional -share down to a whole step of the total's float32 spacing and gives the steps -left over, one each, to the members whose shares lost most in rounding. The pool -then keeps nothing of that total; for totals under £268 million, each holding -passes a capital limit only where its proportional share does; and a sole holder -whose balance reaches the total counts exactly the total. For stocks and shares -ISAs the model takes the smaller of `stocks_and_shares_isa` and -`share_like_capital` as the total. Data that store only household totals hold no -balances, so the pool keeps the whole total. The formulas count a balance only -while the programme's `sources` lists the household source that includes it, so -a reform that drops `cash_isa` or `share_like_capital` from `sources` drops the -balances with it. For a Universal Credit unit that reports its capital +and `share_like_capital_without_sale_expenses` before they allocate the +remainder between benefit units. Where the balances sum to less than the total +the model holds for the year, the remainder stays in the pool. Where their +stored sum exceeds the total, the model scales them to sum to the total exactly: +it rounds each proportional share down to a whole step of the total's float32 +spacing and gives the steps left over, one each, to the members whose shares +lost most in rounding. The pool then keeps nothing of that total; for totals +under £268 million, each holding passes a capital limit only where its +proportional share does; and a sole holder whose balance reaches the total +counts exactly the total. For stocks and shares ISAs the model takes the smaller +of `stocks_and_shares_isa` and `share_like_capital` as the total. Data that +store only household totals hold no balances, so the pool keeps the whole total. +The formulas count a balance only while the programme's `sources` lists the +household source that includes it, so a reform that drops `cash_isa` or +`share_like_capital_without_sale_expenses` from `sources` drops the balances +with it. For a Universal Credit unit that reports its capital (`benunit_reported_capital` or `uc_reported_capital`, zero or more), the formula leaves the unit's claimant's and partner's ISAs in the pool and subtracts the report, as it does for their company holdings. A nonnegative @@ -146,10 +147,11 @@ replaces covered components rather than adding them again. For example, £5,000 savings and a £3,000 ordinary cash ISA give £8,000 UC capital. [UC regulation 72](https://www.legislation.gov.uk/uksi/2013/376/regulation/72) then gives eight £4.35 monthly tariff units, or £34.80 a month. Stocks-and-shares -ISA holdings remain within `share_like_capital`. The separate existing -`lifetime_isa_countable_capital` valuation is unchanged. It does not gain -transaction-level first-home or terminal-illness valuation from the new flow -inputs. +ISA holdings remain within `share_like_capital`, in its part without sale +expenses, which every means test counts at withdrawal value. The separate +existing `lifetime_isa_countable_capital` valuation is unchanged. It does not +gain transaction-level first-home or terminal-illness valuation from the new +flow inputs. Population estimates depend on the input balances, reported-capital overrides, benefit take-up and calibrated weights as well as the capital diff --git a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml index 76b7c40c94..c124928df2 100644 --- a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml +++ b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml @@ -14,7 +14,7 @@ description: > Everything else in share_like_capital takes the deduction: directly held shares, and on datasets that do not itemise it, all of corporate_wealth. Directly held shares include employee shares and share options, which the - Wealth and Assets Survey asks about together, so share options also take + Wealth and Assets Survey records as one total, so share options also take the deduction, an approximation. metadata: label: Share-like holdings without expenses of sale diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml index 1563961bed..d99438122f 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml @@ -9,8 +9,9 @@ # have no costs of sale (ADM H1673-H1674; DMG 29680-29681, 52680-52681, # 84771-84772; HBGM W1.530-W1.531), and the survey bucket of unit and # investment trusts is treated the same. An ISA is valued at what the person -# would get by withdrawing it, with no 10% (ADM H1656; DMG 29662, 52662, -# 84748). Expected values are worked by hand from those rules. +# would get by withdrawing it (ADM H1656; DMG 29662, 52662, 84748), and the +# model takes no 10% from it because H1656 says nothing about costs of sale. +# Expected values are worked by hand from those rules. - name: UC unsplit corporate_wealth keeps the flat 10% treatment period: 2026 diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml index 86162714b5..cf77891e80 100644 --- a/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml @@ -15,8 +15,9 @@ # ESA Regs 2008 reg 113; SPC Regs 2002 reg 19). It counts savings, cash ISAs # and each stocks and shares ISA balance the formula moves out of # share_like_capital at face value: an ISA is valued at what the holder would -# get by withdrawing it, with no deduction for expenses of sale (ADM -# H1656-H1658; DMG 29662-29664, 52662, 84748-84750). +# get by withdrawing it (ADM H1656-H1658; DMG 29662-29664, 52662, +# 84748-84750), and the model reads H1656's silence on costs of sale as no +# deduction. - name: Case 1, a lodger's cash ISA stays out of the main benefit unit's capital. period: 2025 diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index a6e7e57944..00cab177dc 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -26,7 +26,8 @@ 7. Valuation by type: given only itemised holdings, with the ISAs held as the person's own balances, all six means tests count savings, cash ISAs, unit trusts and stocks and shares ISAs in full and directly held shares less - 10%, rounded by each programme's rule, to within a penny. + 10%, rounded by each programme's rule, to within a penny plus float32's + step at that size. """ import numpy as np diff --git a/policyengine_uk/tests/test_capital_valuation_properties.py b/policyengine_uk/tests/test_capital_valuation_properties.py index 3298677890..6ea388515d 100644 --- a/policyengine_uk/tests/test_capital_valuation_properties.py +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -229,8 +229,9 @@ def check_valuation(units): assert "savings" in node.sources counted = set(node.sources) # Every name on the sale-expense list must be a counted source: - # valued_capital reads only node.sources, so a listed name outside - # them is never valued, and the intersection check below can't see it. + # valued_capital values only the names in node.sources, so it never + # values a listed name outside them, and the intersection check below + # can't see one. assert set(node.sale_expenses.sources) <= counted, ( variable, sorted(set(node.sale_expenses.sources) - counted), diff --git a/policyengine_uk/tests/test_isa_balances.py b/policyengine_uk/tests/test_isa_balances.py index 588d221b6c..9e98ba3004 100644 --- a/policyengine_uk/tests/test_isa_balances.py +++ b/policyengine_uk/tests/test_isa_balances.py @@ -63,8 +63,8 @@ def test_stored_household_totals_without_person_balances_project_with_savings(): assert shares == pytest.approx(2_000.0 * growth) # Savings, the cash ISA and the stocks-and-shares ISA all reach the # capital pool at their value: an ISA is valued at what its holder would - # get by withdrawing it, with no deduction for expenses of sale (ADM - # H1656), so the itemised ISA sits in the part of share_like_capital + # get by withdrawing it (ADM H1656), which says nothing about costs of + # sale, so the itemised ISA sits in the part of share_like_capital # without them. without = simulation.calculate("share_like_capital_without_sale_expenses", 2027) with_expenses = simulation.calculate("share_like_capital_with_sale_expenses", 2027) diff --git a/policyengine_uk/tests/test_stored_household_totals.py b/policyengine_uk/tests/test_stored_household_totals.py index 8fd7c15b46..265999eaf3 100644 --- a/policyengine_uk/tests/test_stored_household_totals.py +++ b/policyengine_uk/tests/test_stored_household_totals.py @@ -218,8 +218,8 @@ def test_stored_household_totals_grow_past_the_projection_horizon(): ) # Savings, the cash ISA and the stocks-and-shares ISA make up the capital, # each at its value. A decision maker values an ISA at what its holder - # would get by withdrawing it, with no deduction for expenses of sale (ADM - # H1656), so the stored stocks-and-shares ISA reaches the capital through + # would get by withdrawing it (ADM H1656), which says nothing about costs + # of sale, so the stored stocks-and-shares ISA reaches the capital through # share_like_capital_without_sale_expenses. The parts grow alike, so # capital keeps the same ratio to savings in every year: 6 for this # household. diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py index bbd8b72f33..00e7e484f3 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -5,6 +5,8 @@ # gov.dwp.share_like_capital.without_sale_expenses must be in this list. A # reform that adds a holding outside it would leave a household that itemises # only that holding with all of its share-like capital under the deduction. +# share_like_capital sums the same three names, so such a reform must add +# the holding there too. COMPONENTS = [ "directly_held_shares", "unit_and_investment_trusts", From 43ac48ab5eeb8b83d1966c75b1f43dfd3caa6faf Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 10:15:41 -0500 Subject: [PATCH 40/48] Route person ISAs by the exempt list and keep the share parts and company deductions consistent under reforms Answers review fold-r1 at 8f755b981. - P1: household_sources(law) replaces the HOUSEHOLD_SOURCE_OF constant. It maps a stocks and shares ISA balance to the share-like part that holds the household's ISAs under the period's gov.dwp.share_like_capital.without_sale_expenses. counted_person_sources, pooled_person_capital (now given parameters by all six formulas) and valued_person_capital read it, so a reform that takes stocks_and_shares_isa off the exempt list nets the balance out of the part with sale expenses and values it less 10%. stocks_and_shares_isa_countable_capital bounds balances by that part where it falls short of min(stocks_and_shares_isa, share_like_capital) by more than share_like_capital's float32 spacing; rounding alone leaves it short by at most half that, so nonnegative holdings keep today's bound. - P2: the part with sale expenses is held between nil and share_like_capital where the itemised sum is positive, so signed holdings can't push the parts apart. The property test draws signed components, includes the 1e9 / -1e9 / 1 case, and asserts the parts sum to the total within half its float32 spacing. - P3: household_uc_company_holding_pool_scale is nil when UC's sources don't list share_like_capital_with_sale_expenses, so no holding leaves the pool; the owner's own assessment still takes it off a report. - P4: the CTR docstring says the household route doesn't yet count share_like_capital, and older datasets may mix it with pension wealth. - P5/P6: the share-split fragment, the exempt parameter, the ISA docs page and two test docstrings name the six DWP capital assessments instead of every means test; the ISA docs page and the touched docstrings describe the routing and bound. Co-Authored-By: Claude Opus 5.5 --- changelog.d/sale-expense-share-split.fixed.md | 2 +- .../isa-inputs-and-capital-flows.md | 31 ++- .../without_sale_expenses.yaml | 6 +- .../tests/test_capital_share_components.py | 251 ++++++++++++++++-- policyengine_uk/tests/test_isa_balances.py | 4 +- .../tests/test_person_isa_capital.py | 14 +- policyengine_uk/utils/capital_valuation.py | 22 +- .../variables/gov/dwp/_person_capital_pool.py | 78 ++++-- .../gov/dwp/esa_income_assessable_capital.py | 4 +- .../housing_benefit_assessable_capital.py | 2 +- .../dwp/income_support_assessable_capital.py | 4 +- .../gov/dwp/jsa_income_assessable_capital.py | 4 +- .../pension_credit_assessable_capital.py | 2 +- ...stocks_and_shares_isa_countable_capital.py | 50 +++- ...household_uc_company_holding_pool_scale.py | 14 +- .../household_uc_pool_company_holdings.py | 6 +- ...household_uc_reported_financial_capital.py | 5 +- .../universal_credit/uc_assessable_capital.py | 13 +- ...ouncil_tax_reduction_assessable_capital.py | 7 +- .../share_like_capital_with_sale_expenses.py | 20 +- ...hare_like_capital_without_sale_expenses.py | 5 +- 21 files changed, 431 insertions(+), 113 deletions(-) diff --git a/changelog.d/sale-expense-share-split.fixed.md b/changelog.d/sale-expense-share-split.fixed.md index b1b35caba9..c47b4c7870 100644 --- a/changelog.d/sale-expense-share-split.fixed.md +++ b/changelog.d/sale-expense-share-split.fixed.md @@ -1 +1 @@ -Value share-like capital by asset type in every means test. Directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction. Unit trusts count at full value (ADM H1673-H1674), as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. Stocks and shares ISAs count at their full withdrawal value, a reading that rests on ADM H1656 saying nothing about costs of sale. +Value share-like capital by asset type in the six DWP capital assessments (Universal Credit, Pension Credit, Housing Benefit, Income Support, income-based JSA and income-related ESA). Directly held shares, and any `corporate_wealth` a dataset does not itemise, take the 10% sale-expense deduction. Unit trusts count at full value (ADM H1673-H1674), as does the survey's combined unit and investment trust bucket, an approximation for its investment trusts. Stocks and shares ISAs count at their full withdrawal value, a reading that rests on ADM H1656 saying nothing about costs of sale. diff --git a/docs/book/assumptions/isa-inputs-and-capital-flows.md b/docs/book/assumptions/isa-inputs-and-capital-flows.md index c926b8cba1..d9fef0261b 100644 --- a/docs/book/assumptions/isa-inputs-and-capital-flows.md +++ b/docs/book/assumptions/isa-inputs-and-capital-flows.md @@ -114,9 +114,15 @@ shares ISA balances in their own benefit unit, through `cash_isa_countable_capital` and `stocks_and_shares_isa_countable_capital` in its `person_sources`, and excludes a dependant's balance, a child's junior ISA among them. The formulas subtract a household's counted balances from `cash_isa` -and `share_like_capital_without_sale_expenses` before they allocate the -remainder between benefit units. Where the balances sum to less than the total -the model holds for the year, the remainder stays in the pool. Where their +and from the part of `share_like_capital` that holds the household's stocks and +shares ISAs before they allocate the remainder between benefit units, and value +each balance as they value that part. The part is +`share_like_capital_without_sale_expenses`, counted at face value, while +`gov.dwp.share_like_capital.without_sale_expenses` lists `stocks_and_shares_isa`. +A reform that removes it from that list moves the ISAs into +`share_like_capital_with_sale_expenses`, so the formulas subtract the balances +from that part and count them less 10%. Where the balances sum to less than +the total the model holds for the year, the remainder stays in the pool. Where their stored sum exceeds the total, the model scales them to sum to the total exactly: it rounds each proportional share down to a whole step of the total's float32 spacing and gives the steps left over, one each, to the members whose shares @@ -124,12 +130,17 @@ lost most in rounding. The pool then keeps nothing of that total; for totals under £268 million, each holding passes a capital limit only where its proportional share does; and a sole holder whose balance reaches the total counts exactly the total. For stocks and shares ISAs the model takes the smaller -of `stocks_and_shares_isa` and `share_like_capital` as the total. Data that -store only household totals hold no balances, so the pool keeps the whole total. +of `stocks_and_shares_isa` and `share_like_capital` as the total, or the part +that holds the ISAs where that part falls short of it by more than +`share_like_capital`'s float32 spacing. Rounding alone leaves the part short by +at most half that spacing; a larger shortfall comes from negative holdings +beside the ISAs, itemised holdings that sum to nil or less, or a reform. Data +that store only household totals hold no balances, so the pool keeps the whole +total. The formulas count a balance only while the programme's `sources` lists the -household source that includes it, so a reform that drops `cash_isa` or -`share_like_capital_without_sale_expenses` from `sources` drops the balances -with it. For a Universal Credit unit that reports its capital +household source that includes it, so a reform that drops `cash_isa`, or the +share-like part that holds the ISAs, from `sources` drops the balances with it. +For a Universal Credit unit that reports its capital (`benunit_reported_capital` or `uc_reported_capital`, zero or more), the formula leaves the unit's claimant's and partner's ISAs in the pool and subtracts the report, as it does for their company holdings. A nonnegative @@ -148,8 +159,8 @@ For example, £5,000 savings and a £3,000 ordinary cash ISA give £8,000 UC capital. [UC regulation 72](https://www.legislation.gov.uk/uksi/2013/376/regulation/72) then gives eight £4.35 monthly tariff units, or £34.80 a month. Stocks-and-shares ISA holdings remain within `share_like_capital`, in its part without sale -expenses, which every means test counts at withdrawal value. The separate -existing `lifetime_isa_countable_capital` valuation is unchanged. It does not +expenses, which the six DWP capital assessments count at withdrawal value. The +separate existing `lifetime_isa_countable_capital` valuation is unchanged. It does not gain transaction-level first-home or terminal-illness valuation from the new flow inputs. diff --git a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml index c124928df2..ae1b5ca5c1 100644 --- a/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml +++ b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml @@ -1,6 +1,8 @@ description: > - Itemised share-like holdings valued for every means test without the - deduction for expenses of sale. Unit trusts are valued at the bid price, + Itemised share-like holdings that the six DWP capital assessments + (Universal Credit, Pension Credit, Housing Benefit, Income Support, + income-based JSA and income-related ESA) value without the deduction for + expenses of sale. Unit trusts are valued at the bid price, which the manager pays on withdrawal, with no costs of sale even when sold through a broker (ADM H1673-H1674; DMG 29680-29681, 52680-52681, 84771-84772; HBGM W1.530-W1.531). The Wealth and Assets Survey asks about diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 00cab177dc..dceb39071b 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -10,10 +10,12 @@ 1. share_like_capital is corporate_wealth as supplied (any sign, any fraction) unless the itemised components exceed it beyond the rounding tolerance, in which case it is their sum. -2. With no itemised holdings, the part with sale expenses is all of - share_like_capital and the other part is exactly nil; otherwise the part - with sale expenses is share_like_capital less trusts and ISAs, floored at - nil, and the two parts add up to share_like_capital. +2. Where the itemised holdings sum to nil or less, the part with sale + expenses is all of share_like_capital and the other part is exactly nil; + otherwise the part with sale expenses is share_like_capital less trusts + and ISAs, held between nil and share_like_capital. Whatever the signs of + the holdings, the two parts add up to share_like_capital within half its + float32 spacing. 3. Differential: for identical unitemised inputs, every programme's assessable capital and UC eligibility equal those under the lists before itemising (corporate_wealth valued less 10%), exactly, annually and monthly. @@ -21,15 +23,23 @@ capital by 10% of trusts plus ISAs, against the unitemised lists. 5. A disregarded company holding (UC reg 77(2)) leaves the UC capital pool from the part with sale expenses, whether it was entered within - corporate_wealth or as directly held shares. + corporate_wealth or as directly held shares. A reform that stops UC + counting that part takes no holding out of the pool, and the owner's own + assessment still takes the holding off a report. 6. The exempt list exists from the first date any capital list does. 7. Valuation by type: given only itemised holdings, with the ISAs held as the - person's own balances, all six means tests count savings, cash ISAs, unit - trusts and stocks and shares ISAs in full and directly held shares less - 10%, rounded by each programme's rule, to within a penny plus float32's - step at that size. + person's own balances, the six DWP means tests count savings, cash ISAs, + unit trusts and stocks and shares ISAs in full and directly held shares + less 10%, rounded by each programme's rule, to within a penny plus + float32's step at that size. +8. A reform that removes stocks_and_shares_isa from the exempt list moves a + member's stocks and shares ISA balance with the household's ISAs into the + part with sale expenses: the formulas net the balance out of that part + and count it in the holder's unit less 10%. """ +from fractions import Fraction + import numpy as np import pytest from hypothesis import HealthCheck, example, given, settings @@ -141,7 +151,11 @@ def test_lists_name_the_two_parts(variable): @SETTINGS @given( st.lists( - st.tuples(signed_money, st.tuples(money, money, money), st.booleans()), + st.tuples( + signed_money, + st.tuples(signed_money, signed_money, signed_money), + st.booleans(), + ), min_size=1, max_size=40, ) @@ -150,6 +164,11 @@ def test_lists_name_the_two_parts(variable): @example([(399_999.984375, (0.0, 200_000.0, 199_999.984375), True)]) # Trusts and ISA exceed corporate_wealth by float32 rounding: floored at nil. @example([(16_000.0, (0.0, 8_000.01, 8_000.0), True)]) +# Shares of £1 billion, trusts of -£1 billion and a £1 ISA itemise £1, and +# trusts and ISA come to -£1 billion in float32. Floored at nil alone, the +# part with sale expenses would hold £1 billion and the other -£1 billion, +# which add up to nil; capped at the £1 total, it holds £1 and the other nil. +@example([(0.0, (1_000_000_000.0, -1_000_000_000.0, 1.0), True)]) def test_share_like_capital_and_its_parts(rows): households = [] for corporate_wealth, components, itemise in rows: @@ -171,11 +190,22 @@ def test_share_like_capital_and_its_parts(rows): assert share_like == itemised else: assert share_like == cw - if itemised == 0: + if itemised <= 0: assert got[WITH][i] == share_like and got[WITHOUT][i] == 0 else: - assert got[WITH][i] == max(np.float32(0), np.float32(share_like - exempt)) + assert got[WITH][i] == min( + share_like, max(np.float32(0), np.float32(share_like - exempt)) + ) assert got[WITHOUT][i] == np.float32(share_like - got[WITH][i]) + # The parts add up to the total within half its float32 spacing: + # the part without sale expenses rounds once, and it is no larger + # than the total. + gap = ( + Fraction(float(got[WITH][i])) + + Fraction(float(got[WITHOUT][i])) + - Fraction(float(share_like)) + ) + assert abs(gap) <= Fraction(float(np.spacing(np.abs(share_like)))) / 2 def test_float32_grouping_of_the_exempt_holdings(): @@ -231,6 +261,134 @@ def test_an_empty_exempt_list_values_everything_less_10_percent(): assert got["uc_assessable_capital"] == pytest.approx([11_800, 11_800]) +# The ISAs take the deduction; unit and investment trusts keep full value. +ISAS_WITH_SALE_EXPENSES = { + "gov.dwp.share_like_capital.without_sale_expenses": { + str(YEAR): ["unit_and_investment_trusts"] + } +} +WORKING_AGE = [name for name in NODES if name != "pension_credit_assessable_capital"] + + +def _isa_holders(): + """A sole working-age holder of a £5,000 stocks and shares ISA; a tenant + and a lodger in separate benefit units sharing £1,000 of savings, the + lodger holding a £5,000 ISA; and a sole pension-age holder of a £5,000 + ISA. The ISAs are person balances, with no household total stored, and + no unit claims a passporting benefit.""" + people = { + "holder": {"age": {YEAR: 30}}, + "tenant": {"age": {YEAR: 30}}, + "lodger": {"age": {YEAR: 30}}, + "pensioner": {"age": {YEAR: 70}}, + } + for name in ("holder", "lodger", "pensioner"): + people[name]["stocks_and_shares_isa_balance"] = {YEAR: 5_000} + no_claims = { + "would_claim_uc": {YEAR: False}, + "would_claim_IS": {YEAR: False}, + "would_claim_pc": {YEAR: False}, + } + return { + "people": people, + "benunits": { + f"{name}_unit": {"members": [name], **no_claims} for name in people + }, + "households": { + "alone": {"members": ["holder"]}, + "shared": {"members": ["tenant", "lodger"], "savings": {YEAR: 1_000}}, + "retired": {"members": ["pensioner"]}, + }, + } + + +def test_a_reform_that_takes_isas_out_of_the_exempt_list_values_person_isas_less_10_percent(): + """Each household's share_like_capital is its £5,000 of ISAs, the sum of + the balances. At baseline the part without sale expenses holds it, and + the holder counts the balance in full: £5,000 alone, and in the shared + household £500 of the savings each and the lodger's £5,000, so + [£500, £5,500]. + + Without stocks_and_shares_isa on the exempt list, the part with sale + expenses holds the £5,000 and the balance leaves that part, so the pool + keeps nil of it. The holder counts 90% of the £5,000, £4,500. In the + shared household the pool keeps the £1,000 of savings, £500 for each + unit, and the lodger adds £4,500: [£500, £5,000]. Netting the balance + out of the empty part without sale expenses instead would give the sole + holder £5,000 (a pool of £4,500 less £5,000, floored at nil, plus the + balance in full) and the shared household [£250, £5,250] (a pool of + £1,000 + £4,500 - £5,000 = £500, then the balance in full). + """ + baseline = Simulation(situation=_isa_holders()) + reformed = Simulation(situation=_isa_holders(), reform=ISAS_WITH_SALE_EXPENSES) + assert list(baseline.calculate(WITHOUT, YEAR)) == [5_000, 5_000, 5_000] + assert list(reformed.calculate(WITH, YEAR)) == [5_000, 5_000, 5_000] + assert list(reformed.calculate(WITHOUT, YEAR)) == [0, 0, 0] + for simulation in (baseline, reformed): + assert list( + simulation.calculate("stocks_and_shares_isa_countable_capital", YEAR) + ) == [5_000, 0, 5_000, 5_000] + # Units: holder, tenant, lodger, pensioner. + for name in WORKING_AGE: + assert list(baseline.calculate(name, YEAR)[:3]) == [5_000, 500, 5_500], name + assert list(reformed.calculate(name, YEAR)[:3]) == [4_500, 500, 5_000], name + pension_credit = "pension_credit_assessable_capital" + assert baseline.calculate(pension_credit, YEAR)[3] == 5_000 + assert reformed.calculate(pension_credit, YEAR)[3] == 4_500 + + +def test_the_part_holding_the_isas_bounds_balances_only_beyond_rounding(): + """A sole holder's £100.01 ISA balance inside £20,000.01 of + corporate_wealth: the part with sale expenses is £19,900.00 in float32, + and the part without it, the difference, 100.009765625, a quarter of a + thousandth short of the 100.01000214 balance. That is rounding, so the + holder keeps the whole balance, as before the part bounded it: UC counts + 90% of £19,900, £17,910, plus the part less the balance, plus the + balance, £18,010.01. + + Trusts of -£5,000 beside £6,000 of shares and a lodger's £5,000 ISA + leave share_like_capital at £6,000, all in the part with sale expenses, + and nil in the part that would hold the ISA. The balance can't take + £5,000 out of nil, so the lodger holds nil, and the pool counts 90% of + £6,000, £5,400, shared by two units: [£2,700, £2,700]. Netting £5,000 out + of the empty part would give [£200, £5,200].""" + situation = { + "people": { + "holder": { + "age": {YEAR: 30}, + "stocks_and_shares_isa_balance": {YEAR: 100.01}, + }, + "tenant": {"age": {YEAR: 30}}, + "lodger": { + "age": {YEAR: 30}, + "stocks_and_shares_isa_balance": {YEAR: 5_000}, + }, + }, + "benunits": { + f"{name}_unit": {"members": [name]} + for name in ("holder", "tenant", "lodger") + }, + "households": { + "rounding": { + "members": ["holder"], + "corporate_wealth": {YEAR: 20_000.01}, + }, + "signed": { + "members": ["tenant", "lodger"], + "directly_held_shares": {YEAR: 6_000}, + "unit_and_investment_trusts": {YEAR: -5_000}, + }, + }, + } + sim = Simulation(situation=situation) + assert list(sim.calculate(WITH, YEAR)) == [19_900, 6_000] + assert list(sim.calculate(WITHOUT, YEAR)) == [np.float32(100.009765625), 0] + held = sim.calculate("stocks_and_shares_isa_countable_capital", YEAR) + assert list(held) == [np.float32(100.01), 0, 0] + uc = sim.calculate("uc_assessable_capital", YEAR) + assert list(uc) == [np.float32(18_010.01), 2_700, 2_700] + + def test_the_exempt_list_starts_with_the_first_capital_list(): exempt = system.parameters.gov.dwp.share_like_capital.without_sale_expenses first = min( @@ -432,6 +590,63 @@ def test_a_disregarded_company_holding_leaves_the_part_with_sale_expenses(): assert list(sim.calculate("uc_assessable_capital", YEAR)) == [5_000, 5_000] +def test_a_holding_leaves_no_pool_that_stops_counting_the_part_with_sale_expenses(): + """UC reg 77(2), after a reform drops share_like_capital_with_sale_expenses + from UC's sources and sale-expense list. The household holds £30,000 of + directly held shares and £10,000 of unit trusts, so the part with sale + expenses is £30,000 and the part without £10,000. The owner's £30,000 + holding is shares, inside the part the pool no longer counts, so none of + it leaves the pool: the pool is the £10,000 of trusts at full value, + £5,000 for the owner's unit and £5,000 for the lodger's. Budgeted against + the uncounted part, the holding would take all £10,000 of trusts out of + the pool and leave both units nil. + + With a £40,000 report for the owner's unit, the owner's own assessment + still takes the £30,000 holding off it, £10,000, and the report consumes + the £10,000 pool, leaving the lodger nil.""" + node = NODES["uc_assessable_capital"] + reform = { + f"{node}.{name}": { + str(YEAR): [ + source for source in _parameter(f"{node}.{name}") if source != WITH + ] + } + for name in ("sources", "sale_expenses.sources") + } + for report, expected in ((None, [5_000, 5_000]), (40_000, [10_000, 0])): + owner_unit = {"members": ["owner"]} + if report is not None: + owner_unit["benunit_reported_capital"] = {YEAR: report} + situation = { + "people": { + "owner": { + "age": {YEAR: 40}, + "stands_as_sole_owner_or_partner_of_company": {YEAR: True}, + "owned_company_carries_on_trade": {YEAR: True}, + "owned_company_holding_value": {YEAR: 30_000}, + }, + "lodger": {"age": {YEAR: 30}}, + }, + "benunits": { + "owner_unit": owner_unit, + "lodger_unit": {"members": ["lodger"]}, + }, + "households": { + "household": { + "members": ["owner", "lodger"], + "directly_held_shares": {YEAR: 30_000}, + "unit_and_investment_trusts": {YEAR: 10_000}, + } + }, + } + sim = Simulation(situation=situation, reform=reform) + assert sim.calculate(WITH, YEAR)[0] == 30_000 + assert sim.calculate(WITHOUT, YEAR)[0] == 10_000 + assert sim.calculate("household_uc_company_holding_pool_scale", YEAR)[0] == 0 + assert sim.calculate("household_uc_pool_company_holdings", YEAR)[0] == 0 + assert list(sim.calculate("uc_assessable_capital", YEAR)) == expected, report + + ROUNDS_DOWN = { "uc_assessable_capital": False, "housing_benefit_assessable_capital": False, @@ -477,12 +692,12 @@ def test_a_disregarded_company_holding_leaves_the_part_with_sale_expenses(): @example([(1_813_184, 40_164, 988_571, 7_260, 1_024_413, 30, False)]) def test_itemised_holdings_are_valued_by_type_in_every_means_test(rows): """Given only itemised holdings, with the ISAs held as the person's own - balances, every means test counts savings, a cash ISA, unit trusts and a - stocks-and-shares ISA in full and directly held shares less 10%, rounded - by the programme's rule. The engine adds the holdings in float32, which - can move the shares' value by a fraction of a penny before valuation, so - each total is checked to within a penny plus float32's step at that - size.""" + balances, each of the six DWP means tests counts savings, a cash ISA, unit + trusts and a stocks-and-shares ISA in full and directly held shares less + 10%, rounded by the programme's rule. The engine adds the holdings in + float32, which can move the shares' value by a fraction of a penny before + valuation, so each total is checked to within a penny plus float32's step + at that size.""" people, benunits, homes = {}, {}, {} for i, (savings, cash_isa, shares, trusts, isa, age, claims_uc) in enumerate(rows): people[f"p{i}"] = { diff --git a/policyengine_uk/tests/test_isa_balances.py b/policyengine_uk/tests/test_isa_balances.py index 9e98ba3004..ea107a4011 100644 --- a/policyengine_uk/tests/test_isa_balances.py +++ b/policyengine_uk/tests/test_isa_balances.py @@ -3,8 +3,8 @@ Datasets built before the per-person balances existed store only the household totals. Those totals must keep their stored values, projected with savings, rather than fall to the sum of balances the dataset does not have. -Every means test counts both kinds of ISA at their withdrawal value, without -the 10% for expenses of sale. +The six DWP capital assessments count both kinds of ISA at their withdrawal +value, without the 10% for expenses of sale. """ import pandas as pd diff --git a/policyengine_uk/tests/test_person_isa_capital.py b/policyengine_uk/tests/test_person_isa_capital.py index 669c441b9a..fcf1d996f0 100644 --- a/policyengine_uk/tests/test_person_isa_capital.py +++ b/policyengine_uk/tests/test_person_isa_capital.py @@ -69,8 +69,8 @@ from policyengine_uk.entities import Household, Person from policyengine_uk.system import system from policyengine_uk.variables.gov.dwp._person_capital_pool import ( - HOUSEHOLD_SOURCE_OF, bounded_holdings, + household_sources, ) pytestmark = pytest.mark.usefixtures("cloned_uk_tax_benefit_system") @@ -86,7 +86,10 @@ "esa_income_assessable_capital": "gov.dwp.ESA.income.capital", } MEANS_TEST_CAPITAL = (*CAPITAL, "council_tax_reduction_assessable_capital") -ISA_SOURCES = tuple(HOUSEHOLD_SOURCE_OF) +# Each ISA person source, mapped to the household source that holds it under +# YEAR's law. +HELD_IN = household_sources(system.parameters(f"{YEAR}-01-01")) +ISA_SOURCES = tuple(HELD_IN) SHARE_LIKE_PARTS = ( "share_like_capital_with_sale_expenses", "share_like_capital_without_sale_expenses", @@ -757,10 +760,7 @@ def _share_counted(variable, source): # The share of each ISA person source's value a programme counts: the share # it counts of the household source that holds it. def _isa_shares(variable): - return { - source: _share_counted(variable, HOUSEHOLD_SOURCE_OF[source]) - for source in ISA_SOURCES - } + return {source: _share_counted(variable, HELD_IN[source]) for source in ISA_SOURCES} def _holdings(simulation, variable=None): @@ -1123,7 +1123,7 @@ def test_lists_count_each_isa_once(variable, date): date >= "2017-04-06" ) for name in ISA_SOURCES: - assert HOUSEHOLD_SOURCE_OF[name] in sources + assert household_sources(system.parameters(date))[name] in sources assert name in system.variables # The household pool never names the balances or the ISA total itself. assert not {*BALANCE.values(), "stocks_and_shares_isa"} & set(sources) diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index a10bd0e687..20af57f538 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -16,8 +16,8 @@ from policyengine_uk.utils.supplied_inputs import supplied_input from policyengine_uk.variables.gov.dwp._person_capital_pool import ( - HOUSEHOLD_SOURCE_OF, counted_person_sources, + household_sources, ) # Household inputs holding the debt secured on each capital source, such as a @@ -73,17 +73,23 @@ def valued_person_capital(benunit, period, parameters, capital, counted): amount. The function counts only the sources ``counted_person_sources`` keeps. A - person source that a household source includes (``HOUSEHOLD_SOURCE_OF``) - holds pounds the formulas moved out of that household source, so the - function values it as ``valued_capital`` values the household source: - less the sale-expense rate where ``capital.sale_expenses.sources`` lists - the household source.""" + person source that a household source includes (``household_sources``, + under the law at ``period``) holds pounds the formulas moved out of that + household source, so the function values it as ``valued_capital`` values + the household source: less the sale-expense rate where + ``capital.sale_expenses.sources`` lists the household source. A reform + that takes stocks_and_shares_isa off + gov.dwp.share_like_capital.without_sale_expenses moves the stocks and + shares ISAs into share_like_capital_with_sale_expenses, so it values the + balances less the rate as well.""" person = benunit.members + law = parameters(period) + held_in = household_sources(law) total = 0 - for source in counted_person_sources(capital): + for source in counted_person_sources(capital, law): stored = person(source, period) value = exact_amount(stored) - if HOUSEHOLD_SOURCE_OF.get(source) in capital.sale_expenses.sources: + if held_in.get(source) in capital.sale_expenses.sources: value = less_sale_expenses( value, capital.sale_expenses.rate, capital.round_down ) diff --git a/policyengine_uk/variables/gov/dwp/_person_capital_pool.py b/policyengine_uk/variables/gov/dwp/_person_capital_pool.py index 4358e94f89..8df77efd08 100644 --- a/policyengine_uk/variables/gov/dwp/_person_capital_pool.py +++ b/policyengine_uk/variables/gov/dwp/_person_capital_pool.py @@ -2,51 +2,71 @@ from policyengine_uk.model_api import * -# The formulas map each person source to the household source that already -# includes it, subtract its stored household sum, and allocate the remainder. -# cash_isa includes each cash ISA balance, and -# share_like_capital_without_sale_expenses each stocks and shares ISA balance -# (through stocks_and_shares_isa, which gov.dwp.share_like_capital -# .without_sale_expenses lists, and which share_like_capital holds inside -# corporate_wealth or the itemised sum). No household source includes a person -# source missing here, such as a Lifetime ISA. -HOUSEHOLD_SOURCE_OF = { - "cash_isa_countable_capital": "cash_isa", - "stocks_and_shares_isa_countable_capital": "share_like_capital_without_sale_expenses", -} - - -def counted_person_sources(capital) -> list: + +def household_sources(law) -> dict: + """Each person source a household source includes, mapped to that source. + + The formulas subtract each such person source's stored household sum + from its household source and allocate the remainder. No household + source includes a person source missing here, such as a Lifetime ISA. + ``law`` is the parameter tree at the period, as ``parameters(period)`` + gives it. cash_isa includes each cash ISA balance. share_like_capital + includes each stocks and shares ISA balance, through stocks_and_shares_isa + inside corporate_wealth or the itemised sum, and its part that holds the + ISAs depends on the law: share_like_capital_without_sale_expenses while + gov.dwp.share_like_capital.without_sale_expenses lists + stocks_and_shares_isa, and share_like_capital_with_sale_expenses once a + reform removes it. Every formula that subtracts, values or bounds a + person source reads its household source here. + """ + exempt = law.gov.dwp.share_like_capital.without_sale_expenses + return { + "cash_isa_countable_capital": "cash_isa", + "stocks_and_shares_isa_countable_capital": ( + "share_like_capital_without_sale_expenses" + if "stocks_and_shares_isa" in exempt + else "share_like_capital_with_sale_expenses" + ), + } + + +def counted_person_sources(capital, law) -> list: """The person sources in ``capital.person_sources`` the formulas count. - The formulas count a person source that a household source includes only - while ``capital.sources`` lists that household source. They move the part - of the household source the data tie to a person into the holder's own - benefit unit, so when the list drops the household source they count - neither. + The formulas count a person source that a household source includes + (``household_sources(law)``) only while ``capital.sources`` lists that + household source. They move the part of the household source the data + tie to a person into the holder's own benefit unit, so when the list + drops the household source they count neither. """ sources = set(capital.sources) + held_in = household_sources(law) return [ source for source in capital.person_sources - if source not in HOUSEHOLD_SOURCE_OF or HOUSEHOLD_SOURCE_OF[source] in sources + if source not in held_in or held_in[source] in sources ] -def pooled_person_capital(benunit, source, period, capital, leaves_pool=None): +def pooled_person_capital( + benunit, source, period, parameters, capital, leaves_pool=None +): """The part of the household ``source`` that counted person sources make up. The household sum, for each benefit unit, of the counted person sources - in ``capital.person_sources`` that ``source`` includes, over the members - ``leaves_pool`` selects (all members by default), as Core stores a total. - The formulas subtract it from ``source`` before they allocate the - remainder between benefit units, so they count each of those pounds only - in its holder's own unit. + in ``capital.person_sources`` that ``source`` includes under the law at + ``period`` (``household_sources``), over the members ``leaves_pool`` + selects (all members by default), as Core stores a total. The formulas + subtract it from ``source`` before they allocate the remainder between + benefit units, so they count each of those pounds only in its holder's + own unit. """ person = benunit.members + law = parameters(period) + held_in = household_sources(law) amount = 0 - for person_source in counted_person_sources(capital): - if HOUSEHOLD_SOURCE_OF.get(person_source) == source: + for person_source in counted_person_sources(capital, law): + if held_in.get(person_source) == source: held = person(person_source, period) if leaves_pool is not None: held = held * leaves_pool diff --git a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py index ac12bf0341..82e0293fdd 100644 --- a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py @@ -44,7 +44,9 @@ def formula(benunit, period, parameters): household_capital = valued_capital( lambda source: ( benunit.max(person.household(source, period)) - - pooled_person_capital(benunit, source, period, ESA.capital) + - pooled_person_capital( + benunit, source, period, parameters, ESA.capital + ) ), ESA.capital, ) diff --git a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py index f3a84f8c8f..1b428d057d 100644 --- a/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/housing_benefit/housing_benefit_assessable_capital.py @@ -59,7 +59,7 @@ def formula(benunit, period, parameters): household_capital = valued_capital( lambda source: ( household(source, period) - - pooled_person_capital(benunit, source, period, p) + - pooled_person_capital(benunit, source, period, parameters, p) ), p, ) diff --git a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py index b36f36b1b3..a9f09001ff 100644 --- a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py @@ -49,7 +49,9 @@ def formula(benunit, period, parameters): household_capital = valued_capital( lambda source: ( benunit.max(person.household(source, period)) - - pooled_person_capital(benunit, source, period, IS.means_test.capital) + - pooled_person_capital( + benunit, source, period, parameters, IS.means_test.capital + ) ), IS.means_test.capital, ) diff --git a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py index 4ed0c7ea10..40d4491a28 100644 --- a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py @@ -44,7 +44,9 @@ def formula(benunit, period, parameters): household_capital = valued_capital( lambda source: ( benunit.max(person.household(source, period)) - - pooled_person_capital(benunit, source, period, JSA.capital) + - pooled_person_capital( + benunit, source, period, parameters, JSA.capital + ) ), JSA.capital, ) diff --git a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py index d62e1a4f0d..fb2a68a05c 100644 --- a/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/pension_credit/pension_credit_assessable_capital.py @@ -44,7 +44,7 @@ def formula(benunit, period, parameters): household_capital = valued_capital( lambda source: ( household(source, period) - - pooled_person_capital(benunit, source, period, p) + - pooled_person_capital(benunit, source, period, parameters, p) ), p, ) diff --git a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py index 06de09029a..6d2f5d7bfa 100644 --- a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py @@ -1,6 +1,7 @@ from policyengine_uk.model_api import * from policyengine_uk.variables.gov.dwp._person_capital_pool import ( bounded_person_holding, + household_sources, ) @@ -12,18 +13,25 @@ class stocks_and_shares_isa_countable_capital(Variable): "investor beneficially owns an ordinary ISA's investments, and the named child " "owns a junior ISA's investments. The household's share_like_capital already " "includes the balance, through stocks_and_shares_isa within corporate_wealth " - "or the itemised sum, and its part without sale expenses " - "(share_like_capital_without_sale_expenses) holds it, since " - "gov.dwp.share_like_capital.without_sale_expenses lists stocks_and_shares_isa. " - "Each means test subtracts the balance from that part before allocating the " - "pool between benefit units, and counts it at face value. The formula bounds the " + "or the itemised sum, in the part that holds the household's stocks and shares " + "ISAs: share_like_capital_without_sale_expenses while " + "gov.dwp.share_like_capital.without_sale_expenses lists stocks_and_shares_isa, " + "and share_like_capital_with_sale_expenses under a reform that removes it. Each " + "means test subtracts the balance from that part before allocating the pool " + "between benefit units, and values it as it values that part: at face value, " + "or less the sale-expense rate under such a reform. The formula bounds the " "person's balance by the smaller of stocks_and_shares_isa and " "share_like_capital, so the household never counts more stocks and shares ISA " - "than it holds. When the household's stored balance sum exceeds that total, it " - "scales the balances to sum to the total exactly, rounding each proportional " - "share down or up to a whole float32 step of the total. When the balances sum " - "to less, the rest stays in the pool, and a household with no balances keeps " - "all of share_like_capital there." + "than it holds. It bounds them instead by the part that holds the ISAs where " + "that part falls short of this bound by more than share_like_capital's float32 " + "spacing. Rounding in the subtraction that forms the part falls short by at " + "most half that spacing, so the part takes over only where negative holdings " + "beside the ISAs, itemised holdings that sum to nil or less, or a reform leave " + "it short of the ISAs. When the household's stored balance sum exceeds the " + "bound, the formula scales the balances to sum to it exactly, rounding each " + "proportional share down or up to a whole float32 step of the bound. When the " + "balances sum to less, the rest stays in the pool, and a household with no " + "balances keeps all of share_like_capital there." ) entity = Person definition_period = YEAR @@ -36,12 +44,26 @@ class stocks_and_shares_isa_countable_capital(Variable): ] def formula(person, period, parameters): - household_total = min_( - person.household("stocks_and_shares_isa", period), - person.household("share_like_capital", period), + household = person.household + share_like = household("share_like_capital", period) + household_total = min_(household("stocks_and_shares_isa", period), share_like) + part = household( + household_sources(parameters(period))[ + "stocks_and_shares_isa_countable_capital" + ], + period, ) + # The part without sale expenses is share_like_capital less the part + # with them, so it can miss the holdings it stands for by half of + # share_like_capital's float32 spacing. A larger shortfall is real: + # the part holds less than the ISAs, and the balances can't take + # more out of it than it holds. An infinite share_like_capital gives + # no spacing, and keeps the bound. + with np.errstate(invalid="ignore"): + slack = np.spacing(np.abs(share_like)).astype(np.float64) + short = household_total.astype(np.float64) - part.astype(np.float64) > slack return bounded_person_holding( person, person("stocks_and_shares_isa_balance", period), - household_total, + where(short, part, household_total), ) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py index 5f676f005f..16d1228feb 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py @@ -20,13 +20,23 @@ class household_uc_company_holding_pool_scale(Variable): "capital the pool counts) across override " "floors and separate pool deductions. This allocation is independent " "of row order and treats holders equally. It is a defensive rule for " - "inconsistent inputs, not a statutory determination. It does not " - "change regulation 77 substitution in the owner's own assessment." + "inconsistent inputs, not a statutory determination. Where a reform " + "takes share_like_capital_with_sale_expenses out of the Universal " + "Credit capital sources, the pool holds no part of a holding, so the " + "scale is nil and no holding leaves the pool or a report's share of " + "it. It does not change regulation 77 substitution in the owner's own " + "assessment, which still takes the holding off the owner's report." ) definition_period = YEAR unit = "/1" def formula(household, period, parameters): + capital = parameters(period).gov.dwp.universal_credit.means_test.capital + if HOLDINGS_SOURCE not in capital.sources: + # The pool doesn't count the shares that hold the holdings, so + # deducting them would take other capital, such as unit trusts, + # out of it. + return np.zeros(household.count) share_like = max_(0, household(HOLDINGS_SOURCE, period)) person = household.members holding = person("uc_company_holding_disregard", period) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py index fed3c75aff..35b898ad6d 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_pool_company_holdings.py @@ -46,7 +46,11 @@ class household_uc_pool_company_holdings(Variable): "either the override floor or this deduction. This is a defensive " "rule for inconsistent inputs, not a statutory determination. The " "shared budget prevents holdings from removing ordinary savings or " - "property. It does not change regulation 77 substitution in the " + "property. A reform that takes share_like_capital_with_sale_expenses " + "out of the Universal Credit capital sources sets the scale to nil, " + "so no holding leaves a pool that holds none of it, and none takes " + "the pool's unit trusts or stocks and shares ISAs in its place. It " + "does not change regulation 77 substitution in the " "owner's own assessment. The holdings leave the pool at the value at " "which the pool counts the shares that hold them " "(share_like_capital_with_sale_expenses): 90% where regulation 49(1)(a) " diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py index 5733b684a5..d720ad2982 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_reported_financial_capital.py @@ -30,7 +30,10 @@ class household_uc_reported_financial_capital(Variable): "share_like_capital_with_sale_expenses budget: if their total exceeds it, " "scale each person's holding proportionally before either this " "override floor or the separate pool deduction. This is a defensive " - "rule for inconsistent inputs, not a statutory determination. " + "rule for inconsistent inputs, not a statutory determination. Where " + "a reform takes share_like_capital_with_sale_expenses out of the " + "Universal Credit capital sources, the scale is nil, so a report " + "consumes only itself. " "Holdings already covered by an override " "must not leave the pool twice, while an override below them must not " "leave their remainder for another unit to count. A dependant's " diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py index cbb5875504..0ad3969cd1 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_assessable_capital.py @@ -43,8 +43,13 @@ class uc_assessable_capital(Variable): "values the financial pool's sources whose sale would incur expenses " "(sale_expenses.sources: directly held shares, and all of an " "unitemised corporate_wealth) at 90%. The formula counts a stocks and " - "shares ISA balance it moves out of share_like_capital_without_sale_expenses " - "at its withdrawal value (ADM H1656-H1658). A disregarded holding comes off at the value at which the formula " + "shares ISA balance as it counts the part of share_like_capital it moves " + "the balance out of: at its withdrawal value (ADM H1656-H1658) from " + "share_like_capital_without_sale_expenses, and at 90% under a reform that " + "takes stocks_and_shares_isa off " + "gov.dwp.share_like_capital.without_sale_expenses, which moves the ISAs " + "into share_like_capital_with_sale_expenses. A disregarded holding comes " + "off at the value at which the formula " "counted it: 90% in the pool and in a complete override, which is a " "countable figure, and in full from a recorded financial total, which the " "formula uses without valuation. The formula rounds every amount it " @@ -76,7 +81,9 @@ def formula(benunit, period, parameters): household_financial_capital = valued_capital( lambda source: ( household(source, period) - - pooled_person_capital(benunit, source, period, p, ~covered) + - pooled_person_capital( + benunit, source, period, parameters, p, ~covered + ) ), p, ) diff --git a/policyengine_uk/variables/gov/local_authorities/council_tax_reduction/council_tax_reduction_assessable_capital.py b/policyengine_uk/variables/gov/local_authorities/council_tax_reduction/council_tax_reduction_assessable_capital.py index bc21a1e729..a61893f494 100644 --- a/policyengine_uk/variables/gov/local_authorities/council_tax_reduction/council_tax_reduction_assessable_capital.py +++ b/policyengine_uk/variables/gov/local_authorities/council_tax_reduction/council_tax_reduction_assessable_capital.py @@ -42,9 +42,10 @@ class council_tax_reduction_assessable_capital(Variable): "land and property valued at market value less 10% for the expenses " "of sale, then less any debt secured on that land or property (which " "defaults to nil because the survey does not record it). The schemes also " - "count shares and other investments, which in the data are mixed " - "with pension wealth the schemes disregard, so they are left out for " - "now. The recalculation when capital rises above the limit during an " + "count shares and other investments, but this household route does not " + "yet count share_like_capital; older datasets may mix it with " + "disregarded pension wealth. The recalculation when capital rises above " + "the limit during an " "assessed income period is not modelled." ) definition_period = YEAR diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py index 00e7e484f3..a83f3f5ec9 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -1,7 +1,7 @@ from policyengine_uk.model_api import * # The share-like holdings a dataset can itemise. The formula treats a -# household as itemising only when one of these is positive, so every name in +# household as itemising only when their sum is positive, so every name in # gov.dwp.share_like_capital.without_sale_expenses must be in this list. A # reform that adds a holding outside it would leave a household that itemises # only that holding with all of its share-like capital under the deduction. @@ -21,9 +21,11 @@ class share_like_capital_with_sale_expenses(Variable): "that the means tests value it less 10%: share_like_capital less the " "itemised holdings listed in gov.dwp.share_like_capital." "without_sale_expenses (unit and investment trusts, stocks and shares " - "ISAs), floored at nil. A household with no itemised holdings has all " - "of its share-like capital here, so datasets that carry only " - "corporate_wealth keep the flat 10% on it." + "ISAs), held between nil and share_like_capital, so that the two parts " + "add up to share_like_capital whatever the signs of the holdings. A " + "household whose itemised holdings sum to nil or less has all of its " + "share-like capital here, so datasets that carry only corporate_wealth " + "keep the flat 10% on it, whatever its sign." ) entity = Household definition_period = YEAR @@ -41,4 +43,12 @@ def formula(household, period, parameters): period ).gov.dwp.share_like_capital.without_sale_expenses: without = without + household(variable, period) - return where(itemised > 0, max_(0, share_like - without), share_like) + # share_like_capital is nonnegative wherever the itemised sum is + # positive. Held at or below it, this part leaves the other part + # between nil and share_like_capital, so negative trusts beside + # positive shares can't push the parts apart. + return where( + itemised > 0, + min_(share_like, max_(0, share_like - without)), + share_like, + ) diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py index ad777f2f0b..0c314eb949 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py @@ -5,8 +5,9 @@ class share_like_capital_without_sale_expenses(Variable): label = "share-like capital without expenses of sale" documentation = ( "The part of share_like_capital the means tests value at full value: " - "share_like_capital less share_like_capital_with_sale_expenses. Nil " - "for a household with no itemised holdings." + "share_like_capital less share_like_capital_with_sale_expenses, " + "between nil and share_like_capital. Nil for a household whose " + "itemised holdings sum to nil or less." ) entity = Household definition_period = YEAR From 1b41af9938bb8244dfd8f0269dc30f910022eabb Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 10:16:02 -0500 Subject: [PATCH 41/48] Tighten the wording of the ISA bound, share-part and pool-scale docstrings Comments and documentation strings only. Co-Authored-By: Claude Opus 5.5 --- policyengine_uk/utils/capital_valuation.py | 4 ++-- .../dwp/stocks_and_shares_isa_countable_capital.py | 12 ++++++------ .../household_uc_company_holding_pool_scale.py | 4 ++-- .../wealth/share_like_capital_with_sale_expenses.py | 10 ++++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py index 20af57f538..7652402117 100644 --- a/policyengine_uk/utils/capital_valuation.py +++ b/policyengine_uk/utils/capital_valuation.py @@ -80,8 +80,8 @@ def valued_person_capital(benunit, period, parameters, capital, counted): ``capital.sale_expenses.sources`` lists the household source. A reform that takes stocks_and_shares_isa off gov.dwp.share_like_capital.without_sale_expenses moves the stocks and - shares ISAs into share_like_capital_with_sale_expenses, so it values the - balances less the rate as well.""" + shares ISAs into share_like_capital_with_sale_expenses, so the function + then values the balances less the rate too.""" person = benunit.members law = parameters(period) held_in = household_sources(law) diff --git a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py index 6d2f5d7bfa..b009a00a5e 100644 --- a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py @@ -24,8 +24,8 @@ class stocks_and_shares_isa_countable_capital(Variable): "share_like_capital, so the household never counts more stocks and shares ISA " "than it holds. It bounds them instead by the part that holds the ISAs where " "that part falls short of this bound by more than share_like_capital's float32 " - "spacing. Rounding in the subtraction that forms the part falls short by at " - "most half that spacing, so the part takes over only where negative holdings " + "spacing. Rounding in the subtraction that forms the part leaves it short by " + "at most half that spacing, so the part takes over only where negative holdings " "beside the ISAs, itemised holdings that sum to nil or less, or a reform leave " "it short of the ISAs. When the household's stored balance sum exceeds the " "bound, the formula scales the balances to sum to it exactly, rounding each " @@ -55,10 +55,10 @@ def formula(person, period, parameters): ) # The part without sale expenses is share_like_capital less the part # with them, so it can miss the holdings it stands for by half of - # share_like_capital's float32 spacing. A larger shortfall is real: - # the part holds less than the ISAs, and the balances can't take - # more out of it than it holds. An infinite share_like_capital gives - # no spacing, and keeps the bound. + # share_like_capital's float32 spacing. A larger shortfall means the + # part holds less than the ISAs, and the balances can't take more out + # of it than it holds. An infinite share_like_capital has no spacing, + # and keeps the bound. with np.errstate(invalid="ignore"): slack = np.spacing(np.abs(share_like)).astype(np.float64) short = household_total.astype(np.float64) - part.astype(np.float64) > slack diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py index 16d1228feb..9c80293c8b 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py @@ -23,8 +23,8 @@ class household_uc_company_holding_pool_scale(Variable): "inconsistent inputs, not a statutory determination. Where a reform " "takes share_like_capital_with_sale_expenses out of the Universal " "Credit capital sources, the pool holds no part of a holding, so the " - "scale is nil and no holding leaves the pool or a report's share of " - "it. It does not change regulation 77 substitution in the owner's own " + "scale is nil: no holding leaves the pool, and a report consumes only " + "itself. It does not change regulation 77 substitution in the owner's own " "assessment, which still takes the holding off the owner's report." ) definition_period = YEAR diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py index a83f3f5ec9..1615558813 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -22,7 +22,8 @@ class share_like_capital_with_sale_expenses(Variable): "itemised holdings listed in gov.dwp.share_like_capital." "without_sale_expenses (unit and investment trusts, stocks and shares " "ISAs), held between nil and share_like_capital, so that the two parts " - "add up to share_like_capital whatever the signs of the holdings. A " + "add up to share_like_capital, to within float32 rounding, whatever the " + "signs of the holdings. A " "household whose itemised holdings sum to nil or less has all of its " "share-like capital here, so datasets that carry only corporate_wealth " "keep the flat 10% on it, whatever its sign." @@ -44,9 +45,10 @@ def formula(household, period, parameters): ).gov.dwp.share_like_capital.without_sale_expenses: without = without + household(variable, period) # share_like_capital is nonnegative wherever the itemised sum is - # positive. Held at or below it, this part leaves the other part - # between nil and share_like_capital, so negative trusts beside - # positive shares can't push the parts apart. + # positive. Holding this part between nil and that total keeps the + # other part, the difference, between nil and the total too, so + # negative trusts beside positive shares can't push the two parts + # apart. return where( itemised > 0, min_(share_like, max_(0, share_like - without)), From 28255803007a6c06b1c2b09d362ac7d7a3f5851e Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 12:48:41 -0500 Subject: [PATCH 42/48] Bound person ISA balances by the holdings behind their part, and scope the means-test wording Review fold-r2 P1: the rounding exception bounded a balance by the part that holds the ISAs only where the part fell short by more than share_like_capital's float32 spacing, so exact signed cancellation could leave a pound the part does not hold (2**23 shares, -1 trusts, a 1 ISA). The bound is now the smallest of stocks_and_shares_isa, share_like_capital and the holdings behind the part: the listed holdings' float32 sum, clamped as the part with sale expenses clamps it (nil where the itemised sum is not positive), or, under a reform that moves the ISAs, the part with sale expenses itself, which rounds once from that complement. Adds the witness, its mirror and an unitemised case as regressions, and an exact sweep over signed holdings near powers of two with the ISA exemption on and off and UC counting each part or both. P3: scope the each-means-test claims in the ISA variable, the docs page and the person-ISA test to the six DWP capital assessments, with Council Tax Reduction using them only through its UC and Pension Credit routes, and state the share parts' ranges for signed itemised sums. Co-Authored-By: Claude Opus 5.5 --- .../isa-inputs-and-capital-flows.md | 38 +-- .../tests/test_capital_share_components.py | 221 +++++++++++++++++- .../tests/test_person_isa_capital.py | 10 +- ...stocks_and_shares_isa_countable_capital.py | 79 ++++--- .../share_like_capital_with_sale_expenses.py | 57 +++-- ...hare_like_capital_without_sale_expenses.py | 9 +- 6 files changed, 341 insertions(+), 73 deletions(-) diff --git a/docs/book/assumptions/isa-inputs-and-capital-flows.md b/docs/book/assumptions/isa-inputs-and-capital-flows.md index d9fef0261b..aedaf51e5f 100644 --- a/docs/book/assumptions/isa-inputs-and-capital-flows.md +++ b/docs/book/assumptions/isa-inputs-and-capital-flows.md @@ -109,11 +109,15 @@ changes what the total sums or stops a person balance reading its inputs. A household input in a situation applies only to its own year; the person balances carry the variable-level uprating to later years. -Each means-test formula counts the claimant's and partner's cash and stocks and -shares ISA balances in their own benefit unit, through -`cash_isa_countable_capital` and `stocks_and_shares_isa_countable_capital` in -its `person_sources`, and excludes a dependant's balance, a child's junior ISA -among them. The formulas subtract a household's counted balances from `cash_isa` +Each of the six DWP capital assessments (Universal Credit, Pension Credit, +Housing Benefit, Income Support, income-based JSA and income-related ESA) counts +the claimant's and partner's cash and stocks and shares ISA balances in their +own benefit unit, through `cash_isa_countable_capital` and +`stocks_and_shares_isa_countable_capital` in its `person_sources`, and excludes +a dependant's balance, a child's junior ISA among them. Council Tax Reduction +uses these valuations only through its Universal Credit and Pension Credit +routes; its own household route counts neither ISAs nor share-like capital. +The formulas subtract a household's counted balances from `cash_isa` and from the part of `share_like_capital` that holds the household's stocks and shares ISAs before they allocate the remainder between benefit units, and value each balance as they value that part. The part is @@ -129,14 +133,22 @@ spacing and gives the steps left over, one each, to the members whose shares lost most in rounding. The pool then keeps nothing of that total; for totals under £268 million, each holding passes a capital limit only where its proportional share does; and a sole holder whose balance reaches the total -counts exactly the total. For stocks and shares ISAs the model takes the smaller -of `stocks_and_shares_isa` and `share_like_capital` as the total, or the part -that holds the ISAs where that part falls short of it by more than -`share_like_capital`'s float32 spacing. Rounding alone leaves the part short by -at most half that spacing; a larger shortfall comes from negative holdings -beside the ISAs, itemised holdings that sum to nil or less, or a reform. Data -that store only household totals hold no balances, so the pool keeps the whole -total. +counts exactly the total. For stocks and shares ISAs the model takes as the +total the smallest of `stocks_and_shares_isa`, `share_like_capital` and the +holdings behind the part that holds the ISAs. Behind +`share_like_capital_without_sale_expenses` stand the listed holdings: their +float32 sum, held between nil and `share_like_capital` where the itemised +holdings sum to more than nil, and otherwise nil. The model bounds the +balances by that sum rather than by the part, which it forms by subtracting +the other part and which can round to less than `share_like_capital`'s +float32 spacing either side of the sum, so a balance the sum covers keeps its +whole value. `share_like_capital_with_sale_expenses` rounds once from +`share_like_capital` less that clamped sum, so it never falls below a +balance the difference covers, and it bounds the balances itself. Negative +holdings beside the ISAs, itemised holdings that sum to nil or less, or a +reform can leave these holdings short of the ISAs; the balances then share +what the holdings hold. Data that store only household totals hold no +balances, so the pool keeps the whole total. The formulas count a balance only while the programme's `sources` lists the household source that includes it, so a reform that drops `cash_isa`, or the share-like part that holds the ISAs, from `sources` drops the balances with it. diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index dceb39071b..f71e66f0fe 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -36,6 +36,12 @@ member's stocks and shares ISA balance with the household's ISAs into the part with sale expenses: the formulas net the balance out of that part and count it in the holder's unit less 10%. +9. A person's stocks and shares ISA balance holds no more than the holdings + behind the part that holds the ISAs (trusts and ISAs while listed, held + between nil and share_like_capital; the rest of share_like_capital for the + part with sale expenses), allowing for the one float32 rounding that forms + them, and all of a balance those holdings cover. Each programme counts + each part on its lists within rounding of the holdings behind it. """ from fractions import Fraction @@ -341,14 +347,16 @@ def test_the_part_holding_the_isas_bounds_balances_only_beyond_rounding(): """A sole holder's £100.01 ISA balance inside £20,000.01 of corporate_wealth: the part with sale expenses is £19,900.00 in float32, and the part without it, the difference, 100.009765625, a quarter of a - thousandth short of the 100.01000214 balance. That is rounding, so the - holder keeps the whole balance, as before the part bounded it: UC counts + thousandth short of the 100.01000214 balance. That is rounding: the + listed holdings behind the part, the £100.01 ISA, cover the balance, so + the holder keeps the whole balance, as before the part bounded it: UC counts 90% of £19,900, £17,910, plus the part less the balance, plus the balance, £18,010.01. Trusts of -£5,000 beside £6,000 of shares and a lodger's £5,000 ISA leave share_like_capital at £6,000, all in the part with sale expenses, - and nil in the part that would hold the ISA. The balance can't take + and nil in the part that would hold the ISA: trusts and ISA sum to nil. + The balance can't take £5,000 out of nil, so the lodger holds nil, and the pool counts 90% of £6,000, £5,400, shared by two units: [£2,700, £2,700]. Netting £5,000 out of the empty part would give [£200, £5,200].""" @@ -389,6 +397,213 @@ def test_the_part_holding_the_isas_bounds_balances_only_beyond_rounding(): assert list(uc) == [np.float32(18_010.01), 2_700, 2_700] +UC_NODE = NODES["uc_assessable_capital"] + + +def _uc_lists_without(part): + """A reform that drops ``part`` from UC's capital and sale-expense lists.""" + return { + f"{UC_NODE}.{name}": { + str(YEAR): [ + source for source in _parameter(f"{UC_NODE}.{name}") if source != part + ] + } + for name in ("sources", "sale_expenses.sources") + } + + +def _sole_isa_holders(rows): + """One working-age adult per household and benefit unit, with + corporate_wealth, directly held shares and unit trusts on the household + and a stocks and shares ISA balance on the person, no household ISA total + stored, so stocks_and_shares_isa is the balance.""" + people, benunits, homes = {}, {}, {} + for i, (corporate_wealth, shares, trusts, balance) in enumerate(rows): + people[f"p{i}"] = { + "age": {YEAR: 30}, + "stocks_and_shares_isa_balance": {YEAR: float(balance)}, + } + benunits[f"b{i}"] = {"members": [f"p{i}"]} + homes[f"h{i}"] = { + "members": [f"p{i}"], + "corporate_wealth": {YEAR: float(corporate_wealth)}, + "directly_held_shares": {YEAR: float(shares)}, + "unit_and_investment_trusts": {YEAR: float(trusts)}, + } + return {"people": people, "benunits": benunits, "households": homes} + + +def test_a_balance_counts_nothing_the_holdings_behind_its_part_do_not_hold(): + """Review r2's witness and two like it, where the holdings behind the + part that holds the ISAs come to nil although share_like_capital's + float32 spacing is at least the £1 balance. + + 1. Shares of £8,388,608 (2**23), trusts of -£1 and a £1 ISA balance: + the itemised sum is £8,388,608, so share_like_capital is £8,388,608. + Trusts and ISA sum to exactly nil, so the part with sale expenses is + £8,388,608, the part without nil, and the balance holds nil. With the + part with sale expenses off UC's lists, UC counts nothing; bounded by + the smaller of the ISA total and share_like_capital, the £1 would be + netted from the empty part, floored at nil, and counted: £1. + 2. corporate_wealth of £16,777,216 (2**24), shares of -£2 and a £1 ISA + balance: the itemised sum is -£1, so share_like_capital is the + £16,777,216, all of it in the part with sale expenses, and the + balance holds nil. With that part off UC's lists, UC counts nothing. + 3. With stocks_and_shares_isa off the exempt list, shares of -£1, trusts + of £8,388,608 and a £1 ISA balance: share_like_capital is £8,388,608, + all of it trusts, so the part with sale expenses, which now holds the + ISAs, is nil, and the balance holds nil. With the part without sale + expenses off UC's lists, UC counts nothing, not 90% of £1. + + UC at baseline is 90% of share_like_capital in cases 1 and 2, + £7,549,747.20 and £15,099,494.40, which float32 holds as £7,549,747 and + £15,099,494, and in case 3 under the exempt-list reform alone the + £8,388,608 of trusts in full.""" + rows = [(0, 2**23, -1, 1), (2**24, -2, 0, 1)] + baseline = Simulation(situation=_sole_isa_holders(rows)) + reformed = Simulation( + situation=_sole_isa_holders(rows), reform=_uc_lists_without(WITH) + ) + for sim in (baseline, reformed): + assert list(sim.calculate("share_like_capital", YEAR)) == [2**23, 2**24] + assert list(sim.calculate(WITH, YEAR)) == [2**23, 2**24] + assert list(sim.calculate(WITHOUT, YEAR)) == [0, 0] + held = sim.calculate("stocks_and_shares_isa_countable_capital", YEAR) + assert list(held) == [0, 0] + assert list(baseline.calculate("uc_assessable_capital", YEAR)) == [ + np.float32(7_549_747.2), + np.float32(15_099_494.4), + ] + assert list(reformed.calculate("uc_assessable_capital", YEAR)) == [0, 0] + + mirror = _sole_isa_holders([(0, -1, 2**23, 1)]) + exempt_list = ISAS_WITH_SALE_EXPENSES + for reform, uc in ( + (exempt_list, 2**23), + ({**exempt_list, **_uc_lists_without(WITHOUT)}, 0), + ): + sim = Simulation(situation=mirror, reform=reform) + assert sim.calculate(WITH, YEAR)[0] == 0 + assert sim.calculate(WITHOUT, YEAR)[0] == 2**23 + assert sim.calculate("stocks_and_shares_isa_countable_capital", YEAR)[0] == 0 + assert sim.calculate("uc_assessable_capital", YEAR)[0] == uc + + +def _exact(value): + return Fraction(float(value)) + + +# Signed holdings at and beside powers of two, where share_like_capital's +# float32 spacing is a hundredth of a penny (2**10), £1 (2**23), £2 (2**24) +# and £4 (2**25), and balances of a few pounds up to the power itself. +SWEEP = [ + (corporate_wealth, shares, trusts, balance) + for power in (2.0, 2.0**10, 2.0**23, 2.0**24, 2.0**25) + for corporate_wealth in (0, power) + for shares in (0, power, power - 1, -1, -2, -power) + for trusts in (0, power, power - 1, -1, -2, -power) + for balance in (1, 2, 3, power) +] + + +@pytest.mark.parametrize("isas_exempt", [True, False]) +def test_isa_balances_stay_within_the_holdings_behind_their_part(isas_exempt): + """Invariant 9, swept over SWEEP with the ISAs in each part, and UC + counting both parts, only the part without sale expenses, and only the + part with them. + + Worked in exact arithmetic from the float32 holdings: the holdings behind + the part that holds the ISAs are, where the itemised sum is positive, the + listed holdings' sum (trusts, and the ISA while it is listed) held + between nil and share_like_capital, or for the part with sale expenses + share_like_capital less that; otherwise nil, or all of + share_like_capital. The engine forms them with one float32 rounding, of + the listed sum or of share_like_capital less it. Then: + - the balance holds between nil and the smaller of itself and + share_like_capital, and within that rounding of the smaller of those + and the holdings, so it holds all of a balance the holdings cover; + - each part lies within share_like_capital's float32 spacing plus the + listed sum's rounding of the holdings behind it; + - UC counts each part on its lists at its value there, within the parts' + and the balance's rounding, a penny for each valuation, and float32's + step at the result. + """ + exempt = {} if isas_exempt else ISAS_WITH_SALE_EXPENSES + situation = _sole_isa_holders(SWEEP) + holder_part = WITHOUT if isas_exempt else WITH + for counted in ((WITH, WITHOUT), (WITHOUT,), (WITH,)): + dropped = {WITH, WITHOUT} - set(counted) + reform = dict(exempt) + for part in dropped: + reform |= _uc_lists_without(part) + sim = Simulation(situation=situation, reform=reform or None) + share_like = sim.calculate("share_like_capital", YEAR) + isa_total = sim.calculate("stocks_and_shares_isa", YEAR) + parts = {name: sim.calculate(name, YEAR) for name in (WITH, WITHOUT)} + held = sim.calculate("stocks_and_shares_isa_countable_capital", YEAR) + uc = sim.calculate("uc_assessable_capital", YEAR) + for i, (_, shares, trusts, balance) in enumerate(SWEEP): + row = (SWEEP[i], isas_exempt, counted) + values = [np.float32(v) for v in (shares, trusts, balance)] + itemised = np.float32(np.float32(values[0] + values[1]) + values[2]) + listed = values[1:] if isas_exempt else values[1:2] + listed_sum = sum(_exact(v) for v in listed) + # The engine adds the listed holdings from nil, left to right. + engine_sum = np.float32(0) + for value in listed: + engine_sum = np.float32(engine_sum + value) + sum_rounding = abs(_exact(engine_sum) - listed_sum) + total = _exact(share_like[i]) + if itemised > 0: + behind = {WITHOUT: min(total, max(0, listed_sum))} + behind[WITH] = total - behind[WITHOUT] + rounding = ( + sum_rounding + if isas_exempt + else abs( + _exact(np.float32(share_like[i] - engine_sum)) + - (total - _exact(engine_sum)) + ) + + sum_rounding + ) + else: + behind = {WITHOUT: Fraction(0), WITH: total} + rounding = Fraction(0) + cap = max(Fraction(0), min(_exact(isa_total[i]), total)) + holding = _exact(held[i]) + assert 0 <= holding <= cap, row + assert abs(holding - min(cap, max(0, behind[holder_part]))) <= rounding, row + if behind[holder_part] >= cap: + assert holding == cap, row + spacing = _exact(np.spacing(np.abs(share_like[i]))) + # The part without sale expenses is share_like_capital less the + # other part: less than share_like_capital's spacing either side + # of the engine's clamped listed sum, which bounds the balances. + engine_behind = ( + min(total, max(0, _exact(engine_sum))) if itemised > 0 else 0 + ) + assert abs(_exact(parts[WITHOUT][i]) - engine_behind) < max( + spacing, Fraction(2) ** -149 + ), row + for name in (WITH, WITHOUT): + assert abs(_exact(parts[name][i]) - behind[name]) <= ( + spacing + sum_rounding + ), (row, name) + sale = set(_parameter(f"{UC_NODE}.sale_expenses.sources")) - dropped + value = { + name: Fraction(9, 10) if name in sale else Fraction(1) + for name in counted + } + expected = sum(value[name] * behind[name] for name in counted) + tolerance = ( + sum(abs(_exact(parts[name][i]) - behind[name]) for name in counted) + + rounding + + Fraction(3, 100) + + _exact(np.spacing(np.float32(float(expected)))) + ) + assert abs(_exact(uc[i]) - expected) <= tolerance, (row, uc[i], expected) + + def test_the_exempt_list_starts_with_the_first_capital_list(): exempt = system.parameters.gov.dwp.share_like_capital.without_sale_expenses first = min( diff --git a/policyengine_uk/tests/test_person_isa_capital.py b/policyengine_uk/tests/test_person_isa_capital.py index fcf1d996f0..a6461f1e1d 100644 --- a/policyengine_uk/tests/test_person_isa_capital.py +++ b/policyengine_uk/tests/test_person_isa_capital.py @@ -1,10 +1,10 @@ """Person cash and stocks and shares ISAs count in the holder's benefit unit (#2729). -Each means-test formula counts cash_isa_countable_capital and -stocks_and_shares_isa_countable_capital through person_sources, for the -claimant and partner. The formulas subtract them from the household source -that includes them (cash_isa and share_like_capital) and allocate the -remainder between benefit units. +Each of the six DWP capital assessments (CAPITAL) counts +cash_isa_countable_capital and stocks_and_shares_isa_countable_capital +through person_sources, for the claimant and partner. The formulas subtract +them from the household source that includes them (cash_isa and +share_like_capital) and allocate the remainder between benefit units. For the households below, with no reported capital, the formulas allocate the remainder by claimant weights or, for Pension Credit, pension-age adult diff --git a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py index b009a00a5e..095fb55bf8 100644 --- a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py @@ -3,13 +3,19 @@ bounded_person_holding, household_sources, ) +from policyengine_uk.variables.household.wealth.share_like_capital_with_sale_expenses import ( + holdings_without_sale_expenses, +) class stocks_and_shares_isa_countable_capital(Variable): label = "Stocks and shares ISA value counted as means-tested capital" documentation = ( "The person's stocks and shares ISA balance (stocks_and_shares_isa_balance) as " - "the means tests count it, in the holder's own benefit unit. The account " + "the six DWP capital assessments (Universal Credit, Pension Credit, Housing " + "Benefit, Income Support, income-based JSA and income-related ESA) count it, in " + "the holder's own benefit unit. Council Tax Reduction uses these valuations " + "only through its Universal Credit and Pension Credit routes. The account " "investor beneficially owns an ordinary ISA's investments, and the named child " "owns a junior ISA's investments. The household's share_like_capital already " "includes the balance, through stocks_and_shares_isa within corporate_wealth " @@ -17,21 +23,29 @@ class stocks_and_shares_isa_countable_capital(Variable): "ISAs: share_like_capital_without_sale_expenses while " "gov.dwp.share_like_capital.without_sale_expenses lists stocks_and_shares_isa, " "and share_like_capital_with_sale_expenses under a reform that removes it. Each " - "means test subtracts the balance from that part before allocating the pool " - "between benefit units, and values it as it values that part: at face value, " - "or less the sale-expense rate under such a reform. The formula bounds the " - "person's balance by the smaller of stocks_and_shares_isa and " - "share_like_capital, so the household never counts more stocks and shares ISA " - "than it holds. It bounds them instead by the part that holds the ISAs where " - "that part falls short of this bound by more than share_like_capital's float32 " - "spacing. Rounding in the subtraction that forms the part leaves it short by " - "at most half that spacing, so the part takes over only where negative holdings " - "beside the ISAs, itemised holdings that sum to nil or less, or a reform leave " - "it short of the ISAs. When the household's stored balance sum exceeds the " - "bound, the formula scales the balances to sum to it exactly, rounding each " - "proportional share down or up to a whole float32 step of the bound. When the " - "balances sum to less, the rest stays in the pool, and a household with no " - "balances keeps all of share_like_capital there." + "of the six assessments subtracts the balance from that part before allocating " + "the pool between benefit units, and values it as it values that part: at face " + "value, or less the sale-expense rate under such a reform. The formula bounds " + "the person's balance by the smallest of stocks_and_shares_isa, " + "share_like_capital and the holdings behind the part that holds the ISAs, so " + "the household never counts more stocks and shares ISA than it holds. The " + "holdings behind share_like_capital_without_sale_expenses are the float32 sum " + "of the listed holdings, held between nil and share_like_capital where the " + "itemised holdings sum to more than nil, and otherwise nil. The part itself is " + "share_like_capital less the other part, and its float32 subtractions can " + "leave it less than share_like_capital's float32 spacing either side of that " + "sum. " + "Bounding by the sum keeps the whole of a balance the sum covers, and the " + "pool absorbs the part's rounding. share_like_capital_with_sale_expenses " + "rounds once from share_like_capital less that clamped sum, so it never falls " + "below a balance the difference covers, and it bounds the balances itself. " + "Negative holdings beside the ISAs, itemised holdings that sum to nil or less, " + "or a reform can leave these holdings short of the ISAs; the balances then " + "share what the holdings hold. When the household's stored " + "balance sum exceeds the bound, the formula scales the balances to sum to it " + "exactly, rounding each proportional share down or up to a whole float32 step " + "of the bound. When the balances sum to less, the rest stays in the pool, and " + "a household with no balances keeps all of share_like_capital there." ) entity = Person definition_period = YEAR @@ -47,23 +61,24 @@ def formula(person, period, parameters): household = person.household share_like = household("share_like_capital", period) household_total = min_(household("stocks_and_shares_isa", period), share_like) - part = household( - household_sources(parameters(period))[ - "stocks_and_shares_isa_countable_capital" - ], - period, - ) - # The part without sale expenses is share_like_capital less the part - # with them, so it can miss the holdings it stands for by half of - # share_like_capital's float32 spacing. A larger shortfall means the - # part holds less than the ISAs, and the balances can't take more out - # of it than it holds. An infinite share_like_capital has no spacing, - # and keeps the bound. - with np.errstate(invalid="ignore"): - slack = np.spacing(np.abs(share_like)).astype(np.float64) - short = household_total.astype(np.float64) - part.astype(np.float64) > slack + part = household_sources(parameters(period))[ + "stocks_and_shares_isa_countable_capital" + ] + # Bound the balances by the holdings behind the part that holds the + # ISAs. The part without sale expenses is share_like_capital less the + # other part, so its subtractions can round it below the listed + # holdings it stands for; their float32 sum, clamped as the part with + # sale expenses clamps it, has no such rounding, and a balance that + # sum covers keeps its whole value. The part with sale expenses + # rounds once from share_like_capital less that clamped sum, so it + # never falls below a balance the difference covers. + if part == "share_like_capital_without_sale_expenses": + backing = holdings_without_sale_expenses(household, period, parameters) + else: + backing = household(part, period) + # A missing (NaN) backing leaves the bound unchanged. return bounded_person_holding( person, person("stocks_and_shares_isa_balance", period), - where(short, part, household_total), + where(backing < household_total, backing, household_total), ) diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py index 1615558813..7318965d40 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -18,15 +18,16 @@ class share_like_capital_with_sale_expenses(Variable): label = "share-like capital with expenses of sale" documentation = ( "The part of share_like_capital whose sale would incur expenses, so " - "that the means tests value it less 10%: share_like_capital less the " - "itemised holdings listed in gov.dwp.share_like_capital." + "that the six DWP capital assessments value it less 10%. Where the " + "itemised holdings sum to more than nil, it is share_like_capital less " + "the itemised holdings listed in gov.dwp.share_like_capital." "without_sale_expenses (unit and investment trusts, stocks and shares " - "ISAs), held between nil and share_like_capital, so that the two parts " - "add up to share_like_capital, to within float32 rounding, whatever the " - "signs of the holdings. A " - "household whose itemised holdings sum to nil or less has all of its " - "share-like capital here, so datasets that carry only corporate_wealth " - "keep the flat 10% on it, whatever its sign." + "ISAs), held between nil and share_like_capital, which is then " + "nonnegative, so that the two parts add up to share_like_capital, to " + "within float32 rounding, whatever the signs of the holdings. Where " + "they sum to nil or less, it is all of share_like_capital, whatever " + "its sign, so datasets that carry only corporate_wealth keep the flat " + "10% on it." ) entity = Household definition_period = YEAR @@ -36,14 +37,7 @@ class share_like_capital_with_sale_expenses(Variable): def formula(household, period, parameters): share_like = household("share_like_capital", period) - itemised = add(household, period, COMPONENTS) - # Summed from a numeric zero so that an empty list (every holding - # taking the deduction) still works. - without = 0 * share_like - for variable in parameters( - period - ).gov.dwp.share_like_capital.without_sale_expenses: - without = without + household(variable, period) + itemised, without = _itemised_and_listed(household, period, parameters) # share_like_capital is nonnegative wherever the itemised sum is # positive. Holding this part between nil and that total keeps the # other part, the difference, between nil and the total too, so @@ -54,3 +48,34 @@ def formula(household, period, parameters): min_(share_like, max_(0, share_like - without)), share_like, ) + + +def _itemised_and_listed(household, period, parameters): + """share_like_capital's itemised sum, and the sum of the holdings + gov.dwp.share_like_capital.without_sale_expenses lists, each added in + float32 as the engine adds it: COMPONENTS left to right, and the listed + holdings in list order from nil.""" + itemised = add(household, period, COMPONENTS) + # Summed from a numeric zero so that an empty list (every holding taking + # the deduction) still works. + listed = 0 * household("share_like_capital", period) + for variable in parameters(period).gov.dwp.share_like_capital.without_sale_expenses: + listed = listed + household(variable, period) + return itemised, listed + + +def holdings_without_sale_expenses(household, period, parameters): + """The holdings share_like_capital_without_sale_expenses stands for. + + Where the itemised holdings sum to more than nil, the float32 sum of the + holdings gov.dwp.share_like_capital.without_sale_expenses lists, held + between nil and share_like_capital as share_like_capital_with_sale_expenses + holds its complement; otherwise nil. The part itself is share_like_capital + less share_like_capital_with_sale_expenses, whose float32 subtractions can + leave it less than share_like_capital's float32 spacing either side of this + sum. No subtraction enters the sum: a balance it covers keeps its whole + value, however the part rounds. + """ + share_like = household("share_like_capital", period) + itemised, listed = _itemised_and_listed(household, period, parameters) + return where(itemised > 0, min_(share_like, max_(0, listed)), 0) diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py index 0c314eb949..e442b5aa98 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py @@ -4,10 +4,11 @@ class share_like_capital_without_sale_expenses(Variable): label = "share-like capital without expenses of sale" documentation = ( - "The part of share_like_capital the means tests value at full value: " - "share_like_capital less share_like_capital_with_sale_expenses, " - "between nil and share_like_capital. Nil for a household whose " - "itemised holdings sum to nil or less." + "The part of share_like_capital the six DWP capital assessments value " + "at full value: share_like_capital less " + "share_like_capital_with_sale_expenses. It lies between nil and " + "share_like_capital where the itemised holdings sum to more than nil, " + "and is otherwise nil." ) entity = Household definition_period = YEAR From a238aa2239091056c4beafe4f5d11fe80b162e79 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 13:20:14 -0500 Subject: [PATCH 43/48] Say invariant 9's sweep checks Universal Credit's counting of the parts The sweep counts the parts under Universal Credit only, so the module docstring now says so rather than claiming every programme. Co-Authored-By: Claude Opus 5.5 --- policyengine_uk/tests/test_capital_share_components.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index f71e66f0fe..8f2e06f0ff 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -40,7 +40,7 @@ behind the part that holds the ISAs (trusts and ISAs while listed, held between nil and share_like_capital; the rest of share_like_capital for the part with sale expenses), allowing for the one float32 rounding that forms - them, and all of a balance those holdings cover. Each programme counts + them, and all of a balance those holdings cover. Universal Credit counts each part on its lists within rounding of the holdings behind it. """ From 45c48dc2e6d9aacfdd76cdc045fd5d819c8ea1e1 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 15:56:33 -0500 Subject: [PATCH 44/48] Bound ISA balances by a stored part that falls short of its holdings, and round the reform-route complement once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On the baseline route the bound read only the listed holdings, so a direct input or a reformed formula of either share part could leave the part that holds the ISAs short while the balances kept their value, sending the pool below nil (a lodger's UC capital fell from £5,000 to £2,500). Where the stored part falls short of the holdings behind it by more than share_like_capital's float32 spacing, which the parts' own formulas never do for a list of two holdings, the stored part now bounds the balances, on either route. Under a reform that takes the ISAs off the exempt list, the holdings behind the part with sale expenses are now share_like_capital less the listed holdings computed in float64, so they round once. The stored part rounds the listed float32 sum and then the subtraction, so for a list of two holdings it could fall a pound short of a balance the holdings cover. One-name lists, the default reform included, give the same holdings as before. Rename the £100.01 test, whose name described the old slack rule. Co-Authored-By: Claude Opus 5.5 --- .../isa-inputs-and-capital-flows.md | 16 +- .../tests/test_capital_share_components.py | 195 +++++++++++++++--- ...stocks_and_shares_isa_countable_capital.py | 46 +++-- .../share_like_capital_with_sale_expenses.py | 35 +++- 4 files changed, 239 insertions(+), 53 deletions(-) diff --git a/docs/book/assumptions/isa-inputs-and-capital-flows.md b/docs/book/assumptions/isa-inputs-and-capital-flows.md index aedaf51e5f..2ec0739099 100644 --- a/docs/book/assumptions/isa-inputs-and-capital-flows.md +++ b/docs/book/assumptions/isa-inputs-and-capital-flows.md @@ -142,9 +142,19 @@ holdings sum to more than nil, and otherwise nil. The model bounds the balances by that sum rather than by the part, which it forms by subtracting the other part and which can round to less than `share_like_capital`'s float32 spacing either side of the sum, so a balance the sum covers keeps its -whole value. `share_like_capital_with_sale_expenses` rounds once from -`share_like_capital` less that clamped sum, so it never falls below a -balance the difference covers, and it bounds the balances itself. Negative +whole value. Behind `share_like_capital_with_sale_expenses`, under a reform +that moves the ISAs there, stands `share_like_capital` less the listed +holdings, held between nil and `share_like_capital` where the itemised +holdings sum to more than nil, and otherwise all of `share_like_capital`. +The model computes that complement in float64, because the part itself +rounds the listed holdings' float32 sum and then the subtraction, and could +fall below a balance the holdings cover. For a list of two holdings each of +these holdings rounds at most once, to float32 (for the float64 complement, +unless one amount is more than 2^29 times another), and the parts' formulas +stay within `share_like_capital`'s float32 spacing of them. Where the stored +part falls further short, as a direct input or a reformed formula of either +part can make it, the stored part bounds the balances instead, so the pool +keeps what the part holds. Negative holdings beside the ISAs, itemised holdings that sum to nil or less, or a reform can leave these holdings short of the ISAs; the balances then share what the holdings hold. Data that store only household totals hold no diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 8f2e06f0ff..562f87db96 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -37,11 +37,16 @@ part with sale expenses: the formulas net the balance out of that part and count it in the holder's unit less 10%. 9. A person's stocks and shares ISA balance holds no more than the holdings - behind the part that holds the ISAs (trusts and ISAs while listed, held - between nil and share_like_capital; the rest of share_like_capital for the - part with sale expenses), allowing for the one float32 rounding that forms - them, and all of a balance those holdings cover. Universal Credit counts - each part on its lists within rounding of the holdings behind it. + behind the part that holds the ISAs (the listed holdings, held between + nil and share_like_capital, while the list names the ISAs; the rest of + share_like_capital for the part with sale expenses once it does not), + allowing for the one float32 rounding that forms them, and all of a + balance those holdings cover, for any list of two holdings. Universal + Credit counts each part on its lists within rounding of the holdings + behind it. +10. Where a direct input leaves the stored part that holds the ISAs short + of the holdings behind it, the balances hold no more than the stored + part, so the pool never counts less than nil of it. """ from fractions import Fraction @@ -343,7 +348,7 @@ def test_a_reform_that_takes_isas_out_of_the_exempt_list_values_person_isas_less assert reformed.calculate(pension_credit, YEAR)[3] == 4_500 -def test_the_part_holding_the_isas_bounds_balances_only_beyond_rounding(): +def test_a_balance_its_listed_holdings_cover_keeps_its_whole_value(): """A sole holder's £100.01 ISA balance inside £20,000.01 of corporate_wealth: the part with sale expenses is £19,900.00 in float32, and the part without it, the difference, 100.009765625, a quarter of a @@ -506,19 +511,31 @@ def _exact(value): ] -@pytest.mark.parametrize("isas_exempt", [True, False]) -def test_isa_balances_stay_within_the_holdings_behind_their_part(isas_exempt): - """Invariant 9, swept over SWEEP with the ISAs in each part, and UC - counting both parts, only the part without sale expenses, and only the - part with them. +EXEMPT_NODE = "gov.dwp.share_like_capital.without_sale_expenses" +# The baseline list, and two reforms that take the ISAs off it: the trusts +# alone, and the shares with the trusts, whose float32 sum rounds before the +# part with sale expenses subtracts it. +SWEEP_LISTS = { + "baseline": None, + "trusts": ["unit_and_investment_trusts"], + "shares_and_trusts": ["directly_held_shares", "unit_and_investment_trusts"], +} + + +@pytest.mark.parametrize("exempt_list", list(SWEEP_LISTS)) +def test_isa_balances_stay_within_the_holdings_behind_their_part(exempt_list): + """Invariant 9, swept over SWEEP with each exempt list in SWEEP_LISTS, + and UC counting both parts, only the part without sale expenses, and + only the part with them. Worked in exact arithmetic from the float32 holdings: the holdings behind the part that holds the ISAs are, where the itemised sum is positive, the - listed holdings' sum (trusts, and the ISA while it is listed) held - between nil and share_like_capital, or for the part with sale expenses - share_like_capital less that; otherwise nil, or all of - share_like_capital. The engine forms them with one float32 rounding, of - the listed sum or of share_like_capital less it. Then: + listed holdings' sum held between nil and share_like_capital, or for the + part with sale expenses share_like_capital less that; otherwise nil, or + all of share_like_capital. The engine forms them with one rounding: the + float32 listed sum, or share_like_capital less the listed holdings in + float64, which holds these whole-pound amounts exactly, rounded to + float32 where it bounds the balance. Then: - the balance holds between nil and the smaller of itself and share_like_capital, and within that rounding of the smaller of those and the holdings, so it holds all of a balance the holdings cover; @@ -528,7 +545,9 @@ def test_isa_balances_stay_within_the_holdings_behind_their_part(isas_exempt): and the balance's rounding, a penny for each valuation, and float32's step at the result. """ - exempt = {} if isas_exempt else ISAS_WITH_SALE_EXPENSES + names = SWEEP_LISTS[exempt_list] or _parameter(EXEMPT_NODE) + isas_exempt = "stocks_and_shares_isa" in names + exempt = {} if exempt_list == "baseline" else {EXEMPT_NODE: {str(YEAR): names}} situation = _sole_isa_holders(SWEEP) holder_part = WITHOUT if isas_exempt else WITH for counted in ((WITH, WITHOUT), (WITHOUT,), (WITH,)): @@ -543,10 +562,20 @@ def test_isa_balances_stay_within_the_holdings_behind_their_part(isas_exempt): held = sim.calculate("stocks_and_shares_isa_countable_capital", YEAR) uc = sim.calculate("uc_assessable_capital", YEAR) for i, (_, shares, trusts, balance) in enumerate(SWEEP): - row = (SWEEP[i], isas_exempt, counted) - values = [np.float32(v) for v in (shares, trusts, balance)] - itemised = np.float32(np.float32(values[0] + values[1]) + values[2]) - listed = values[1:] if isas_exempt else values[1:2] + row = (SWEEP[i], exempt_list, counted) + values = dict( + zip( + ( + "directly_held_shares", + "unit_and_investment_trusts", + "stocks_and_shares_isa", + ), + (np.float32(v) for v in (shares, trusts, balance)), + ) + ) + shares, trusts, balance = values.values() + itemised = np.float32(np.float32(shares + trusts) + balance) + listed = [values[name] for name in names] listed_sum = sum(_exact(v) for v in listed) # The engine adds the listed holdings from nil, left to right. engine_sum = np.float32(0) @@ -557,19 +586,16 @@ def test_isa_balances_stay_within_the_holdings_behind_their_part(isas_exempt): if itemised > 0: behind = {WITHOUT: min(total, max(0, listed_sum))} behind[WITH] = total - behind[WITHOUT] - rounding = ( - sum_rounding - if isas_exempt - else abs( - _exact(np.float32(share_like[i] - engine_sum)) - - (total - _exact(engine_sum)) - ) - + sum_rounding - ) else: behind = {WITHOUT: Fraction(0), WITH: total} - rounding = Fraction(0) cap = max(Fraction(0), min(_exact(isa_total[i]), total)) + if isas_exempt: + rounding = sum_rounding if itemised > 0 else Fraction(0) + else: + # The float64 complement is exact here; the bound rounds it + # once, to float32. + bound = min(cap, max(0, behind[WITH])) + rounding = abs(_exact(np.float32(float(bound))) - bound) holding = _exact(held[i]) assert 0 <= holding <= cap, row assert abs(holding - min(cap, max(0, behind[holder_part]))) <= rounding, row @@ -578,13 +604,20 @@ def test_isa_balances_stay_within_the_holdings_behind_their_part(isas_exempt): spacing = _exact(np.spacing(np.abs(share_like[i]))) # The part without sale expenses is share_like_capital less the # other part: less than share_like_capital's spacing either side - # of the engine's clamped listed sum, which bounds the balances. + # of the engine's clamped listed sum, which bounds the balances + # while the list names the ISAs. The part with sale expenses + # stays within that spacing of the holdings behind it, which + # bound them otherwise. So neither stored part falls short of the + # holdings by enough to bound the balances itself. engine_behind = ( min(total, max(0, _exact(engine_sum))) if itemised > 0 else 0 ) assert abs(_exact(parts[WITHOUT][i]) - engine_behind) < max( spacing, Fraction(2) ** -149 ), row + assert abs(_exact(parts[WITH][i]) - behind[WITH]) <= max( + spacing, Fraction(2) ** -149 + ), row for name in (WITH, WITHOUT): assert abs(_exact(parts[name][i]) - behind[name]) <= ( spacing + sum_rounding @@ -604,6 +637,104 @@ def test_isa_balances_stay_within_the_holdings_behind_their_part(isas_exempt): assert abs(_exact(uc[i]) - expected) <= tolerance, (row, uc[i], expected) +def test_a_balance_the_complement_covers_keeps_its_whole_value(): + """A reform that lists directly held shares and trusts, not the ISAs, so + the part with sale expenses holds them: corporate_wealth of £16,777,222, + shares of £16,777,216 (2**24), trusts of £3 and a £3 ISA balance. The + holdings sum to the corporate_wealth, so share_like_capital is + £16,777,222, whose float32 spacing is £2. Shares and trusts sum to + £16,777,219, which + float32 rounds to £16,777,220, so the part with sale expenses is £2 and + the part without £16,777,220. The holdings behind the part with sale + expenses are £16,777,222 less £16,777,219, £3, which cover the balance, + so the holder keeps all £3. With the part without sale expenses off + UC's lists, UC counts 90% of the £2 part less the £3 balance, a pool + below nil that it floors at nil, plus 90% of the balance: £2.70, 90% of + the £3 behind the part. Bounded by the £2 part, the holder would keep + £2, and UC would count £1.80. With both parts counted, UC counts the + £16,777,220 in full and 90% of the £2 part, £16,777,221.80, which float32 + holds as £16,777,222.""" + situation = _sole_isa_holders([(16_777_222, 2**24, 3, 3)]) + exempt = { + EXEMPT_NODE: {str(YEAR): ["directly_held_shares", "unit_and_investment_trusts"]} + } + for reform, uc in ( + (exempt, 16_777_222), + ({**exempt, **_uc_lists_without(WITHOUT)}, np.float32(2.7)), + ): + sim = Simulation(situation=situation, reform=reform) + assert sim.calculate("share_like_capital", YEAR)[0] == 16_777_222 + assert sim.calculate(WITH, YEAR)[0] == 2 + assert sim.calculate(WITHOUT, YEAR)[0] == 16_777_220 + assert sim.calculate("stocks_and_shares_isa_countable_capital", YEAR)[0] == 3 + assert sim.calculate("uc_assessable_capital", YEAR)[0] == uc + + +def _holder_and_lodger(household): + """A holder with a £5,000 stocks and shares ISA balance and a lodger in + separate working-age benefit units sharing £10,000 of savings, with + ``household``'s inputs on the household. No household ISA total is + stored, so stocks_and_shares_isa is the balance.""" + return { + "people": { + "holder": { + "age": {YEAR: 30}, + "stocks_and_shares_isa_balance": {YEAR: 5_000}, + }, + "lodger": {"age": {YEAR: 30}}, + }, + "benunits": { + "holder_unit": {"members": ["holder"]}, + "lodger_unit": {"members": ["lodger"]}, + }, + "households": { + "home": { + "members": ["holder", "lodger"], + "savings": {YEAR: 10_000}, + **{name: {YEAR: value} for name, value in household.items()}, + } + }, + } + + +@pytest.mark.parametrize( + "household, reform, held, uc", + [ + # The part without sale expenses entered as nil: the listed £5,000 ISA + # would back the balance, but the part holds nothing, so the balance + # holds nil and the pool counts the savings, £5,000 for each unit. + # Bounded by the listed holdings alone, the holder would keep £5,000 + # and the pool fall to £5,000: [£7,500, £2,500]. + ({WITHOUT: 0}, None, 0, [5_000, 5_000]), + # Entered as £2,000: the balance holds the £2,000 the part holds. + ({WITHOUT: 2_000}, None, 2_000, [7_000, 5_000]), + # The part with sale expenses entered as all £5,000 of + # share_like_capital leaves nil in the part without, so the balance + # holds nil and the pool counts £10,000 and 90% of £5,000: £7,250 for + # each unit, not [£9,750, £4,750]. + ({WITH: 5_000}, None, 0, [7_250, 7_250]), + # With the ISAs off the exempt list, the part with sale expenses + # entered as nil: the £5,000 complement would back the balance, but + # the part holds nothing, so the pool counts £10,000 and the £5,000 + # in the part without sale expenses: £7,500 for each unit. + ({WITH: 0}, ISAS_WITH_SALE_EXPENSES, 0, [7_500, 7_500]), + ], +) +def test_a_stored_part_short_of_its_holdings_bounds_the_balances( + household, reform, held, uc +): + """Invariant 10: where a direct input leaves the stored part that holds + the ISAs short of the holdings behind it, the balance holds no more than + the part, so the pool keeps what the part holds.""" + sim = Simulation(situation=_holder_and_lodger(household), reform=reform) + part = WITHOUT if reform is None else WITH + stored = sim.calculate(part, YEAR)[0] + holding = sim.calculate("stocks_and_shares_isa_countable_capital", YEAR) + assert list(holding) == [held, 0] + assert holding[0] <= stored + assert list(sim.calculate("uc_assessable_capital", YEAR)) == uc + + def test_the_exempt_list_starts_with_the_first_capital_list(): exempt = system.parameters.gov.dwp.share_like_capital.without_sale_expenses first = min( diff --git a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py index 095fb55bf8..0dbaac78a3 100644 --- a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py @@ -4,6 +4,7 @@ household_sources, ) from policyengine_uk.variables.household.wealth.share_like_capital_with_sale_expenses import ( + holdings_with_sale_expenses, holdings_without_sale_expenses, ) @@ -34,11 +35,20 @@ class stocks_and_shares_isa_countable_capital(Variable): "itemised holdings sum to more than nil, and otherwise nil. The part itself is " "share_like_capital less the other part, and its float32 subtractions can " "leave it less than share_like_capital's float32 spacing either side of that " - "sum. " - "Bounding by the sum keeps the whole of a balance the sum covers, and the " - "pool absorbs the part's rounding. share_like_capital_with_sale_expenses " - "rounds once from share_like_capital less that clamped sum, so it never falls " - "below a balance the difference covers, and it bounds the balances itself. " + "sum. The holdings behind share_like_capital_with_sale_expenses are " + "share_like_capital less the listed holdings, held between nil and " + "share_like_capital where the itemised holdings sum to more than nil, and " + "otherwise all of share_like_capital, computed in float64; the part itself " + "rounds the listed sum and then the subtraction. For a list of two " + "holdings, each of these holdings rounds at most once, to float32 (for the " + "float64 complement, unless one amount is more than 2**29 times another), " + "so bounding by them keeps the whole of a balance they cover, and the pool " + "absorbs the part's " + "rounding. While the list names at most two holdings, the parts' formulas " + "stay within share_like_capital's float32 spacing of these holdings. Where " + "the stored part falls further short, as a direct input or a reformed " + "formula of either part can make it, the stored part bounds the balances " + "instead, so the pool keeps what the part holds. " "Negative holdings beside the ISAs, itemised holdings that sum to nil or less, " "or a reform can leave these holdings short of the ISAs; the balances then " "share what the holdings hold. When the household's stored " @@ -65,17 +75,27 @@ def formula(person, period, parameters): "stocks_and_shares_isa_countable_capital" ] # Bound the balances by the holdings behind the part that holds the - # ISAs. The part without sale expenses is share_like_capital less the - # other part, so its subtractions can round it below the listed - # holdings it stands for; their float32 sum, clamped as the part with - # sale expenses clamps it, has no such rounding, and a balance that - # sum covers keeps its whole value. The part with sale expenses - # rounds once from share_like_capital less that clamped sum, so it - # never falls below a balance the difference covers. + # ISAs, formed with one rounding, so that a balance they cover keeps + # its whole value. The part without sale expenses is + # share_like_capital less the other part, so its subtractions can + # round it below the listed holdings it stands for; their float32 + # sum, clamped as the part with sale expenses clamps it, has no such + # rounding. The part with sale expenses subtracts that float32 sum + # and rounds again; its complement in float64 rounds at most once. if part == "share_like_capital_without_sale_expenses": backing = holdings_without_sale_expenses(household, period, parameters) else: - backing = household(part, period) + backing = holdings_with_sale_expenses(household, period, parameters) + # The formulas net the balances out of the stored part. While the + # list names at most two holdings, the parts' formulas stay within + # share_like_capital's float32 spacing of these holdings. A direct + # input or a reformed formula can leave the stored part further + # short, and the stored part then bounds the balances, so the pool + # keeps what the part holds. + stored = household(part, period) + with np.errstate(invalid="ignore"): + short = backing - stored > np.spacing(np.abs(share_like)) + backing = where(short, stored, backing) # A missing (NaN) backing leaves the bound unchanged. return bounded_person_holding( person, diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py index 7318965d40..081d96e359 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -70,12 +70,37 @@ def holdings_without_sale_expenses(household, period, parameters): Where the itemised holdings sum to more than nil, the float32 sum of the holdings gov.dwp.share_like_capital.without_sale_expenses lists, held between nil and share_like_capital as share_like_capital_with_sale_expenses - holds its complement; otherwise nil. The part itself is share_like_capital - less share_like_capital_with_sale_expenses, whose float32 subtractions can - leave it less than share_like_capital's float32 spacing either side of this - sum. No subtraction enters the sum: a balance it covers keeps its whole - value, however the part rounds. + holds its complement; otherwise nil. It is the sum the other part + subtracts, so it rounds once for a list of two holdings, as the baseline + list is. The part itself is share_like_capital less + share_like_capital_with_sale_expenses, whose float32 subtractions leave it + less than share_like_capital's float32 spacing either side of this sum. No + subtraction enters the sum: a balance it covers keeps its whole value, + however the part rounds. """ share_like = household("share_like_capital", period) itemised, listed = _itemised_and_listed(household, period, parameters) return where(itemised > 0, min_(share_like, max_(0, listed)), 0) + + +def holdings_with_sale_expenses(household, period, parameters): + """The holdings share_like_capital_with_sale_expenses stands for. + + Where the itemised holdings sum to more than nil, share_like_capital less + the holdings gov.dwp.share_like_capital.without_sale_expenses lists, held + between nil and share_like_capital; otherwise all of share_like_capital. + The part itself subtracts the listed holdings' float32 sum, which rounds + once for a list of two holdings, and then rounds again. This complement + runs in float64, which holds the sum and difference of float32 amounts + exactly unless one is more than some 500 million (2**29) times another, + so it rounds at most once, to float32, where it bounds a balance: a + balance it covers keeps its whole value, however the part rounds. + """ + share_like = np.asarray(household("share_like_capital", period), np.float64) + itemised = add(household, period, COMPONENTS) + listed = np.zeros_like(share_like) + for variable in parameters(period).gov.dwp.share_like_capital.without_sale_expenses: + listed = listed + np.asarray(household(variable, period), np.float64) + with np.errstate(invalid="ignore"): + complement = np.minimum(share_like, np.maximum(0, share_like - listed)) + return np.where(itemised > 0, complement, share_like) From 2d4b7adf94887d5d9c5dd3bca53075c147e5d069 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 19:55:36 -0500 Subject: [PATCH 45/48] Bound ISA balances by an overridden stored part however little it falls short MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review r3 (P2). The fallback in stocks_and_shares_isa_countable_capital switched to the stored part only where it fell more than share_like_capital's float32 spacing short of the holdings behind it, so it could not tell the parts' own rounding from a direct input or a replaced or neutralised formula within that spacing. With share_like_capital of 2**23, a £1 ISA balance and the part that holds the ISAs entered as nil, the holder kept £1 the part did not hold: UC for a holder and a lodger sharing £10,000 of savings came to [£5,000.50, £4,999.50], or [£5,000.45, £4,999.55] with the ISAs off the exempt list, instead of [£5,000, £5,000]. The rounding allowance now applies only where both stored parts equal the split the parts' own formulas give. formula_split recomputes share_like_capital_with_sale_expenses with its own formula from the same share_like_capital, itemised holdings and exempt list, casts it to float32 as the engine stores a formula result, and takes the other part as share_like_capital less it, as that part's formula does. The same float32 operations on the same values give the same result, so the formulas' own split always matches and keeps its rounding allowance exactly as before. Where either stored part differs, the stored part bounds the balances wherever it falls short of the holdings. Values equal to the formulas' split, however supplied, give the formulas' results. The variable's documentation and the ISA assumptions page say so. Adds the reviewer's two witnesses (both routes) and structural variants, replacing either part's formula or neutralising the part, as regressions that fail at 45c48dc2e, and a test that a replacement giving the formulas' values changes nothing while an input of the other part still bounds the balances by the part that holds the ISAs. Co-Authored-By: Claude Opus 5.5 --- .../isa-inputs-and-capital-flows.md | 14 +- .../tests/test_capital_share_components.py | 171 +++++++++++++++++- ...stocks_and_shares_isa_countable_capital.py | 35 +++- .../share_like_capital_with_sale_expenses.py | 57 ++++-- 4 files changed, 247 insertions(+), 30 deletions(-) diff --git a/docs/book/assumptions/isa-inputs-and-capital-flows.md b/docs/book/assumptions/isa-inputs-and-capital-flows.md index 2ec0739099..b0e4ce9eb5 100644 --- a/docs/book/assumptions/isa-inputs-and-capital-flows.md +++ b/docs/book/assumptions/isa-inputs-and-capital-flows.md @@ -151,10 +151,16 @@ rounds the listed holdings' float32 sum and then the subtraction, and could fall below a balance the holdings cover. For a list of two holdings each of these holdings rounds at most once, to float32 (for the float64 complement, unless one amount is more than 2^29 times another), and the parts' formulas -stay within `share_like_capital`'s float32 spacing of them. Where the stored -part falls further short, as a direct input or a reformed formula of either -part can make it, the stored part bounds the balances instead, so the pool -keeps what the part holds. Negative +stay within `share_like_capital`'s float32 spacing of them. The model lets +the balances exceed the stored part by no more than that spacing, and only +where both stored parts equal the split the parts' own formulas give from +`share_like_capital` and the itemised holdings; where that split falls +further short, the stored part bounds the balances. Where a direct input, or +a replaced or neutralised formula of either part, makes either stored part +differ from that split, the stored part bounds the balances wherever it +falls short of the holdings, however little, so the pool keeps what the +part holds. Inputs or formulas that give exactly the formulas' values leave +every result as the formulas give it. Negative holdings beside the ISAs, itemised holdings that sum to nil or less, or a reform can leave these holdings short of the ISAs; the balances then share what the holdings hold. Data that store only household totals hold no diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 562f87db96..779ecb4b25 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -57,6 +57,7 @@ from hypothesis import strategies as st from policyengine_uk import CountryTaxBenefitSystem, Simulation +from policyengine_uk.model_api import Household, Reform, Variable from policyengine_uk.variables.household.wealth.share_like_capital import ( RELATIVE_TOLERANCE, ) @@ -670,16 +671,16 @@ def test_a_balance_the_complement_covers_keeps_its_whole_value(): assert sim.calculate("uc_assessable_capital", YEAR)[0] == uc -def _holder_and_lodger(household): - """A holder with a £5,000 stocks and shares ISA balance and a lodger in - separate working-age benefit units sharing £10,000 of savings, with - ``household``'s inputs on the household. No household ISA total is +def _holder_and_lodger(household, balance=5_000): + """A holder with a stocks and shares ISA balance of ``balance`` and a + lodger in separate working-age benefit units sharing £10,000 of savings, + with ``household``'s inputs on the household. No household ISA total is stored, so stocks_and_shares_isa is the balance.""" return { "people": { "holder": { "age": {YEAR: 30}, - "stocks_and_shares_isa_balance": {YEAR: 5_000}, + "stocks_and_shares_isa_balance": {YEAR: balance}, }, "lodger": {"age": {YEAR: 30}}, }, @@ -735,6 +736,166 @@ def test_a_stored_part_short_of_its_holdings_bounds_the_balances( assert list(sim.calculate("uc_assessable_capital", YEAR)) == uc +def _returning(name, value): + """A structural reform that replaces the formula of the household + variable ``name`` with one giving ``value``.""" + + class replaced(Variable): + label = name + entity = Household + definition_period = "year" + value_type = float + + def formula(household, period, parameters): + return household.filled_array(value) + + replaced.__name__ = name + + class Replace(Reform): + def apply(self): + self.update_variable(replaced) + + return Replace + + +class _NeutraliseWithout(Reform): + def apply(self): + self.neutralize_variable(WITHOUT) + + +class _WithoutByAnotherFormula(Reform): + """Replaces the part without sale expenses' formula with another that + gives the same values: share_like_capital less the other part.""" + + def apply(self): + class share_like_capital_without_sale_expenses(Variable): + label = "share-like capital without expenses of sale" + entity = Household + definition_period = "year" + value_type = float + + def formula(household, period, parameters): + return household("share_like_capital", period) - household(WITH, period) + + self.update_variable(share_like_capital_without_sale_expenses) + + +# share_like_capital of £8,388,608 (2**23), whose float32 spacing is £1, +# beside £8,388,607 of directly held shares or of trusts. +SPACING_SHARES = {"corporate_wealth": 2**23, "directly_held_shares": 2**23 - 1} +SPACING_TRUSTS = {"corporate_wealth": 2**23, "unit_and_investment_trusts": 2**23 - 1} +BASELINE_ROUTE = _uc_lists_without(WITH) +REFORM_ROUTE = {**ISAS_WITH_SALE_EXPENSES, **_uc_lists_without(WITHOUT)} + + +@pytest.mark.parametrize( + "household, reform, part", + [ + ({**SPACING_SHARES, WITHOUT: 0}, BASELINE_ROUTE, WITHOUT), + (SPACING_SHARES, (BASELINE_ROUTE, _returning(WITHOUT, 0)), WITHOUT), + (SPACING_SHARES, (BASELINE_ROUTE, _NeutraliseWithout), WITHOUT), + (SPACING_SHARES, (BASELINE_ROUTE, _returning(WITH, 2**23)), WITHOUT), + ({**SPACING_TRUSTS, WITH: 0}, REFORM_ROUTE, WITH), + (SPACING_TRUSTS, (REFORM_ROUTE, _returning(WITH, 0)), WITH), + ], + ids=[ + "without_entered_as_nil", + "without_replaced_by_nil", + "without_neutralised", + "with_replaced_by_the_total", + "isas_with_sale_expenses_with_entered_as_nil", + "isas_with_sale_expenses_with_replaced_by_nil", + ], +) +def test_an_override_within_rounding_still_bounds_the_balances(household, reform, part): + """Review r3's witnesses, where a direct input or a replaced or + neutralised formula leaves the stored part that holds the ISAs £1 short + of the holdings behind it, within share_like_capital's £1 float32 + spacing. The holder still keeps nothing the part does not hold. + + The holder's balance is £1, and the household has £8,388,608 (2**23) of + corporate_wealth and share_like_capital. Directly held shares of + £8,388,607 leave the listed £1 ISA behind the part without sale + expenses, which is nil: entered as nil, given by a formula replaced to + give nil or neutralised, or left as share_like_capital less a part with + sale expenses replaced to give all £8,388,608. With the ISAs off the + exempt list and trusts of £8,388,607 instead of the shares, the £1 + complement stands behind the part with sale expenses, entered or + replaced as nil. + + The balance holds nil. With the other part off UC's lists, the pool is + the £10,000 of savings, £5,000 for each unit. Bounded by the holdings + alone, the holder kept £1 and the pool netted it from the empty part: + [£5,000.50, £4,999.50], or with the ISAs valued less 10%, [£5,000.45, + £4,999.55].""" + sim = Simulation(situation=_holder_and_lodger(household, balance=1), reform=reform) + assert sim.calculate("share_like_capital", YEAR)[0] == 2**23 + assert sim.calculate(part, YEAR)[0] == 0 + held = sim.calculate("stocks_and_shares_isa_countable_capital", YEAR) + assert list(held) == [0, 0] + assert list(sim.calculate("uc_assessable_capital", YEAR)) == [5_000, 5_000] + + +def test_only_a_split_that_differs_from_the_formulas_loses_the_rounding(): + """A reform that replaces a part's formula with one giving the same + values changes nothing, while an input of the part that does not hold + the ISAs, which leaves the part that does as its formula gives it, + still makes that part bound the balances. + + 1. A sole holder's £100.01 balance in £20,000.01 of corporate_wealth, + as in test_a_balance_its_listed_holdings_cover_keeps_its_whole_value, + with the formula of the part without sale expenses replaced by one + giving share_like_capital less the other part: the split is the + formulas', so the holder keeps the whole balance against the + 100.009765625 part, and UC counts £18,010.01. + 2. The two-name list of + test_a_balance_the_complement_covers_keeps_its_whole_value, where + the £2 part with sale expenses holds the ISAs and £3 of holdings + stand behind it, with the same replacement: the holder keeps all £3, + and with the part without sale expenses off UC's lists, UC counts + £2.70. With that part entered as nil instead, the split differs from + the formulas', so the stored £2 part bounds the balance: the holder + keeps £2, and UC counts 90% of the £2 part less the £2 balance, nil, + plus 90% of the balance: £1.80.""" + rounding = { + "people": { + "holder": { + "age": {YEAR: 30}, + "stocks_and_shares_isa_balance": {YEAR: 100.01}, + } + }, + "benunits": {"holder_unit": {"members": ["holder"]}}, + "households": { + "home": {"members": ["holder"], "corporate_wealth": {YEAR: 20_000.01}} + }, + } + sim = Simulation(situation=rounding, reform=_WithoutByAnotherFormula) + assert sim.calculate(WITHOUT, YEAR)[0] == np.float32(100.009765625) + held = sim.calculate("stocks_and_shares_isa_countable_capital", YEAR) + assert list(held) == [np.float32(100.01)] + uc = sim.calculate("uc_assessable_capital", YEAR) + assert list(uc) == [np.float32(18_010.01)] + + exempt = { + EXEMPT_NODE: {str(YEAR): ["directly_held_shares", "unit_and_investment_trusts"]} + } + lists = {**exempt, **_uc_lists_without(WITHOUT)} + complement = _sole_isa_holders([(16_777_222, 2**24, 3, 3)]) + entered = _sole_isa_holders([(16_777_222, 2**24, 3, 3)]) + entered["households"]["h0"][WITHOUT] = {YEAR: 0.0} + for situation, reform, without, holding, capital in ( + (complement, (lists, _WithoutByAnotherFormula), 16_777_220, 3, 2.7), + (entered, lists, 0, 2, 1.8), + ): + sim = Simulation(situation=situation, reform=reform) + assert sim.calculate(WITH, YEAR)[0] == 2 + assert sim.calculate(WITHOUT, YEAR)[0] == without + held = sim.calculate("stocks_and_shares_isa_countable_capital", YEAR) + assert held[0] == holding + uc = sim.calculate("uc_assessable_capital", YEAR) + assert uc[0] == np.float32(capital) + + def test_the_exempt_list_starts_with_the_first_capital_list(): exempt = system.parameters.gov.dwp.share_like_capital.without_sale_expenses first = min( diff --git a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py index 0dbaac78a3..611533b1ad 100644 --- a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py @@ -4,6 +4,7 @@ household_sources, ) from policyengine_uk.variables.household.wealth.share_like_capital_with_sale_expenses import ( + formula_split, holdings_with_sale_expenses, holdings_without_sale_expenses, ) @@ -45,10 +46,17 @@ class stocks_and_shares_isa_countable_capital(Variable): "so bounding by them keeps the whole of a balance they cover, and the pool " "absorbs the part's " "rounding. While the list names at most two holdings, the parts' formulas " - "stay within share_like_capital's float32 spacing of these holdings. Where " - "the stored part falls further short, as a direct input or a reformed " - "formula of either part can make it, the stored part bounds the balances " - "instead, so the pool keeps what the part holds. " + "stay within share_like_capital's float32 spacing of these holdings. The " + "formula lets the balances exceed the stored part by no more than that " + "spacing, and only where both stored parts equal the split the parts' own " + "formulas give from share_like_capital and the itemised holdings; where " + "that split falls further short, the stored part bounds the balances. " + "Where a direct input, or a replaced or neutralised formula of either part, " + "makes either stored part differ from that split, the stored part bounds " + "the balances wherever it falls short of the holdings, however little, so " + "the balances hold no more than the part and the pool keeps what the part " + "holds. Inputs or formulas that give exactly the formulas' values leave " + "every result as the formulas give it. " "Negative holdings beside the ISAs, itemised holdings that sum to nil or less, " "or a reform can leave these holdings short of the ISAs; the balances then " "share what the holdings hold. When the household's stored " @@ -88,13 +96,22 @@ def formula(person, period, parameters): backing = holdings_with_sale_expenses(household, period, parameters) # The formulas net the balances out of the stored part. While the # list names at most two holdings, the parts' formulas stay within - # share_like_capital's float32 spacing of these holdings. A direct - # input or a reformed formula can leave the stored part further - # short, and the stored part then bounds the balances, so the pool - # keeps what the part holds. + # share_like_capital's float32 spacing of these holdings, and that + # rounding is all the bound lets the balances exceed the stored + # part by. It allows it only where both stored parts are the split + # the parts' own formulas give. Where a direct input or a replaced + # or neutralised formula of either part changes either value, the + # stored part bounds the balances wherever it falls short of the + # holdings, by however little, so the pool keeps what the part + # holds. Where the formulas' own split falls further short, the + # stored part bounds the balances too. stored = household(part, period) with np.errstate(invalid="ignore"): - short = backing - stored > np.spacing(np.abs(share_like)) + short = where( + formula_split(household, period, parameters), + backing - stored > np.spacing(np.abs(share_like)), + stored < backing, + ) backing = where(short, stored, backing) # A missing (NaN) backing leaves the bound unchanged. return bounded_person_holding( diff --git a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py index 081d96e359..6729290eb4 100644 --- a/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -36,18 +36,51 @@ class share_like_capital_with_sale_expenses(Variable): quantity_type = STOCK def formula(household, period, parameters): - share_like = household("share_like_capital", period) - itemised, without = _itemised_and_listed(household, period, parameters) - # share_like_capital is nonnegative wherever the itemised sum is - # positive. Holding this part between nil and that total keeps the - # other part, the difference, between nil and the total too, so - # negative trusts beside positive shares can't push the two parts - # apart. - return where( - itemised > 0, - min_(share_like, max_(0, share_like - without)), - share_like, - ) + return _formula_with_sale_expenses(household, period, parameters) + + +def _formula_with_sale_expenses(household, period, parameters): + """share_like_capital_with_sale_expenses's formula.""" + share_like = household("share_like_capital", period) + itemised, without = _itemised_and_listed(household, period, parameters) + # share_like_capital is nonnegative wherever the itemised sum is + # positive. Holding this part between nil and that total keeps the + # other part, the difference, between nil and the total too, so + # negative trusts beside positive shares can't push the two parts + # apart. + return where( + itemised > 0, + min_(share_like, max_(0, share_like - without)), + share_like, + ) + + +def formula_split(household, period, parameters): + """Whether each household's two stored parts are the split the parts' + own formulas give. + + Recomputes share_like_capital_with_sale_expenses with its own formula, + from the stored share_like_capital and itemised holdings and the law's + exempt list, and stores it as the engine stores a formula result, in + float32; the part without sale expenses is share_like_capital less that, + as its formula subtracts it. The same float32 operations on the same + values give the same result, so where both parts come from these + formulas, the stored parts equal the recomputed ones exactly. A direct + input, or a reform that replaces or neutralises either part's formula, + gives a split that differs from it unless every value agrees, and a + split whose values all agree gives every result the formulas give. A + missing (NaN) part never equals its recomputation. + """ + share_like = household("share_like_capital", period) + with_expenses = np.asarray( + _formula_with_sale_expenses(household, period, parameters), np.float32 + ) + return ( + household("share_like_capital_with_sale_expenses", period) == with_expenses + ) & ( + household("share_like_capital_without_sale_expenses", period) + == share_like - with_expenses + ) def _itemised_and_listed(household, period, parameters): From 84bda06a12743049c97a8c99c20fe93946a679ff Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 19:55:46 -0500 Subject: [PATCH 46/48] Describe the override bound in invariant 10 and the stored-part test Review r3 (P3). Invariant 10 and the docstring of test_a_stored_part_short_of_its_holdings_bounds_the_balances said a directly supplied part falling short of its holdings forces the balances below it, while the code at 45c48dc2e switched to the part only beyond share_like_capital's float32 spacing. With the previous commit the claim holds for any shortfall once either stored part differs from the formulas' split. Invariant 10 now says the balances exceed the stored part only where both parts are the formulas' split, and then by no more than that spacing; that an input or a replaced or neutralised formula making either part differ bounds them by the stored part however little it falls short; and that values equal to the formulas' change no result. The test docstring notes its shortfalls all exceed the spacing and points to the test of those within it. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_capital_share_components.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 779ecb4b25..e88c4227c7 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -44,9 +44,14 @@ balance those holdings cover, for any list of two holdings. Universal Credit counts each part on its lists within rounding of the holdings behind it. -10. Where a direct input leaves the stored part that holds the ISAs short - of the holdings behind it, the balances hold no more than the stored - part, so the pool never counts less than nil of it. +10. The balances hold more than the stored part that holds the ISAs only + where both stored parts equal the split the parts' own formulas give, + and then by no more than share_like_capital's float32 spacing. Where a + direct input, or a replaced or neutralised formula of either part, makes + either stored part differ from that split, the balances hold no more than + the stored part, however little it falls short of the holdings behind + it, so the pool never counts less than nil of it. Inputs or formulas that + give exactly the formulas' values change no result. """ from fractions import Fraction @@ -724,9 +729,12 @@ def _holder_and_lodger(household, balance=5_000): def test_a_stored_part_short_of_its_holdings_bounds_the_balances( household, reform, held, uc ): - """Invariant 10: where a direct input leaves the stored part that holds - the ISAs short of the holdings behind it, the balance holds no more than - the part, so the pool keeps what the part holds.""" + """Invariant 10: where a direct input of either part leaves the stored + part that holds the ISAs short of the holdings behind it, the balance + holds no more than the part, so the pool keeps what the part holds. Each + shortfall here exceeds share_like_capital's float32 spacing; + test_an_override_within_rounding_still_bounds_the_balances covers + shortfalls within it.""" sim = Simulation(situation=_holder_and_lodger(household), reform=reform) part = WITHOUT if reform is None else WITH stored = sim.calculate(part, YEAR)[0] From 74980bdd8ec44390ca4b5f61621e8adf3d6633e1 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 21:33:24 -0500 Subject: [PATCH 47/48] State the ISA override bound only where it holds: nil for parts of nil or less, holdings for NaN Invariant 10, the variable's documentation and formula comment, and the ISA assumptions page said the balances hold no more than the stored part that holds the ISAs, and that the pool never counts less than nil of it. That overstates the guarantee. bounded_holdings floors the bound at nil, so a stored part below nil cannot bound the balances below nil. With the part entered as -1, or given as -20 by the formulas' own split (the verifier's cases), the balances hold nil and the pool counts the negative part as it stands. A missing (NaN) stored part is never the formulas' split and never less than the holdings, so the holdings stay the bound. Each passage now says what the code does: the balances hold no more than the stored part, or nil where it is nil or less, plus at most share_like_capital's float32 spacing where both parts are the formulas' split, and a NaN part leaves the bound at the holdings. The claim that the pool never counts less than nil now covers only overridden parts of nil or more; the stored-part test's docstring says its parts are all nil or more. Text only: no formula, assertion or expected value changes. Co-Authored-By: Claude Opus 5.5 --- .../isa-inputs-and-capital-flows.md | 22 +++++---- .../tests/test_capital_share_components.py | 25 +++++----- ...stocks_and_shares_isa_countable_capital.py | 49 +++++++++++-------- 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/docs/book/assumptions/isa-inputs-and-capital-flows.md b/docs/book/assumptions/isa-inputs-and-capital-flows.md index b0e4ce9eb5..515136f8d2 100644 --- a/docs/book/assumptions/isa-inputs-and-capital-flows.md +++ b/docs/book/assumptions/isa-inputs-and-capital-flows.md @@ -151,16 +151,18 @@ rounds the listed holdings' float32 sum and then the subtraction, and could fall below a balance the holdings cover. For a list of two holdings each of these holdings rounds at most once, to float32 (for the float64 complement, unless one amount is more than 2^29 times another), and the parts' formulas -stay within `share_like_capital`'s float32 spacing of them. The model lets -the balances exceed the stored part by no more than that spacing, and only -where both stored parts equal the split the parts' own formulas give from -`share_like_capital` and the itemised holdings; where that split falls -further short, the stored part bounds the balances. Where a direct input, or -a replaced or neutralised formula of either part, makes either stored part -differ from that split, the stored part bounds the balances wherever it -falls short of the holdings, however little, so the pool keeps what the -part holds. Inputs or formulas that give exactly the formulas' values leave -every result as the formulas give it. Negative +stay within `share_like_capital`'s float32 spacing of them. The balances +hold no more than the stored part, or nil where the part is nil or less, +except that where both stored parts equal the split the parts' own formulas +give from `share_like_capital` and the itemised holdings, the model lets +them hold up to that spacing more; where that split falls further short, the +stored part bounds the balances. Where a direct input, or a replaced or +neutralised formula of either part, makes either stored part differ from +that split, the stored part bounds the balances wherever it falls short of +the holdings, however little, so the pool never counts less than nil of a +stored part of nil or more. A missing (NaN) stored part that holds the ISAs +leaves the bound at the holdings. Inputs or formulas that give exactly the +formulas' values leave every result as the formulas give it. Negative holdings beside the ISAs, itemised holdings that sum to nil or less, or a reform can leave these holdings short of the ISAs; the balances then share what the holdings hold. Data that store only household totals hold no diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index e88c4227c7..06da2e951d 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -44,14 +44,16 @@ balance those holdings cover, for any list of two holdings. Universal Credit counts each part on its lists within rounding of the holdings behind it. -10. The balances hold more than the stored part that holds the ISAs only - where both stored parts equal the split the parts' own formulas give, - and then by no more than share_like_capital's float32 spacing. Where a - direct input, or a replaced or neutralised formula of either part, makes - either stored part differ from that split, the balances hold no more than - the stored part, however little it falls short of the holdings behind - it, so the pool never counts less than nil of it. Inputs or formulas that - give exactly the formulas' values change no result. +10. The balances hold no more than the stored part that holds the ISAs, + or nil where that part is nil or less, except that where both stored + parts equal the split the parts' own formulas give, they may hold up to + share_like_capital's float32 spacing more. Where a direct input, or a + replaced or neutralised formula of either part, makes either stored part + differ from that split, the stored part bounds the balances however + little it falls short of the holdings behind it, so the pool never counts + less than nil of a stored part of nil or more. A missing (NaN) stored + part that holds the ISAs leaves the bound at those holdings. Inputs or + formulas that give exactly the formulas' values change no result. """ from fractions import Fraction @@ -730,9 +732,10 @@ def test_a_stored_part_short_of_its_holdings_bounds_the_balances( household, reform, held, uc ): """Invariant 10: where a direct input of either part leaves the stored - part that holds the ISAs short of the holdings behind it, the balance - holds no more than the part, so the pool keeps what the part holds. Each - shortfall here exceeds share_like_capital's float32 spacing; + part that holds the ISAs, nil or more in each case here, short of the + holdings behind it, the balance holds no more than the part, so the pool + never counts less than nil of it. Each shortfall here exceeds + share_like_capital's float32 spacing; test_an_override_within_rounding_still_bounds_the_balances covers shortfalls within it.""" sim = Simulation(situation=_holder_and_lodger(household), reform=reform) diff --git a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py index 611533b1ad..35b9b21b86 100644 --- a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py @@ -47,16 +47,18 @@ class stocks_and_shares_isa_countable_capital(Variable): "absorbs the part's " "rounding. While the list names at most two holdings, the parts' formulas " "stay within share_like_capital's float32 spacing of these holdings. The " - "formula lets the balances exceed the stored part by no more than that " - "spacing, and only where both stored parts equal the split the parts' own " - "formulas give from share_like_capital and the itemised holdings; where " - "that split falls further short, the stored part bounds the balances. " - "Where a direct input, or a replaced or neutralised formula of either part, " - "makes either stored part differ from that split, the stored part bounds " - "the balances wherever it falls short of the holdings, however little, so " - "the balances hold no more than the part and the pool keeps what the part " - "holds. Inputs or formulas that give exactly the formulas' values leave " - "every result as the formulas give it. " + "balances hold no more than the stored part, or nil where the part is nil " + "or less, except that where both stored parts equal the split the parts' " + "own formulas give from share_like_capital and the itemised holdings, the " + "formula lets them hold up to that spacing more; where that split falls " + "further short, the stored part bounds the balances. Where a direct input, " + "or a replaced or neutralised formula of either part, makes either stored " + "part differ from that split, the stored part bounds the balances wherever " + "it falls short of the holdings, however little, so the pool never counts " + "less than nil of a stored part of nil or more. A missing (NaN) stored part " + "that holds the ISAs leaves the bound at the holdings. Inputs or formulas " + "that give exactly the formulas' values leave every result as the formulas " + "give it. " "Negative holdings beside the ISAs, itemised holdings that sum to nil or less, " "or a reform can leave these holdings short of the ISAs; the balances then " "share what the holdings hold. When the household's stored " @@ -94,17 +96,22 @@ def formula(person, period, parameters): backing = holdings_without_sale_expenses(household, period, parameters) else: backing = holdings_with_sale_expenses(household, period, parameters) - # The formulas net the balances out of the stored part. While the - # list names at most two holdings, the parts' formulas stay within - # share_like_capital's float32 spacing of these holdings, and that - # rounding is all the bound lets the balances exceed the stored - # part by. It allows it only where both stored parts are the split - # the parts' own formulas give. Where a direct input or a replaced - # or neutralised formula of either part changes either value, the - # stored part bounds the balances wherever it falls short of the - # holdings, by however little, so the pool keeps what the part - # holds. Where the formulas' own split falls further short, the - # stored part bounds the balances too. + # The formulas net the balances out of the stored part. The bound + # holds the balances to no more than the stored part, or nil where + # the part is nil or less, as bounded_holdings floors a negative + # bound at nil. While the list names at most two holdings, the + # parts' formulas stay within share_like_capital's float32 spacing + # of these holdings, and that rounding is all the bound lets the + # balances exceed that by. It allows it only where both stored + # parts are the split the parts' own formulas give. Where a direct + # input or a replaced or neutralised formula of either part changes + # either value, the stored part bounds the balances wherever it + # falls short of the holdings, by however little, so the pool never + # counts less than nil of a stored part of nil or more. Where the + # formulas' own split falls further short, the stored part bounds + # the balances too. A missing (NaN) stored part is never the + # formulas' split and never less than the holdings, so it leaves + # the bound at the holdings. stored = household(part, period) with np.errstate(invalid="ignore"): short = where( From 0f35157f9bdd909e05ab63ee9d999ee8f3f8c55b Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 22:32:58 -0500 Subject: [PATCH 48/48] Qualify the ISA stored-part bound text for missing aggregates Review r4 found that invariant 10, the variable documentation and comment, and the ISA assumptions page state the stored-part bound without exception. Where stocks_and_shares_isa or share_like_capital is missing (NaN), household_total and so the overall bound are NaN, the comparisons are false, and bounded_holdings leaves finite balances of nil or more unchanged, so a balance can exceed the stored part. Each passage now limits the guarantees to the case where none of the bound's three amounts is missing, and says what happens otherwise. The text also said a missing stored part "leaves the bound at the holdings". That is true of the holdings term only: the bound is still the smallest of stocks_and_shares_isa, share_like_capital and the holdings. It now says the missing part never replaces the holdings as a bound, and the code comment says "overall bound" where it means the final one. Text only: no executable line, assertion or expected value changes. Co-Authored-By: Claude Opus 5.5 --- .../isa-inputs-and-capital-flows.md | 26 +++++---- .../tests/test_capital_share_components.py | 25 ++++---- ...stocks_and_shares_isa_countable_capital.py | 57 +++++++++++-------- 3 files changed, 63 insertions(+), 45 deletions(-) diff --git a/docs/book/assumptions/isa-inputs-and-capital-flows.md b/docs/book/assumptions/isa-inputs-and-capital-flows.md index 515136f8d2..4e20e15bc1 100644 --- a/docs/book/assumptions/isa-inputs-and-capital-flows.md +++ b/docs/book/assumptions/isa-inputs-and-capital-flows.md @@ -151,17 +151,21 @@ rounds the listed holdings' float32 sum and then the subtraction, and could fall below a balance the holdings cover. For a list of two holdings each of these holdings rounds at most once, to float32 (for the float64 complement, unless one amount is more than 2^29 times another), and the parts' formulas -stay within `share_like_capital`'s float32 spacing of them. The balances -hold no more than the stored part, or nil where the part is nil or less, -except that where both stored parts equal the split the parts' own formulas -give from `share_like_capital` and the itemised holdings, the model lets -them hold up to that spacing more; where that split falls further short, the -stored part bounds the balances. Where a direct input, or a replaced or -neutralised formula of either part, makes either stored part differ from -that split, the stored part bounds the balances wherever it falls short of -the holdings, however little, so the pool never counts less than nil of a -stored part of nil or more. A missing (NaN) stored part that holds the ISAs -leaves the bound at the holdings. Inputs or formulas that give exactly the +stay within `share_like_capital`'s float32 spacing of them. Where none of +`stocks_and_shares_isa`, `share_like_capital` and these holdings is missing +(NaN), the balances hold no more than the stored part, or nil where the part +is nil or less, except that where both stored parts equal the split the +parts' own formulas give from `share_like_capital` and the itemised +holdings, the model lets them hold up to that spacing more; where that split +falls further short, the stored part bounds the balances. With all three +present, where a direct input, or a replaced or neutralised formula of +either part, makes either stored part differ from that split, the stored +part bounds the balances wherever it falls short of the holdings, however +little, so the pool never counts less than nil of a stored part of nil or +more. A missing (NaN) stored part that holds the ISAs never replaces the +holdings as a bound on the balances. A missing `stocks_and_shares_isa` or +`share_like_capital` makes the overall bound missing, so finite balances of +nil or more pass through unchanged. Inputs or formulas that give exactly the formulas' values leave every result as the formulas give it. Negative holdings beside the ISAs, itemised holdings that sum to nil or less, or a reform can leave these holdings short of the ISAs; the balances then share diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 06da2e951d..66c485f513 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -44,16 +44,21 @@ balance those holdings cover, for any list of two holdings. Universal Credit counts each part on its lists within rounding of the holdings behind it. -10. The balances hold no more than the stored part that holds the ISAs, - or nil where that part is nil or less, except that where both stored - parts equal the split the parts' own formulas give, they may hold up to - share_like_capital's float32 spacing more. Where a direct input, or a - replaced or neutralised formula of either part, makes either stored part - differ from that split, the stored part bounds the balances however - little it falls short of the holdings behind it, so the pool never counts - less than nil of a stored part of nil or more. A missing (NaN) stored - part that holds the ISAs leaves the bound at those holdings. Inputs or - formulas that give exactly the formulas' values change no result. +10. Where none of stocks_and_shares_isa, share_like_capital and the + holdings behind the part that holds the ISAs is missing (NaN), the + balances hold no more than that stored part, or nil where it is nil or + less, except that where both stored parts equal the split the parts' own + formulas give, they may hold up to share_like_capital's float32 spacing + more. With all three present, where a direct input, or a replaced or + neutralised formula of either part, makes either stored part differ from + that split, the stored part bounds the balances however little it falls + short of the holdings behind it, so the pool never counts less than nil + of a stored part of nil or more. A missing (NaN) stored part that holds + the ISAs never replaces those holdings as a bound on the balances. A + missing stocks_and_shares_isa or share_like_capital makes the overall + bound missing, so finite balances of nil or more pass through unchanged. + Inputs or formulas that give exactly the formulas' values change no + result. """ from fractions import Fraction diff --git a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py index 35b9b21b86..515cb25a65 100644 --- a/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py +++ b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py @@ -46,19 +46,23 @@ class stocks_and_shares_isa_countable_capital(Variable): "so bounding by them keeps the whole of a balance they cover, and the pool " "absorbs the part's " "rounding. While the list names at most two holdings, the parts' formulas " - "stay within share_like_capital's float32 spacing of these holdings. The " - "balances hold no more than the stored part, or nil where the part is nil " - "or less, except that where both stored parts equal the split the parts' " - "own formulas give from share_like_capital and the itemised holdings, the " - "formula lets them hold up to that spacing more; where that split falls " - "further short, the stored part bounds the balances. Where a direct input, " - "or a replaced or neutralised formula of either part, makes either stored " - "part differ from that split, the stored part bounds the balances wherever " - "it falls short of the holdings, however little, so the pool never counts " - "less than nil of a stored part of nil or more. A missing (NaN) stored part " - "that holds the ISAs leaves the bound at the holdings. Inputs or formulas " - "that give exactly the formulas' values leave every result as the formulas " - "give it. " + "stay within share_like_capital's float32 spacing of these holdings. Where " + "none of stocks_and_shares_isa, share_like_capital and these holdings is " + "missing (NaN), the balances hold no more than the stored part, or nil " + "where the part is nil or less, except that where both stored parts equal " + "the split the parts' own formulas give from share_like_capital and the " + "itemised holdings, the formula lets them hold up to that spacing more; " + "where that split falls further short, the stored part bounds the " + "balances. With all three present, where a direct input, or a replaced or " + "neutralised formula of either part, makes either stored part differ from " + "that split, the stored part bounds the balances wherever it falls short " + "of the holdings, however little, so the pool never counts less than nil " + "of a stored part of nil or more. A missing (NaN) stored part that holds " + "the ISAs never replaces the holdings as a bound on the balances. A " + "missing stocks_and_shares_isa or share_like_capital makes the overall " + "bound missing, so finite balances of nil or more pass through unchanged. " + "Inputs or formulas that give exactly the formulas' values leave every " + "result as the formulas give it. " "Negative holdings beside the ISAs, itemised holdings that sum to nil or less, " "or a reform can leave these holdings short of the ISAs; the balances then " "share what the holdings hold. When the household's stored " @@ -96,22 +100,27 @@ def formula(person, period, parameters): backing = holdings_without_sale_expenses(household, period, parameters) else: backing = holdings_with_sale_expenses(household, period, parameters) - # The formulas net the balances out of the stored part. The bound - # holds the balances to no more than the stored part, or nil where - # the part is nil or less, as bounded_holdings floors a negative - # bound at nil. While the list names at most two holdings, the - # parts' formulas stay within share_like_capital's float32 spacing - # of these holdings, and that rounding is all the bound lets the - # balances exceed that by. It allows it only where both stored - # parts are the split the parts' own formulas give. Where a direct + # The formulas net the balances out of the stored part. Where none + # of stocks_and_shares_isa, share_like_capital and the backing is + # missing (NaN), the overall bound holds the balances to no more + # than the stored part, or nil where the part is nil or less, as + # bounded_holdings floors a negative overall bound at nil. While the + # list names at most two holdings, the parts' formulas stay within + # share_like_capital's float32 spacing of these holdings, and that + # rounding is all the overall bound lets the balances exceed that + # by. It allows it only where both stored parts are the split the + # parts' own formulas give. With all three present, where a direct # input or a replaced or neutralised formula of either part changes # either value, the stored part bounds the balances wherever it # falls short of the holdings, by however little, so the pool never # counts less than nil of a stored part of nil or more. Where the # formulas' own split falls further short, the stored part bounds # the balances too. A missing (NaN) stored part is never the - # formulas' split and never less than the holdings, so it leaves - # the bound at the holdings. + # formulas' split and never less than the holdings, so the backing + # stays the holdings. A missing stocks_and_shares_isa or + # share_like_capital makes household_total, and so the overall + # bound, missing, and bounded_holdings then leaves finite balances + # of nil or more unchanged. stored = household(part, period) with np.errstate(invalid="ignore"): short = where( @@ -120,7 +129,7 @@ def formula(person, period, parameters): stored < backing, ) backing = where(short, stored, backing) - # A missing (NaN) backing leaves the bound unchanged. + # A missing (NaN) backing drops out of the overall bound. return bounded_person_holding( person, person("stocks_and_shares_isa_balance", period),