Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cc48226
Add firm entity and firm-side tax rules
vahid-ahmadi Nov 21, 2026
5c7a4d7
Add firm regression gate, incidence and integration tests; keep Emplo…
vahid-ahmadi Nov 21, 2026
96c9f86
Keep firms through core clones, guard firm dataset loading, net R&D c…
vahid-ahmadi Nov 22, 2026
95974f6
Hide firm input variables from household input pickers
vahid-ahmadi Nov 22, 2026
aa15b25
Register firm programmes and document the firm entity
vahid-ahmadi Nov 22, 2026
06c2a84
Verify firm parameter values and references against legislation
vahid-ahmadi Nov 22, 2026
efeb6f6
Address second review: prior-year EA limit at baseline, live househol…
vahid-ahmadi Nov 22, 2026
42939b5
Add firm microsimulation, microcosm contract and reform example tests…
vahid-ahmadi Nov 22, 2026
1b320d8
Clip pay-distribution inputs, Employment Allowance parity test, docs
vahid-ahmadi Nov 22, 2026
3a29982
Add firm minimum wage floor, boundary tests for CT, levy, VAT and SBRR
vahid-ahmadi Nov 22, 2026
ca037fa
Guard the minimum wage floor before October 2010, clip negative input…
vahid-ahmadi Nov 22, 2026
57a99a6
RDEC payable cap at notional tax, group-shared and RDEC-free bank sur…
vahid-ahmadi Nov 22, 2026
287c02f
Wales and Scotland firm business rates, pubs live-music limit, SBRR t…
vahid-ahmadi Nov 22, 2026
5ae31d4
RDEC PAYE/NIC cap applies only when supplied, via an explicit flag ra…
vahid-ahmadi Nov 22, 2026
d856de5
Review follow-ups: RDEC cap flag docs, SBRR rounding note, Wales and …
vahid-ahmadi Nov 22, 2026
7484867
Mandatory charitable rate relief in Wales and Scotland
vahid-ahmadi Nov 22, 2026
6853866
Welsh retail multiplier and higher-multiplier exclusions; more firm b…
vahid-ahmadi Nov 22, 2026
0067440
Fix three firm rules: partial exemption rounding, s.59A balancing cha…
vahid-ahmadi Nov 23, 2026
0d1c250
Fix six firm rules from a third audit: R&D loss, SME credit cap, CIHC…
vahid-ahmadi Nov 23, 2026
fa48a29
Document the announced-value and float32 decisions in the firm docs
vahid-ahmadi Nov 23, 2026
9574718
Merge remote-tracking branch 'origin/main' into firm-entity-engine
vahid-ahmadi Nov 26, 2026
70a842c
Cap policyengine-core below 3.38 and test the firm entity against cor…
vahid-ahmadi Nov 26, 2026
57a0afc
Subtract the full Employment Allowance change in the firm-only total
vahid-ahmadi Nov 26, 2026
0bc727a
Carry VAT rule changes, at baseline rates, into the firm-only total
vahid-ahmadi Nov 26, 2026
c7e09f9
Add off-payroll NIC, Class 1A on termination awards, Class 1B, group …
vahid-ahmadi Nov 27, 2026
015d498
Add the Patent Box, RPDT, DST and the energy profits levy to firms; p…
vahid-ahmadi Nov 27, 2026
466e0f3
Test that every firm input is hidden and the new inputs default to no…
vahid-ahmadi Nov 27, 2026
b40cca0
Pin the supplied NIC base over the pay split; fix firm docs from the …
vahid-ahmadi Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
74 changes: 74 additions & 0 deletions .github/workflows/core_master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# The firm entity and the code that reads policyengine-core internals,
# tested against core's default branch, master.
#
# policyengine-uk gives the firm entity a root population by replacing core's
# TaxBenefitSystem.instantiate_entities and Simulation.clone, imports core's
# private _branch_clone, and reads private Simulation and Holder attributes in
# simulation.py. A core release that renames any of them would break
# `import policyengine_uk` for every user. pyproject.toml caps core below the
# next minor version, and this job runs the tests that use those internals on
# core's master, so a rename shows here before a release reaches the cap.
#
# It is not a required check: a red run means core master has moved, not that
# the pull request is wrong. The core version gate
# (tests/code_health/test_core_version_gate.py) is left out, because it fails
# by design on any core it has not qualified. It runs on pull requests that
# change code, every Monday, and by hand.

name: Core master
on:
pull_request:
branches:
- main
paths:
- policyengine_uk/**
- pyproject.toml
- uv.lock
- .github/workflows/core_master.yaml
schedule:
- cron: "0 7 * * 1"
workflow_dispatch:

concurrency:
group: core-master-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
Core-Master:
name: Firm and core-internals tests on policyengine-core master
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 45
steps:
- name: Checkout repo
uses: actions/checkout@v6
- name: Install the locked environment
uses: ./.github/actions/test-environment
- name: Install policyengine-core from master
run: |
set -euo pipefail
uv pip install --python .venv/bin/python \
"policyengine-core @ git+https://github.com/PolicyEngine/policyengine-core@master"
python -c "import importlib.metadata as m; print('policyengine-core', m.version('policyengine-core'))"
- name: Smoke-import
run: python -c "import policyengine_uk; print('import OK')"
- name: Python tests
run: >-
pytest -n 4
policyengine_uk/tests/test_firm_entity.py
policyengine_uk/tests/test_firm_incidence.py
policyengine_uk/tests/test_firm_regression_gate.py
policyengine_uk/tests/test_firm_yaml_guard.py
policyengine_uk/tests/test_entity_ids.py
policyengine_uk/tests/test_subsample.py
policyengine_uk/tests/test_input_dataframe_export.py
policyengine_uk/tests/test_dataframe_dataset.py
policyengine_uk/tests/test_supplied_inputs.py
policyengine_uk/tests/test_measurement_branches.py
- name: Firm YAML tests
run: >-
policyengine-core test -c policyengine_uk
policyengine_uk/tests/policy/integration/firm
policyengine_uk/tests/policy/baseline/gov/hmrc/corporation_tax
policyengine_uk/tests/policy/baseline/gov/hmrc/business_rates/firm
1 change: 1 addition & 0 deletions changelog.d/firm-entity-engine-rules-4.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added off-payroll employer National Insurance, Class 1A on termination awards, Class 1B, group relief, the Patent Box, the VAT partial exemption de minimis tests and direct attribution, Northern Ireland business rates, the soft drinks industry levy, the plastic packaging tax, the residential property developer tax, the digital services tax and the energy profits levy to the firm entity, all inert at their default inputs.
13 changes: 13 additions & 0 deletions changelog.d/firm-entity-engine.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Added a firm entity beside person, benefit unit and household, with firm-level rules for employer National Insurance and the Employment Allowance, the apprenticeship levy, corporation tax with capital allowances, R&D relief and the bank surcharge, business rates in England, firm-side VAT and employer auto-enrolment contributions. Household results are unchanged.
Added a firm-level National Minimum Wage floor: firm_minimum_wage_cost tops low-paid hours up to the adult rate, and the apprenticeship levy and default employer National Insurance and auto-enrolment approximations read the higher paybill.
Added the R&D expenditure credit notional tax deduction to the payable credit, and to the bank surcharge the exclusion of the credit from surcharge profits, a group share of the allowance and day-weighting of the rate across the 1 January 2027 change.
Added firm business rates for Wales and Scotland with charitable relief, the live music venue limit on the pubs relief large-venue rate, the three-decimal small business rate relief taper factor, and firm employer Class 1A National Insurance.
Added the PAYE and National Insurance cap on the payable R&D expenditure credit.
Added the 2026-27 Welsh retail multiplier and the public-service exclusions from the Welsh higher multiplier.
Rounded the VAT partial exemption recovery percentage up as reg 101(4)-(5) of the VAT Regulations 1995 requires.
Added the balancing charge on disposals of fully expensed plant (section 59A) and the exclusion of plant for leasing from full expensing, which gets the annual investment allowance and the main-rate first-year allowance instead.
Applied the English RHL multipliers to occupied property only, the standard multiplier to empty and charity property before 2024-25, and the empty property exemption below £2,900 rateable value.
Set the SME R&D payable credit's trading loss against the same period's non-trading profits (CTA 2009 s.1056(2)(a)), capped that credit by PAYE and NIC from April 2021, and added `firm_small_profits_rate_excluded` for close investment-holding and non-resident companies.
Capped policyengine-core below 3.38, because the firm entity reads core internals, and added a Core master workflow that runs the firm and core-internals tests against core's default branch.
Changed firm_tax_change_total to subtract the full change in the Employment Allowance, computed on each simulation's own employer National Insurance liabilities, so that with the gross change in household ni_employer a firm that stays under the allowance after a rate rise nets to zero.
Added the change in firm VAT from VAT rules other than the rates (the registration threshold, the flat rate scheme and partial exemption), with the rates held at baseline, to firm_tax_change_total.
33 changes: 17 additions & 16 deletions docs/book/programs/gov/hmrc/firm-vat.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Firm-level VAT (planned)

```{warning}
**Not yet modelled.** PolicyEngine UK models VAT only on *household
consumption*: the `vat` variable applies `gov.hmrc.vat.standard_rate` and
`gov.hmrc.vat.reduced_rate` to each household's standard- and reduced-rate
spending (`full_rate_vat_consumption`, `reduced_rate_vat_consumption`), then
grosses the result up to VAT receipts. VAT on the household's own electricity
and gas bills (`domestic_energy_vat`, at `gov.hmrc.vat.domestic_electricity_rate`
and `gov.hmrc.vat.reduced_rate`) is added once, without the gross-up. There is
no business side. This page
sets out the scope for adding firm-level VAT and a `Firm` entity, tracked in
[#1320](https://github.com/PolicyEngine/policyengine-uk/issues/1320), which is
still open (October 2026). The companion analysis issue,
[#1333](https://github.com/PolicyEngine/policyengine-uk/issues/1333), was
closed on 20 October 2026 as a duplicate of #1320.
# Firm-level VAT

```{note}
**Partly modelled.** PolicyEngine UK now has a `Firm` entity and firm-side
VAT rules (see [Firms](../../../usage/firms.md)): the registration threshold
(`gov.hmrc.vat.registration.threshold`, £90,000 since 1 April 2024),
output VAT on standard- and reduced-rated supplies, recoverable input VAT
with a partial exemption share, net liability (`firm_vat`) and the flat
rate scheme, including the limited cost trader rate. Supplies are firm
inputs; the sector-driven supply split, VAT groups, cross-border rules and
a calibrated firm dataset are not yet modelled. The household-side `vat`
variable is unchanged, and firm-side VAT is not yet linked to it. Tracked
in [#1320](https://github.com/PolicyEngine/policyengine-uk/issues/1320).
The design notes below predate the implementation: the `Firm` entity was
built as a population of its own, with no person members, rather than the
group entity with an owner role sketched under "Entity", and the variable
and parameter names differ.
```

## Why firm-level VAT?
Expand Down
176 changes: 176 additions & 0 deletions docs/book/usage/firm-reforms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Firm reforms

This page runs three static reforms to firm taxes through the Python API. The first two change corporation tax rules for a few firms in a situation. The third changes the Employment Allowance in a small dataset of households and firms, and spreads the change in firm tax over households with non-default incidence shares. The [Firms](firms.md) page describes the firm entity, its inputs and the programmes it models.

```{note}
The figures on this page come from small, made-up firms and households. They show how the model computes a reform; they are not estimates of UK revenue or of household impacts. Population totals need a calibrated firm dataset, which does not exist yet. `firm_tax_incidence` is not yet a term of `household_tax` or `gov_tax`, so these reforms leave household net income unchanged.
```

Every example uses the 2026-27 tax year. `policyengine_uk/tests/test_firm_docs_examples.py` repeats each example and checks every figure below.

## Raise the corporation tax main rate

This reform raises the corporation tax main rate from 25% to 27%. A reform passed to `Simulation` keeps the current law in `sim.baseline`, so one simulation gives both sets of results.

```python
from policyengine_uk import Simulation

firms = {
"large_company": {"firm_taxable_trading_profit": {2026: 2_000_000}},
"mid_company": {"firm_taxable_trading_profit": {2026: 150_000}},
"small_company": {"firm_taxable_trading_profit": {2026: 40_000}},
"sole_trader": {
"firm_legal_form": "SOLE_TRADER",
"firm_taxable_trading_profit": {2026: 80_000},
},
}
reform = {"gov.hmrc.corporation_tax.main_rate": {"2026-01-01.2100-12-31": 0.27}}

sim = Simulation(situation={"firms": firms}, reform=reform)
sim.baseline.calculate("corporation_tax", 2026) # [500_000, 36_000, 7_600, 0]
sim.calculate("corporation_tax", 2026) # [540_000, 39_000, 7_600, 0]
```

| Firm | Taxable profit | Current law | Reform | Change |
|---|---|---|---|---|
| Large company | £2,000,000 | £500,000 | £540,000 | +£40,000 |
| Mid-sized company | £150,000 | £36,000 | £39,000 | +£3,000 |
| Small company | £40,000 | £7,600 | £7,600 | £0 |
| Sole trader | £80,000 | £0 | £0 | £0 |

- The large company's profit exceeds the £250,000 upper limit, so it pays the main rate on all of it: 27% × £2,000,000 = £540,000.
- The mid-sized company's profit falls between the £50,000 lower limit and the upper limit. It pays the main rate less marginal relief of 3/200 × (£250,000 − £150,000) = £1,500. The reform leaves the relief unchanged and raises the tax from 25% × £150,000 − £1,500 = £36,000 to 27% × £150,000 − £1,500 = £39,000.
- The small company's profit is below the lower limit, so it pays the 19% small profits rate under both systems: 19% × £40,000 = £7,600.
- Only companies pay corporation tax, so the sole trader pays none under either system.

## Change the main-pool writing-down allowance

Companies deduct a writing-down allowance on the reducing balance of their main pool of plant and machinery. The rate is `gov.hmrc.corporation_tax.capital_allowances.writing_down_allowance.main_rate`, which is 14% for 2026-27. This reform raises it to 18%.

```python
firms = {
"manufacturer": {
"firm_taxable_trading_profit": {2026: 1_000_000},
"firm_main_pool_brought_forward": {2026: 500_000},
},
"workshop": {
"firm_taxable_trading_profit": {2026: 100_000},
"firm_main_pool_brought_forward": {2026: 200_000},
},
}
reform = {
"gov.hmrc.corporation_tax.capital_allowances.writing_down_allowance.main_rate": {
"2026-01-01.2100-12-31": 0.18
}
}

sim = Simulation(situation={"firms": firms}, reform=reform)
sim.calculate("firm_main_pool_writing_down_allowance", 2026) # [90_000, 36_000]
sim.calculate("firm_taxable_profit", 2026) # [910_000, 64_000]
sim.calculate("corporation_tax", 2026) # [227_500, 13_210]
```

| | Manufacturer, current law | Manufacturer, reform | Workshop, current law | Workshop, reform |
|---|---|---|---|---|
| Writing-down allowance | £70,000 | £90,000 | £28,000 | £36,000 |
| Taxable profit | £930,000 | £910,000 | £72,000 | £64,000 |
| Corporation tax | £232,500 | £227,500 | £15,330 | £13,210 |
| Main pool carried forward | £430,000 | £410,000 | £172,000 | £164,000 |

The reform raises the manufacturer's allowance by 4% × £500,000 = £20,000. Its taxable profit is above the upper limit, so its corporation tax falls by 25% × £20,000 = £5,000.

The workshop's allowance rises by 4% × £200,000 = £8,000. Its taxable profit stays in the marginal relief band, where each pound of profit carries tax of 25% + 3/200 = 26.5%. Its corporation tax falls by 26.5% × £8,000 = £2,120:

- Current law: 25% × £72,000 − 3/200 × (£250,000 − £72,000) = £18,000 − £2,670 = £15,330.
- Reform: 25% × £64,000 − 3/200 × (£250,000 − £64,000) = £16,000 − £2,790 = £13,210.

A higher allowance this year leaves a smaller balance to carry forward, so the reform also lowers the allowances available in later years.

## Cut the Employment Allowance and allocate the change to households

`firm_tax_change_total` and `firm_tax_incidence` compare a reform with its baseline across a population, so they need a dataset: in a situation both are 0. This example builds a dataset of two households, each with a weight of 1,000, and three kinds of firm. It cuts the Employment Allowance from £10,500 to £5,000 and sets the incidence shares to 50% capital, 25% consumers and 25% workers in place of the default 100% capital.

```python
import pandas as pd
from policyengine_uk import Microsimulation
from policyengine_uk.data import UKSingleYearDataset

dataset = UKSingleYearDataset(
person=pd.DataFrame(
{
"person_id": [1, 2],
"person_benunit_id": [1, 2],
"person_household_id": [1, 2],
"age": [30, 50],
"employment_income": [25_000.0, 75_000.0],
}
),
benunit=pd.DataFrame({"benunit_id": [1, 2]}),
household=pd.DataFrame(
{
"household_id": [1, 2],
"household_weight": [1_000.0, 1_000.0],
"region": "LONDON",
"rent": 0.0,
"tenure_type": "OWNED_OUTRIGHT",
"council_tax": 0.0,
"corporate_sector_wealth": [0.0, 100_000.0],
"consumption": [20_000.0, 30_000.0],
}
),
firm=pd.DataFrame(
{
"firm_id": [1, 2, 3],
"firm_weight": [100.0, 300.0, 50.0],
"firm_paybill": [2_000_000.0, 150_000.0, 60_000.0],
"firm_employees": [40.0, 5.0, 2.0],
}
),
fiscal_year=2026,
)
reform = {
"gov.hmrc.national_insurance.employment_allowance.amount": {
"2026-01-01.2100-12-31": 5_000
},
"gov.contrib.policyengine.firm_incidence.capital": {"2026-01-01.2100-12-31": 0.5},
"gov.contrib.policyengine.firm_incidence.consumer": {"2026-01-01.2100-12-31": 0.25},
"gov.contrib.policyengine.firm_incidence.labour": {"2026-01-01.2100-12-31": 0.25},
}

sim = Microsimulation(dataset=dataset, reform=reform)
sim.baseline.calculate("employment_allowance", 2026) # [10_500, 10_500, 7_500]
sim.calculate("employment_allowance", 2026) # [5_000, 5_000, 5_000]
sim.calculate("firm_tax_change_total", 2026) # [2_325_000, 2_325_000]
sim.calculate("firm_tax_incidence", 2026) # [377.81, 1_947.19]
```

### Firm tax change

Each firm's employer National Insurance before the allowance is 15% of its pay above £5,000 per employee. The allowance covers that liability up to the allowance amount.

| Firm | Weight | Employer NI before allowance | Allowance, current law | Allowance, reform | Extra tax per firm |
|---|---|---|---|---|---|
| 1 | 100 | £270,000 | £10,500 | £5,000 | £5,500 |
| 2 | 300 | £18,750 | £10,500 | £5,000 | £5,500 |
| 3 | 50 | £7,500 | £7,500 | £5,000 | £2,500 |

`firm_tax_change_total` weights each firm's extra tax by `firm_weight`: 100 × £5,500 + 300 × £5,500 + 50 × £2,500 = £2,325,000. Every household carries the same total.

### Household incidence

`firm_tax_incidence` gives each household a share of the total. The share combines three keys, weighted by the incidence parameters:

| Key | Household 1 | Household 2 | Incidence share |
|---|---|---|---|
| Capital: `shareholding` | 0 | 0.001 | 50% |
| Consumers: `consumption_shareholding` | 0.0004 | 0.0006 | 25% |
| Workers: share of weighted employment income | 0.00025 | 0.00075 | 25% |

Household 2 holds all of the corporate sector wealth: £100,000 out of a weighted total of 1,000 × £100,000, a share of 0.001. Consumption shares are £20,000 and £30,000 out of 1,000 × £50,000. Employment income shares are £25,000 and £75,000 out of 1,000 × £100,000.

- Household 1: £2,325,000 × (50% × 0 + 25% × 0.0004 + 25% × 0.00025) = £377.81.
- Household 2: £2,325,000 × (50% × 0.001 + 25% × 0.0006 + 25% × 0.00075) = £1,947.19.

Weighted by household, the incidence adds back to the firm total: 1,000 × (£377.81 + £1,947.19) = £2,325,000. The reform leaves `household_tax` and `gov_tax` unchanged for both households, since `firm_tax_incidence` is not yet a term of either.

Household `ni_employer` counts the change in gross employer National Insurance, so `firm_tax_change_total` subtracts the full change in the Employment Allowance, each simulation computing it on its own liabilities. Together they count the change in what firms pay after the allowance. A firm that stays under the allowance after a rate rise nets to zero: its gross liability and its allowance rise by the same amount, so the household side adds the rise and the firm side takes it off. The firm-side total is then negative, and with the default incidence it is spread by shareholding rather than to the workers whose gross National Insurance rose. That is acceptable only while `firm_tax_incidence` stays out of `household_tax`.
Loading
Loading