Skip to content

Commit

Permalink
more tetss
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Jul 6, 2024
1 parent ee8916e commit 40af2ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
33 changes: 18 additions & 15 deletions ogcore/pensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ def deriv_NDC(r, w, e, Y, per_rmn, p):
d_theta_empty = np.zeros(per_rmn)
delta_ret_amount = delta_ret(r, Y, p)
g_ndc_amount = g_ndc(r, Y, p)
print("g_ndc = ", g_ndc_amount)
print("delta_ret = ", delta_ret_amount)
d_theta = deriv_NDC_loop(
w,
e,
Expand Down Expand Up @@ -505,29 +507,29 @@ def g_ndc(r, Y, p):
Compute growth rate used for contributions to NDC pension
"""
if p.ndc_growth_rate == "r":
g_ndc = r
g_ndc = r[-1]
elif p.ndc_growth_rate == "Curr GDP":
g_ndc = (Y[1:] - Y[:-1]) / Y[:-1]
elif p.ndc_growth_rate == "LR GDP":
g_ndc = p.g_y + p.g_n
g_ndc = p.g_y[-1] + p.g_n[-1]
else:
g_ndc = p.g_y + p.g_n
g_ndc = p.g_y[-1] + p.g_n[-1]

return g_ndc


def g_dir(r, Y, p):
def g_dir(r, Y, g_y, g_n, dir_growth_rate):
"""
Compute growth rate used for contributions to NDC pension
"""
if p.dir_growth_rate == "r":
g_dir = r
elif p.dir_growth_rate == "Curr GDP":
if dir_growth_rate == "r":
g_dir = r[-1]
elif dir_growth_rate == "Curr GDP":
g_dir = (Y[1:] - Y[:-1]) / Y[:-1]
elif p.dir_growth_rate == "LR GDP":
g_dir = p.g_y + p.g_n
elif dir_growth_rate == "LR GDP":
g_dir = g_y[-1] + g_n[-1]
else:
g_dir = p.g_y + p.g_n
g_dir = g_y[-1] + g_n[-1]

return g_dir

Expand All @@ -538,7 +540,7 @@ def delta_ret(r, Y, p):
"""
surv_rates = 1 - p.mort_rates_SS
dir_delta_s_empty = np.zeros(p.S - p.retire + 1)
g_dir_value = g_dir(r, Y, p)
g_dir_value = g_dir(r, Y, p.g_y, p.g_n, p.dir_growth_rate)
print("G dir value type = ", type(p.S))
print("G dir value type = ", type(p.retire))
print("G dir value type = ", type(surv_rates))
Expand Down Expand Up @@ -577,15 +579,16 @@ def deriv_PS_loop(w, e, S, S_ret, per_rmn, d_theta, vpoint, factor):


@numba.jit
def deriv_NDC_loop(w, e, per_rmn, S, S_ret, tau_p, g_ndc, delta_ret, d_theta):

def deriv_NDC_loop(
w, e, per_rmn, S, S_ret, tau_p, g_ndc_value, delta_ret_value, d_theta
):
for s in range((S - per_rmn), S_ret):
d_theta[s - (S - per_rmn)] = (
tau_p
* w[s - (S - per_rmn)]
* e[s - (S - per_rmn)]
* delta_ret
* (1 + g_ndc) ** (S_ret - s - 1)
* delta_ret_value
* (1 + g_ndc_value) ** (S_ret - s - 1)
)

return d_theta
Expand Down
10 changes: 6 additions & 4 deletions tests/test_pensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ def test_deriv_S(args, deriv_PS_expected):
p.S = 4
p.retire = 2
per_rmn = p.S
p.g_y = 0.03
p.g_y = np.ones(p.T) * 0.03
p.g_n = np.ones(p.T) * 0.0
p.g_n_SS = 0.0
p.ndc_growth_rate = "LR GDP"
p.dir_growth_rate = "r"
Expand All @@ -336,7 +337,7 @@ def test_deriv_S(args, deriv_PS_expected):
p.mort_rates_SS = np.array([0.01, 0.05, 0.3, 1])
w = np.array([1.2, 1.1, 1.21, 1])
e = np.array([1.1, 1.11, 0.9, 0.87])
r = 0.02
r = np.ones(p.T) * 0.02
d_NDC_expected1 = np.array([0.757437326, 0.680222841, 0.0, 0.0])
args1 = (r, w, e, None, per_rmn, p)

Expand All @@ -345,7 +346,8 @@ def test_deriv_S(args, deriv_PS_expected):
p2.S = 4
p2.retire = 2
per_rmn2 = 3
p2.g_y = 0.04
p2.g_y = np.ones(p2.T) * 0.04
p2.g_n = np.ones(p2.T) * 0.0
p2.g_n_SS = 0.0
p2.ndc_growth_rate = "LR GDP"
p2.dir_growth_rate = "LR GDP"
Expand All @@ -354,7 +356,7 @@ def test_deriv_S(args, deriv_PS_expected):
p2.mort_rates_SS = np.array([0.1, 0.2, 0.4, 0.6, 1.0])
w2 = np.array([1.1, 1.21, 1.25])
e2 = np.array([1.11, 0.9, 1.0])
r2 = 0.04
r2 = np.ones(p2.T) * 0.04
d_NDC_expected2 = np.array([0.396808466, 0.0, 0.0])
args2 = (r2, w2, e2, None, per_rmn2, p2)

Expand Down

0 comments on commit 40af2ed

Please sign in to comment.