Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export const CountryCard = ({
</div>
<div ref={debtRef}>
<h3 className={styles.heading}>
External public debt at face value, % of GDP, {year}
External public debt at present value, % of GDP, {year}
</h3>
<DebtBar value={debt} capacity={capacity} width={debtWidth} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export const DebtThresholds = ({
<div className={styles.tool}>
<div className={styles.chartCard}>
<p className={styles.title}>
External public debt at face value against peak debt service, {year} to{' '}
External public debt at present value against peak debt service, {year} to{' '}
{lastYear}
</p>
<div className={styles.whatIf}>
Expand Down
28 changes: 19 additions & 9 deletions prototypes/app/debt-thresholds/_data/fixture.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion prototypes/app/debt-thresholds/_data/inputs.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions prototypes/app/debt-thresholds/_data/pipeline/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pipeline.creditors import groups, net_flows
from pipeline.panel import Panel, Series, amount_of, span, whole
from pipeline.project import project_service
from pipeline.valuation import present_value


def build_view(
Expand Down Expand Up @@ -79,6 +80,7 @@ def revenue(year: int, fiscal=fiscal) -> float | None:
built[iso3] = {
"year": view.base,
"debtFace": whole(stock),
"debtPV": whole(present_value(keys, view.base)),
"gdp": whole(gdp(view.base)),
**capacity_for(capacity.get(iso3), view.base),
"years": years,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def coverage_rows(built: Mapping[str, dict], view: View) -> list[dict]:
base = built[country.iso3]
base_row = next(r for r in base["years"] if r["year"] == view.base)
cells = {
"debt stock": base["debtFace"] is not None,
"debt stock": base["debtPV"] is not None,
"debt service": base_row["service"] is not None,
"GDP": base["gdp"] is not None,
"revenue": base_row["revenue"] is not None,
Expand Down
2 changes: 1 addition & 1 deletion prototypes/app/debt-thresholds/_data/pipeline/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def build_thresholds(out: Path, *, client: httpx.Client, now: datetime, ids: str
data = {
"baseYears": [v.base for v in both],
"defaultYear": default_year,
"measure": "face",
"measure": "pv",
"vintages": {
str(v.base): {
"ids": v.ids,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"ppg_principal": "DT.AMT.DPPG.CD",
"ppg_disb": "DT.DIS.DPPG.CD",
"ppg_stock": "DT.DOD.DPPG.CD",
"ppg_concessional_stock": "DT.DOD.ALLC.CD",
"ppg_grant_element": "DT.GRE.DPPG",
"mlat_service": "DT.TDS.MLAT.CD",
"mlat_principal": "DT.AMT.MLAT.CD",
"mlat_disb": "DT.DIS.MLAT.CD",
Expand Down
33 changes: 33 additions & 0 deletions prototypes/app/debt-thresholds/_data/pipeline/valuation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""The present value of external public debt, estimated from IDS concessionality."""

from collections.abc import Mapping

from pipeline.config import FIRST_FLOW_YEAR
from pipeline.panel import Series, span


def present_value(keys: Mapping[str, Series], base: int) -> float | None:
"""Return the base year's PPG debt stock with its concessional part discounted.

The IMF-World Bank thresholds are set on the present value of debt, which IDS does
not publish. The estimate takes the concessional share of the stock
(`DT.DOD.ALLC.CD` over `DT.DOD.DPPG.CD`, capped at one) and the mean grant element
of new commitments from 2015 to the base year (`DT.GRE.DPPG`, in %), and returns
face value * (1 - share * grant element). Commercial debt stays at face value.

Returns None when the stock, the concessional stock or every grant element is missing.
"""
face = keys.get("ppg_stock", {}).get(base)
concessional = keys.get("ppg_concessional_stock", {}).get(base)
elements = [
value
for year, value in keys.get("ppg_grant_element", {}).items()
if year in span(FIRST_FLOW_YEAR, base)
]
if face is None or concessional is None or not elements:
return None
if face <= 0:
return face
share = min(1.0, concessional / face)
grant_element = sum(elements) / len(elements) / 100
return face * (1 - share * grant_element)
9 changes: 8 additions & 1 deletion prototypes/app/debt-thresholds/_data/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def test_build_view_shapes_records_and_inputs_for_every_country() -> None:
"mlat_service": dict.fromkeys(every_year, 10.0),
}
panel = {iso3: {key: dict(series) for key, series in flows.items()} for iso3 in ISO3}
panel[ISO3[0]] |= {"ppg_stock": {2024: 100.0}, "imf_stock": {2024: 20.0}}
panel[ISO3[0]] |= {
"ppg_stock": {2024: 100.0},
"imf_stock": {2024: 20.0},
"ppg_concessional_stock": {2024: 50.0},
"ppg_grant_element": {2024: 40.0},
}
built, inputs = build_view(
VIEW,
panel,
Expand All @@ -45,6 +50,7 @@ def test_build_view_shapes_records_and_inputs_for_every_country() -> None:
assert set(built) == set(inputs) == set(ISO3)
first = built[ISO3[0]]
assert first["debtFace"] == 100 # PPG only: the debt test leaves out IMF credit
assert first["debtPV"] == 80 # half concessional at a 40% grant element
assert inputs[ISO3[0]]["external_debt"] == {"2024": 120.0} # the projection keeps it
assert first["gdp"] == 10_000_000_000
assert first["capacitySource"] == "dsa"
Expand All @@ -55,4 +61,5 @@ def test_build_view_shapes_records_and_inputs_for_every_country() -> None:
assert inputs[ISO3[0]]["external_debt"] == {"2024": 120.0}
assert inputs[ISO3[0]]["projection_error"] is None
assert built[ISO3[1]]["debtFace"] is None # no stock reported
assert built[ISO3[1]]["debtPV"] is None
assert built[ISO3[1]]["capacity"] is None
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def built_for(view_base: int, *, gap: str | None = None) -> dict[str, dict]:
for country in COUNTRIES:
built[country.iso3] = {
"debtFace": 1.0,
"debtPV": 1.0,
"gdp": None if country.iso3 == gap else 1.0,
"capacity": {} if country.iso3 != "BTN" else None,
"years": [
Expand Down
40 changes: 40 additions & 0 deletions prototypes/app/debt-thresholds/_data/tests/test_valuation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Tests for the present-value estimate of the debt stock."""

import pytest

from pipeline.valuation import present_value


def _keys(*, face=1000.0, concessional=600.0, elements=None) -> dict:
return {
"ppg_stock": {2024: face},
"ppg_concessional_stock": {2024: concessional},
"ppg_grant_element": elements if elements is not None else {2015: 30.0, 2024: 50.0},
}


def test_present_value_discounts_the_concessional_share_by_the_mean_grant_element() -> None:
# 60% concessional, mean grant element 40%: 1000 * (1 - 0.6 * 0.4)
assert present_value(_keys(), 2024) == pytest.approx(760.0)


@pytest.mark.parametrize(
("keys", "expected"),
[
# Grant elements outside 2015 to the base year are ignored.
(_keys(elements={2014: 90.0, 2024: 50.0, 2025: 90.0}), 700.0),
# A concessional stock above the PPG stock counts as all of it.
(_keys(concessional=1200.0), 600.0),
# No concessional debt leaves face value.
(_keys(concessional=0.0), 1000.0),
],
)
def test_present_value_edges(keys: dict, expected: float) -> None:
assert present_value(keys, 2024) == pytest.approx(expected)


@pytest.mark.parametrize("missing", ["ppg_stock", "ppg_concessional_stock", "ppg_grant_element"])
def test_present_value_is_missing_without_its_inputs(missing: str) -> None:
keys = _keys()
keys[missing] = {}
assert present_value(keys, 2024) is None
Loading
Loading