Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ policyengine_uk/calibration/*.h5
!docs/**/*.ipynb
!uprating_growth_factors.csv

# Virtual environments
# Virtual environments
.venv/
venv/
env/
Expand All @@ -82,4 +82,4 @@ coverage.xml
cover/

# Docs
**/_build/
**/_build/
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
fixed:
- Basic state pension calculation.
Original file line number Diff line number Diff line change
@@ -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 # Reported amount (under 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 # Capped at maximum (137.60 * 52)

- name: Non-basic state pension type returns zero for basic_state_pension
period: 2021
input:
people:
person1:
state_pension_reported: 5000
state_pension_type: NEW # Not basic pension
age: 70
output:
basic_state_pension: 0 # basic_state_pension is only for BASIC type

- 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
36 changes: 26 additions & 10 deletions policyengine_uk/variables/gov/dwp/basic_state_pension.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,38 @@ class basic_state_pension(Variable):

def formula(person, period, parameters):
simulation = person.simulation
if simulation.dataset is None:
return 0
try:
data_year = min(simulation.dataset.years)
except:
has_dataset = simulation.dataset is not None

# Determine the data year: from dataset if available, otherwise current
if has_dataset:
try:
data_year = min(simulation.dataset.years)
except:
data_year = period.start.year
else:
data_year = period.start.year

reported = person("state_pension_reported", data_year) / WEEKS_IN_YEAR
type = person("state_pension_type", period)
pension_type = person("state_pension_type", period)
maximum_basic_sp = parameters(
data_year
).gov.dwp.state_pension.basic_state_pension.amount

# For BASIC pension type, cap at the maximum; otherwise return 0
amount_in_data_year = where(
type == type.possible_values.BASIC,
pension_type == pension_type.possible_values.BASIC,
min_(reported, maximum_basic_sp),
0,
)
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

# Apply triple lock uprating only when using dataset
# (i.e., when data year differs from simulation period)
if has_dataset:
triple_lock = (
parameters.gov.economic_assumptions.indices.triple_lock
)
uprating = triple_lock(period) / triple_lock(data_year)
else:
uprating = 1

return amount_in_data_year * uprating * WEEKS_IN_YEAR