Skip to content

Commit 4615306

Browse files
committed
more tests
1 parent a5f3b5b commit 4615306

File tree

2 files changed

+133
-21
lines changed

2 files changed

+133
-21
lines changed

ogcore/pensions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ def DB_amount(w, e, n, j, p):
197197
w_S = np.append((p.w_preTP * np.ones(p.S))[:(-per_rmn)], w)
198198
n_S = np.append(p.n_preTP[:(-per_rmn), j], n)
199199

200-
DB_s = np.zeros(p.retirement_age)
200+
DB_s = np.zeros(p.retire)
201201
DB = np.zeros(p.S)
202202
# TODO: we set a rep_rate_py in params, but not rep_rate. What is it???
203203
DB = DB_1dim_loop(
204204
w_S,
205205
p.e[:, j],
206206
n_S,
207-
p.retirement_age,
207+
p.retire,
208208
p.S,
209209
p.g_y,
210210
L_inc_avg_s,
@@ -219,7 +219,7 @@ def DB_amount(w, e, n, j, p):
219219

220220
else:
221221
if np.ndim(n) == 1:
222-
DB_s = np.zeros(p.retirement_age)
222+
DB_s = np.zeros(p.retire)
223223
DB = np.zeros(p.S)
224224
DB = DB_1dim_loop(
225225
w,
@@ -238,14 +238,14 @@ def DB_amount(w, e, n, j, p):
238238
)
239239

240240
elif np.ndim(n) == 2:
241-
DB_sj = np.zeros((p.retirement_age, p.J))
241+
DB_sj = np.zeros((p.retire, p.J))
242242
DB = np.zeros((p.S, p.J))
243243
L_inc_avg_sj = np.zeros((p.last_career_yrs, p.J))
244244
DB = DB_2dim_loop(
245245
w,
246246
e,
247247
n,
248-
p.retirement_age,
248+
p.retire,
249249
p.S,
250250
p.g_y,
251251
L_inc_avg_sj,
@@ -553,7 +553,7 @@ def delta_ret(self, r, Y, p):
553553

554554
@numba.jit
555555
def deriv_DB_loop(
556-
w, e, S, S_ret, per_rmn, d_theta, last_career_yrs, rep_rate_py, yr_contr
556+
w, e, S, S_ret, per_rmn, last_career_yrs, rep_rate_py, yr_contr
557557
):
558558
d_theta = np.zeros(per_rmn)
559559
num_per_retire = S - S_ret
@@ -626,9 +626,9 @@ def PS_2dim_loop(w, e, n, S_ret, S, J, g_y, vpoint, factor, L_inc_avg_sj, PS):
626626
L_inc_avg_sj[s, :] = (
627627
w[s] / np.exp(g_y * (u - s)) * e[s, :] * n[s, :]
628628
)
629-
PS[u, :] = (
630-
MONTHS_IN_A_YEAR * vpoint * L_inc_avg_sj.sum(axis=0)
631-
) / (factor * THOUSAND)
629+
PS[u, :] = (MONTHS_IN_A_YEAR * vpoint * L_inc_avg_sj.sum(axis=0)) / (
630+
factor * THOUSAND
631+
)
632632

633633
return PS
634634

tests/test_pensions.py

Lines changed: 124 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_replacement_rate_vals(n, w, factor, j, p_in, expected):
7979
# })
8080
p.S = 7
8181
p.rep_rate_py = 0.2
82-
p.retirement_age = 4
82+
p.retire = 4
8383
p.last_career_yrs = 3
8484
p.yr_contr = 4
8585
p.g_y = 0.03
@@ -89,24 +89,136 @@ def test_replacement_rate_vals(n, w, factor, j, p_in, expected):
8989
n = np.array([0.4, 0.45, 0.4, 0.42, 0.3, 0.2, 0.2])
9090
L_inc_avg = np.zeros(0)
9191
L_inc_avg_s = np.zeros(p.last_career_yrs)
92-
DB_s = np.zeros(p.retirement_age)
9392
DB = np.zeros(p.S)
94-
DB_loop_expected1 = np.array([0, 0, 0, 0, 0.337864778, 0.327879365, 0.318189065])
95-
args1 = w, e, n, p.retirement_age, p.S, p.g_y, L_inc_avg_s, L_inc_avg, DB_s, DB
93+
DB_loop_expected1 = np.array(
94+
[0, 0, 0, 0, 0.337864778, 0.327879365, 0.318189065]
95+
)
96+
args1 = (
97+
w,
98+
e,
99+
n,
100+
p.retire,
101+
p.S,
102+
p.g_y,
103+
L_inc_avg_s,
104+
L_inc_avg,
105+
DB,
106+
p.last_career_yrs,
107+
p.rep_rate_py,
108+
p.yr_contr,
109+
)
96110

97111
test_data = [(args1, DB_loop_expected1)]
98-
# (classes2, args2, NDC_expected2)]
99112

100-
@pytest.mark.parametrize('args,DB_loop_expected', test_data,
101-
ids=['SS/Complete'])
113+
114+
@pytest.mark.parametrize(
115+
"args,DB_loop_expected", test_data, ids=["SS/Complete"]
116+
)
102117
def test_DB_1dim_loop(args, DB_loop_expected):
103118
"""
104119
Test of the pensions.DB_1dim_loop() function.
105120
"""
106121

107-
w, e, n, S_ret, S, g_y, L_inc_avg_s, L_inc_avg, DB_s, DB = args
122+
(
123+
w,
124+
e,
125+
n,
126+
S_ret,
127+
S,
128+
g_y,
129+
L_inc_avg_s,
130+
L_inc_avg,
131+
DB,
132+
last_career_yrs,
133+
rep_rate_py,
134+
yr_contr,
135+
) = args
108136
DB_loop = pensions.DB_1dim_loop(
109-
w, e, n, S_ret, S, g_y, L_inc_avg_s, L_inc_avg, DB,
110-
p.last_career_yrs,
111-
p.rep_rate_py, p.yr_contr)
112-
assert (np.allclose(DB_loop, DB_loop_expected))
137+
w,
138+
e,
139+
n,
140+
S_ret,
141+
S,
142+
g_y,
143+
L_inc_avg_s,
144+
L_inc_avg,
145+
DB,
146+
last_career_yrs,
147+
rep_rate_py,
148+
yr_contr,
149+
)
150+
assert np.allclose(DB_loop, DB_loop_expected)
151+
152+
153+
p = Specifications()
154+
p.S = 7
155+
p.retire = 4
156+
per_rmn = p.S
157+
p.last_career_yrs = 3
158+
p.yr_contr = p.retire
159+
p.rep_rate_py = 0.2
160+
p.g_y = 0.03
161+
w = np.array([1.2, 1.1, 1.21, 1, 1.01, 0.99, 0.8])
162+
e = np.array([1.1, 1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
163+
deriv_DB_loop_expected = np.array(
164+
[0.352, 0.3256, 0.2904, 0.232, 0.0, 0.0, 0.0]
165+
)
166+
d_theta_empty = np.zeros_like(w)
167+
args3 = (
168+
w,
169+
e,
170+
p.S,
171+
p.retire,
172+
per_rmn,
173+
p.last_career_yrs,
174+
p.rep_rate_py,
175+
p.yr_contr,
176+
)
177+
178+
test_data = [(args3, deriv_DB_loop_expected)]
179+
180+
181+
@pytest.mark.parametrize("args,deriv_DB_loop_expected", test_data)
182+
def test_deriv_DB_loop(args, deriv_DB_loop_expected):
183+
"""
184+
Test of the pensions.deriv_DB_loop() function.
185+
"""
186+
(w, e, S, retire, per_rmn, last_career_yrs, rep_rate_py, yr_contr) = args
187+
deriv_DB_loop = pensions.deriv_DB_loop(
188+
w, e, S, retire, per_rmn, last_career_yrs, rep_rate_py, yr_contr
189+
)
190+
191+
assert np.allclose(deriv_DB_loop, deriv_DB_loop_expected)
192+
193+
194+
p = Specifications()
195+
p.S = 7
196+
p.retire = 4
197+
p.vpoint = 0.4
198+
w = np.array([1.2, 1.1, 1.21, 1, 1.01, 0.99, 0.8])
199+
e = np.array([1.1, 1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
200+
p.g_y = 0.03
201+
factor = 2
202+
d_theta_empty = np.zeros_like(w)
203+
deriv_PS_loop_expected1 = np.array(
204+
[0.003168, 0.0029304, 0.0026136, 0.002088, 0, 0, 0]
205+
)
206+
args3 = (w, e, p.S, p.retire, per_rmn, d_theta_empty, p.vpoint, factor)
207+
208+
test_data = [(args3, deriv_PS_loop_expected1)]
209+
210+
211+
@pytest.mark.parametrize(
212+
"args,deriv_PS_loop_expected", test_data, ids=["SS/Complete"]
213+
)
214+
def test_deriv_PS_loop(args, deriv_PS_loop_expected):
215+
"""
216+
Test of the pensions.deriv_PS_loop() function.
217+
"""
218+
(w, e, S, retire, per_rmn, d_theta_empty, vpoint, factor) = args
219+
220+
deriv_PS_loop = pensions.deriv_PS_loop(
221+
w, e, S, retire, per_rmn, d_theta_empty, vpoint, factor
222+
)
223+
224+
assert np.allclose(deriv_PS_loop, deriv_PS_loop_expected)

0 commit comments

Comments
 (0)