diff --git a/CHANGELOG.md b/CHANGELOG.md index 24bd01193..0153b4f9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.25.3] - 2026-11-24 + +### Adds +- Adds government debt contracted abroad at its own interest rate, addressing Issue #1125 (concessional debt from official lenders), and usable for any government debt contracted abroad, concessional or commercial. The new time-varying parameter `alpha_D_ext` (default 0.0) sets this debt as a share of GDP, and `r_D_ext_annual` (default 0.0, time varying, converted to a model-period rate `r_D_ext`) its real interest rate. Each period the government receives the new external borrowing and pays its interest, in the budget constraint of the steady state and the time path (`fiscal.D_G_path`, `fiscal.get_G_ss`, and the balanced-budget case of `fiscal.get_TR`), and the interest is paid abroad at `r_D_ext` in the resource constraint. The debt is held only by foreigners and is separate from the market debt `D`: it does not enter households' portfolio return `r_p`, and `debt_ratio_ss`, the closure rule and `zeta_D` refer to market debt. +- Adds `fiscal.get_D_ext`, which returns the stock of debt contracted abroad, new external borrowing, and its interest in the steady state or along the time path. +- Adds `D_ext`, `new_borrowing_ext`, and `debt_service_ext` to the steady-state and time-path output (with their descriptions in `model_variables.json`, and in `utils.unstationarize_vars`), and includes external interest in `total_government_outlays`. The debt is a share of GDP in the reform as well, including when `baseline_spending=True`, except in the first period: a reform starts from the baseline's stock, as it does for market debt and public capital. +- Adds the debt contracted abroad to the government budget constraint, the budget closure rules, and their stationarized forms in the documentation, and adds it and foreign aid to the goods market clearing condition. +- Adds tests of `fiscal.get_D_ext`, of the steady-state spending and the time path of debt and spending with debt contracted abroad (the budget constraint holds each period), of the premium on total debt, of the new parameters, a steady-state solution that balances the budget and clears the goods market, and a time path (marked `local`) with a falling external debt that keeps the budget and the goods market in balance in every period. + +### Updates +- The debt-elastic premium on `r_gov` (`r_gov_DY`, `r_gov_DY2`) is evaluated at all government debt, market debt plus debt contracted abroad. With `alpha_D_ext` at its default of zero this is the market-debt ratio, so results are unchanged. +- The debt-to-GDP ratio in `output_tables.macro_table_SS` and in the calibration moments counts debt contracted abroad, and `output_plots.plot_all` adds it to the debt-to-GDP plot when it is not zero. Both are unchanged when `alpha_D_ext` is zero. + ## [0.25.2] - 2026-11-23 ### Added @@ -942,6 +955,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Any earlier versions of OG-USA can be found in the [`OG-Core`](https://github.com/PSLmodels/OG-Core) repository [release history](https://github.com/PSLmodels/OG-Core/releases) from [v.0.6.4](https://github.com/PSLmodels/OG-Core/releases/tag/v0.6.4) (Jul. 20, 2021) or earlier. +[0.25.3]: https://github.com/PSLmodels/OG-Core/compare/v0.25.2...v0.25.3 [0.25.2]: https://github.com/PSLmodels/OG-Core/compare/v0.25.1...v0.25.2 [0.25.1]: https://github.com/PSLmodels/OG-Core/compare/v0.25.0...v0.25.1 [0.25.0]: https://github.com/PSLmodels/OG-Core/compare/v0.24.6...v0.25.0 diff --git a/docs/book/content/api/fiscal.rst b/docs/book/content/api/fiscal.rst index a8fc50f0b..41d4a398e 100644 --- a/docs/book/content/api/fiscal.rst +++ b/docs/book/content/api/fiscal.rst @@ -10,4 +10,4 @@ ogcore.fiscal .. automodule:: ogcore.fiscal :members: D_G_path, get_D_ss, get_G_ss, get_debt_service_f, get_TR, - get_r_gov, get_I_g, get_foreign_aid, get_K_g + get_r_gov, get_I_g, get_foreign_aid, get_D_ext, get_K_g diff --git a/docs/book/content/intro/parameters.md b/docs/book/content/intro/parameters.md index e977b294d..4c34ccf75 100644 --- a/docs/book/content/intro/parameters.md +++ b/docs/book/content/intro/parameters.md @@ -304,6 +304,20 @@ _Valid Range:_ min = 0.0 and max = 1.0 _Out-of-Range Action:_ error +#### `alpha_D_ext` +_Description:_ Stock of government debt contracted abroad at its own interest rate, as a share of GDP: for example concessional loans from multilateral and bilateral lenders (official development assistance), or bonds and loans on commercial terms. This debt is held only by foreigners and is not part of the market debt D: it does not enter households' portfolio return, pays r_D_ext_annual, and is paid abroad at that rate. The debt-elastic premium on r_gov is evaluated at all government debt, D plus this debt, while the budget closure rule (debt_ratio_ss) and zeta_D refer to market debt. Set value for base year, click '+' to add value for next year. All future years not specified are set to last value entered. +_Value Type:_ float +_Valid Range:_ min = 0.0 and max = 3.0 +_Out-of-Range Action:_ error + + +#### `r_D_ext_annual` +_Description:_ Annual real interest rate paid on government debt contracted abroad (alpha_D_ext), in units of the model's output: for debt in foreign currency, the foreign-currency rate less foreign inflation, plus any expected real depreciation. Set value for base year, click '+' to add value for next year. All future years not specified are set to last value entered. +_Value Type:_ float +_Valid Range:_ min = -0.2 and max = 0.2 +_Out-of-Range Action:_ error + + ### Government Pension Parameters #### `retirement_age` diff --git a/docs/book/content/theory/government.md b/docs/book/content/theory/government.md index b97f9604e..b12912ef6 100644 --- a/docs/book/content/theory/government.md +++ b/docs/book/content/theory/government.md @@ -785,6 +785,8 @@ Foreign aid to the domestic government, $FA_t$, is treated the same way. In the This means that changes to `alpha_FA` in the reform have no effect when `baseline_spending=True`; use `alpha_bs_FA` to change the level of foreign aid relative to the baseline instead. +Debt contracted abroad $D^{ext}_t$ is not affected by `baseline_spending`. In a reform simulation the stock owed in the first period is the baseline's, since debt already owed when the reform begins cannot depend on it (as with market debt $D_0$ and public capital); from the second period on it is the fraction $\alpha_{D,ext,t}$ of GDP in the reform. + Note that the budget closure rule (described in Section ref{`SecUnbalGBCcloseRule`}) still takes effect in the case of `baseline_spending=True`. What this means is that the relation described above holds until the period in which the closure rules takes effect. Once the closure rule begins, the path of $G$ (and/or $TR$, depending on the closure rule used) will adjust as determined by the rule to close the government budget in the long run. (SecUnbalGBCrev)= @@ -832,11 +834,11 @@ Note that the budget closure rule (described in Section ref{`SecUnbalGBCcloseRul (SecUnbalGBCbudgConstr)= ## Government Budget Constraint - Let the level of government debt in period $t$ be given by $D_t$. The government budget constraint requires that government revenue $Rev_t$, external foreign assistance, $FA_t$, plus the budget deficit ($D_{t+1} - D_t$) equal expenditures on interest on the debt, government spending on public goods $G_t$, total infrastructure investments $I_{g,t}$, total pension outlays, total transfer payments to households $TR_t$, and $UBI_t$ every period $t$. When the funded defined contribution pillar is on, net FDC fund revenue $\Psi^{fdc}_t - \Phi^{fdc}_t$ also enters the constraint (see {ref}`SecGovPensionsFDC`), + Let the level of government debt in period $t$ be given by $D_t$. The government may also owe debt contracted abroad at its own interest rate, $D^{ext}_t$, described below. The government budget constraint requires that government revenue $Rev_t$, external foreign assistance, $FA_t$, plus the budget deficit financed by new borrowing ($D_{t+1} - D_t$ and $D^{ext}_{t+1} - D^{ext}_t$) equal expenditures on interest on the debt, government spending on public goods $G_t$, total infrastructure investments $I_{g,t}$, total pension outlays, total transfer payments to households $TR_t$, and $UBI_t$ every period $t$. When the funded defined contribution pillar is on, net FDC fund revenue $\Psi^{fdc}_t - \Phi^{fdc}_t$ also enters the constraint (see {ref}`SecGovPensionsFDC`), ```{math} :label: EqUnbalGBCbudgConstr - D_{t+1} + Rev_t + \Psi^{fdc}_t + FA_t = (1 + r_{gov,t})D_t + G_t + I_{g,t} + Pensions_t + TR_t + UBI_t + \Phi^{fdc}_t \quad\forall t + D_{t+1} + D^{ext}_{t+1} + Rev_t + \Psi^{fdc}_t + FA_t = (1 + r_{gov,t})D_t + (1 + r_{ext,t})D^{ext}_t + G_t + I_{g,t} + Pensions_t + TR_t + UBI_t + \Phi^{fdc}_t \quad\forall t ``` where $r_{gov,t}$ is the interest rate paid by the government defined in equation {eq}`EqUnbalGBC_rate_wedge` below, $G_{t}$ is government spending on public goods, $I_{g,t}$ is total government spending on infrastructure investment, $TR_{t}$ are non-pension government transfers, $UBI_t$ is the total UBI transfer outlays across households in time $t$, and $\Psi^{fdc}_t$ and $\Phi^{fdc}_t$ are the FDC fund revenue paid to the government and the transfers the government pays the fund, both zero when the pillar is off or `r_fdc_wedge` is zero. All variables in {eq}`EqUnbalGBCbudgConstr` are real variables denominated in units of current-period output in industry $M$ the numeraire ($p_{M,t}=1$ for all $t$). @@ -873,6 +875,15 @@ Note that the budget closure rule (described in Section ref{`SecUnbalGBCcloseRul where $\delta_g$ is the depreciation rate on infrastructure and $\phi_g$ (`infra_investment_leakage_rate`) is the fraction of infrastructure investment lost to leakage (e.g., corruption or other frictions). The stock of public capital in each industry $m$ complements labor and private capital in the production function of the representative firm, in Equation {eq}`EqFirmsCESprodfun`. + Governments also borrow abroad directly, outside the domestic bond market: from official lenders such as multilateral development banks and bilateral donors, often on concessional terms (at interest rates well below market rates, in amounts the lenders decide), and on commercial terms through bonds and loans issued abroad. `OG-Core` models this debt contracted abroad as a stock $D^{ext}_t$ held entirely by foreigners, set as a time-dependent fraction $\alpha_{D,ext,t}$ (`alpha_D_ext`) of GDP and paying the exogenous real interest rate $r_{ext,t}$ (`r_D_ext_annual`, converted to a model-period rate). The model has no exchange rate, so for debt in foreign currency $r_{ext,t}$ is the foreign-currency rate less foreign inflation, plus any expected real depreciation. + + ```{math} + :label: EqUnbalGBC_D_ext + D^{ext}_t = \alpha_{D,ext,t}\: Y_t \quad\forall t + ``` + + The government receives the new external borrowing $D^{ext}_{t+1} - D^{ext}_t$ and pays the interest $r_{ext,t}D^{ext}_t$ each period. Debt contracted abroad is separate from the market debt $D_t$: it is not part of household savings, so it does not enter the household portfolio return $r_{p,t}$ in {eq}`eq_portfolio_return`, and the debt-to-GDP target $\alpha_D$ of the budget closure rule and the share of new market debt bought by foreigners $\zeta_D$ refer to market debt; $D^f_t$ is then the part of market debt held by foreigners. The debt-elastic premium on $r_{gov,t}$ in {eq}`EqUnbalGBC_rate_wedge` is evaluated at all government debt, $D_t + D^{ext}_t$. Its interest is paid abroad at $r_{ext,t}$ in the goods market clearing condition (Chapter {ref}`Chap_MarkClr`). Because the stock is set by $\alpha_{D,ext,t}$, a reform that changes borrowing changes market debt only, unless it also changes $\alpha_{D,ext,t}$; and in the steady state all government debt is $\alpha_D + \alpha_{D,ext}$ of GDP. In the steady state the stock grows with GDP, so the government borrows $\left[(1+g_n)e^{g_y} - 1\right]D^{ext}$ a period and pays $r_{ext}D^{ext}$ in interest: when $r_{ext}$ is below the growth rate, as concessional rates usually are, the long-run budget receives a permanent net inflow from abroad. (Market debt held at $\alpha_D$ has the same property whenever $r_{gov}$ is below growth; the difference is that $r_{ext}$ is set by the user.) Phasing $\alpha_{D,ext,t}$ down to zero, for example as the debt is repaid, avoids it. By default $\alpha_{D,ext,t} = 0$. + Aggregate spending on UBI at time $t$ is the sum of UBI payments across all households at time $t$: ```{math} @@ -888,10 +899,10 @@ Note that the budget closure rule (described in Section ref{`SecUnbalGBCcloseRul ```{math} :label: EqUnbalGBC_rate_wedge - r_{gov, t} = (1 - \tau_{d, t})r_{t} - \mu_{d} + \beta_{1}\frac{D_t}{Y_t} + \beta_{2}\left(\frac{D_t}{Y_t}\right)^2 + r_{gov, t} = (1 - \tau_{d, t})r_{t} - \mu_{d} + \beta_{1}\frac{D_t + D^{ext}_t}{Y_t} + \beta_{2}\left(\frac{D_t + D^{ext}_t}{Y_t}\right)^2 ``` - where $r_t$ is the marginal product of capital faced by firms. The two parameters, $\tau_{d,t}$ and $\mu_{d,t}$ can be used to allow for a government interest rate that is a percentage hair cut from the market rate or a government interest rate with a constant risk premium. The parameters $\beta_1$ and $\beta_2$ can be used to allow for a quadratic risk premium on government debt that is a function of the debt-to-GDP ratio. + where $r_t$ is the marginal product of capital faced by firms. The two parameters, $\tau_{d,t}$ and $\mu_{d,t}$ can be used to allow for a government interest rate that is a percentage hair cut from the market rate or a government interest rate with a constant risk premium. The parameters $\beta_1$ and $\beta_2$ can be used to allow for a quadratic risk premium on government debt that is a function of the debt-to-GDP ratio. The ratio counts all government debt, the market debt $D_t$ and the debt contracted abroad $D^{ext}_t$, since the risk of the government's debt depends on everything it owes; with no debt contracted abroad it is $D_t/Y_t$. (SecUnbalGBCcloseRule)= @@ -930,8 +941,8 @@ Note that the budget closure rule (described in Section ref{`SecUnbalGBCcloseRul &\text{where}\quad g_{g,t} = \begin{cases} 1 \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\quad\:\text{if}\quad t < T_{G1} \\ - \frac{\left[\rho_{d}\alpha_{D}Y_{t} + (1-\rho_{d})D_{t}\right] - (1+r_{gov,t})D_{t} - I_{g,t} - TR_{t} - UBI_{t} + Rev_{t} + FA_{t}}{\alpha_g Y_t} \quad\text{if}\quad T_{G1}\leq t= p.tG1) and (t < p.tG2): G[t] = ( growth[t + 1] @@ -144,6 +163,7 @@ def D_G_path(r, dg_fixed_values, p, fdc_fund_revenue=0.0): - (1 + r_gov[t]) * D[t] + total_tax_revenue[t] + foreign_aid[t] + + ext_net[t] - agg_pension_outlays[t] - I_g[t - 1] - TR[t] @@ -155,6 +175,7 @@ def D_G_path(r, dg_fixed_values, p, fdc_fund_revenue=0.0): - (1 + r_gov[t]) * D[t] + total_tax_revenue[t] + foreign_aid[t] + + ext_net[t] - agg_pension_outlays[t] - I_g[t - 1] - TR[t] @@ -174,13 +195,17 @@ def D_G_path(r, dg_fixed_values, p, fdc_fund_revenue=0.0): + agg_pension_outlays[t - 1] - total_tax_revenue[t - 1] - foreign_aid[t - 1] + - ext_net[t - 1] + ) + r_gov[t] = get_r_gov( + r[t], D[t] / Y[t] + ext_ratio[t], p, method="scalar", t=t ) - r_gov[t] = get_r_gov(r[t], D[t] / Y[t], p, method="scalar", t=t) G[t] = ( growth[t] * (p.debt_ratio_ss * Y[t]) - (1 + r_gov[t]) * D[t] + total_tax_revenue[t] + foreign_aid[t] + + ext_net[t] - agg_pension_outlays[t] - I_g[t - 1] - TR[t] @@ -195,6 +220,7 @@ def D_G_path(r, dg_fixed_values, p, fdc_fund_revenue=0.0): + agg_pension_outlays[t] - total_tax_revenue[t] - foreign_aid[t] + - ext_net[t] ) D_ratio_max = np.amax(D[: p.T] / Y[: p.T]) print("Maximum debt ratio: ", D_ratio_max) @@ -292,6 +318,8 @@ def get_G_ss( .. math:: \bar{G} = \bar{Rev} + \bar{\Psi} - \bar{\Phi} + \overline{FA} + \bar{D}\bigl[(1 + \bar{g}_n)e^{g_y} - (1 + \bar{r}_{gov})\bigr] + + \bar{D}^{ext}\bigl[(1 + \bar{g}_n)e^{g_y} + - (1 + \bar{r}_{ext})\bigr] - \bar{I}_g - \bar{TR} - \overline{UBI} Args: @@ -323,11 +351,14 @@ def get_G_ss( if p.budget_balance: G = p.alpha_G[-1] * Y else: + _, new_borrowing_ext, debt_service_ext = get_D_ext(Y, p, "SS") G = ( total_tax_revenue + fdc_fund_revenue + new_borrowing + foreign_aid + + new_borrowing_ext + - debt_service_ext - (agg_pension_outlays + TR + debt_service + UBI_outlays + I_g) ) @@ -409,10 +440,13 @@ def get_TR( """ if p.budget_balance: + _, new_borrowing_ext, debt_service_ext = get_D_ext(Y, p, method) new_TR = ( total_tax_revenue + fdc_fund_revenue + foreign_aid + + new_borrowing_ext + - debt_service_ext - agg_pension_outlays - G - UBI_outlays @@ -543,6 +577,65 @@ def get_foreign_aid(Y, FA_baseline, p, method="SS"): return foreign_aid +def get_D_ext(Y, p, method="SS"): + r""" + Find the stock of government debt contracted abroad at its own + interest rate (for example concessional loans from official lenders, + or bonds and loans on commercial terms), the new external borrowing, + and its interest. This debt is held only by foreigners and is not part + of the market debt D or of households' portfolio. + + .. math:: + \begin{split} + \hat{D}^{ext}_{t} &= \alpha_{D,ext,t}\hat{Y}_{t} \\ + \text{new external borrowing}_t &= e^{g_y}\left(1 + + \tilde{g}_{n,t+1}\right)\hat{D}^{ext}_{t+1} - + \hat{D}^{ext}_{t} \\ + \text{external debt service}_t &= r_{ext,t}\hat{D}^{ext}_{t} + \end{split} + + In a reform's time path the period-0 stock is the baseline's + (``p.D_ext0_baseline``), since debt already owed when the reform + begins cannot depend on it; later periods follow alpha_D_ext. + + Args: + Y (array_like): aggregate output + p (OG-Core Specifications object): model parameters + method (str): either 'SS' for steady-state or 'TPI' for transition + path + + Returns: + (tuple): external debt variables: + + * D_ext (array_like): stock of debt contracted abroad + * new_borrowing_ext (array_like): new external borrowing + * debt_service_ext (array_like): interest on external debt + """ + if method == "SS": + D_ext = p.alpha_D_ext[-1] * Y + new_borrowing_ext = D_ext * ((1 + p.g_n_ss) * np.exp(p.g_y) - 1) + debt_service_ext = p.r_D_ext[-1] * D_ext + else: + # The stock in period T needs output in period T, beyond the + # path; output is at its steady state by then, so carry the + # last value forward. + Y_path = np.append(Y[: p.T], Y[p.T - 1]) + D_ext = p.alpha_D_ext[: p.T + 1] * Y_path + # In a reform the debt the economy starts with is inherited: it + # stays at the baseline's period-0 level, as market debt and + # public capital do (set in TPI.get_initial_SS_values) + D_ext0 = getattr(p, "D_ext0_baseline", None) + if not p.baseline and D_ext0 is not None: + D_ext[0] = D_ext0 + new_borrowing_ext = ( + D_ext[1:] * np.exp(p.g_y) * (1 + p.g_n[: p.T]) - D_ext[:-1] + ) + D_ext = D_ext[:-1] + debt_service_ext = p.r_D_ext[: p.T] * D_ext + + return D_ext, new_borrowing_ext, debt_service_ext + + def get_K_g(K_g0, I_g, p, method): r""" Law of motion for the government capital stock diff --git a/ogcore/model_variables.json b/ogcore/model_variables.json index 14bbe8133..e42c0a448 100644 --- a/ogcore/model_variables.json +++ b/ogcore/model_variables.json @@ -315,7 +315,7 @@ "toGDP_label": "Consumption Tax Revenue-to-GDP" }, "D": { - "desc": "Total government debt", + "desc": "Government debt issued in the domestic market (market debt), excluding debt contracted abroad (D_ext)", "section": "Government Revenues, Outlays, and Debt", "type": "array-like", "TPI dimensions": "T", @@ -341,6 +341,33 @@ "label": "Domestically-owned Gov Debt ($D^d_t$)", "toGDP_label": "Domestically-owned Debt-to-GDP ($D^d_{t}/Y_t$)" }, + "D_ext": { + "desc": "Government debt contracted abroad at its own interest rate (alpha_D_ext times GDP), held entirely by foreigners and outside the household portfolio", + "section": "Government Revenues, Outlays, and Debt", + "type": "array-like", + "TPI dimensions": "T", + "SS dimensions": "scalar", + "label": "Gov Debt Contracted Abroad ($D^{ext}_t$)", + "toGDP_label": "External Debt-to-GDP ($D^{ext}_{t}/Y_t$)" + }, + "new_borrowing_ext": { + "desc": "New borrowing of government debt contracted abroad", + "section": "Government Revenues, Outlays, and Debt", + "type": "array-like", + "TPI dimensions": "T", + "SS dimensions": "scalar", + "label": "New External Borrowing", + "toGDP_label": "New External Borrowing-to-GDP" + }, + "debt_service_ext": { + "desc": "Interest on government debt contracted abroad, at r_D_ext", + "section": "Government Revenues, Outlays, and Debt", + "type": "array-like", + "TPI dimensions": "T", + "SS dimensions": "scalar", + "label": "External Debt Service", + "toGDP_label": "External Debt Service-to-GDP" + }, "new_borrowing": { "desc": "New government borrowing, equal to budget deficit", "section": "Government Revenues, Outlays, and Debt", diff --git a/ogcore/output_plots.py b/ogcore/output_plots.py index ff584625d..72f9bab12 100644 --- a/ogcore/output_plots.py +++ b/ogcore/output_plots.py @@ -1005,13 +1005,17 @@ def plot_all(base_output_path, reform_output_path, save_path): path=os.path.join(save_path, "SpendGDPratio.png"), ) - # Debt-GDP in base and reform-- vertical lines at tG1, tG2 + # Debt-GDP in base and reform-- vertical lines at tG1, tG2; with debt + # contracted abroad (D_ext), plot it alongside market debt + debt_vars = ["D"] + if "D_ext" in base_tpi and np.any(np.asarray(base_tpi["D_ext"]) != 0): + debt_vars.append("D_ext") plot_gdp_ratio( base_tpi, base_params, reform_tpi, reform_params, - var_list=["D"], + var_list=debt_vars, num_years_to_plot=min(base_params.T, 150), start_year=base_params.start_year, vertical_line_years=[ diff --git a/ogcore/output_tables.py b/ogcore/output_tables.py index 739834fec..e75599f72 100644 --- a/ogcore/output_tables.py +++ b/ogcore/output_tables.py @@ -195,9 +195,10 @@ def macro_table_SS( if v != "D/Y": diff = ((reform_ss[v] - base_ss[v]) / base_ss[v]) * 100 else: - diff = ( - reform_ss["D"] / reform_ss["Y"] - base_ss["D"] / base_ss["Y"] - ) + # all government debt: market debt plus debt contracted abroad + diff = (reform_ss["D"] + reform_ss.get("D_ext", 0.0)) / reform_ss[ + "Y" + ] - (base_ss["D"] + base_ss.get("D_ext", 0.0)) / base_ss["Y"] table_dict["% Change (or pp diff)"].append(diff) # Make df with dict so can use pandas functions table_df = pd.DataFrame.from_dict( @@ -1199,7 +1200,11 @@ def model_fit_table( elif target_desc == r"Infrastructure spending to GDP ratio $(I_g/Y)$": model_val = tpi_output["I_g"][t] / tpi_output["Y"][t] elif target_desc == r"Debt to GDP ratio $(D/Y)$": - model_val = tpi_output["D"][t] / tpi_output["Y"][t] + # all government debt: market debt plus debt contracted abroad + model_val = ( + tpi_output["D"][t] + + (tpi_output["D_ext"][t] if "D_ext" in tpi_output else 0.0) + ) / tpi_output["Y"][t] # Distributional moments elif target_desc == "Gini coefficient, wealth": dist = tpi_output["b_sp1"][t] diff --git a/ogcore/parameters.py b/ogcore/parameters.py index 358683a22..dc453d4ed 100644 --- a/ogcore/parameters.py +++ b/ogcore/parameters.py @@ -320,11 +320,13 @@ def compute_default_params(self): "alpha_T", "alpha_I", "alpha_FA", + "alpha_D_ext", "alpha_bs_G", "alpha_bs_T", "alpha_bs_I", "alpha_bs_FA", "world_int_rate_annual", + "r_D_ext_annual", "adjustment_factor_for_cit_receipts", "tau_bq", "h_wealth", @@ -474,6 +476,14 @@ def compute_default_params(self): self.S, ) + # interest rate on government debt contracted abroad (D_ext) + self.r_D_ext = rate_conversion( + self.r_D_ext_annual, + self.starting_age, + self.ending_age, + self.S, + ) + # exogenous NDC credited and discount rate paths (used when # ndc_growth_rate or dir_growth_rate is 'exogenous'), converted # to model-period rates and extended to length T + S diff --git a/ogcore/utils.py b/ogcore/utils.py index 91acb38de..27ae8c15b 100644 --- a/ogcore/utils.py +++ b/ogcore/utils.py @@ -1357,6 +1357,9 @@ def unstationarize_vars( "UBI_path", "new_borrowing_f", "debt_service_f", + "D_ext", + "new_borrowing_ext", + "debt_service_ext", ]: non_stationary_output = tpi_vars[var][:T] * pop_growth * prod_growth elif var in [ diff --git a/pyproject.toml b/pyproject.toml index 0b0f0e86e..4541e4ee2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ogcore" -version = "0.25.2" +version = "0.25.3" authors = [ {name = "Jason DeBacker and Richard W. Evans"}, ] diff --git a/tests/test_SS.py b/tests/test_SS.py index 6b93aa885..31756c84f 100644 --- a/tests/test_SS.py +++ b/tests/test_SS.py @@ -8,7 +8,7 @@ import numpy as np import os import pickle -from ogcore import SS, utils, aggregates +from ogcore import SS, utils, aggregates, fiscal from ogcore.parameters import Specifications from ogcore import firm @@ -447,6 +447,66 @@ def test_SS_solver(baseline, param_updates, filename, dask_client): ) +def test_SS_solver_D_ext(dask_client): + # With government debt contracted abroad (D_ext), the steady state + # holds the stock at its share of GDP, balances the government budget + # with its flows, clears the goods market with its interest paid + # abroad, and prices the premium on r_gov at all government debt. + p = Specifications(baseline=True, num_workers=NUM_WORKERS) + p.update_specifications({"alpha_D_ext": [0.3], "r_D_ext_annual": [0.01]}) + p.frac_tax_payroll = np.zeros(p.frac_tax_payroll.shape) + p.output_base = CUR_PATH + b_guess = np.ones((p.S, p.J)) * 0.07 + n_guess = np.ones((p.S, p.J)) * 0.35 * p.ltilde + rguess = 0.06483431412921253 + wguess = firm.get_w_from_r(rguess, p, "SS") + BQguess = aggregates.get_BQ(rguess, b_guess, None, p, "SS", False) + ss = SS.SS_solver( + b_guess, + n_guess, + rguess, + rguess, + wguess, + np.ones(p.M), + 0.6376591201150815, + BQguess, + 0.05738932081035772, + None, + None, + 139355.1547340256, + p, + dask_client, + False, + ) + + Y = ss["Y"] + assert np.isclose(ss["D_ext"], 0.3 * Y) + assert np.isclose( + ss["new_borrowing_ext"], + 0.3 * Y * ((1 + p.g_n_ss) * np.exp(p.g_y) - 1), + ) + assert np.isclose(ss["debt_service_ext"], p.r_D_ext[-1] * 0.3 * Y) + assert np.isclose( + ss["G"], + ss["total_tax_revenue"] + + ss["new_borrowing"] + + ss["foreign_aid"] + + ss["new_borrowing_ext"] + - ss["debt_service_ext"] + - ss["agg_pension_outlays"] + - ss["TR"] + - ss["debt_service"] + - ss["UBI"] + - ss["I_g"], + ) + # the premium is evaluated at all long-run government debt + assert np.isclose( + ss["r_gov"], + fiscal.get_r_gov(ss["r"], p.debt_ratio_ss + 0.3, p, "scalar", t=-1), + ) + assert np.abs(ss["resource_constraint_error"]).max() < 1e-6 + + param_updates5 = {"zeta_K": [1.0], "budget_balance": True, "alpha_G": [0.0]} filename5 = "SS_solver_outputs_baseline_small_open_budget_balance.pkl" param_updates6 = { diff --git a/tests/test_TPI.py b/tests/test_TPI.py index 252647f55..e5770cbd3 100644 --- a/tests/test_TPI.py +++ b/tests/test_TPI.py @@ -1434,6 +1434,66 @@ def test_run_TPI_extra(baseline, param_updates, filename, tmpdir, dask_client): ) +@pytest.mark.local +def test_run_TPI_D_ext(tmpdir, dask_client): + """ + A baseline transition with government debt contracted abroad (D_ext) + that falls over time and gets dearer: the stock, its new borrowing and + its interest follow alpha_D_ext and r_D_ext period by period, the + government budget holds in every period with these flows in it, and + the goods market clears along the path with the interest paid abroad. + """ + baseline_dir = os.path.join(tmpdir, "baseline") + p = Specifications( + baseline=True, + baseline_dir=baseline_dir, + output_base=baseline_dir, + num_workers=NUM_WORKERS, + ) + p.update_specifications( + { + "alpha_D_ext": [0.3, 0.25, 0.2, 0.15, 0.1, 0.05, 0.0], + "r_D_ext_annual": [-0.01, 0.0, 0.01, 0.02], + } + ) + SS.ENFORCE_SOLUTION_CHECKS = True + ss_outputs = SS.run_SS(p, client=dask_client) + utils.mkdirs(os.path.join(p.baseline_dir, "SS")) + with open(os.path.join(p.baseline_dir, "SS", "SS_vars.pkl"), "wb") as f: + pickle.dump(ss_outputs, f) + tpi = TPI.run_TPI(p, client=dask_client) + + T = p.T + Y = tpi["Y"][:T] + growth = np.exp(p.g_y) * (1 + p.g_n[:T]) + # the stock and its flows + assert np.allclose(tpi["D_ext"], p.alpha_D_ext[:T] * Y) + D_ext_next = p.alpha_D_ext[1 : T + 1] * np.append(Y[1:], Y[-1]) + assert np.allclose( + tpi["new_borrowing_ext"], D_ext_next * growth - tpi["D_ext"] + ) + assert np.allclose(tpi["debt_service_ext"], p.r_D_ext[:T] * tpi["D_ext"]) + assert tpi["D_ext"][10] == 0.0 + # the government budget, period by period + D = tpi["D"] + ext_net = tpi["new_borrowing_ext"] - tpi["debt_service_ext"] + outlays = ( + (1 + tpi["r_gov"][: T - 1]) * D[: T - 1] + + tpi["G"][: T - 1] + + tpi["I_g"][: T - 1] + + tpi["TR"][: T - 1] + + tpi["UBI"][: T - 1] + + tpi["agg_pension_outlays"][: T - 1] + - tpi["total_tax_revenue"][: T - 1] + - tpi["foreign_aid"][: T - 1] + - ext_net[: T - 1] + ) + assert np.allclose(D[1:T] * growth[: T - 1], outlays, atol=1e-8) + # the goods market along the path + rc = np.abs(np.asarray(tpi["resource_constraint_error"])[: T - 1]) + assert rc.max() < p.RC_TPI + + @pytest.mark.local def test_run_TPI_anderson_initial_wealth(tmpdir, dask_client): """ diff --git a/tests/test_fiscal.py b/tests/test_fiscal.py index 04f3c92b1..1923606d0 100644 --- a/tests/test_fiscal.py +++ b/tests/test_fiscal.py @@ -477,3 +477,237 @@ def test_get_K_g(K_g0, I_g, method, leakage, expected): test_val = fiscal.get_K_g(K_g0, I_g, p, method) assert np.allclose(test_val, expected) + + +@pytest.mark.parametrize( + "method", + ["SS", "TPI"], + ids=["SS", "TPI"], +) +def test_get_D_ext(method): + """ + Test of the stock, new borrowing, and interest on external (D_ext) + government debt. + """ + p = Specifications() + p.T = 2 + p.g_y = 0.03 + p.g_n_ss = 0.02 + p.g_n = np.array([0.02, 0.01]) + p.alpha_D_ext = np.array([0.1, 0.5, 0.5]) + p.r_D_ext = np.array([0.01, -0.01, -0.01]) + Y = np.array([0.2, 4.0]) + if method == "SS": + D_ext, new_borrowing_ext, debt_service_ext = fiscal.get_D_ext( + Y[-1], p, method + ) + expected = ( + 2.0, + 2.0 * (1.02 * np.exp(0.03) - 1), + -0.01 * 2.0, + ) + else: + D_ext, new_borrowing_ext, debt_service_ext = fiscal.get_D_ext( + Y, p, method + ) + # the stock in period T uses output in period T - 1 + expected = ( + np.array([0.02, 2.0]), + np.array( + [ + 2.0 * np.exp(0.03) * 1.02 - 0.02, + 2.0 * np.exp(0.03) * 1.01 - 2.0, + ] + ), + np.array([0.01 * 0.02, -0.01 * 2.0]), + ) + for test_val, expected_val in zip( + (D_ext, new_borrowing_ext, debt_service_ext), expected + ): + assert np.allclose(test_val, expected_val) + + +def test_get_D_ext_reform_keeps_baseline_initial_stock(): + """ + In a reform's time path the debt contracted abroad that is owed in + period 0 is the baseline's, not alpha_D_ext times reform output; later + periods follow alpha_D_ext, and the first period's new borrowing is + measured from the inherited stock. The baseline is unaffected. + """ + p = Specifications() + p.T = 2 + p.g_y = 0.03 + p.g_n = np.array([0.02, 0.01]) + p.alpha_D_ext = np.array([0.1, 0.5, 0.5]) + p.r_D_ext = np.array([0.01, -0.01, -0.01]) + Y = np.array([0.2, 4.0]) + p.D_ext0_baseline = 0.03 + p.baseline = False + D_ext, new_borrowing_ext, debt_service_ext = fiscal.get_D_ext(Y, p, "TPI") + assert np.allclose(D_ext, [0.03, 2.0]) + assert np.allclose( + new_borrowing_ext, + [ + 2.0 * np.exp(0.03) * 1.02 - 0.03, + 2.0 * np.exp(0.03) * 1.01 - 2.0, + ], + ) + assert np.allclose(debt_service_ext, [0.01 * 0.03, -0.01 * 2.0]) + # the baseline ignores the attribute + p.baseline = True + D_ext, _, _ = fiscal.get_D_ext(Y, p, "TPI") + assert np.allclose(D_ext, [0.02, 2.0]) + # a reform whose baseline predates D_ext keeps the ratio + p.baseline = False + p.D_ext0_baseline = None + D_ext, _, _ = fiscal.get_D_ext(Y, p, "TPI") + assert np.allclose(D_ext, [0.02, 2.0]) + + +def test_get_D_ext_zero_by_default(): + """ + With the default parameters there is no debt contracted abroad. + """ + p = Specifications() + Y = np.ones(p.T) * 2.0 + for method, y in (("SS", 2.0), ("TPI", Y)): + for v in fiscal.get_D_ext(y, p, method): + assert np.allclose(v, 0.0) + + +def test_get_G_ss_D_ext(): + """ + Debt contracted abroad adds its new borrowing, less its interest, to + the resources that finance steady-state government spending. + """ + Y = 2.2 + new_borrowing = 0.072076633 + debt_service = 0.042345192 + p = Specifications() + p.update_specifications({"alpha_D_ext": [0.3], "r_D_ext_annual": [0.01]}) + test_G = fiscal.get_G_ss( + Y, 2.3, 0.0, 1.6, 0.0, 0.0, 0.0, new_borrowing, debt_service, p + ) + D_ext = 0.3 * Y + expected_G = ( + expected_G1 + + D_ext * ((1 + p.g_n_ss) * np.exp(p.g_y) - 1) + - p.r_D_ext[-1] * D_ext + ) + + assert np.allclose(test_G, expected_G) + + +def test_D_G_path_D_ext_budget_constraint(): + """ + With debt contracted abroad, the time path of market debt and spending + satisfies the government budget constraint each period: + growth * D_{t+1} + new external borrowing_t + Rev_t + FA_t = + (1 + r_gov_t) D_t + external interest_t + G_t + I_g_t + TR_t + UBI_t + + pensions_t. + """ + p = Specifications() + p.update_specifications( + { + "T": 320, + "S": 80, + "debt_ratio_ss": 1.2, + "tG1": 20, + "tG2": 256, + "alpha_T": [0.09], + "alpha_G": [0.05], + "rho_G": 0.1, + "g_y_annual": 0.03, + "alpha_FA": [0.01], + "alpha_D_ext": [0.2, 0.25, 0.3], + "r_D_ext_annual": [-0.01], + }, + raise_errors=False, + ) + r = np.ones(p.T + p.S) * 0.05 + p.g_n = np.ones(p.T + p.S) * 0.02 + Y_path = Y.copy() + TR_path = TR.copy() + zeros = np.zeros_like(TR_path) + foreign_aid = p.alpha_FA[: p.T] * Y_path[: p.T] + dg_fixed_values = ( + Y_path, + Revenue, + zeros, + zeros, + TR_path, + zeros, + foreign_aid, + Gbaseline, + 0.59, + ) + D, G, _, _, r_gov, _, _, _ = fiscal.D_G_path(r, dg_fixed_values, p) + _, new_borrowing_ext, debt_service_ext = fiscal.get_D_ext(Y_path, p, "TPI") + growth = np.exp(p.g_y) * (1 + p.g_n[: p.T - 1]) + lhs = ( + growth * D[1 : p.T] + + new_borrowing_ext[: p.T - 1] + + Revenue[: p.T - 1] + + foreign_aid[: p.T - 1] + ) + rhs = ( + (1 + r_gov[: p.T - 1]) * D[: p.T - 1] + + debt_service_ext[: p.T - 1] + + G[: p.T - 1] + + TR_path[: p.T - 1] + ) + assert np.allclose(lhs, rhs) + # the closure rule still brings market debt to its target + assert np.isclose(D[p.T - 1] / Y_path[p.T - 2], p.debt_ratio_ss) + + +@pytest.mark.parametrize( + "alpha_D_ext", [[0.0], [0.2, 0.25, 0.3]], ids=["none", "some"] +) +def test_D_G_path_premium_on_total_debt(alpha_D_ext): + """ + The debt-elastic premium on r_gov is evaluated at all government debt, + market debt D plus debt contracted abroad D_ext. With no debt + contracted abroad it is the market-debt ratio, as before. + """ + p = Specifications() + p.update_specifications( + { + "T": 320, + "S": 80, + "debt_ratio_ss": 1.2, + "tG1": 20, + "tG2": 256, + "alpha_T": [0.09], + "alpha_G": [0.05], + "rho_G": 0.1, + "g_y_annual": 0.03, + "r_gov_DY": -0.04, + "r_gov_DY2": 0.02, + "alpha_D_ext": alpha_D_ext, + "r_D_ext_annual": [-0.01], + }, + raise_errors=False, + ) + r = np.ones(p.T + p.S) * 0.05 + p.g_n = np.ones(p.T + p.S) * 0.02 + zeros = np.zeros_like(TR) + dg_fixed_values = ( + Y.copy(), + Revenue, + zeros, + zeros, + TR.copy(), + zeros, + zeros[: p.T], + Gbaseline, + 0.59, + ) + D, _, _, _, r_gov, _, _, _ = fiscal.D_G_path(r, dg_fixed_values, p) + D_ext, _, _ = fiscal.get_D_ext(Y, p, "TPI") + total = (D[: p.T] + D_ext) / Y[: p.T] + expected = fiscal.get_r_gov(r[: p.T], total, p, "TPI") + assert np.allclose(r_gov[: p.T], expected) + if alpha_D_ext == [0.0]: + market = fiscal.get_r_gov(r[: p.T], D[: p.T] / Y[: p.T], p, "TPI") + assert np.allclose(r_gov[: p.T], market) diff --git a/tests/test_parameters.py b/tests/test_parameters.py index 818795d6c..307dd3346 100644 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -83,6 +83,27 @@ def test_alpha_FA_extended_over_time_path(): assert specs.alpha_FA[-1] == 0.03 +def test_D_ext_parameters_extended_and_converted(): + # External debt (D_ext) and its interest rate may vary over the time + # path; the annual rate is converted to a model-period rate. + specs = Specifications() + assert np.all(specs.alpha_D_ext == 0.0) + assert np.all(specs.r_D_ext == 0.0) + specs.update_specifications( + { + "alpha_D_ext": [0.1, 0.2], + "r_D_ext_annual": [0.01, -0.02], + } + ) + assert specs.alpha_D_ext.shape[0] == specs.T + specs.S + assert specs.alpha_D_ext[0] == 0.1 + assert specs.alpha_D_ext[-1] == 0.2 + assert specs.r_D_ext.shape[0] == specs.T + specs.S + years_per_period = (specs.ending_age - specs.starting_age) / specs.S + assert np.isclose(specs.r_D_ext[0], 1.01**years_per_period - 1) + assert np.isclose(specs.r_D_ext[-1], 0.98**years_per_period - 1) + + def test_tau_payroll_extended_over_T_and_J(): # tau_payroll may vary over the time path and across lifetime income # groups, so it should be extrapolated to T+S x J from a scalar, a diff --git a/uv.lock b/uv.lock index d71c5388c..f830be339 100644 --- a/uv.lock +++ b/uv.lock @@ -2027,7 +2027,7 @@ wheels = [ [[package]] name = "ogcore" -version = "0.25.2" +version = "0.25.3" source = { editable = "." } dependencies = [ { name = "dask" },