Skip to content

Commit 164a4dd

Browse files
MaxGhenisclaude
andcommitted
Implement CPP retirement pension
- Add CPP retirement pension parameters (maximum, average, eligibility age) - Implement eligibility based on age 60+ and contribution history - Calculate benefit proportional to years of contribution (up to 40 years) - Use average monthly benefit as basis for calculation - Add test coverage for various age and contribution scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 78aef80 commit 164a4dd

7 files changed

Lines changed: 160 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
description: Average monthly CPP retirement pension at age 65
2+
values:
3+
2020-01-01: 710.41
4+
2021-01-01: 702.77
5+
2022-01-01: 727.61
6+
2023-01-01: 758.32
7+
2024-01-01: 816.52
8+
2025-01-01: 844.53
9+
metadata:
10+
unit: currency-CAD
11+
period: month
12+
label: CPP average monthly retirement pension
13+
reference:
14+
- title: CPP retirement pension amount
15+
href: https://www.canada.ca/en/services/benefits/publicpensions/cpp/cpp-benefit/amount.html
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
description: Minimum age for CPP retirement pension eligibility
2+
values:
3+
2020-01-01: 60
4+
metadata:
5+
unit: year
6+
period: year
7+
label: CPP retirement pension eligibility age
8+
reference:
9+
- title: CPP retirement pension eligibility
10+
href: https://www.canada.ca/en/services/benefits/publicpensions/cpp/cpp-benefit/eligibility.html
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
description: Maximum monthly CPP retirement pension at age 65
2+
values:
3+
2020-01-01: 1_175.83
4+
2021-01-01: 1_203.75
5+
2022-01-01: 1_253.59
6+
2023-01-01: 1_306.57
7+
2024-01-01: 1_364.60
8+
2025-01-01: 1_433.00
9+
metadata:
10+
unit: currency-CAD
11+
period: month
12+
label: CPP maximum monthly retirement pension
13+
reference:
14+
- title: CPP retirement pension amount
15+
href: https://www.canada.ca/en/services/benefits/publicpensions/cpp/cpp-benefit/amount.html
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
- name: CPP retirement pension with full contributions
2+
period: 2024
3+
input:
4+
age: 65
5+
cpp_years_of_contribution: 40
6+
output:
7+
# Full contributions (40 years) = average monthly benefit
8+
# $816.52 * 12 = $9,798.24
9+
cpp_retirement_pension: 9_798.24
10+
11+
- name: CPP retirement pension with partial contributions
12+
period: 2024
13+
input:
14+
age: 65
15+
cpp_years_of_contribution: 20
16+
output:
17+
# 20/40 years = 50% of average benefit
18+
# $816.52 * 0.5 * 12 = $4,899.12
19+
cpp_retirement_pension: 4_899.12
20+
21+
- name: No pension below age 60
22+
period: 2024
23+
input:
24+
age: 55
25+
cpp_years_of_contribution: 30
26+
output:
27+
cpp_retirement_pension: 0
28+
29+
- name: No pension without contributions
30+
period: 2024
31+
input:
32+
age: 65
33+
cpp_years_of_contribution: 0
34+
output:
35+
cpp_retirement_pension: 0
36+
37+
- name: CPP retirement pension for 2025
38+
period: 2025
39+
input:
40+
age: 70
41+
cpp_years_of_contribution: 45
42+
output:
43+
# Capped at 40 years = full average benefit
44+
# $844.53 * 12 = $10,134.36
45+
cpp_retirement_pension: 10_134.36
46+
47+
- name: Minimum contribution scenario
48+
period: 2024
49+
input:
50+
age: 60
51+
cpp_years_of_contribution: 1
52+
output:
53+
# 1/40 years = 2.5% of average benefit
54+
# $816.52 * 0.025 * 12 = $244.956
55+
cpp_retirement_pension: 244.956
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from policyengine_canada.model_api import *
2+
3+
4+
class cpp_retirement_eligible(Variable):
5+
value_type = bool
6+
entity = Person
7+
label = "Eligible for CPP retirement pension"
8+
definition_period = YEAR
9+
documentation = "Whether person is eligible for CPP retirement pension"
10+
11+
def formula(person, period, parameters):
12+
p = parameters(period).gov.cra.benefits.cpp.retirement
13+
14+
# Check age requirement (60+)
15+
age = person("age", period)
16+
meets_age = age >= p.eligibility_age
17+
18+
# Check contribution requirement (simplified - at least 1 year)
19+
years_contributed = person("cpp_years_of_contribution", period)
20+
has_contributions = years_contributed > 0
21+
22+
return meets_age & has_contributions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from policyengine_canada.model_api import *
2+
3+
4+
class cpp_retirement_pension(Variable):
5+
value_type = float
6+
entity = Person
7+
label = "CPP retirement pension"
8+
definition_period = YEAR
9+
unit = CAD
10+
documentation = "Annual CPP retirement pension amount"
11+
adds = ["cpp_retirement_pension"]
12+
13+
def formula(person, period, parameters):
14+
p = parameters(period).gov.cra.benefits.cpp.retirement
15+
16+
# Check eligibility
17+
eligible = person("cpp_retirement_eligible", period)
18+
19+
# Simplified calculation based on years of contribution
20+
# Use average between 0 and maximum based on contribution years
21+
years_contributed = person("cpp_years_of_contribution", period)
22+
23+
# Assume full contributions after 40 years
24+
contribution_factor = min_(years_contributed / 40, 1)
25+
26+
# Calculate monthly amount between 0 and maximum
27+
# For simplicity, use average as midpoint
28+
monthly_amount = contribution_factor * p.average_monthly
29+
30+
# Convert to annual
31+
annual_amount = monthly_amount * 12
32+
33+
return where(eligible, annual_amount, 0)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from policyengine_canada.model_api import *
2+
3+
4+
class cpp_years_of_contribution(Variable):
5+
value_type = float
6+
entity = Person
7+
label = "Years of CPP contributions"
8+
definition_period = YEAR
9+
unit = "year"
10+
documentation = "Number of years person has contributed to CPP"

0 commit comments

Comments
 (0)