Skip to content

Commit 52e7480

Browse files
committed
tests with new parameter definitions
1 parent 699d4b5 commit 52e7480

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

ogcore/pensions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ def DB_amount(w, e, n, j, p):
189189
Calculate public pension from a defined benefits system.
190190
"""
191191
L_inc_avg = np.zeros(0)
192-
L_inc_avg_s = np.zeros(p.avg_earn_num_years)
192+
equiv_periods = int(round((p.S / 80.0) * p.avg_earn_num_years)) - 1
193+
L_inc_avg_s = np.zeros(equiv_periods)
193194

194195
if n.shape[0] < p.S:
195196
per_rmn = n.shape[0]
@@ -212,7 +213,7 @@ def DB_amount(w, e, n, j, p):
212213
L_inc_avg_s,
213214
L_inc_avg,
214215
DB,
215-
p.avg_earn_num_years,
216+
equiv_periods,
216217
p.alpha_db,
217218
p.yr_contr,
218219
)
@@ -232,15 +233,15 @@ def DB_amount(w, e, n, j, p):
232233
L_inc_avg_s,
233234
L_inc_avg,
234235
DB,
235-
p.avg_earn_num_years,
236+
equiv_periods,
236237
p.alpha_db,
237238
p.yr_contr,
238239
)
239240

240241
elif np.ndim(n) == 2:
241242
DB_sj = np.zeros((p.retire, p.J))
242243
DB = np.zeros((p.S, p.J))
243-
L_inc_avg_sj = np.zeros((p.avg_earn_num_years, p.J))
244+
L_inc_avg_sj = np.zeros((equiv_periods, p.J))
244245
DB = DB_2dim_loop(
245246
w,
246247
e,
@@ -251,7 +252,7 @@ def DB_amount(w, e, n, j, p):
251252
L_inc_avg_sj,
252253
L_inc_avg,
253254
DB,
254-
p.avg_earn_num_years,
255+
equiv_periods,
255256
p.alpha_db,
256257
p.yr_contr,
257258
)
@@ -443,7 +444,7 @@ def deriv_DB(w, e, per_rmn, p):
443444
"""
444445
Change in DB pension benefits for another unit of labor supply
445446
"""
446-
447+
equiv_periods = int(round((p.S / 80.0) * p.avg_earn_num_years)) - 1
447448
if per_rmn < (p.S - p.retire + 1):
448449
d_theta = np.zeros(p.S)
449450
else:
@@ -453,7 +454,7 @@ def deriv_DB(w, e, per_rmn, p):
453454
p.S,
454455
p.retire,
455456
per_rmn,
456-
p.avg_earn_num_years,
457+
equiv_periods,
457458
p.alpha_db,
458459
p.yr_contr,
459460
)

tests/test_pensions.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,24 @@ def test_replacement_rate_vals(n, w, factor, j, p_in, expected):
7373

7474

7575
p = Specifications()
76-
# p.update_specifications({
77-
# "S": 7,
78-
# "rep_rate_py": 0.2
79-
# })
8076
p.S = 7
81-
p.rep_rate_py = 0.2
77+
p.alpha_db = 0.2
8278
p.retire = 4
83-
p.last_career_yrs = 3
79+
p.avg_earn_num_years = 50
8480
p.yr_contr = 4
8581
p.g_y = np.ones(p.T) * 0.03
8682
j = 1
8783
w = np.array([1.2, 1.1, 1.21, 1.0, 1.01, 0.99, 0.8])
8884
e = np.array([1.1, 1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
8985
n = np.array([0.4, 0.45, 0.4, 0.42, 0.3, 0.2, 0.2])
86+
equiv_periods = int(round((p.S / 80.0) * p.avg_earn_num_years)) - 1
9087
L_inc_avg = np.zeros(0)
91-
L_inc_avg_s = np.zeros(p.last_career_yrs)
88+
L_inc_avg_s = np.zeros(equiv_periods)
9289
DB = np.zeros(p.S)
9390
DB_loop_expected1 = np.array(
9491
[0, 0, 0, 0, 0.337864778, 0.327879365, 0.318189065]
9592
)
93+
9694
args1 = (
9795
w,
9896
e,
@@ -103,8 +101,8 @@ def test_replacement_rate_vals(n, w, factor, j, p_in, expected):
103101
L_inc_avg_s,
104102
L_inc_avg,
105103
DB,
106-
p.last_career_yrs,
107-
p.rep_rate_py,
104+
equiv_periods,
105+
p.alpha_db,
108106
p.yr_contr,
109107
)
110108

@@ -154,24 +152,25 @@ def test_DB_1dim_loop(args, DB_loop_expected):
154152
p.S = 7
155153
p.retire = 4
156154
per_rmn = p.S
157-
p.last_career_yrs = 3
155+
p.avg_earn_num_years = 50
158156
p.yr_contr = p.retire
159-
p.rep_rate_py = 0.2
157+
p.alpha_db = 0.2
160158
p.g_y = np.ones(p.T) * 0.03
161159
w = np.array([1.2, 1.1, 1.21, 1, 1.01, 0.99, 0.8])
162160
e = np.array([1.1, 1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
163161
deriv_DB_loop_expected = np.array(
164162
[0.352, 0.3256, 0.2904, 0.232, 0.0, 0.0, 0.0]
165163
)
166164
d_theta_empty = np.zeros_like(w)
165+
equiv_periods = int(round((p.S / 80.0) * p.avg_earn_num_years)) - 1
167166
args3 = (
168167
w,
169168
e,
170169
p.S,
171170
p.retire,
172171
per_rmn,
173-
p.last_career_yrs,
174-
p.rep_rate_py,
172+
equiv_periods,
173+
p.alpha_db,
175174
p.yr_contr,
176175
)
177176

@@ -228,9 +227,9 @@ def test_deriv_PS_loop(args, deriv_PS_loop_expected):
228227
p = Specifications()
229228
p.S = 7
230229
p.retire = 4
231-
p.last_career_yrs = 3
230+
p.avg_earn_num_years = 50
232231
p.yr_contr = p.retire
233-
p.rep_rate_py = 0.2
232+
p.alpha_db = 0.2
234233
p.g_y = np.ones(p.T) * 0.03
235234
n_ddb1 = np.array([0.4, 0.45, 0.4, 0.42, 0.3, 0.2, 0.2])
236235
w_ddb1 = np.array([1.2, 1.1, 1.21, 1, 1.01, 0.99, 0.8])
@@ -246,7 +245,7 @@ def test_deriv_PS_loop(args, deriv_PS_loop_expected):
246245
p2.retire = 5
247246
p2.last_career_yrs = 2
248247
p2.yr_contr = p2.retire
249-
p2.rep_rate_py = 0.2
248+
p2.alpha_db = 0.2
250249
p2.g_y = 0.03
251250
n_ddb2 = np.array([0.45, 0.4, 0.42, 0.3, 0.2, 0.2])
252251
w_ddb1 = np.array([1.1, 1.21, 1, 1.01, 0.99, 0.8])
@@ -387,9 +386,9 @@ def test_deriv_NDC(args, d_NDC_expected):
387386
p.pension_system = "Defined Benefits"
388387
p.S = 7
389388
p.retire = 4
390-
p.last_career_yrs = 3
389+
p.avg_earn_num_years = 50
391390
p.yr_contr = p.retire
392-
p.rep_rate_py = 0.2
391+
p.alpha_db = 0.2
393392
p.g_y = np.ones(p.T) * 0.03
394393
w_db = np.array([1.2, 1.1, 1.21, 1.0, 1.01, 0.99, 0.8])
395394
e_db = np.array([1.1, 1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
@@ -449,14 +448,16 @@ def test_deriv_NDC(args, d_NDC_expected):
449448
p4 = Specifications()
450449
p4.pension_system = "US-Style Social Security"
451450
p4.S = 7
452-
p4.retire = 4
451+
p4.retire = (np.ones(p4.T) * 4).astype(int)
453452
w_ss = np.array([1.2, 1.1, 1.21, 1.0, 1.01, 0.99, 0.8])
454453
e_ss = np.array([1.1, 1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
455454
n_ss = np.array([0.4, 0.45, 0.4, 0.42, 0.3, 0.2, 0.2])
456455
omegas = (1 / p4.S) * np.ones(p4.S)
457-
theta = 0.4
458-
p.replacement_rate_adjust = np.ones(p4.T)
459-
pension_expected_ss = [0, 0, 0, 0, 0.004164689, 0.004041603, 0.003922156]
456+
theta = np.array([0.4, 0.4])
457+
p4.replacement_rate_adjust = np.ones(p4.T)
458+
pension_expected_ss = [0, 0, 0, 0, 0.404, 0.396, 0.32]
459+
method = "TPI"
460+
shift = False
460461
args_ss = (r, w_ss, n_ss, Y, theta, t, j, shift, method, e_ss, factor, p4)
461462

462463

@@ -592,9 +593,9 @@ def test_delta_ret_loop(args, dir_delta_ret_expected):
592593
p = Specifications()
593594
p.S = 7
594595
p.retire = 4
595-
p.last_career_yrs = 3
596+
p.avg_earn_num_years = 50
596597
p.yr_contr = p.retire
597-
p.rep_rate_py = 0.2
598+
p.alpha_db = 0.2
598599
p.g_y = np.ones(p.T) * 0.03
599600
j = 1
600601
w = np.array([1.2, 1.1, 1.21, 1.0, 1.01, 0.99, 0.8])
@@ -607,9 +608,9 @@ def test_delta_ret_loop(args, dir_delta_ret_expected):
607608
p2 = Specifications()
608609
p2.S = 7
609610
p2.retire = 4
610-
p2.last_career_yrs = 3
611+
p.avg_earn_num_years = 50
611612
p2.yr_contr = p2.retire
612-
p2.rep_rate_py = 0.2
613+
p2.alpha_db = 0.2
613614
p2.g_y = np.ones(p2.T) * 0.03
614615
j = 1
615616
w2 = np.array([1.21, 1.0, 1.01, 0.99, 0.8])
@@ -663,9 +664,9 @@ def test_DB(args, DB_expected):
663664
p.S = 7
664665
p.retire = 4
665666
per_rmn = p.S
666-
p.last_career_yrs = 3
667+
p.avg_earn_num_years = 50
667668
p.yr_contr = p.retire
668-
p.rep_rate_py = 0.2
669+
p.alpha_db = 0.2
669670
w_ddb = np.array([1.2, 1.1, 1.21, 1, 1.01, 0.99, 0.8])
670671
e_ddb = np.array([1.1, 1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
671672
p.g_y = np.ones(p.T) * 0.03

0 commit comments

Comments
 (0)