Skip to content

Commit

Permalink
Updated get_RM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rickecon committed Sep 10, 2024
1 parent 9bd48b2 commit 7344ff5
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ogcore/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ def get_RM(Y, p, method):
RM[t] = ((1 + p.g_RM[t]) / (np.exp(p.g_y) * (1 + p.g_n[t]))) * RM[
t - 1
]
rho_vec = np.linspace(0, 1, p.tG2 - p.tG1)
for t in range(p.tG1, p.tG2 - 1):
RM[t] = p.rho_RM * p.alpha_RM_T * Y[t] + (
(1 - p.rho_RM)
RM[t] = (
rho_vec[t - p.tG1] * p.alpha_RM_T * Y[t]
+ (1 - rho_vec[t - p.tG1])
* ((1 + p.g_RM[t]) / (np.exp(p.g_y) * (1 + p.g_n[t])))
* RM[t - 1]
)
Expand Down
1 change: 1 addition & 0 deletions ogcore/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def compute_default_params(self):
"zeta_K",
"r_gov_scale",
"r_gov_shift",
"g_RM",
]
for item in tp_param_list:
param_in = getattr(self, item)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_SS.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ def test_euler_equation_solver(input_tuple, ubi_j, p, expected):
"initial_guess_TR_SS": 0.06,
}
filename2 = "run_SS_baseline_use_zeta.pkl"
param_updates3 = {"zeta_K": [1.0], "initial_guess_r_SS": 0.10}
param_updates3 = {"zeta_K": [1.0], "initial_guess_r_SS": 0.04}
filename3 = "run_SS_baseline_small_open.pkl"
param_updates4 = {
"zeta_K": [1.0],
Expand All @@ -1021,7 +1021,7 @@ def test_euler_equation_solver(input_tuple, ubi_j, p, expected):
"initial_guess_TR_SS": 0.06,
}
filename6 = "run_SS_reform_use_zeta.pkl"
param_updates7 = {"zeta_K": [1.0], "initial_guess_r_SS": 0.10}
param_updates7 = {"zeta_K": [1.0], "initial_guess_r_SS": 0.04}
filename7 = "run_SS_reform_small_open.pkl"
param_updates8 = {
"zeta_K": [1.0],
Expand Down
179 changes: 179 additions & 0 deletions tests/test_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,185 @@ def test_get_BQ(r, b_splus1, j, p, method, PreTP, expected):
BQ = aggr.get_BQ(r, b_splus1, j, p, method, PreTP)
assert np.allclose(BQ, expected)

# Set up test for get_RM
Y_RM_1 = 0.625
p_RM_1 = Specifications(baseline=True)
p_RM_1.alpha_RM_1 = 0.05
p_RM_1.alpha_RM_T = 0.05
p_RM_1.g_RM = (
((np.exp(p_RM_1.g_y) * (1 + p_RM_1.g_n_ss)) - 1) *
np.ones(p_RM_1.T + p_RM_1.S)
)
Y_RM_2 = Y_RM_1 * np.ones(p_RM_1.T + p_RM_1.S)
p_RM_3 = copy.deepcopy(p_RM_1)
p_RM_3.g_RM = (
((np.exp(p_RM_1.g_y) * (1 + p_RM_1.g_n_ss)) - 1 + 0.005) *
np.ones(p_RM_1.T + p_RM_1.S)
)
expected_RM_1 = 0.03125
expected_RM_2 = np.array(
[
0.03125 , 0.03107792, 0.03091237, 0.03075153, 0.0305999 , 0.03045509,
0.03031471, 0.03018496, 0.03007849, 0.02998137, 0.02989228, 0.02981457,
0.02974598, 0.02967802, 0.02961485, 0.0295564 , 0.02950259, 0.02945346,
0.02940861, 0.02936794, 0.0293313 , 0.02930701, 0.02929526, 0.02929475,
0.02930538, 0.02932674, 0.02936019, 0.02940232, 0.02945246, 0.02950992,
0.02957364, 0.02964255, 0.02971554, 0.02979144, 0.02986916, 0.02994745,
0.03002574, 0.03010308, 0.03017881, 0.03025273, 0.03032412, 0.03039269,
0.03045844, 0.03052127, 0.03058095, 0.03063723, 0.03069058, 0.03074124,
0.03078938, 0.03083523, 0.03087825, 0.03091818, 0.03095533, 0.0309901 ,
0.03102291, 0.03105326, 0.03108156, 0.03110763, 0.03113148, 0.03115336,
0.03117259, 0.03118943, 0.03120391, 0.03121603, 0.03122628, 0.03123451,
0.03124089, 0.03124577, 0.03124937, 0.03125197, 0.03125341, 0.03125376,
0.03125323, 0.03125219, 0.03125085, 0.03124934, 0.0312479 , 0.03124663,
0.03124557, 0.03124484, 0.03124424, 0.03124372, 0.03124352, 0.03124368,
0.03124409, 0.03124472, 0.03124558, 0.03124652, 0.03124735, 0.03124826,
0.03124923, 0.03125015, 0.031251 , 0.03125182, 0.0312525 , 0.031253 ,
0.03125329, 0.03125338, 0.03125329, 0.03125304, 0.03125267, 0.0312522 ,
0.03125167, 0.03125112, 0.03125056, 0.03125004, 0.03124956, 0.03124915,
0.03124881, 0.03124856, 0.0312484 , 0.03124833, 0.03124834, 0.03124842,
0.03124857, 0.03124877, 0.03124901, 0.03124927, 0.03124954, 0.0312498 ,
0.03125005, 0.03125003, 0.03125002, 0.03125001, 0.03125001, 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 ,
0.03125 , 0.03125 , 0.03125 , 0.03125
]
)
expected_RM_3 = np.array(
[
0.03125 , 0.03122852, 0.03121269, 0.03120076, 0.03119738, 0.0312002 ,
0.03120689, 0.0312239 , 0.03126453, 0.0313146 , 0.03137285, 0.03144293,
0.03152261, 0.03160301, 0.03168856, 0.03177927, 0.03187514, 0.03197627,
0.0320823 , 0.03219318, 0.03230883, 0.03242431, 0.03253865, 0.03264945,
0.03275579, 0.03285663, 0.03295314, 0.03304137, 0.03312065, 0.0331905 ,
0.03325025, 0.03329941, 0.03333762, 0.03336462, 0.03338037, 0.03338477,
0.03337854, 0.03336207, 0.03333609, 0.03330184, 0.03325994, 0.03321149,
0.0331578 , 0.03310002, 0.03303904, 0.03297562, 0.0329112 , 0.03284683,
0.03278338, 0.03272166, 0.03266152, 0.03260304, 0.03254675, 0.03249326,
0.03244301, 0.03239548, 0.03235101, 0.03230928, 0.03227011, 0.03223354,
0.03219864, 0.0321654 , 0.0321336 , 0.03210296, 0.03207372, 0.03204546,
0.03201809, 0.03199175, 0.03196643, 0.03194218, 0.03191868, 0.03189579,
0.03187356, 0.03185224, 0.03183187, 0.03181251, 0.03179425, 0.03177713,
0.03176108, 0.03174616, 0.03173208, 0.03171875, 0.03170634, 0.03169485,
0.03168412, 0.0316741 , 0.03166473, 0.03165586, 0.03164726, 0.03163908,
0.03163129, 0.03162377, 0.03161646, 0.03160939, 0.03160244, 0.03159554,
0.03158866, 0.0315818 , 0.03157497, 0.03156817, 0.03156143, 0.03155477,
0.03154823, 0.03154182, 0.03153557, 0.03152949, 0.03152362, 0.03151794,
0.03151248, 0.03150724, 0.03150221, 0.03149739, 0.03149277, 0.03148833,
0.03148406, 0.03147995, 0.03147598, 0.03147212, 0.03146837, 0.0314647 ,
0.0314611 , 0.0314573 , 0.0314536 , 0.03144998, 0.03144644, 0.03144297,
0.03143957, 0.03143624, 0.03143298, 0.03142978, 0.03142664, 0.03142357,
0.03142055, 0.03141759, 0.03141468, 0.03141183, 0.03140903, 0.03140628,
0.03140358, 0.03140093, 0.03139832, 0.03139576, 0.03139325, 0.03139078,
0.03138835, 0.03138596, 0.03138361, 0.0313813 , 0.03137902, 0.03137679,
0.03137459, 0.03137242, 0.03137029, 0.03136819, 0.03136613, 0.0313641 ,
0.0313621 , 0.03136013, 0.03135818, 0.03135627, 0.03135439, 0.03135253,
0.0313507 , 0.0313489 , 0.03134712, 0.03134537, 0.03134365, 0.03134195,
0.03134027, 0.03133861, 0.03133698, 0.03133537, 0.03133379, 0.03133222,
0.03133067, 0.03132915, 0.03132765, 0.03132616, 0.0313247 , 0.03132325,
0.03132182, 0.03132041, 0.03131902, 0.03131765, 0.03131629, 0.03131495,
0.03131363, 0.03131232, 0.03131103, 0.03130975, 0.03130849, 0.03130725,
0.03130602, 0.0313048 , 0.0313036 , 0.03130242, 0.03130124, 0.03130008,
0.03129894, 0.03129781, 0.03129669, 0.03129558, 0.03129448, 0.0312934 ,
0.03129233, 0.03129127, 0.03129022, 0.03128919, 0.03128816, 0.03128715,
0.03128615, 0.03128515, 0.03128417, 0.0312832 , 0.03128224, 0.03128129,
0.03128035, 0.03127942, 0.0312785 , 0.03127759, 0.03127668, 0.03127579,
0.0312749 , 0.03127403, 0.03127316, 0.0312723 , 0.03127145, 0.03127061,
0.03126978, 0.03126895, 0.03126814, 0.03126733, 0.03126653, 0.03126573,
0.03126495, 0.03126417, 0.03126339, 0.03126263, 0.03126187, 0.03126112,
0.03126038, 0.03125964, 0.03125891, 0.03125819, 0.03125747, 0.03125676,
0.03125606, 0.03125536, 0.03125467, 0.03125399, 0.03125331, 0.03125263,
0.03125197, 0.03125131, 0.03125065, 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125 , 0.03125,
0.03125 , 0.03125 , 0.03125 , 0.03125
]
)
test_data_RM = [
(Y_RM_1, p_RM_1, "SS", expected_RM_1),
(Y_RM_2, p_RM_1, "TPI", expected_RM_2),
(Y_RM_2, p_RM_3, "TPI", expected_RM_3)
]
@pytest.mark.parametrize(
"Y,p,method,expected",
test_data_RM,
ids=[
"SS, alpha_RM_T=0.05",
"TPI, constant growth",
"TPI, extra growth",
],
)
def test_get_RM(Y, p, method, expected):
"""
Test of aggregate remittances function.
"""
RM = aggr.get_RM(Y, p, method)
assert np.allclose(RM, expected)


p = Specifications()
rho_vec = np.zeros((1, 40))
Expand Down

0 comments on commit 7344ff5

Please sign in to comment.