From 333a6b96c999ccc7aec034af62a085135903bf22 Mon Sep 17 00:00:00 2001 From: Vahid Ahmadi Date: Thu, 24 Jul 2025 12:51:42 +0100 Subject: [PATCH 1/2] state pension edit --- changelog_entry.yaml | 2 +- .../baseline/gov/dwp/basic_state_pension.yaml | 44 +++++++++++++++++++ .../variables/gov/dwp/basic_state_pension.py | 28 ++++++++---- 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 policyengine_uk/tests/policy/baseline/gov/dwp/basic_state_pension.yaml diff --git a/changelog_entry.yaml b/changelog_entry.yaml index 2de94b35e..d913d2c0e 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -1,4 +1,4 @@ - bump: patch changes: fixed: - - Parameterize age 35 threshold in LHA shared accommodation rules \ No newline at end of file + - Basic state pension calculation. \ No newline at end of file diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/basic_state_pension.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/basic_state_pension.yaml new file mode 100644 index 000000000..a802fee73 --- /dev/null +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/basic_state_pension.yaml @@ -0,0 +1,44 @@ +- name: Basic state pension calculation with normal parameters + period: 2021 + input: + people: + person1: + state_pension_reported: 5000 + state_pension_type: BASIC + age: 70 + output: + basic_state_pension: 5000 # Should be capped at the minimum of reported and maximum + +- name: Basic state pension caps at maximum when reported exceeds maximum + period: 2021 + input: + people: + person1: + state_pension_reported: 10000 # Higher than maximum + state_pension_type: BASIC + age: 70 + output: + basic_state_pension: 7155.2 # Should be capped at maximum (137.60 * 52) + +- name: Non-basic state pension not affected by basic pension maximum + period: 2021 + input: + people: + person1: + state_pension_reported: 5000 + state_pension_type: NEW # Not basic pension + age: 70 + output: + basic_state_pension: 5000 # Should not be affected by basic pension maximum + +- name: Basic state pension should be zero when maximum is zero + period: 2021 + input: + gov.dwp.state_pension.basic_state_pension.amount: 0 + people: + person1: + state_pension_reported: 5000 + state_pension_type: BASIC + age: 70 + output: + basic_state_pension: 0 \ No newline at end of file diff --git a/policyengine_uk/variables/gov/dwp/basic_state_pension.py b/policyengine_uk/variables/gov/dwp/basic_state_pension.py index 549dda4de..b94ad768d 100644 --- a/policyengine_uk/variables/gov/dwp/basic_state_pension.py +++ b/policyengine_uk/variables/gov/dwp/basic_state_pension.py @@ -10,11 +10,16 @@ class basic_state_pension(Variable): def formula(person, period, parameters): simulation = person.simulation - if simulation.dataset is None: - return 0 + has_dataset = simulation.dataset is not None + + data_year = simulation.dataset.time_period if has_dataset else period + + reported = where( + has_dataset, + person("state_pension_reported", data_year) / WEEKS_IN_YEAR, + person("state_pension_reported", period) / WEEKS_IN_YEAR, + ) - data_year = simulation.dataset.time_period - reported = person("state_pension_reported", data_year) / WEEKS_IN_YEAR type = person("state_pension_type", period) maximum_basic_sp = parameters( data_year @@ -22,8 +27,15 @@ def formula(person, period, parameters): amount_in_data_year = where( type == type.possible_values.BASIC, min_(reported, maximum_basic_sp), - 0, + reported, ) - triple_lock = parameters.gov.economic_assumptions.indices.triple_lock - uprating_since_data_year = triple_lock(period) / triple_lock(data_year) - return amount_in_data_year * uprating_since_data_year * WEEKS_IN_YEAR + uprating_factor = where( + has_dataset, + parameters.gov.economic_assumptions.yoy_growth.triple_lock(period) + / parameters.gov.economic_assumptions.yoy_growth.triple_lock( + data_year + ), + 1, + ) + + return amount_in_data_year * uprating_factor * WEEKS_IN_YEAR From 026f135eef62982b7efdf6803b92af33afbbf566 Mon Sep 17 00:00:00 2001 From: Vahid Ahmadi Date: Thu, 24 Jul 2025 12:58:53 +0100 Subject: [PATCH 2/2] state pension edit --- changelog_entry.yaml | 2 +- .../baseline/gov/dwp/basic_state_pension.yaml | 44 +++++++++++++++++++ .../variables/gov/dwp/basic_state_pension.py | 28 ++++++++---- 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 policyengine_uk/tests/policy/baseline/gov/dwp/basic_state_pension.yaml diff --git a/changelog_entry.yaml b/changelog_entry.yaml index 2de94b35e..d913d2c0e 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -1,4 +1,4 @@ - bump: patch changes: fixed: - - Parameterize age 35 threshold in LHA shared accommodation rules \ No newline at end of file + - Basic state pension calculation. \ No newline at end of file diff --git a/policyengine_uk/tests/policy/baseline/gov/dwp/basic_state_pension.yaml b/policyengine_uk/tests/policy/baseline/gov/dwp/basic_state_pension.yaml new file mode 100644 index 000000000..a802fee73 --- /dev/null +++ b/policyengine_uk/tests/policy/baseline/gov/dwp/basic_state_pension.yaml @@ -0,0 +1,44 @@ +- name: Basic state pension calculation with normal parameters + period: 2021 + input: + people: + person1: + state_pension_reported: 5000 + state_pension_type: BASIC + age: 70 + output: + basic_state_pension: 5000 # Should be capped at the minimum of reported and maximum + +- name: Basic state pension caps at maximum when reported exceeds maximum + period: 2021 + input: + people: + person1: + state_pension_reported: 10000 # Higher than maximum + state_pension_type: BASIC + age: 70 + output: + basic_state_pension: 7155.2 # Should be capped at maximum (137.60 * 52) + +- name: Non-basic state pension not affected by basic pension maximum + period: 2021 + input: + people: + person1: + state_pension_reported: 5000 + state_pension_type: NEW # Not basic pension + age: 70 + output: + basic_state_pension: 5000 # Should not be affected by basic pension maximum + +- name: Basic state pension should be zero when maximum is zero + period: 2021 + input: + gov.dwp.state_pension.basic_state_pension.amount: 0 + people: + person1: + state_pension_reported: 5000 + state_pension_type: BASIC + age: 70 + output: + basic_state_pension: 0 \ No newline at end of file diff --git a/policyengine_uk/variables/gov/dwp/basic_state_pension.py b/policyengine_uk/variables/gov/dwp/basic_state_pension.py index 549dda4de..b94ad768d 100644 --- a/policyengine_uk/variables/gov/dwp/basic_state_pension.py +++ b/policyengine_uk/variables/gov/dwp/basic_state_pension.py @@ -10,11 +10,16 @@ class basic_state_pension(Variable): def formula(person, period, parameters): simulation = person.simulation - if simulation.dataset is None: - return 0 + has_dataset = simulation.dataset is not None + + data_year = simulation.dataset.time_period if has_dataset else period + + reported = where( + has_dataset, + person("state_pension_reported", data_year) / WEEKS_IN_YEAR, + person("state_pension_reported", period) / WEEKS_IN_YEAR, + ) - data_year = simulation.dataset.time_period - reported = person("state_pension_reported", data_year) / WEEKS_IN_YEAR type = person("state_pension_type", period) maximum_basic_sp = parameters( data_year @@ -22,8 +27,15 @@ def formula(person, period, parameters): amount_in_data_year = where( type == type.possible_values.BASIC, min_(reported, maximum_basic_sp), - 0, + reported, ) - triple_lock = parameters.gov.economic_assumptions.indices.triple_lock - uprating_since_data_year = triple_lock(period) / triple_lock(data_year) - return amount_in_data_year * uprating_since_data_year * WEEKS_IN_YEAR + uprating_factor = where( + has_dataset, + parameters.gov.economic_assumptions.yoy_growth.triple_lock(period) + / parameters.gov.economic_assumptions.yoy_growth.triple_lock( + data_year + ), + 1, + ) + + return amount_in_data_year * uprating_factor * WEEKS_IN_YEAR