From ef165dfc6b060404a34524003c7dd083ca486a58 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 6 Jun 2026 00:50:49 +0100 Subject: [PATCH] Fix Class 4 NI annual maximum rate factor --- changelog.d/1765.md | 1 + .../tests/test_ni_class_4_maximum.py | 26 +++++++++++++++++++ .../class_4/ni_class_4_maximum.py | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 changelog.d/1765.md create mode 100644 policyengine_uk/tests/test_ni_class_4_maximum.py diff --git a/changelog.d/1765.md b/changelog.d/1765.md new file mode 100644 index 000000000..542bd1537 --- /dev/null +++ b/changelog.d/1765.md @@ -0,0 +1 @@ +- Correct the Class 4 National Insurance annual maximum calculation to use the current main Class 4 rate factor. diff --git a/policyengine_uk/tests/test_ni_class_4_maximum.py b/policyengine_uk/tests/test_ni_class_4_maximum.py new file mode 100644 index 000000000..108049c99 --- /dev/null +++ b/policyengine_uk/tests/test_ni_class_4_maximum.py @@ -0,0 +1,26 @@ +import pytest + +from policyengine_uk import Simulation + + +def test_class_4_annual_maximum_uses_current_main_rate_factor(): + year = 2026 + monthly_primary_class_1 = {f"{year}-{month:02d}": 500 for month in range(1, 13)} + sim = Simulation( + situation={ + "people": { + "person": { + "age": {year: 40}, + "self_employment_income": {year: 100_000}, + "ni_class_1_employee_primary": monthly_primary_class_1, + } + }, + "benunits": {"benunit": {"members": ["person"]}}, + "households": {"household": {"members": ["person"]}}, + } + ) + + assert sim.calculate("ni_class_4_maximum", year)[0] == pytest.approx( + 46_484, + abs=0.01, + ) diff --git a/policyengine_uk/variables/gov/hmrc/national_insurance/class_4/ni_class_4_maximum.py b/policyengine_uk/variables/gov/hmrc/national_insurance/class_4/ni_class_4_maximum.py index bfe1f4b5d..c7d44a059 100644 --- a/policyengine_uk/variables/gov/hmrc/national_insurance/class_4/ni_class_4_maximum.py +++ b/policyengine_uk/variables/gov/hmrc/national_insurance/class_4/ni_class_4_maximum.py @@ -30,7 +30,7 @@ def formula(person, period, parameters): case_1 = (step_4 >= 0) & (step_4 > other_aggregate_contributions) case_2 = (step_4 >= 0) & (step_4 <= other_aggregate_contributions) case_3 = step_4 < 0 - step_5 = step_4 * 100 / 9 + step_5 = step_4 / main_rate profits = person("self_employment_income", period) step_6 = lpl - min_(upl, profits) step_7 = max_(0, step_6 - step_5)