Skip to content

Commit

Permalink
Updated .py files with remittances
Browse files Browse the repository at this point in the history
  • Loading branch information
rickecon committed Sep 6, 2024
1 parent 079b583 commit 881ad75
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/book/content/api/aggregates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ ogcore.aggregates
------------------------------------------

.. automodule:: ogcore.aggregates
:members: get_L, get_I, get_B, get_BQ, get_C, revenue, get_r_p,
:members: get_L, get_I, get_B, get_BQ, get_RM, get_C, revenue, get_r_p,
resource_constraint, get_K_splits, get_ptilde
26 changes: 23 additions & 3 deletions ogcore/SS.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def euler_equation_solver(guesses, *args):
w (scalar): real wage rate
p_tilde (scalar): composite good price
bq (Numpy array): bequest amounts by age, length S
rm (scalar): remittance amounts by age, length S
tr (scalar): government transfer amount by age, length S
ubi (vector): universal basic income (UBI) payment, length S
factor (scalar): scaling factor converting model units to dollars
Expand All @@ -64,7 +65,7 @@ def euler_equation_solver(guesses, *args):
errros (Numpy array): errors from FOCs, length 2S
"""
(r, w, p_tilde, bq, tr, ubi, factor, j, p) = args
(r, w, p_tilde, bq, rm, tr, ubi, factor, j, p) = args

b_guess = np.array(guesses[: p.S])
n_guess = np.array(guesses[p.S :])
Expand All @@ -81,6 +82,7 @@ def euler_equation_solver(guesses, *args):
b_splus1,
n_guess,
bq,
rm,
factor,
tr,
ubi,
Expand All @@ -101,6 +103,7 @@ def euler_equation_solver(guesses, *args):
b_splus1,
n_guess,
bq,
rm,
factor,
tr,
ubi,
Expand Down Expand Up @@ -155,6 +158,7 @@ def euler_equation_solver(guesses, *args):
b_splus1,
n_guess,
bq,
rm,
taxes,
p.e[-1, :, j],
p,
Expand All @@ -174,8 +178,8 @@ def inner_loop(outer_loop_vars, p, client):
Args:
outer_loop_vars (tuple): tuple of outer loop variables,
(bssmat, nssmat, r_p, r, w, p_m, BQ, TR, factor) or
(bssmat, nssmat, r_p, r, w, p_m, BQ, Y, TR, factor)
(bssmat, nssmat, r_p, r, w, p_m, BQ, RM, TR, factor) or
(bssmat, nssmat, r_p, r, w, p_m, BQ, RM, Y, TR, factor)
bssmat (Numpy array): initial guess at savings, size = SxJ
nssmat (Numpy array): initial guess at labor supply, size = SxJ
r_p (scalar): return on household investment portfolio
Expand Down Expand Up @@ -226,11 +230,13 @@ def inner_loop(outer_loop_vars, p, client):
p_m = np.array(p_m) # TODO: why is this a list otherwise?
p_i = np.dot(p.io_matrix, p_m)
BQ = np.array(BQ)
RM = np.array(aggr.get_RM(Y, p, "SS"))
# initialize array for euler errors
euler_errors = np.zeros((2 * p.S, p.J))

p_tilde = aggr.get_ptilde(p_i, p.tau_c[-1, :], p.alpha_c)
bq = household.get_bq(BQ, None, p, "SS")
rm = household.get_rm(RM, None, p, "SS")
tr = household.get_tr(TR, None, p, "SS")
ubi = p.ubi_nom_array[-1, :, :] / factor

Expand All @@ -242,6 +248,7 @@ def inner_loop(outer_loop_vars, p, client):
w,
p_tilde,
bq[:, j],
rm[:, j],
tr[:, j],
ubi[:, j],
factor,
Expand Down Expand Up @@ -312,6 +319,7 @@ def inner_loop(outer_loop_vars, p, client):
b_splus1,
nssmat,
bq,
rm,
net_tax,
np.squeeze(p.e[-1, :, :]),
p,
Expand Down Expand Up @@ -400,6 +408,8 @@ def inner_loop(outer_loop_vars, p, client):
new_factor = factor
new_BQ = aggr.get_BQ(new_r_p, bssmat, None, p, "SS", False)
new_bq = household.get_bq(new_BQ, None, p, "SS")
new_RM = aggr.get_RM(Y, p, "SS")
new_rm = household.get_rm(new_RM, None, p, "SS")
tr = household.get_tr(TR, None, p, "SS")
theta = pensions.replacement_rate_vals(nssmat, new_w, new_factor, None, p)

Expand Down Expand Up @@ -444,6 +454,7 @@ def inner_loop(outer_loop_vars, p, client):
bssmat,
nssmat,
new_bq,
new_rm,
taxss,
np.squeeze(p.e[-1, :, :]),
p,
Expand Down Expand Up @@ -532,6 +543,7 @@ def inner_loop(outer_loop_vars, p, client):
K_vec,
L_vec,
Y_vec,
new_RM,
new_TR,
Y,
new_factor,
Expand All @@ -556,6 +568,7 @@ def SS_solver(
p_m (array_like): good prices
Y (scalar): real GDP
BQ (array_like): aggregate bequest amount(s)
RM (array_like): remittance amount(s)
TR (scalar): lump sum transfer amount
factor (scalar): scaling factor converting model units to dollars
p (OG-Core Specifications object): model parameters
Expand Down Expand Up @@ -599,6 +612,7 @@ def SS_solver(
new_K_vec,
new_L_vec,
new_Y_vec,
new_RM,
new_TR,
new_Y,
new_factor,
Expand Down Expand Up @@ -679,6 +693,7 @@ def SS_solver(
p_m_ss = new_p_m
p_i_ss = np.dot(p.io_matrix, p_m_ss)
p_tilde_ss = aggr.get_ptilde(p_i_ss, p.tau_c[-1, :], p.alpha_c)
RM_ss = new_RM
TR_ss = new_TR
Yss = new_Y
I_g_ss = fiscal.get_I_g(Yss, p.alpha_I[-1])
Expand Down Expand Up @@ -723,6 +738,7 @@ def SS_solver(
factor_ss = factor
bqssmat = household.get_bq(BQss, None, p, "SS")
trssmat = household.get_tr(TR_ss, None, p, "SS")
rmssmat = household.get_rm(RM_ss, None, p, "SS")
ubissmat = p.ubi_nom_array[-1, :, :] / factor_ss
theta = pensions.replacement_rate_vals(nssmat, wss, factor_ss, None, p)

Expand Down Expand Up @@ -823,6 +839,7 @@ def SS_solver(
bssmat_splus1,
nssmat,
bqssmat,
rmssmat,
taxss,
np.squeeze(p.e[-1, :, :]),
p,
Expand Down Expand Up @@ -979,6 +996,7 @@ def SS_solver(
"r_p_ss": r_p_ss,
"theta": theta,
"BQss": BQss,
"RMss": RM_ss,
"factor_ss": factor_ss,
"bssmat_s": bssmat_s,
"cssmat": cssmat,
Expand All @@ -987,6 +1005,7 @@ def SS_solver(
"bqssmat": bqssmat,
"TR_ss": TR_ss,
"trssmat": trssmat,
"rmssmat": rmssmat,
"Gss": Gss,
"total_tax_revenue": total_tax_revenue,
"business_tax_revenue": business_tax_revenue,
Expand Down Expand Up @@ -1072,6 +1091,7 @@ def SS_fsolve(guesses, *args):
new_K_vec,
new_L_vec,
new_Y_vec,
new_RM,
new_TR,
new_Y,
new_factor,
Expand Down
47 changes: 47 additions & 0 deletions ogcore/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,53 @@ def get_BQ(r, b_splus1, j, p, method, preTP):
return BQ


def get_RM(Y, p, method):
r"""
Calculation of aggregate remittances.
.. math::
\hat{RM}_{t} = \begin{cases}
\alpha_{RM,1}\hat{Y}_t \quad\text{for}\quad t=1 \\
\frac{(1+g_{RM,t})}{e^{g_y}(1+\tilde{g}_{n,t})}\hat{RM}_{t-1}
\quad\text{for}\quad 2\leq t\leq T_{G1} \\
\rho_{RM}\alpha_{RM,T}\hat{Y}_t
+ (1-\rho_{RM})\frac{(1+g_{RM,t})}{e^{g_y}(1+\tilde{g}_{n,t})}
\hat{RM}_{t-1} \quad\text{for}\quad T_{G1}< t<T_{G2} \\
\alpha_{RM,T}\hat{Y}_t \quad\text{for}\quad t\geq T_{G2}
\end{cases}
Args:
Y (array_like): GDP steady state or time path
p (OG-Core Specifications object): model parameters
method (str): adjusts calculation dimensions based on SS or TPI
Returns:
RM (array_like): aggregate remittances
"""
if method == "SS":
RM = p.alpha_RM_T * Y
elif method == "TPI":
RM = np.zeros_like(Y)
RM[0] = p.alpha_RM_1 * Y[0]
for t in range(1, p.tG1):
RM[t] = (
(1 + p.g_RM[t]) / (np.exp(p.g_y) * (1 + p.g_n[t]))
) * RM[t - 1]
for t in range(p.tG1, p.tG2 - 1):
RM[t] = (
p.rho_RM * p.alpha_RM_T * Y[t]
+ (
(1 - p.rho_RM)
* ((1 + p.g_RM[t]) / (np.exp(p.g_y) * (1 + p.g_n[t])))
* RM[t - 1]
)
)
RM[p.tG2 - 1:] = p.alpha_RM_T * Y[p.tG2 - 1:]

return RM


def get_C(c, p, method):
r"""
Calculation of aggregate consumption.
Expand Down
15 changes: 11 additions & 4 deletions ogcore/household.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def get_rm(RM, j, p, method):
return rm


def get_cons(r_p, w, p_tilde, b, b_splus1, n, bq, net_tax, e, p):
def get_cons(r_p, w, p_tilde, b, b_splus1, n, bq, rm, net_tax, e, p):
r"""
Calculate household composite consumption.
Expand All @@ -304,6 +304,7 @@ def get_cons(r_p, w, p_tilde, b, b_splus1, n, bq, net_tax, e, p):
b_splus1 (Numpy array): household savings one period ahead
n (Numpy array): household labor supply
bq (Numpy array): household bequests received
rm (Numpy array): household remittances received
net_tax (Numpy array): household net taxes paid
e (Numpy array): effective labor units
p (OG-Core Specifications object): model parameters
Expand All @@ -313,8 +314,10 @@ def get_cons(r_p, w, p_tilde, b, b_splus1, n, bq, net_tax, e, p):
"""
cons = (
(1 + r_p) * b + w * e * n + bq - b_splus1 * np.exp(p.g_y) - net_tax
(1 + r_p) * b + w * e * n + bq + rm - net_tax
- b_splus1 * np.exp(p.g_y)
) / p_tilde

return cons


Expand Down Expand Up @@ -369,6 +372,7 @@ def FOC_savings(
b_splus1,
n,
bq,
rm,
factor,
tr,
ubi,
Expand Down Expand Up @@ -402,6 +406,7 @@ def FOC_savings(
b_splus2 (Numpy array): household savings two periods ahead
n (Numpy array): household labor supply
bq (Numpy array): household bequests received
rm (Numpy array): household remittances received
factor (scalar): scaling factor converting model units to dollars
tr (Numpy array): government transfers to household
ubi (Numpy array): universal basic income payment
Expand Down Expand Up @@ -498,7 +503,7 @@ def FOC_savings(
etr_params,
p,
)
cons = get_cons(r, w, p_tilde, b, b_splus1, n, bq, taxes, e, p)
cons = get_cons(r, w, p_tilde, b, b_splus1, n, bq, rm, taxes, e, p)
deriv = (
(1 + r)
- (
Expand Down Expand Up @@ -555,6 +560,7 @@ def FOC_labor(
b_splus1,
n,
bq,
rm,
factor,
tr,
ubi,
Expand Down Expand Up @@ -588,6 +594,7 @@ def FOC_labor(
b_splus1 (Numpy array): household savings one period ahead
n (Numpy array): household labor supply
bq (Numpy array): household bequests received
rm (Numpy array): household bequests received
factor (scalar): scaling factor converting model units to dollars
tr (Numpy array): government transfers to household
ubi (Numpy array): universal basic income payment
Expand Down Expand Up @@ -686,7 +693,7 @@ def FOC_labor(
etr_params,
p,
)
cons = get_cons(r, w, p_tilde, b, b_splus1, n, bq, taxes, e, p)
cons = get_cons(r, w, p_tilde, b, b_splus1, n, bq, rm, taxes, e, p)
deriv = (
1
- tau_payroll
Expand Down

0 comments on commit 881ad75

Please sign in to comment.