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..c47b4c7870 --- /dev/null +++ b/changelog.d/sale-expense-share-split.fixed.md @@ -0,0 +1 @@ +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/changelog.d/uc-capital-sale-expenses.fixed.md b/changelog.d/uc-capital-sale-expenses.fixed.md new file mode 100644 index 0000000000..102b57f784 --- /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 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/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 diff --git a/docs/book/assumptions/isa-inputs-and-capital-flows.md b/docs/book/assumptions/isa-inputs-and-capital-flows.md index c6e0836479..4e20e15bc1 100644 --- a/docs/book/assumptions/isa-inputs-and-capital-flows.md +++ b/docs/book/assumptions/isa-inputs-and-capital-flows.md @@ -109,26 +109,72 @@ 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` -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 +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 +`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 +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 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. 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 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 +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. +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 +192,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 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. 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/data/uprating_indices.yaml b/policyengine_uk/data/uprating_indices.yaml index 28c4e25851..a99ddb28c2 100644 --- a/policyengine_uk/data/uprating_indices.yaml +++ b/policyengine_uk/data/uprating_indices.yaml @@ -137,6 +137,7 @@ gov.economic_assumptions.yoy_growth.obr.per_capita.gdp: # Non-residential purchase prices and land retain GDP-per-capita growth. - non_residential_property_purchased - owned_land +- owned_land_secured_debt # A formula of benunit_reported_capital; listed so a dataset that stores it # directly is uprated like the input. - pension_credit_reported_capital diff --git a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/person_sources.yaml b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/person_sources.yaml index b3c563348f..ba64a22c41 100644 --- a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/person_sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/person_sources.yaml @@ -14,7 +14,8 @@ description: > investments, and the named child owns a junior ISA's investments (Individual Savings Account Regulations 1998 reg. 4(6)(a) and reg. 2B(c)). The formulas subtract each bounded ISA balance from its household source (`cash_isa`, - `share_like_capital`) and count it in the holder's unit. When a household's + `share_like_capital_without_sale_expenses`) and count it in the holder's + unit. When a household's balances exceed its total, the model scales them to sum to the total exactly, rounding each share down or up to a whole float32 step of the total. When a reform removes a household source from `sources`, the formulas 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/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..e360c3ff9a --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/rate.yaml @@ -0,0 +1,18 @@ +description: > + 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: + 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 + - 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 new file mode 100644 index 0000000000..1ef23e854e --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sale_expenses/sources.yaml @@ -0,0 +1,44 @@ +description: > + Capital sources whose sale would incur expenses, so that income-related ESA + 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). `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 (which then still + folds in unit trusts, ISAs and, on datasets built before private pension + wealth was split out, non-defined-benefit pension wealth). 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 + unit: list + 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, 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. 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 + - 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 8665590684..9d29f74739 100644 --- a/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/ESA/income/capital/sources.yaml @@ -3,7 +3,8 @@ description: > at their cash value, without a generic cash sale-cost deduction. Where the data tie a cash ISA or stocks and shares ISA balance to a member, the formulas count it through `person_sources` in the holder's own benefit - unit and subtract it from `cash_isa` or `share_like_capital` before they + unit and subtract it from `cash_isa` or + `share_like_capital_without_sale_expenses` before they allocate the rest. Model variables currently mapped to countable income-related Employment and Support Allowance capital. The Employment and Support Allowance Regulations @@ -12,7 +13,9 @@ 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 they exceed it beyond float32 rounding (see `share_like_capital`), so a household given only the components has them @@ -45,6 +48,7 @@ values: - savings - cash_isa - 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/person_sources.yaml b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/person_sources.yaml index fdbd6f8d02..254d365c13 100644 --- a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/person_sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/person_sources.yaml @@ -15,7 +15,8 @@ description: > child owns a junior ISA's investments (Individual Savings Account Regulations 1998 reg. 4(6)(a) and reg. 2B(c)). The formulas subtract each bounded ISA balance from its household source (`cash_isa`, - `share_like_capital`) and count it in the holder's unit. When a household's + `share_like_capital_without_sale_expenses`) and count it in the holder's + unit. When a household's balances exceed its total, the model scales them to sum to the total exactly, rounding each share down or up to a whole float32 step of the total. When a reform removes a household source from `sources`, the formulas 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/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..e67f83c653 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/rate.yaml @@ -0,0 +1,21 @@ +description: > + 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: + 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 + - 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 new file mode 100644 index 0000000000..7db3f2fd1b --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sale_expenses/sources.yaml @@ -0,0 +1,42 @@ +description: > + Capital sources whose sale would incur expenses, so that income-based JSA + 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). `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 (which then still + folds in unit trusts, ISAs and, on datasets built before private pension + wealth was split out, non-defined-benefit pension wealth). 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 + unit: list + 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, 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. 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 + - 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 d30ee0a503..28f7d3ee60 100644 --- a/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/JSA/income/capital/sources.yaml @@ -3,7 +3,8 @@ description: > at their cash value, without a generic cash sale-cost deduction. Where the data tie a cash ISA or stocks and shares ISA balance to a member, the formulas count it through `person_sources` in the holder's own benefit - unit and subtract it from `cash_isa` or `share_like_capital` before they + unit and subtract it from `cash_isa` or + `share_like_capital_without_sale_expenses` before they allocate the rest. Model variables currently mapped to countable income-based Jobseeker's Allowance capital. The Jobseeker's Allowance Regulations 1996 treat capital @@ -12,7 +13,9 @@ 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 they exceed it beyond float32 rounding (see `share_like_capital`), so a household given only the components has them @@ -45,6 +48,7 @@ values: - savings - cash_isa - 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/person_sources.yaml b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/person_sources.yaml index 9a019c1541..557055ba2c 100644 --- a/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/person_sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/person_sources.yaml @@ -17,7 +17,8 @@ description: > child owns a junior ISA's investments (Individual Savings Account Regulations 1998 reg. 4(6)(a) and reg. 2B(c)). In the ordinary calculation, the formula subtracts each bounded ISA balance from its household source - (`cash_isa`, `share_like_capital`) and counts it in the holder's unit. For a + (`cash_isa`, `share_like_capital_without_sale_expenses`) and counts it in the holder's + unit. For a family on a passporting benefit, or at pension age on a guarantee credit, the formula returns zero capital, and for a savings-credit-only award it uses the Pension Credit capital assessment. When a household's balances 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/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..45b58092df --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/rate.yaml @@ -0,0 +1,27 @@ +description: > + Share of the current market or surrender value deducted from Housing Benefit + 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: + 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 + - 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 new file mode 100644 index 0000000000..b55b9f2552 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/housing_benefit/means_test/capital/sale_expenses/sources.yaml @@ -0,0 +1,58 @@ +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 (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 + 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 (which then still + folds in unit trusts, ISAs and, on datasets built before private pension + wealth was split out, non-defined-benefit pension wealth). 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 + 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: 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, 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 + 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 + href: https://assets.publishing.service.gov.uk/media/5a7ec5d840f0b6230268b71f/hbgm-bp1-assessment-of-capital.pdf#page=83 +values: + 2006-04-10: + - owned_land + - other_residential_property_value + - non_residential_property_value + - 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 bd01c601ac..beaa8e9e17 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 @@ -3,7 +3,8 @@ description: > at their cash value, without a generic cash sale-cost deduction. Where the data tie a cash ISA or stocks and shares ISA balance to a member, the formulas count it through `person_sources` in the holder's own benefit - unit and subtract it from `cash_isa` or `share_like_capital` before they + unit and subtract it from `cash_isa` or + `share_like_capital_without_sale_expenses` before they allocate the rest. Model variables currently mapped to countable Housing Benefit capital. The Housing Benefit Regulations 2006 treat the whole of a claimant's capital as @@ -11,7 +12,9 @@ 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 they exceed it beyond float32 rounding (see `share_like_capital`), so a household given @@ -53,6 +56,7 @@ values: - savings - cash_isa - 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/person_sources.yaml b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/person_sources.yaml index 2fad42f98d..f3310ceef8 100644 --- a/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/person_sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/person_sources.yaml @@ -15,7 +15,8 @@ description: > investments, and the named child owns a junior ISA's investments (Individual Savings Account Regulations 1998 reg. 4(6)(a) and reg. 2B(c)). The formulas subtract each bounded ISA balance from its household source (`cash_isa`, - `share_like_capital`) and count it in the holder's unit. When a household's + `share_like_capital_without_sale_expenses`) and count it in the holder's + unit. When a household's balances exceed its total, the model scales them to sum to the total exactly, rounding each share down or up to a whole float32 step of the total. When a reform removes a household source from `sources`, the formulas 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/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..dd572337df --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/rate.yaml @@ -0,0 +1,20 @@ +description: > + Share of the current market or surrender value deducted from Income Support + 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: + 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 + - 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 new file mode 100644 index 0000000000..fb14e6420c --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/income_support/means_test/capital/sale_expenses/sources.yaml @@ -0,0 +1,42 @@ +description: > + Capital sources whose sale would incur expenses, so that Income Support + 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). `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 (which then still + folds in unit trusts, ISAs and, on datasets built before private pension + wealth was split out, non-defined-benefit pension wealth). 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 + unit: list + 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, 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. 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 + - 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 e4ea10e98b..4e8f8766f1 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,13 +3,16 @@ description: > at their cash value, without a generic cash sale-cost deduction. Where the data tie a cash ISA or stocks and shares ISA balance to a member, the formulas count it through `person_sources` in the holder's own benefit - unit and subtract it from `cash_isa` or `share_like_capital` before they + unit and subtract it from `cash_isa` or + `share_like_capital_without_sale_expenses` before they allocate the rest. Capital sources included in the Income Support capital test. `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 they exceed it beyond float32 rounding (see `share_like_capital`), so a household given only the components has them @@ -34,6 +37,7 @@ values: - savings - cash_isa - 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/person_sources.yaml b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/person_sources.yaml index 194718020a..e62e156da8 100644 --- a/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/person_sources.yaml +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/person_sources.yaml @@ -16,7 +16,8 @@ description: > child owns a junior ISA's investments (Individual Savings Account Regulations 1998 reg. 4(6)(a) and reg. 2B(c)). The formula subtracts each bounded ISA balance from its household source (`cash_isa`, - `share_like_capital`) and counts it in the holder's unit. A nonnegative + `share_like_capital_without_sale_expenses`) and counts it in the holder's + unit. A nonnegative `pension_credit_reported_capital` replaces that unit's calculated capital. When a household's balances exceed its total, the model scales them to sum to the total exactly, rounding each share down or up to a whole float32 step 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/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..09c5550767 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/rate.yaml @@ -0,0 +1,20 @@ +description: > + Share of the current market or surrender value deducted from Pension 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. 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: + 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 + - 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 new file mode 100644 index 0000000000..ade6847f6e --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/pension_credit/income/capital/sale_expenses/sources.yaml @@ -0,0 +1,44 @@ +description: > + Capital sources whose sale would incur expenses, so that Pension Credit + 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). `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 (which then still + folds in unit trusts, ISAs and, on datasets built before private pension + wealth was split out, non-defined-benefit pension wealth). 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 + unit: list + 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-84715 + 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, 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 + - 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 6c5a9bd5ca..931d710012 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 @@ -3,7 +3,8 @@ description: > at their cash value, without a generic cash sale-cost deduction. Where the data tie a cash ISA or stocks and shares ISA balance to a member, the formulas count it through `person_sources` in the holder's own benefit - unit and subtract it from `cash_isa` or `share_like_capital` before they + unit and subtract it from `cash_isa` or + `share_like_capital_without_sale_expenses` before they allocate the rest. PolicyEngine approximation of Pension Credit capital sources that count toward deemed income from capital, excluding the claimant's main home. @@ -11,8 +12,11 @@ description: > (Part I) disregard the value of the right to receive income from an occupational or personal pension scheme or under a retirement annuity contract; the notional income rule for undrawn money purchase pots - (regulation 18) is not modelled. `share_like_capital` is `corporate_wealth` - as supplied, or the sum of its itemised components (`directly_held_shares`, + (regulation 18) is not modelled. + `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 they exceed it beyond float32 rounding (see `share_like_capital`), so a household given only the components has them counted and no holding counts twice. @@ -36,4 +40,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..ae1b5ca5c1 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/share_like_capital/without_sale_expenses.yaml @@ -0,0 +1,35 @@ +description: > + 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 + 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 (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 records as one total, so share options also take + the deduction, an approximation. +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: + 1996-10-07: + - unit_and_investment_trusts + - stocks_and_shares_isa diff --git a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/property_sale_cost_rate.yaml b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/property_sale_cost_rate.yaml deleted file mode 100644 index 9cd29f27b4..0000000000 --- a/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/property_sale_cost_rate.yaml +++ /dev/null @@ -1,14 +0,0 @@ -description: > - Proportion deducted from current property market value where sale entails - expenses, before subtracting secured encumbrances (regulation 49). Broad - household property inputs are assumed to incur sale expenses. Cash financial - proxies do not receive this deduction. -values: - 2013-04-29: 0.1 -metadata: - label: Universal Credit property sale expense deduction - unit: /1 - period: year - reference: - - title: The Universal Credit Regulations 2013 reg. 49(1) - href: https://www.legislation.gov.uk/uksi/2013/376/regulation/49/1 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/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..394de65fac --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/rate.yaml @@ -0,0 +1,21 @@ +description: > + Share of the current market or surrender value deducted from Universal + 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. It applies to the countable + property in property_sources (other residential and non-residential + property, assumed to have costs of sale) and to the financial sources listed + in sale_expenses.sources. +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: 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 new file mode 100644 index 0000000000..5797b232a5 --- /dev/null +++ b/policyengine_uk/parameters/gov/dwp/universal_credit/means_test/capital/sale_expenses/sources.yaml @@ -0,0 +1,38 @@ +description: > + Universal Credit financial capital sources (capital.sources) whose sale + would incur expenses, so that they are valued at 90% of market value. + `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 the costs of selling them (ADM H1665), and all of `corporate_wealth` + on datasets that do not itemise it (which then still folds in unit trusts, + ISAs and, on datasets built before private pension wealth was split out, + non-defined-benefit pension wealth). 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. `savings` is not listed: the 10% applies + where selling normally needs an agent, broker, solicitor or accountant + (H1604-H1605), the costs of withdrawing money are not costs of sale (H1607), + and an account is valued at its balance (H1675). Countable property is + valued through property_sources with the same rate, and real property always + has costs of sale (H1606). +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: 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, 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: + - 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 a7a116c5f3..0b0484033c 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 @@ -3,37 +3,40 @@ description: > at their cash value, without a generic cash sale-cost deduction. Where the data tie a cash ISA or stocks and shares ISA balance to a member, the formulas count it through `person_sources` in the holder's own benefit - unit and subtract it from `cash_isa` or `share_like_capital` before they + unit and subtract it from `cash_isa` or + `share_like_capital_without_sale_expenses` before they allocate the rest. Household financial proxies for Universal Credit: savings and share-like - financial wealth. `share_like_capital` is `corporate_wealth` as supplied, or - the sum of its itemised components (`directly_held_shares`, - `unit_and_investment_trusts`, `stocks_and_shares_isa`) where they exceed it - beyond float32 rounding, so a household given only the components has them - counted and no holding counts twice. A nonnegative benunit_reported_capital - replaces these financial proxies and covered person-level sources, including - a Lifetime ISA. Each benefit unit's complete uc_reported_capital override, - otherwise its observed financial total, reduces this financial pool. - Subtracting complete overrides retains the inherited allocation convention. - An override precedes regulation 77 company substitution and includes its - claimant's and partner's holdings: consume at least their disregarded - holdings after applying one household share_like_capital budget without - removing them again from the pool. First clip each person's holding to [0, - max(0, share_like_capital)], with positive infinity mapped to the upper - bound and negative infinity to zero. If total bounded holdings exceed - nonnegative share_like_capital, scale each person's bounded holding - proportionally before override floors and separate pool deductions. This is - a defensive rule for inconsistent inputs, not a statutory determination; - regulation 77 substitution in the owner's own assessment is unchanged. The - residual is allocated by claimant/partner counts to benefit units with - neither a financial observation nor a complete override, including units - that do not receive UC. This allocation is an assumption about unobserved - ownership, not a statutory rule. Countable property is valued and shared - independently through property_sources across ALL claimant/partner adults, - with complete-override units consuming their shares. Main-home property and - the named private_pension_wealth input are excluded under Schedule 10 - paragraphs 1 and 10. For missing-report households, the legacy - corporate_wealth proxy, and so share_like_capital, can still contain non-DB + financial wealth, in two parts: `share_like_capital_with_sale_expenses` + (directly held shares, and all of an unitemised `corporate_wealth`) and + `share_like_capital_without_sale_expenses` (unit and investment trusts and + stocks and shares ISAs). Together they are `share_like_capital`: + `corporate_wealth` as supplied, or the sum of its itemised components + (`directly_held_shares`, `unit_and_investment_trusts`, + `stocks_and_shares_isa`) where they exceed it beyond float32 rounding. A + nonnegative benunit_reported_capital replaces these financial proxies and + covered person-level sources, including a Lifetime ISA. Each benefit unit's + complete uc_reported_capital override, otherwise its observed financial + total, reduces this financial pool. Subtracting complete overrides retains + the inherited allocation convention. An override precedes regulation 77 + company substitution and includes its claimant's and partner's holdings: + consume at least their disregarded holdings after applying one household + share-like capital budget without removing them again from the pool. First + clip each person's holding to [0, max(0, the part with sale expenses)], with + positive infinity mapped to the upper bound and negative infinity to zero. + If total bounded holdings exceed that nonnegative budget, scale each + person's bounded holding proportionally before override floors and separate + pool deductions. This is a defensive rule for inconsistent inputs, not a + statutory determination; regulation 77 substitution in the owner's own + assessment is unchanged. The residual is allocated by claimant/partner + counts to benefit units with neither a financial observation nor a complete + override, including units that do not receive UC. This allocation is an + assumption about unobserved ownership, not a statutory rule. Countable + property is valued and shared independently through property_sources across + ALL claimant/partner adults, with complete-override units consuming their + shares. Main-home property and the named private_pension_wealth input are + excluded under Schedule 10 paragraphs 1 and 10. For missing-report + households, the legacy corporate_wealth proxy can still contain non-DB pension wealth that is not separately identified and removed. Asset-specific Schedule 10 disregards within these broad financial classes are not separately observed. @@ -52,4 +55,5 @@ values: 2013-04-29: - savings - cash_isa - - share_like_capital + - share_like_capital_with_sale_expenses + - share_like_capital_without_sale_expenses diff --git a/policyengine_uk/parameters/gov/local_authorities/council_tax_reduction/capital/sale_expenses/rate.yaml b/policyengine_uk/parameters/gov/local_authorities/council_tax_reduction/capital/sale_expenses/rate.yaml index 692911d156..de2f6e2484 100644 --- a/policyengine_uk/parameters/gov/local_authorities/council_tax_reduction/capital/sale_expenses/rate.yaml +++ b/policyengine_uk/parameters/gov/local_authorities/council_tax_reduction/capital/sale_expenses/rate.yaml @@ -4,8 +4,8 @@ description: > a flat 10% whatever the actual costs, taken from the market value before any encumbrance secured on the asset is deducted (DMG 29624). The encumbrance is then deducted where an asset-specific secured-debt input - exists (other residential and non-residential property); those inputs - default to nil because the survey does not record them. + exists (land, other residential property and non-residential property); + those inputs default to nil because the survey does not record them. values: 2013-04-01: 0.1 metadata: 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 93cff38dce..a5da7a25a8 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 @@ -20,7 +20,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 @@ -231,4 +233,6 @@ corporate_wealth: 2_000 private_pension_wealth: 150_000 output: - esa_income_assessable_capital: 3_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/housing_benefit/housing_benefit_capital.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/housing_benefit/housing_benefit_capital.yaml index d6eee69d34..5c10a19a8d 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 claimant and partner 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 7173dd1ede..9043a46422 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 @@ -22,7 +22,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 @@ -231,4 +233,6 @@ corporate_wealth: 2000 private_pension_wealth: 150000 output: - income_support_assessable_capital: 3000 + # 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 024036709e..aec8eaf01f 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; 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/finance/benefit/family/universal_credit/company/uc_company_analogous_business.yaml b/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/company/uc_company_analogous_business.yaml index be74f2340d..aad23c70e5 100644 --- a/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/company/uc_company_analogous_business.yaml +++ b/policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/company/uc_company_analogous_business.yaml @@ -242,7 +242,9 @@ uc_mif_applies: [false] uc_company_capital: [0] uc_company_holding_disregard: [0] - uc_assessable_capital: 25_000 + # Outside reg. 77 the holding is ordinary shares, valued at 90% for the + # expenses of sale (reg. 49(1)(a)). + uc_assessable_capital: 22_500 - name: An investor in a company with many shareholders is not treated as its owner # H4364: such a shareholder has no influence over the running of the @@ -270,7 +272,8 @@ output: uc_company_owner_treatment_applies: [false] uc_individual_earned_income: [0] - uc_assessable_capital: 12_000 + # Ordinary shares, valued at 90% for the expenses of sale (reg. 49(1)(a)). + uc_assessable_capital: 10_800 - name: A company carrying on neither a trade nor a property business is outside the rule # Reg. 77(1) needs a company "carrying on a trade or a property business". @@ -292,7 +295,8 @@ corporate_wealth: 10_000 output: uc_company_owner_treatment_applies: [false] - uc_assessable_capital: 10_000 + # Ordinary shares, valued at 90% for the expenses of sale (reg. 49(1)(a)). + uc_assessable_capital: 9_000 - name: Each partner's company is attributed to the couple's capital # Joint claimants' capital is combined against one limit (Welfare Reform @@ -483,7 +487,9 @@ savings: 10_000 corporate_wealth: 30_000 output: - household_uc_pool_company_holdings: 30_000 + # The 30,000 holding leaves the pool at the 90% at which corporate_wealth + # is counted (reg. 49(1)(a)). + household_uc_pool_company_holdings: 27_000 uc_assessable_capital: [5_000, 5_000] - name: A benunit that reports its capital has its own holding taken off what it reports @@ -507,7 +513,10 @@ household: members: person output: - uc_assessable_capital: 35_000 + # The complete override is a countable figure, so the holding inside it + # is counted at 90% (reg. 49(1)(a)) and comes off at that value: + # 50,000 - 27,000 + 15,000 of company capital. + uc_assessable_capital: 38_000 - name: A dependant's company earnings are not the claimant's earned income # Reg. 22(1)(b) deducts "the claimant's earned income (or, in the case of @@ -647,5 +656,7 @@ savings: 8_000 corporate_wealth: 12_000 output: - household_uc_pool_company_holdings: 12_000 + # The 12,000 holding leaves the pool at the 90% at which corporate_wealth + # is counted (reg. 49(1)(a)). + household_uc_pool_company_holdings: 10_800 uc_assessable_capital: [0, 8_000] 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 efa082474e..c1b2ab85ae 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 @@ -297,7 +297,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/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 new file mode 100644 index 0000000000..32701e2a25 --- /dev/null +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation.yaml @@ -0,0 +1,644 @@ +# 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. 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 + 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 + +- 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 + +- name: UC rounds the share valuation to the nearest 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 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: + 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, 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] + +- 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 + +- 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 + +- 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 + +- name: Every means test counts a cash ISA and savings at face value and a mortgaged second home less sale expenses and the mortgage + period: 2026 + absolute_error_margin: 0 + input: + people: + person: + age: 70 + cash_isa_balance: 4_000 + benunits: + benunit: + members: person + would_claim_uc: false + would_claim_IS: false + in_receipt_of_guarantee_credit: false + in_receipt_of_savings_credit_only: false + housing_benefit_on_passporting_benefit: false + households: + household: + members: person + savings: 3_000 + other_residential_property_value: 100_000 + other_residential_property_secured_debt: 60_000 + output: + # The formulas move the 4,000 cash ISA out of the household's cash_isa + # into its holder's own benefit unit at face value, count the 3,000 of + # savings at face value, and value the second home at 100,000 less 10% + # (10,000) less the 60,000 mortgage: 3,000 + 4,000 + 30,000 = 37,000. + cash_isa: 4_000 + cash_isa_countable_capital: 4_000 + uc_assessable_capital: 37_000 + housing_benefit_assessable_capital: 37_000 + income_support_assessable_capital: 37_000 + jsa_income_assessable_capital: 37_000 + esa_income_assessable_capital: 37_000 + pension_credit_assessable_capital: 37_000 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..d99438122f --- /dev/null +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/capital_valuation_share_split.yaml @@ -0,0 +1,262 @@ +# corporate_wealth itemised into directly_held_shares, unit_and_investment_trusts +# 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 +# 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 (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 + 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: + 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. + 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: + share_like_capital_with_sale_expenses: 4_000 + 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: + 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 part not itemised 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: + 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 + +- 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: + 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 + +- 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: + 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 + 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/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 6b32d58624..d0b49c7cf7 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 @@ -65,10 +65,11 @@ - name: Case 4, rent from a let property is not Pension Credit income; the property counts through deemed income. # SPC Regs 2002 Sch IV para 18 disregards any actual income from capital, so - # the £10,476 of rent does not count. Deemed income (reg 15(6)): capital - # 55,825 - 10,000 = 45,825, ceil(45,825 / 500) = 92, so £92 a week, 4,784 a - # year. Guarantee credit = (238 - 92) x 52 = 7,592. Savings credit is nil, as - # qualifying income (£92 a week) is below the savings credit threshold. + # the £10,476 of rent does not count. Capital: 455 + 90% of 55,370 (reg. + # 19(a)) = 50,288. Deemed income (reg 15(6)): 50,288 - 10,000 = 40,288, + # ceil(40,288 / 500) = 81, so £81 a week, 4,212 a year. Guarantee credit = + # (238 - 81) x 52 = 8,164. Savings credit is nil, as qualifying income (£81 a + # week) falls below the savings credit threshold. period: 2026 absolute_error_margin: 0.01 input: @@ -85,12 +86,12 @@ other_residential_property_value: 55_370 savings: 455 output: - pension_credit_assessable_capital: 55_825 - pension_credit_deemed_income: 4_784 - pension_credit_income: 4_784 - guarantee_credit: 7_592 + pension_credit_assessable_capital: 50_288 + pension_credit_deemed_income: 4_212 + pension_credit_income: 4_212 + guarantee_credit: 8_164 savings_credit: 0 - pension_credit: 7_592 + pension_credit: 8_164 - name: Case 5, 2026 Pension Credit uses tariff income with the published guarantee rate. period: 2026 @@ -110,12 +111,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/policy/baseline/gov/dwp/person_isa_capital.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/person_isa_capital.yaml index 2b88881ea0..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 @@ -8,7 +8,16 @@ # reg 88(2); ESA reg 83(2)). The formula subtracts the identified ISA balances # 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. +# a unit on the IS, JSA or ESA claim path. Each programme values the pool's +# 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 (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 @@ -70,7 +79,7 @@ # 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. + # the 6,000 ISA at face value. uc_assessable_capital: [6_000, 9_000] housing_benefit_assessable_capital: [6_000, 9_000] @@ -101,10 +110,11 @@ output: share_like_capital: 9_000 # The formula subtracts the child's 6,000 ISA from corporate wealth - # 9,000 and allocates the remaining 3,000: 2,000 to the parents and 1,000 - # to the child's unit. - uc_assessable_capital: [2_000, 7_000] - housing_benefit_assessable_capital: [2_000, 7_000] + # 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 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 @@ -180,6 +190,8 @@ members: [parent, adult_child] savings: 2_000 output: + # The parent's claiming unit takes the 2,000 of savings; the child's unit + # 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. @@ -209,7 +221,7 @@ # 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 and 2,000. + # 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. @@ -268,7 +280,8 @@ output: # 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 and 3,000. + # 2,000 to the lodger, and the couple's unit adds their 4,000 cash ISA + # 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] @@ -368,7 +381,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 @@ -378,13 +391,15 @@ household: members: [tenant, lodger] output: - # Pooling this ISA would give each claimant 17,000, above reg 18's - # 16,000 limit. The formula attributes it to its holder. - uc_assessable_capital: [0, 34_000] + # 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. +# 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. @@ -398,7 +413,7 @@ cash_isa_balance: 16_790 stocks_holder: age: 30 - stocks_and_shares_isa_balance: 16_790 + stocks_and_shares_isa_balance: 18_567 benunits: cash_unit: members: cash_holder @@ -566,6 +581,7 @@ share_like_capital: 100 output: stocks_and_shares_isa_countable_capital: 100 + # 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. 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 95951f1d60..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 @@ -121,5 +121,160 @@ output: household_uc_reported_financial_capital: 10_000 household_uc_pool_company_holdings: 0 - uc_assessable_capital: [0, 20_000] + # corporate_wealth is valued at 90% (reg. 49(1)(a)), and the holding + # inside the countable override comes off at that value: the owner keeps + # 10,000 - 9,000 = 1,000, and the pool is 20,000 + 9,000 - 10,000 = + # 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] + +- 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/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_capital_valuation.yaml b/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_capital_valuation.yaml new file mode 100644 index 0000000000..bdfb816174 --- /dev/null +++ b/policyengine_uk/tests/policy/baseline/gov/local_authorities/council_tax_reduction/council_tax_reduction_capital_valuation.yaml @@ -0,0 +1,29 @@ +# Outside the Pension Credit, Universal Credit and passported routes, each +# scheme calculates capital at its current market or surrender value less, +# where there would be expenses attributable to the sale, 10 per cent, and +# less the amount of any encumbrance secured on it (SI 2012/2885 Sch 1 para +# 32; SI 2012/2886 Sch para 65; WSI 2013/3029 Sch 1 para 26 and Sch 6 para +# 28; SSI 2012/319 reg 42; SSI 2012/303 reg 46; SSI 2021/249 reg 70(1)). +# Expected values are worked by hand from those provisions. + +- name: The household route values mortgaged land less sale expenses and the mortgage + period: 2026 + absolute_error_margin: 0 + input: + people: + applicant: + age: 40 + benunits: + benunit: + members: applicant + would_claim_uc: false + households: + household: + members: applicant + country: ENGLAND + local_authority: MAIDSTONE + # 50,000 less 10% (5,000) less the 20,000 secured on it = 25,000. + owned_land: 50_000 + owned_land_secured_debt: 20_000 + output: + council_tax_reduction_assessable_capital: 25_000 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 c83d3ed49a..52cc7e13fe 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 @@ -474,12 +474,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 savings and the second property @@ -673,20 +677,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 diff --git a/policyengine_uk/tests/shard_durations.toml b/policyengine_uk/tests/shard_durations.toml index a3849e47dc..09c8dd3996 100644 --- a/policyengine_uk/tests/shard_durations.toml +++ b/policyengine_uk/tests/shard_durations.toml @@ -14,7 +14,7 @@ # the others. The last shard runs the tests that need the dataset, so this # table leaves them out: regenerate it from the other shards' logs. [seconds] -"policyengine_uk/tests/test_capital_share_components.py::test_capital_matches_the_original_lists" = 1951 +"policyengine_uk/tests/test_capital_share_components.py::test_unitemised_inputs_match_the_lists_before_itemising" = 1951 "policyengine_uk/tests/test_mixed_age_couple_properties.py::test_mixed_age_couple_invariants" = 1044 "policyengine_uk/tests/test_dated_reform_routes.py::test_routes_agree_on_start_stop_keys" = 668 "policyengine_uk/tests/test_pension_tax_allowance_properties.py::test_the_full_new_state_pension_pays_no_income_tax_at_any_rate" = 549 @@ -154,7 +154,7 @@ "policyengine_uk/tests/test_dfe_childcare_student_support_properties.py::test_tax_free_childcare_work_condition_matches_reg_13" = 151 "policyengine_uk/tests/test_salary_sacrifice_ni_measure_properties.py::test_measures_equal_the_difference_of_complete_liabilities[full-year Category A directors]" = 151 "policyengine_uk/tests/test_uc_claimant_income_properties.py::test_member_order_does_not_matter" = 151 -"policyengine_uk/tests/test_capital_share_components.py::test_share_like_capital_keeps_the_supplied_aggregate" = 150 +"policyengine_uk/tests/test_capital_share_components.py::test_share_like_capital_and_its_parts" = 150 "policyengine_uk/tests/test_housing_benefit_specified_accommodation_disregard_properties.py::test_no_para_18_amount_without_the_input" = 150 "policyengine_uk/tests/test_income_support_eligibility_properties.py::test_excluded_member_never_changes_is_eligibility" = 150 "policyengine_uk/tests/test_income_support_eligibility_properties.py::test_is_eligibility_matches_a_family_by_family_reading" = 150 @@ -399,7 +399,7 @@ "policyengine_uk/tests/test_pension_annual_allowance_properties.py::test_unused_allowance_reduces_chargeable_amount_one_for_one" = 84 "policyengine_uk/tests/test_property_transaction_tax_purchase_properties.py::test_additional_purchase_is_charged_on_its_own_price" = 84 "policyengine_uk/tests/test_trading_loss_properties.py::test_zero_profit_trade_loss_cannot_raise_tax_or_reduce_programme_award[housing_benefit-2024]" = 84 -"policyengine_uk/tests/test_capital_share_components.py::test_float32_rounding_at_the_limit_keeps_eligibility" = 83 +"policyengine_uk/tests/test_capital_share_components.py::test_float32_rounding_at_the_limit_keeps_the_aggregate" = 83 "policyengine_uk/tests/test_energy_bills_rebate_council_tax_reduction_properties.py::test_a_larger_reduction_never_lowers_the_payment" = 83 "policyengine_uk/tests/test_housing_benefit_savings_credit_only_properties.py::test_net_income_does_not_fall_where_savings_credit_ends" = 83 "policyengine_uk/tests/test_cares_for_severely_disabled_person_properties.py::test_input_false_without_a_reported_award_pays_no_carer_benefit" = 82 diff --git a/policyengine_uk/tests/test_capital_share_components.py b/policyengine_uk/tests/test_capital_share_components.py index 608aa1e94d..66c485f513 100644 --- a/policyengine_uk/tests/test_capital_share_components.py +++ b/policyengine_uk/tests/test_capital_share_components.py @@ -1,25 +1,75 @@ -"""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 are positive and exceed it by more than the - float32 rounding tolerance, in which case it is exactly their sum. -2. Differential: for identical inputs that carry no components, or components - consistent with corporate_wealth, every programme's assessable capital, and - UC eligibility, equal those under the original lists (corporate_wealth), - exactly, annually and monthly. -3. A household given only the components has them counted, down to a penny. -4. A disregarded company holding (UC reg 77(2)) is budgeted against, and - leaves the UC financial pool from, share_like_capital, whether it was - entered within corporate_wealth or as an itemised component. + unless the itemised components exceed it beyond the rounding tolerance, in + which case it is their sum. +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. +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. +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. 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, 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%. +9. A person's stocks and shares ISA balance holds no more than the holdings + 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 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 + import numpy as np import pytest -from hypothesis import HealthCheck, given, settings +from hypothesis import HealthCheck, example, given, settings 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, ) @@ -29,13 +79,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( @@ -58,16 +113,20 @@ def _parameter(path): return _node(path)(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: {f"{YEAR}-01-01.{YEAR + 4}-12-31": 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") } # Pounds and pence, as a dataset stores them in float64; the engine rounds @@ -78,11 +137,10 @@ def _parameter(path): ) -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}"], @@ -91,121 +149,856 @@ 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): - # A projected year as well, where the inputs are uprated. - for period in (YEAR, f"{YEAR}-01", YEAR + 1, f"{YEAR + 1}-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) - # Where a programme lists the sources whose sale incurs expenses, it names - # the same share-like variable, or shares would silently lose the - # deduction. - node = _node(SOURCE_LISTS[variable].rsplit(".", 1)[0]) - if "sale_expenses" in node.children: - sale = list(node.sale_expenses.sources(f"{YEAR}-01-01")) - assert not {"corporate_wealth", *COMPONENTS} & set(sale) +@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) + # 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"} @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, ) ) -def test_share_like_capital_keeps_the_supplied_aggregate(rows): +# 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)]) +# 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: 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(0) - for component in COMPONENTS: - itemised = np.float32(itemised + np.float32(assets.get(component, 0))) + values = [np.float32(assets.get(c, 0)) for c in COMPONENTS] + # 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 itemised > 0 and itemised - cw > tolerance: - assert value == itemised # exactly the components' sum + assert share_like == itemised else: - assert value == cw # exactly the supplied aggregate + assert share_like == cw + if itemised <= 0: + assert got[WITH][i] == share_like and got[WITHOUT][i] == 0 + else: + 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 -@SETTINGS -@given( - st.lists( - st.tuples(money, signed_money, st.tuples(money, money, money), st.booleans()), - 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_float32_grouping_of_the_exempt_holdings(): + """Trusts and ISA summed first: corporate_wealth of £399,999.984375 and + £200,000 + £199,999.984375 of exempt holdings both round to £400,000 in + float32, so the part with sale expenses is nil; subtracting the two one at + a time would leave £0.015625.""" + 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_float32_rounding_at_the_limit_keeps_eligibility(): - """Components whose float32 sum overshoots £16,000 by a fraction of a penny.""" +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 = [ { - "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, + "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): []}} + 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]) + + +# 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_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 + 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: 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].""" + 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] + + +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) +] + + +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 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; + - 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. + """ + 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,)): + 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], 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) + 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] + else: + behind = {WITHOUT: Fraction(0), WITH: total} + 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 + 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 + # 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 + ), (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_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, 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: balance}, + }, + "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 of either part leaves the stored + 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) + 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 _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( + min(entry.instant_str for entry in _node(f"{node}.sources").values_list) + for node in NODES.values() + ) + assert first == "1996-10-07" + assert min(entry.instant_str for entry in exempt.values_list) == first + + +@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 +@given( + st.lists(st.tuples(money, signed_money), min_size=1, max_size=30), +) +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": 15_999.99, "corporate_wealth": 0.01}, + {"savings": 0, "corporate_wealth": 17_777.78}, # 90% is £16,000.002 ] - _assert_same_as_original(households) - assert _results(households)["share_like_capital"][0] == 16_000 + # A projected year as well, where the inputs are uprated. + for period in (YEAR, f"{YEAR}-01", YEAR + 1, f"{YEAR + 1}-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_one_unit_of_float32_rounding_above_a_power_of_two_keeps_the_aggregate(): - """Pence-valued components whose float32 sum lands one unit in the last place - (£0.00195) above £16,384.01: more than 1e-7 of the value, less than 1e-6.""" +@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_384.01, - "directly_held_shares": 16_015.98, - "unit_and_investment_trusts": 286.98, - "stocks_and_shares_isa": 81.05, + "savings": savings, + "corporate_wealth": float(sum(components)), + **dict(zip(COMPONENTS, components)), } + for savings, components in rows ] - itemised = np.float32( - np.float32(np.float32(16_015.98) + np.float32(286.98)) + np.float32(81.05) - ) - assert itemised - np.float32(16_384.01) == np.float32(0.001953125) - assert _results(households)["share_like_capital"][0] == np.float32(16_384.01) - _assert_same_as_original(households) + 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) + # Uprated separately in float32, the components still round to their + # aggregate in a projected year, so share-like capital is the aggregate. + sim = Simulation(situation=_situation(households, age=30)) + for year in (YEAR, YEAR + 1): + assert np.array_equal( + sim.calculate("share_like_capital", year), + sim.calculate("corporate_wealth", year), + ), year + + +def test_components_alone_are_valued_by_type(): + households = [ + { + "savings": 1_000, + "directly_held_shares": 4_000, + "unit_and_investment_trusts": 3_000, + "stocks_and_shares_isa": 5_000, + } + ] + got = _results(households, age=30) + assert got["share_like_capital"][0] == 12_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) def test_a_component_penny_at_the_limit_counts(): @@ -213,10 +1006,10 @@ def test_a_component_penny_at_the_limit_counts(): as_component = [{"savings": 16_000, "directly_held_shares": 0.01}] as_aggregate = [{"savings": 16_000, "corporate_wealth": 0.01}] for period in (YEAR, f"{YEAR}-01"): - component = _results(as_component, period=period) - aggregate = _results(as_aggregate, period=period) + component = _results(as_component, period=period, age=30) + aggregate = _results(as_aggregate, period=period, age=30) assert component["share_like_capital"][0] == np.float32(0.01) - for variable in (*SOURCE_LISTS, "is_uc_eligible"): + for variable in (*NODES, "is_uc_eligible"): assert np.array_equal(component[variable], aggregate[variable]), variable assert not component["is_uc_eligible"][0] @@ -233,29 +1026,63 @@ def test_a_genuine_excess_over_the_aggregate_counts(): assert _results(households)["share_like_capital"][0] == np.float32(16_000.10) -def test_components_alone_are_counted(): +def test_float32_rounding_at_the_limit_keeps_the_aggregate(): + """Components whose float32 sum overshoots £16,000 by a fraction of a + penny keep the aggregate; an unitemised penny at the limit counts as + before itemising.""" + split = [ + { + "corporate_wealth": 16_000, + "directly_held_shares": 6_744.81, + "unit_and_investment_trusts": 6_581.24, + "stocks_and_shares_isa": 2_673.95, + } + ] + itemised = np.float32( + np.float32(np.float32(6_744.81) + np.float32(6_581.24)) + np.float32(2_673.95) + ) + assert itemised > np.float32(16_000) + assert _results(split)["share_like_capital"][0] == 16_000 + unitemised = [ + {"savings": 15_999.99, "corporate_wealth": 0.01}, + {"savings": 6_001, "corporate_wealth": -2}, + ] + for period in (YEAR, f"{YEAR}-01"): + new = _results(unitemised, period=period) + old = _results(unitemised, reform=UNITEMISED_REFORM, period=period) + for variable in (*NODES, "is_uc_eligible"): + assert np.array_equal(new[variable], old[variable]), (variable, period) + + +def test_one_unit_of_float32_rounding_above_a_power_of_two_keeps_the_aggregate(): + """Pence-valued components whose float32 sum lands one unit in the last place + (£0.00195) above £16,384.01: more than 1e-7 of the value, less than 1e-6.""" households = [ { - "savings": 1_000, - "directly_held_shares": 4_000, - "unit_and_investment_trusts": 3_000, - "stocks_and_shares_isa": 5_000, + "corporate_wealth": 16_384.01, + "directly_held_shares": 16_015.98, + "unit_and_investment_trusts": 286.98, + "stocks_and_shares_isa": 81.05, } ] - got = _results(households) - assert got["share_like_capital"][0] == 12_000 - assert got["uc_assessable_capital"][0] == 13_000 + itemised = np.float32( + np.float32(np.float32(16_015.98) + np.float32(286.98)) + np.float32(81.05) + ) + assert itemised - np.float32(16_384.01) == np.float32(0.001953125) + assert _results(households)["share_like_capital"][0] == np.float32(16_384.01) -def test_a_disregarded_company_holding_leaves_the_capital_that_counts_it(): - """UC reg 77(2): a holding entered as an itemised component leaves the - pool as one entered within corporate_wealth does. Two unreported adults - share £10,000 of savings once the owner's £30,000 holding is disregarded.""" +def test_a_disregarded_company_holding_leaves_the_part_with_sale_expenses(): + """UC reg 77(2): the owner's £30,000 holding leaves the pool at the 90% its + shares are counted at, whether it was entered within corporate_wealth or + as directly held shares. Two unreported adults share £10,000 of savings.""" from policyengine_uk.variables.gov.dwp.universal_credit.household_uc_company_holding_pool_scale import ( HOLDINGS_SOURCE, ) - assert HOLDINGS_SOURCE in _parameter(SOURCE_LISTS["uc_assessable_capital"]) + node = NODES["uc_assessable_capital"] + assert HOLDINGS_SOURCE in _parameter(f"{node}.sources") + assert HOLDINGS_SOURCE in _parameter(f"{node}.sale_expenses.sources") for shares in ({"corporate_wealth": 30_000}, {"directly_held_shares": 30_000}): situation = { "people": { @@ -281,5 +1108,155 @@ def test_a_disregarded_company_holding_leaves_the_capital_that_counts_it(): } sim = Simulation(situation=situation) assert sim.calculate("household_uc_company_holding_pool_scale", YEAR)[0] == 1 - assert sim.calculate("household_uc_pool_company_holdings", YEAR)[0] == 30_000 + # 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] + + +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, + "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)]) +# 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, 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}"] = { + "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 + tolerance = 0.01 + float(np.spacing(np.float32(expected))) + assert abs(float(values[i]) - expected) <= tolerance, ( + variable, + rows[i], + values[i], + ) 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..6ea388515d --- /dev/null +++ b/policyengine_uk/tests/test_capital_valuation_properties.py @@ -0,0 +1,647 @@ +"""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). 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). 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: + +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 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 + 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 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. Pennies: 90% of any whole-penny value stored as a float32 input is the + 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. + 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% 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 +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, + 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; 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", + "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"} +# The assets whose sale incurs expenses, fixed here from the law rather than +# 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", + "share_like_capital_with_sale_expenses", +} +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 in share_like_capital's two parts. These +# households hold share-like wealth only as unitemised corporate_wealth, so +# all of it is in the part with expenses of sale and none is without. +INPUT_OF = {"share_like_capital_with_sale_expenses": "corporate_wealth"} +NIL_SOURCES = {"share_like_capital_without_sale_expenses"} + + +def asset(unit, source): + if source in NIL_SOURCES: + return 0.0 + return unit["assets"][INPUT_OF.get(source, source)] + + +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} | { + 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 + # 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}"], + "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()}, + **{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), + ) + 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 + + +def parameter_node(sim, path): + return reduce(getattr, path.split("."), sim.tax_benefit_system.parameters(YEAR)) + + +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) + + +def expected_capital(unit, node, variable=None): + """Reg. 49(1) applied source by source, independently of the model.""" + total = 0.0 + if variable == "uc_assessable_capital": + # Universal Credit values countable property on its own path + # (property_sources), outside the financial sources. + for source in [ + "other_residential_property_value", + "non_residential_property_value", + ]: + total += max( + 0.0, + asset(unit, source) * (1 - LEGAL_RATE) - unit["debts"][DEBTS[source]], + ) + for source in node.sources: + value = asset(unit, source) + 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 + return total + + +def close(a, b): + return abs(a - b) <= 1 + 1e-6 * abs(b) + + +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 + assert "savings" in node.sources + counted = set(node.sources) + # Every name on the sale-expense list must be a counted source: + # 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), + ) + 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 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, variable) + 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( + asset(unit, s) * (1 - LEGAL_RATE * (s in SALE_EXPENSE_ASSETS)) + for s in node.sources + 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 +@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, + valued["guarantee_credit"][i], + valued["hb_passported"][i], + ): + cash = sum(unit["assets"][asset] for asset in CASH_ASSETS) + assert close(valued[variable][i], cash), variable + + +@PROPERTY_SETTINGS +@given( + st.lists(households(), min_size=20, max_size=200), + 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 + + +@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; 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) + # 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(): + # 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, 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. 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 + # 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 + + +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, age) in enumerate(rows): + people[f"p{i}"] = { + "age": {YEAR: age}, + "lifetime_isa_balance": {YEAR: lisa / 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, 1_500_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. 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, 24, 30), + (0, 0, 100_004, 30), + (1_599_981, 0, 26, 30), + (1_524_977, 0, 100_030, 30), + ] + * 3 +) +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, 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 = 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, ( + variable, + rows[i], + 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 + + +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_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 + # 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/tests/test_isa_balances.py b/policyengine_uk/tests/test_isa_balances.py index a38b6cc2f4..ea107a4011 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. +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 import pytest -from policyengine_uk import Microsimulation +from policyengine_uk import Microsimulation, Simulation from policyengine_uk.data.dataset_schema import UKSingleYearDataset @@ -59,10 +61,18 @@ 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, 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 (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) + 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] - assert capital == pytest.approx(6_000.0 * growth, rel=1e-5) + expected = (1_000.0 + 3_000.0 + 2_000.0) * growth + assert capital == pytest.approx(expected, rel=1e-5) def test_household_totals_sum_the_person_balances_in_every_year(): @@ -85,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) 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 61c0fe3d0a..346cf198e9 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. The strategy for this property always gives the other unit someone over State Pension age, nothing recorded and household capital, @@ -116,7 +118,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) diff --git a/policyengine_uk/tests/test_person_isa_capital.py b/policyengine_uk/tests/test_person_isa_capital.py index 9b105fd5b4..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 @@ -17,9 +17,15 @@ plus the ISAs of members no unit counts (dependants, and for Pension 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. 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. + shares and each programme's penny rounding. Each programme values + 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. @@ -63,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") @@ -80,7 +86,14 @@ "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", +) BALANCE = { "cash_isa_countable_capital": "cash_isa_balance", "stocks_and_shares_isa_countable_capital": "stocks_and_shares_isa_balance", @@ -392,11 +405,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), shared by three + # 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]) == [8_000, 4_000] + 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(): @@ -430,12 +444,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. @@ -486,10 +503,20 @@ def test_both_forms_in_one_dataset_add_up_to_the_stored_total(): ] -def _household_capital(simulation, year): - return sum( - simulation.calculate(name, year) - for name in ("savings", "cash_isa", "share_like_capital") +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_like ) @@ -515,28 +542,30 @@ 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) + 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 make the first pool, 3,000 for - # each claimant, and each unit adds its members' 5,000 and 6,000 of ISAs. - # The second pool, savings 12,000 and 3,000 of trusts, gives the parents - # 10,000 and their son 5,000 in UC, and the pension-age parents all - # 15,000 in Pension Credit. - expected_uc = [11_000, 9_000, 14_000, 11_000] - assert list(simulation.calculate("uc_assessable_capital", YEAR)) == expected_uc + # 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 + ) for name in CAPITAL: if name != "pension_credit_assessable_capital": capital = simulation.calculate(name, YEAR) - assert list(capital[:2]) == expected_uc[:2], name - assert list(simulation.calculate("pension_credit_assessable_capital", YEAR)) == [ - 0, - 0, - 19_000, - 0, - ] + 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, 19_000, 0], abs=0.001) # One benefit unit each, with a child: the adults' cash and stocks and shares @@ -714,11 +743,28 @@ def _check_counted_isas(simulation): return counted -def _holdings(simulation): - return sum( - simulation.calculate(name, YEAR) - for name in ("savings", "cash_isa", "share_like_capital") - ) +def _share_counted(variable, source): + """The share of household ``source``'s market value ``variable`` counts. + + 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 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: the share +# it counts of the household source that holds it. +def _isa_shares(variable): + return {source: _share_counted(variable, HELD_IN[source]) for source in ISA_SOURCES} + + +def _holdings(simulation, variable=None): + return _household_capital(simulation, YEAR, variable) @SITUATION_SETTINGS @@ -732,7 +778,6 @@ def test_a_pound_counts_once_in_working_age_means_tests(units, holdings): simulation = Simulation(situation=_situation(units, assets)) counted = _check_counted_isas(simulation) dependants = ~simulation.calculate("is_claimant_or_partner", YEAR) - uncounted = sum((amount * dependants).sum() for amount in counted.values()) for name in ( "uc_assessable_capital", "housing_benefit_assessable_capital", @@ -740,15 +785,23 @@ def test_a_pound_counts_once_in_working_age_means_tests(units, holdings): "jsa_income_assessable_capital", "esa_income_assessable_capital", ): + weights = _isa_shares(name) + uncounted = sum( + (weights[source] * amount * dependants).sum() + for source, amount in counted.items() + ) capital = simulation.calculate(name, YEAR) - # Float32 shares of the remainder round to within a few pence. + # 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)[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( - simulation.map_result(amount * ~dependants, "person", "benunit", how="sum") - for amount in counted.values() + simulation.map_result( + weights[source] * amount * ~dependants, "person", "benunit", how="sum" + ) + for source, amount in counted.items() ) assert (capital >= own * (1 - 1e-6) - 0.01).all(), name @@ -857,22 +910,27 @@ def test_a_pound_counts_once_in_pension_credit(households): > 0 ) counts = simulation.calculate("is_claimant_or_partner", YEAR) & in_pension_unit + weights = _isa_shares("pension_credit_assessable_capital") uncounted = sum( - _by_household(simulation, "person", amount * ~counts) - for amount in counted.values() + _by_household(simulation, "person", weights[source] * amount * ~counts) + for source, amount in counted.items() ) capital = simulation.calculate("pension_credit_assessable_capital", YEAR) - # Float32 shares of the remainder round to within a few pence. + # 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), 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 # pool keeps savings of 1,000 and the 4,500 of share_like_capital - # beyond its 2,000 of ISAs: 2,750 for each pension-age adult. - own = sum(counted.values()) + # beyond its 2,000 of ISAs, which Pension Credit values less 10% at + # 4,050: 2,525 for each pension-age adult. + own = sum(weights[source] * amount for source, amount in counted.items()) assert list(capital[-3:]) == pytest.approx( - [2_750 + own[-3], 2_750 + own[-2], 0], rel=1e-6 + [2_525 + own[-3], 2_525 + own[-2], 0], rel=1e-6, abs=0.01 ) @@ -1027,22 +1085,26 @@ 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, 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 4,000 stocks and shares ISA. 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, 5_000]), - ("share_like_capital", [1_000, 11_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 and the ISAs, 16,000 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") == [8_000, 8_000] assert capital("housing_benefit_assessable_capital") == [1_000, 15_000] @@ -1061,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/tests/test_savings_credit_only_receipt_properties.py b/policyengine_uk/tests/test_savings_credit_only_receipt_properties.py index 7197148782..f075c56cc0 100644 --- a/policyengine_uk/tests/test_savings_credit_only_receipt_properties.py +++ b/policyengine_uk/tests/test_savings_credit_only_receipt_properties.py @@ -185,7 +185,13 @@ def family(ages, **overrides): # recipient; and a working-age family. KNOWN_FAMILIES = [ family([90], state_pension=12_480.0), - family([90], state_pension=12_480.0, savings=12_000.0, other_property=4_400.0), + family( + [90], + state_pension=12_480.0, + savings=12_000.0, + other_property=4_400.0, + shares=500.0, + ), family([90], state_pension=12_480.0, savings=12_000.0, rent=6_000.0), family([90], state_pension=12_480.0, would_claim_pc=False), family([70], state_pension=9_000.0), @@ -234,6 +240,7 @@ def situation(units, would_claim_pc=None): "council_tax": {YEAR: unit["council_tax"]}, "savings": {YEAR: unit["savings"]}, "other_residential_property_value": {YEAR: unit["other_property"]}, + "corporate_wealth": {YEAR: unit.get("shares", 0.0)}, } return {"people": people, "benunits": benunits, "households": households} @@ -394,11 +401,13 @@ 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 16,400 (savings 12,000 and property 4,400) against the - # 16,000 limit and gets no council tax reduction, where the scheme's - # own rules count the property less 10% for the expenses of sale, - # 12,000 + 3,960 = 15,960, and give 2,000. The tenant has no Housing - # Benefit tariff income, where + # tested on 16,410 (savings 12,000, property 4,400 less 10% for the + # expenses of sale, 3,960, and shares 500 less 10%, 450; SPC Regs 2002 + # reg. 19(a)) against the 16,000 limit and gets no council tax + # reduction, where the scheme's own household route counts the + # savings and the property less 10%, 12,000 + 3,960 = 15,960, leaves + # out shares (council tax reduction capital sources), and gives 2,000. + # The tenant has no Housing Benefit tariff income, where # Housing Benefit's own rules count 4 a week on savings of 12,000 # (208). Its Housing Benefit income is the same on both routes: with # no savings credit paid, the Pension Credit assessment is the State @@ -411,7 +420,7 @@ def test_known_families_detect_main(): "housing_benefit_tariff_income", ] capital = "council_tax_reduction_assessable_capital" - assert main[capital][OWNER_WITH_CAPITAL] == 16_400 + assert main[capital][OWNER_WITH_CAPITAL] == 16_410 assert fix[capital][OWNER_WITH_CAPITAL] == 15_960 reduction = "simulated_council_tax_reduction_benunit" assert main[reduction][OWNER_WITH_CAPITAL] == 0 @@ -421,7 +430,7 @@ def test_known_families_detect_main(): assert assessed_differently(fix, not_claiming, known) == [] -def single_pensioner(savings=0.0, other_property=0.0): +def single_pensioner(savings=0.0, other_property=0.0, shares=0.0): # Single, aged 90, State Pension 12,480 (240 a week), owning in Maidstone # with council tax of 2,000. return { @@ -441,6 +450,7 @@ def single_pensioner(savings=0.0, other_property=0.0): "council_tax": {YEAR: 2_000}, "savings": {YEAR: savings}, "other_residential_property_value": {YEAR: other_property}, + "corporate_wealth": {YEAR: shares}, } }, } @@ -501,24 +511,28 @@ def read(simulation, variable): def test_stopping_pension_credit_payments_ends_the_pension_credit_capital_test(): - # Savings of 12,000 and other property worth 4,400. The Pension Credit - # assessment of capital counts both (16,400), 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 of 500, over 10,000: 6,400 / - # 500 = 12.8, so 13 a week (SPC Regs 2002 reg 15(6)). Income is 240.00 + + # Savings of 12,000, other property worth 4,400 and shares worth 500. The + # Pension Credit assessment of capital counts all three, the property and + # the shares less 10% for the expenses of sale (SPC Regs 2002 reg. 19(a)): + # 12,000 + 3,960 + 450 = 16,410, 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 of 500, over 10,000: 6,410 / + # 500 = 12.82, so 13 a week (SPC Regs 2002 reg 15(6)). Income is 240.00 + # 13.00 = 253.00 a week, so the savings credit is 0.6 x (238.00 - 208.07) # - 0.4 x (253.00 - 238.00) = 17.958 - 6.00 = 11.958 a week (621.82). - data = single_pensioner(savings=12_000.0, other_property=4_400.0) + data = single_pensioner(savings=12_000.0, other_property=4_400.0, shares=500.0) unreformed = Simulation(situation=data) 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] == 16_400 + assert unreformed.calculate(capital, YEAR)[0] == 16_410 assert unreformed.calculate("council_tax_reduction", YEAR)[0] == 0 # With Pension Credit not paid the scheme's own capital rule applies: the # savings and the property less 10% for the expenses of sale (SI # 2012/2885 Sch 1 para 32(a)), 12,000 + 3,960 = 15,960, within the limit. + # The household route leaves the shares out (council tax reduction + # capital sources). # Tariff income is 1 a week for each 500, or part of 500, over 10,000 # (Sch 1 para 37): 5,960 / 500 = 11.92, so 12 a week, 624 a year. Income # 12,480 + 624 = 13,104 is below the applicable amount of 256.00 a week diff --git a/policyengine_uk/tests/test_stock_capital_periods.py b/policyengine_uk/tests/test_stock_capital_periods.py index 3ad2e0226f..92d4d82100 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,7 +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("uc_assessable_capital", "2026-01")[0] == 34_800 + 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, 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] @@ -43,7 +51,46 @@ 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 ) + + +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 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 + 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/tests/test_stored_household_totals.py b/policyengine_uk/tests/test_stored_household_totals.py index 1088176bda..265999eaf3 100644 --- a/policyengine_uk/tests/test_stored_household_totals.py +++ b/policyengine_uk/tests/test_stored_household_totals.py @@ -216,10 +216,21 @@ 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, + # each at its value. A decision maker values an ISA at what its holder + # 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. + 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) + face_value = savings[year][0] + cash_isa[year][0] + shares_isa[year][0] + 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) @pytest.mark.parametrize( diff --git a/policyengine_uk/tests/test_uc_company_override_properties.py b/policyengine_uk/tests/test_uc_company_override_properties.py index 735847e6b8..1fac837bf1 100644 --- a/policyengine_uk/tests/test_uc_company_override_properties.py +++ b/policyengine_uk/tests/test_uc_company_override_properties.py @@ -20,6 +20,9 @@ pytestmark = pytest.mark.usefixtures("cloned_uk_tax_benefit_system") YEAR = 2026 +# corporate_wealth is valued at 90% for the expenses of sale (UC Regs 2013 +# reg. 49(1)(a)); disregarded holdings inside it leave the pool at that value. +SHARE_VALUE = 0.9 LAYOUTS = { "one-owner": ((10_000,), (), ()), "two-owners-one-unit": ((4_000, 6_000), (), ()), @@ -53,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) @@ -67,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, @@ -132,14 +135,15 @@ def test_company_overrides_conserve_capital_and_keep_holdings_out_of_other_units for row, (specs, adults, holdings, dependants, corporate, savings) in zip( assessed, cases ): - pool = corporate + savings + # The pool counts corporate_wealth at 90% (reg. 49(1)(a)), and holdings + # inside it leave the pool at that value. + pool = SHARE_VALUE * corporate + savings missing = [ "override" not in spec and spec.get("financial", -1) < 0 for spec in specs ] 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 = [ @@ -150,8 +154,22 @@ 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 = [holding * scale for holding in bounded_holdings] - extra_holding_draw = bounded_dependants * scale + sum( + 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% (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"] - market) + 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 else max(0, holding - spec["override"]) @@ -181,9 +199,20 @@ def test_company_overrides_conserve_capital_and_keep_holdings_out_of_other_units # Account for what regulation 77 actually removes from reporting # 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 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(holding, reported) - for holding, reported, absent in zip(holdings, explicit, missing) + min(SHARE_VALUE * holding, reported) + if "override" in spec + 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 + ) if not absent ) assert row.sum() + owner_substitution + extra_holding_draw == pytest.approx( @@ -303,7 +332,8 @@ def test_regrouping_holdings_between_holders_and_units_preserves_residual_pool() savings, ) ) - expected.append(savings + max(0, corporate - total)) + # Shares left after the holdings count at 90% (reg. 49(1)(a)). + expected.append(savings + SHARE_VALUE * max(0, corporate - total)) situation, residual_rows = _pool_property_situation(cases) capital = np.asarray( Simulation(situation=situation).calculate("uc_assessable_capital", YEAR) diff --git a/policyengine_uk/tests/test_uc_company_owner_properties.py b/policyengine_uk/tests/test_uc_company_owner_properties.py index beafcec75b..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,13 +67,22 @@ 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 +# 2013 reg. 49(1)(a)), so a disregarded holding inside it comes off at 90%. +SHARE_VALUE = 0.9 PROPERTY_SETTINGS = settings( max_examples=10, deadline=None, @@ -121,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))) @@ -265,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): @@ -488,7 +514,7 @@ def test_capital_and_earnings_identities(unit_list): assert close(earned, max(before, floor)) else: assert close(earned, before) - disregarded = min(holdings, unit["corporate_wealth"]) + disregarded = SHARE_VALUE * min(holdings, unit["corporate_wealth"]) expected = base["uc_assessable_capital"][i] - disregarded + company_capital assert close(got["uc_assessable_capital"][i], expected) @@ -612,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 @@ -621,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"]): @@ -634,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} @@ -645,12 +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"] + 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} ) diff --git a/policyengine_uk/tests/test_uc_property_capital.py b/policyengine_uk/tests/test_uc_property_capital.py index 02435651c5..bf697457b3 100644 --- a/policyengine_uk/tests/test_uc_property_capital.py +++ b/policyengine_uk/tests/test_uc_property_capital.py @@ -285,7 +285,10 @@ def test_missing_financial_and_spi_style_inputs_retain_the_financial_proxy(finan }, ) situation["people"]["p0_0"]["lifetime_isa_balance"] = {YEAR: 4_000} - assert _values(Simulation(situation=situation))[0] == 18_000 + # 4,000 of savings + 90% of 2,000 of shares and of 10,000 of property + # (reg. 49(1)(a)) + 75% of the 4,000 Lifetime ISA: 4,000 + 1,800 + 9,000 + # + 3,000. + assert _values(Simulation(situation=situation))[0] == 17_800 @pytest.mark.parametrize("financial", [-1, 0, 6_000]) @@ -559,16 +562,21 @@ def test_complete_override_company_holding_cannot_leak_into_missing_unit_pool( # owner's holding. It consumes at least that holding from the pool once, # including when zero or smaller than the holding, and supersedes the # financial observation. + # The holding sits in corporate_wealth, which counts at 90% (reg. + # 49(1)(a)), so it is 9,000 of countable capital and the pool is 6,000 + + # 9,000 = 15,000. + holding = 0.9 * 10_000 assert _values(simulation, "household_uc_pool_company_holdings")[0] == 0 - assert _values(simulation, "household_uc_reported_financial_capital")[0] == max( - complete_override, 10_000 - ) + assert _values(simulation, "household_uc_reported_financial_capital")[ + 0 + ] == pytest.approx(max(complete_override, holding)) np.testing.assert_allclose( _values(simulation), [ - max(0, complete_override - 10_000), - max(0, 16_000 - max(complete_override, 10_000)), + max(0, complete_override - holding), + max(0, 6_000 + holding - max(complete_override, holding)), ], + atol=0.01, ) @@ -595,5 +603,8 @@ def test_owner_override_consumes_company_holding_once_in_twenty_thousand_savings # £30k household pool less the owner's £10k override leaves £20k. The # override includes the holding; removing it again would leave £10k and # incorrectly award the other unit £4,263.60 Universal Credit in 2026. - np.testing.assert_allclose(_values(simulation, year=year), [0, 20_000]) + # With corporate_wealth counted at 90% (reg. 49(1)(a)) the pool is 20,000 + + # 9,000 = 29,000; the override consumes 10,000, leaving 19,000, and the + # owner keeps 10,000 less the 9,000 holding. + np.testing.assert_allclose(_values(simulation, year=year), [1_000, 19_000]) assert _values(simulation, "universal_credit", year=year)[1] == 0 diff --git a/policyengine_uk/tests/test_uc_property_capital_mock.py b/policyengine_uk/tests/test_uc_property_capital_mock.py index 6f32099a88..a84f8278ee 100644 --- a/policyengine_uk/tests/test_uc_property_capital_mock.py +++ b/policyengine_uk/tests/test_uc_property_capital_mock.py @@ -192,10 +192,13 @@ def test_mock_owner_override_consumes_its_company_holding_once(tmp_path): ), ) - # The owner's override already contains the holding. The other unit keeps - # the £20k residual and is ineligible for UC after the H5 input round trip. + # The owner's override already contains the holding, counted at the 90% + # at which corporate_wealth is valued (reg. 49(1)(a)): the pool is £20k + + # £9k, the override consumes £10k, and the other unit keeps the £19k + # residual and is ineligible for UC after the H5 input round trip; the + # owner keeps £10k less the £9k holding. np.testing.assert_allclose( - simulation.calculate("uc_assessable_capital", year), [0, 20_000] + simulation.calculate("uc_assessable_capital", year), [1_000, 19_000] ) assert simulation.calculate("universal_credit", year)[1] == 0 @@ -363,7 +366,9 @@ def test_mock_property_valuation_uses_the_assessment_year(tmp_path): assert simulation.calculate("uc_assessable_capital", 2026)[0] == 24_000 -@pytest.mark.parametrize("reported, expected", [(6_000, 6_000), (0, 0), (-1, 56_000)]) +# With nothing reported, Pension Credit values the property at 90% (SPC Regs +# 2002 reg. 19(a)): 6,000 + 45,000. +@pytest.mark.parametrize("reported, expected", [(6_000, 6_000), (0, 0), (-1, 51_000)]) def test_mock_pension_credit_keeps_its_existing_reported_capital_contract( tmp_path, reported, expected ): diff --git a/policyengine_uk/utils/capital_valuation.py b/policyengine_uk/utils/capital_valuation.py new file mode 100644 index 0000000000..7652402117 --- /dev/null +++ b/policyengine_uk/utils/capital_valuation.py @@ -0,0 +1,218 @@ +"""Value means-tested capital as the capital-valuation regulations require. + +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, 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 +from policyengine_core.model_api import max_ + +from policyengine_uk.utils.supplied_inputs import supplied_input +from policyengine_uk.variables.gov.dwp._person_capital_pool import ( + counted_person_sources, + household_sources, +) + +# 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", + "owned_land": "owned_land_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, 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 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 - exact_amount(value_of(SECURED_DEBT[source]))) + total = total + value + 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 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, and only + 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 + amount. + + The function counts only the sources ``counted_person_sources`` keeps. A + 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 the function + then values the balances less the rate too.""" + person = benunit.members + law = parameters(period) + held_in = household_sources(law) + total = 0 + for source in counted_person_sources(capital, law): + stored = person(source, period) + value = exact_amount(stored) + if held_in.get(source) in capital.sale_expenses.sources: + value = less_sale_expenses( + value, capital.sale_expenses.rate, capital.round_down + ) + if source in CALCULATED_PERSON_SOURCES: + 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 + ): + 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, 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 + ) + 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 + + +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.""" + return 1 - sale_expenses.rate if source in sale_expenses.sources else 1 + + +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. + + 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 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 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. 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) + pennies = np.round(wide, 2) + # 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), + 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) + + +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 next to a whole or half penny (206.99999999999997 pence for 90% of + £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/utils/supplied_inputs.py b/policyengine_uk/utils/supplied_inputs.py index a5d5f05ab6..60b8a15e44 100644 --- a/policyengine_uk/utils/supplied_inputs.py +++ b/policyengine_uk/utils/supplied_inputs.py @@ -97,6 +97,7 @@ "pip_m_points", "local_bus_trips", "local_bus_uncapped_single_fare", + "lifetime_isa_countable_capital", "miscellaneous_income_trading_allowance_deduction", "monthly_domestic_energy_consumption", "ni_class_4_losses_brought_forward", diff --git a/policyengine_uk/variables/gov/dwp/_person_capital_pool.py b/policyengine_uk/variables/gov/dwp/_person_capital_pool.py index 94683e99d6..8df77efd08 100644 --- a/policyengine_uk/variables/gov/dwp/_person_capital_pool.py +++ b/policyengine_uk/variables/gov/dwp/_person_capital_pool.py @@ -2,49 +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 each stocks -# and shares ISA balance (through stocks_and_shares_isa, 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", -} - - -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 c4d0991e28..82e0293fdd 100644 --- a/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/esa_income_assessable_capital.py @@ -1,6 +1,10 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import ( + round_to_penny, + valued_capital, + valued_person_capital, +) from policyengine_uk.variables.gov.dwp._person_capital_pool import ( - counted_person_sources, pooled_person_capital, ) @@ -11,7 +15,12 @@ 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. For capital whose owner the data do not identify, the model " + "capital test. " + "The formula values each household source, less the ISA balances it " + "counts in their holders' own benunits, at market value less 10% where a sale would incur " + "expenses and less any debt secured on it (reg. 113), and values each " + "such ISA balance as it values that household source. " + "For capital whose owner the data do not identify, the model " "allocates the full household remainder to any benunit with a reported " "income-related ESA award and falls back to a claimant-and-partner share when " "nobody in the household reports such an award. No regulation sets that " @@ -32,10 +41,14 @@ 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)) - - pooled_person_capital(benunit, source, period, ESA.capital) - for source in ESA.capital.sources + household_capital = valued_capital( + lambda source: ( + benunit.max(person.household(source, period)) + - pooled_person_capital( + benunit, source, period, parameters, ESA.capital + ) + ), + ESA.capital, ) # Regulation 83(2) excludes children's and young persons' capital. # The claimant/partner weights approximate otherwise unobserved ownership. @@ -54,11 +67,11 @@ 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(person(source, period) * claimant_or_partner) - for source in counted_person_sources(ESA.capital) + person_capital = valued_person_capital( + benunit, period, parameters, ESA.capital, claimant_or_partner ) 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 b8e4fdfd59..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 @@ -1,6 +1,11 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import ( + exact_amount, + round_to_penny, + valued_capital, + valued_person_capital, +) from policyengine_uk.variables.gov.dwp._person_capital_pool import ( - counted_person_sources, pooled_person_capital, ) @@ -10,7 +15,13 @@ class housing_benefit_assessable_capital(Variable): entity = BenUnit label = "Housing Benefit assessable capital" documentation = ( - "Housing Benefit capital counted from the configured capital sources. The " + "Housing Benefit capital counted from the configured capital sources. " + "The formula values each household source, less the ISA balances it " + "counts in their holders' own benunits, 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), and values each " + "such ISA balance as it values that household source. " + "The " "formula counts person-level sources, such as a Lifetime ISA and the cash and " "stocks and shares ISAs, only in the holder's own benunit and only for its " "claimant or partner (is_claimant_or_partner), and excludes dependants' " @@ -45,15 +56,16 @@ def formula(benunit, period, parameters): "housing_benefit_pension_age_regulations_apply", period ) p = parameters(period).gov.dwp.housing_benefit.means_test.capital - household_capital = sum( - household(source, period) - - pooled_person_capital(benunit, source, period, p) - for source in p.sources + household_capital = valued_capital( + lambda source: ( + household(source, period) + - pooled_person_capital(benunit, source, period, parameters, p) + ), + p, ) claimant_or_partner = person("is_claimant_or_partner", period) - person_capital = sum( - benunit.sum(person(source, period) * claimant_or_partner) - for source in counted_person_sources(p) + person_capital = valued_person_capital( + benunit, period, parameters, p, claimant_or_partner ) benunit_claimants_and_partners = add( benunit, period, ["is_claimant_or_partner"] @@ -81,7 +93,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 @@ -103,8 +115,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 82fd5a0cfe..a9f09001ff 100644 --- a/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/income_support_assessable_capital.py @@ -1,6 +1,10 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import ( + round_to_penny, + valued_capital, + valued_person_capital, +) from policyengine_uk.variables.gov.dwp._person_capital_pool import ( - counted_person_sources, pooled_person_capital, ) @@ -11,7 +15,12 @@ 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. For capital whose owner the data do not identify, the model " + "capital test. " + "The formula values each household source, less the ISA balances it " + "counts in their holders' own benunits, at market value less 10% where a sale would incur " + "expenses and less any debt secured on it (reg. 49), and values each " + "such ISA balance as it values that household source. " + "For capital whose owner the data do not identify, the model " "allocates the full household remainder to any benunit on the IS claim path " "and falls back to a claimant-and-partner share when nobody in the household " "claims on that path. No regulation sets that allocation; it approximates " @@ -28,7 +37,6 @@ class income_support_assessable_capital(Variable): def formula(benunit, period, parameters): IS = parameters(period).gov.dwp.income_support - capital = IS.means_test.capital person = benunit.members would_claim_is = benunit("would_claim_IS", period) @@ -38,10 +46,14 @@ def formula(benunit, period, parameters): # If nobody in the household is on that path, use claimant/partner # weights. Regulation 23 excludes children's and young persons' capital; # the household allocation itself is a modelling convention. - household_capital = sum( - benunit.max(person.household(source, period)) - - pooled_person_capital(benunit, source, period, capital) - for source in capital.sources + household_capital = valued_capital( + lambda source: ( + benunit.max(person.household(source, period)) + - pooled_person_capital( + benunit, source, period, parameters, IS.means_test.capital + ) + ), + IS.means_test.capital, ) benunit_claimants_and_partners = add( benunit, period, ["is_claimant_or_partner"] @@ -61,11 +73,13 @@ 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(person(source, period) * claimant_or_partner) - for source in counted_person_sources(capital) + 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 ) - 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 2cf466c410..40d4491a28 100644 --- a/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py +++ b/policyengine_uk/variables/gov/dwp/jsa_income_assessable_capital.py @@ -1,6 +1,10 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import ( + round_to_penny, + valued_capital, + valued_person_capital, +) from policyengine_uk.variables.gov.dwp._person_capital_pool import ( - counted_person_sources, pooled_person_capital, ) @@ -11,7 +15,12 @@ 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. For capital whose owner the data do not identify, the model " + "capital test. " + "The formula values each household source, less the ISA balances it " + "counts in their holders' own benunits, at market value less 10% where a sale would incur " + "expenses and less any debt secured on it (reg. 111), and values each " + "such ISA balance as it values that household source. " + "For capital whose owner the data do not identify, the model " "allocates the full household remainder to any benunit with a reported " "income-based JSA award and falls back to a claimant-and-partner share when " "nobody in the household reports such an award. No regulation sets that " @@ -32,10 +41,14 @@ 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)) - - pooled_person_capital(benunit, source, period, JSA.capital) - for source in JSA.capital.sources + household_capital = valued_capital( + lambda source: ( + benunit.max(person.household(source, period)) + - pooled_person_capital( + benunit, source, period, parameters, JSA.capital + ) + ), + JSA.capital, ) # Regulation 88(2) excludes children's and young persons' capital. # The claimant/partner weights approximate otherwise unobserved ownership. @@ -54,11 +67,11 @@ 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(person(source, period) * claimant_or_partner) - for source in counted_person_sources(JSA.capital) + person_capital = valued_person_capital( + benunit, period, parameters, JSA.capital, claimant_or_partner ) 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/lifetime_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/lifetime_isa_countable_capital.py index 6daf2817c3..83ce5d8dea 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 lifetime_isa_surrender_value class lifetime_isa_countable_capital(Variable): @@ -23,8 +24,8 @@ class lifetime_isa_countable_capital(Variable): "https://www.legislation.gov.uk/uksi/1998/1870/schedule", ] - def formula(person, period, parameters): - p = parameters(period).gov.hmrc.isa.lifetime - balance = person("lifetime_isa_balance", period) - charge_free = person("age", period) >= p.charge_free_age - return where(charge_free, balance, balance * (1 - p.withdrawal_charge)) + # 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 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 1e009aa3a3..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 @@ -1,6 +1,11 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import ( + exact_amount, + round_to_penny, + valued_capital, + valued_person_capital, +) from policyengine_uk.variables.gov.dwp._person_capital_pool import ( - counted_person_sources, pooled_person_capital, ) @@ -10,7 +15,12 @@ class pension_credit_assessable_capital(Variable): entity = BenUnit label = "Pension Credit assessable capital" documentation = ( - "Pension Credit capital counted from the configured capital sources. The " + "Pension Credit capital counted from the configured capital sources. " + "The formula values each household source, less the ISA balances it " + "counts in their holders' own benunits, at market value less 10% where a sale would incur " + "expenses and less any debt secured on it (reg. 19), and values each " + "such ISA balance as it values that household source. " + "The " "formula allocates the household remainder only across the household's " "pension-age adults, so unrelated working-age adults leave a pensioner " "couple's share undiluted. The formula counts person-level sources, such as a " @@ -31,15 +41,16 @@ 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) - - pooled_person_capital(benunit, source, period, p) - for source in p.sources + household_capital = valued_capital( + lambda source: ( + household(source, period) + - pooled_person_capital(benunit, source, period, parameters, p) + ), + p, ) claimant_or_partner = person("is_claimant_or_partner", period) - person_capital = sum( - benunit.sum(person(source, period) * claimant_or_partner) - for source in counted_person_sources(p) + 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) @@ -58,10 +69,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/stocks_and_shares_isa_countable_capital.py b/policyengine_uk/variables/gov/dwp/stocks_and_shares_isa_countable_capital.py index 38e90fab4d..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 @@ -1,6 +1,12 @@ from policyengine_uk.model_api import * from policyengine_uk.variables.gov.dwp._person_capital_pool import ( bounded_person_holding, + 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, ) @@ -8,19 +14,62 @@ 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 " - "or the itemised sum, so each means test subtracts it from the household pool " - "before allocating the pool between benefit units. 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." + "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 " + "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. 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 " + "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 " + "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 @@ -33,12 +82,56 @@ 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_sources(parameters(period))[ + "stocks_and_shares_isa_countable_capital" + ] + # Bound the balances by the holdings behind the part that holds the + # 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 = holdings_with_sale_expenses(household, period, parameters) + # 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 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( + formula_split(household, period, parameters), + backing - stored > np.spacing(np.abs(share_like)), + stored < backing, + ) + backing = where(short, stored, backing) + # A missing (NaN) backing drops out of the overall bound. return bounded_person_holding( person, person("stocks_and_shares_isa_balance", period), - household_total, + where(backing < household_total, backing, household_total), ) 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_company_holding_pool_scale.py b/policyengine_uk/variables/gov/dwp/universal_credit/household_uc_company_holding_pool_scale.py index c208ec85f1..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 @@ -1,8 +1,9 @@ from policyengine_uk.model_api import * -# The capital source that holds a disregarded company holding: the share-like -# capital the UC financial pool counts, so holdings are budgeted against it. -HOLDINGS_SOURCE = "share_like_capital" +# The capital source that holds a disregarded company holding: a holding is +# shares in a company, which have expenses of sale, so it sits in that part of +# the share-like capital the UC financial pool counts and is budgeted against it. +HOLDINGS_SOURCE = "share_like_capital_with_sale_expenses" class household_uc_company_holding_pool_scale(Variable): @@ -12,20 +13,30 @@ class household_uc_company_holding_pool_scale(Variable): documentation = ( "Common proportional scale for disregarded company holdings when " "deducting them from the household financial pool. Before budgeting, " - "clip each person's holding to [0, max(0, share_like_capital)], mapping " + "clip each person's holding to [0, max(0, share_like_capital_with_sale_expenses)], mapping " "positive infinity to the upper bound and negative infinity to zero. " "Total bounded holdings " - "share one budget of nonnegative share_like_capital (the share-like " + "share one budget of nonnegative share_like_capital_with_sale_expenses (the share-like " "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: 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 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 fe96f39a8f..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 @@ -1,4 +1,9 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import ( + counted_share, + exact_amount, + round_to_penny, +) from policyengine_uk.variables.gov.dwp.universal_credit.household_uc_company_holding_pool_scale import ( HOLDINGS_SOURCE, ) @@ -26,20 +31,30 @@ 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 " - "is shares, held within the household's share_like_capital. Each " - "person's holding is first clipped to [0, max(0, share_like_capital)], " + "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, which have " + "expenses of sale, held within the household's " + "share_like_capital_with_sale_expenses. Each person's holding is first " + "clipped to [0, max(0, share_like_capital_with_sale_expenses)], " "with positive infinity mapped to the upper bound and negative infinity " "to zero before any multiplication. All household holdings then share " - "one nonnegative share_like_capital budget " + "one nonnegative share_like_capital_with_sale_expenses budget " "through household_uc_company_holding_pool_scale: when their total " "exceeds it, scale each person's holding proportionally before " "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 " - "owner's own assessment." + "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) " + "deducts 10% for the expenses of selling shares." ) definition_period = YEAR unit = GBP @@ -54,8 +69,8 @@ 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(HOLDINGS_SOURCE, period)) + holding = exact_amount(person("uc_company_holding_disregard", period)) + upper_bound = max_(0, exact_amount(person.household(HOLDINGS_SOURCE, period))) finite_holding = np.where( np.isfinite(holding), holding, np.where(holding > 0, upper_bound, 0) ) @@ -64,4 +79,10 @@ def formula(household, period, parameters): * person.household("household_uc_company_holding_pool_scale", period) * ~off_reported_capital ) - return holdings + # The holdings sit in HOLDINGS_SOURCE, 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 round_to_penny( + holdings * counted_share(p.sale_expenses, HOLDINGS_SOURCE), + 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 eaaae275f0..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 @@ -1,4 +1,9 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import ( + counted_share, + exact_amount, + round_to_penny, +) from policyengine_uk.variables.gov.dwp.universal_credit.household_uc_company_holding_pool_scale import ( HOLDINGS_SOURCE, ) @@ -16,21 +21,31 @@ class household_uc_reported_financial_capital(Variable): "replaces ordinary sources before regulation 77 company substitution, " "so it includes its claimant's and partner's disregarded holdings. " "Consume the larger of the override and those holdings after applying " - "household_uc_company_holding_pool_scale. Each person's holding is " - "first clipped to [0, max(0, share_like_capital)], with positive infinity " + "household_uc_company_holding_pool_scale and valuing them as the " + "shares that hold them are valued (90% under regulation 49(1)). Each " + "person's holding is first clipped to [0, max(0, " + "share_like_capital_with_sale_expenses)], with positive infinity " "mapped to the upper bound and negative infinity to zero before any " - "multiplication. All household holdings share " - "one nonnegative share_like_capital budget: if their total exceeds it, " + "multiplication. All household holdings share one nonnegative " + "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 " "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,24 +53,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(HOLDINGS_SOURCE, 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(HOLDINGS_SOURCE, 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 the shares, and the holdings in them, at the reg. + # 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 = round_to_penny( + own_holdings * counted_share(p.sale_expenses, HOLDINGS_SOURCE), + p.round_down, ) 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) 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 11ca5eac23..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 @@ -1,6 +1,15 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import ( + counted_share, + 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, +) from policyengine_uk.variables.gov.dwp._person_capital_pool import ( - counted_person_sources, pooled_person_capital, ) @@ -30,7 +39,22 @@ class uc_assessable_capital(Variable): "for the claimant and partner of a unit that reports its capital: it leaves " "their ISAs in the pool and subtracts the report, as for their company " "holdings. Under regulation 77, it replaces disregarded company holdings with " - "the claimant's or partner's share of company capital." + "the claimant's or partner's share of company capital. Regulation 49(1) " + "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 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 " + "calculates to the nearest penny (regulation 6(1)), including this " + "capital, which it tests against the limit." ) definition_period = YEAR unit = GBP @@ -54,26 +78,33 @@ def formula(benunit, period, parameters): (person.benunit("benunit_reported_capital", period) >= 0) | (person.benunit("uc_reported_capital", period) >= 0) ) - household_financial_capital = sum( - household(source, period) - - pooled_person_capital(benunit, source, period, p, ~covered) - for source in p.sources + household_financial_capital = valued_capital( + lambda source: ( + household(source, period) + - pooled_person_capital( + benunit, source, period, parameters, p, ~covered + ) + ), + p, ) + # A reg. 77 holding sits in the shares with sale expenses, so it is + # counted at the same 90% as the shares around it wherever they are + # valued. + holding_value = counted_share(p.sale_expenses, HOLDINGS_SOURCE) benunit_claimants = benunit.sum(claimant_or_partner) - person_capital = sum( - benunit.sum(person(source, period) * claimant_or_partner) - for source in counted_person_sources(p) + person_capital = valued_person_capital( + benunit, period, parameters, p, claimant_or_partner ) - 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, @@ -83,7 +114,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( @@ -93,10 +124,17 @@ def formula(benunit, period, parameters): ) assessed_capital = where( complete_override >= 0, - max_(0, complete_override - own_holdings), - 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 d59947a042..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,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import exact_amount, less_sale_expenses class uc_non_residential_property_capital(Variable): @@ -21,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, market_value * (1 - p.property_sale_cost_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 eaeebb1435..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,4 +1,5 @@ from policyengine_uk.model_api import * +from policyengine_uk.utils.capital_valuation import exact_amount, less_sale_expenses class uc_other_residential_property_capital(Variable): @@ -21,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, market_value * (1 - p.property_sale_cost_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, + ) diff --git a/policyengine_uk/variables/gov/dwp/universal_credit/uc_reported_capital.py b/policyengine_uk/variables/gov/dwp/universal_credit/uc_reported_capital.py index c59e6dfb3a..cce696e238 100644 --- a/policyengine_uk/variables/gov/dwp/universal_credit/uc_reported_capital.py +++ b/policyengine_uk/variables/gov/dwp/universal_credit/uc_reported_capital.py @@ -22,7 +22,7 @@ class uc_reported_capital(Variable): "override can change a missing-report unit's capital. The complete " "override consumes its amount, or its claimant's and partner's " "disregarded company holdings after their proportional share of the " - "household share_like_capital budget if larger, " + "household share_like_capital_with_sale_expenses budget if larger, " "from the financial pool, taking " "precedence over the same unit's financial report. " "This variable does not derive from the financial-only FRS total. " 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 05115192ad..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 @@ -7,10 +7,11 @@ # The debt input secured on each capital source. The schemes deduct "the # amount of any encumbrance secured on it" from that asset after the sale # expenses, so a source is never valued below nil and negative equity in one -# source does not reduce another. Land has no secured-debt input. +# source does not reduce another. 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", } @@ -39,11 +40,12 @@ class council_tax_reduction_assessable_capital(Variable): "the applicant's: savings, land and property other than the home " "(gov.local_authorities.council_tax_reduction.capital.sources), with " "land and property valued at market value less 10% for the expenses " - "of sale, then less any debt secured on that 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 " + "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, 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 new file mode 100644 index 0000000000..6729290eb4 --- /dev/null +++ b/policyengine_uk/variables/household/wealth/share_like_capital_with_sale_expenses.py @@ -0,0 +1,139 @@ +from policyengine_uk.model_api import * + +# The share-like holdings a dataset can itemise. The formula treats a +# 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. +# 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", + "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 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, 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 + value_type = float + unit = GBP + quantity_type = STOCK + + def formula(household, period, parameters): + 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): + """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. 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) 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..e442b5aa98 --- /dev/null +++ b/policyengine_uk/variables/household/wealth/share_like_capital_without_sale_expenses.py @@ -0,0 +1,22 @@ +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 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 + 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 + ) 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 ec04a1c86d..d64fe5a50b 100644 --- a/policyengine_uk/variables/input/non_residential_property_secured_debt.py +++ b/policyengine_uk/variables/input/non_residential_property_secured_debt.py @@ -7,10 +7,14 @@ class non_residential_property_secured_debt(Variable): label = "Debt secured on non-residential property" documentation = ( "Outstanding encumbrances secured specifically on the household's " - "non-residential property. Excludes main-home mortgage debt and unsecured " - "debt. Deducted after sale expenses in UC regulation 49 valuation. " - "The survey lacks reliable property-specific debt flags, so the " - "default zero is a modelling approximation unless supplied explicitly." + "non-residential property. 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 " + "debt flags, so the default zero is a modelling approximation unless " + "supplied explicitly." ) definition_period = YEAR unit = GBP 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 ff3488f386..adfa435fa8 100644 --- a/policyengine_uk/variables/input/other_residential_property_secured_debt.py +++ b/policyengine_uk/variables/input/other_residential_property_secured_debt.py @@ -7,10 +7,14 @@ class other_residential_property_secured_debt(Variable): label = "Debt secured on other residential property" documentation = ( "Outstanding encumbrances secured specifically on the household's " - "other residential property. Excludes main-home mortgage debt and unsecured " - "debt. Deducted after sale expenses in UC regulation 49 valuation. " - "The survey lacks reliable property-specific debt flags, so the " - "default zero is a modelling approximation unless supplied explicitly." + "other residential property. 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 " + "debt flags, so the default zero is a modelling approximation unless " + "supplied explicitly." ) definition_period = YEAR unit = GBP 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..18d93d7c0b --- /dev/null +++ b/policyengine_uk/variables/input/owned_land_secured_debt.py @@ -0,0 +1,25 @@ +from policyengine_uk.model_api import * + + +class owned_land_secured_debt(Variable): + value_type = float + entity = Household + label = "Debt secured on owned land" + documentation = ( + "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 " + "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." + ) + definition_period = YEAR + unit = GBP + quantity_type = STOCK + default_value = 0 + uprating = "gov.economic_assumptions.indices.obr.per_capita.gdp" + reference = "https://www.legislation.gov.uk/uksi/2013/376/regulation/49/1"