#!/usr/bin/env python3 """CXV general-government debt sensitivities: not forecasts or affordability tests. Run beside cxv-general-government-inputs.json (frozen official-source inputs). Both regions cover general government, not federal-only versus all-government. EU-27 aggregation is a statistical member-country total, not a pooled EU budget. Net interest = primary balance minus overall balance; this is NOT gross expense. The source baseline is 2025. Additional deficits begin in 2026; last year is 2050. Each transition uses the same year's GDP for flows and end-year debt stocks: i_y = r_y * d_previous / (1+g) d_y = d_previous/(1+g) + i_y - pb_y where i is NET interest/GDP. Initial effective NET cost = i_2025 / d_2025; this is a calibration proxy, not a market bond yield. Stock-flow adjustments, asset sales, FX changes, policy responses and feedback to growth are omitted. Common explicit illustrative assumptions: nominal growth 4%; effective net cost rises 1 percentage point with a six-year time constant; revenue/GDP and baseline primary balance constant. Additional annual deficits: 0, 0.3 or 1pp GDP. These are sensitivity cases, not actual industrial-policy trajectories. Next-step stabilising primary balance = (r-g)/(1+g)*d_end. Positive is surplus; adjustment = required balance minus scenario balance. Negative values are valid. 25% net-interest/revenue is selected diagnostic only, not a legal/safety ceiling. No runtime download, secret or third-party Python dependency. """ import argparse import csv import json import math from pathlib import Path START_YEAR, END_YEAR = 2025, 2050 HORIZON = END_YEAR - START_YEAR TAU, NOMINAL_GROWTH, NET_COST_INCREASE = 6.0, 0.04, 0.01 SCENARIOS = [("Baseline balance held constant", 0.0), ("Additional annual deficit 0.3pp GDP", 0.003), ("Additional annual deficit 1.0pp GDP", 0.01)] EU_CODES = {"AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", "GRC", "HUN", "IRL", "ITA", "LVA", "LTU", "LUX", "MLT", "NLD", "POL", "PRT", "ROU", "SVK", "SVN", "ESP", "SWE"} INPUT_PATH = Path(__file__).with_name("cxv-general-government-inputs.json") def load_inputs(filename=INPUT_PATH): data = json.loads(Path(filename).read_text(encoding="utf-8")) if data.get("government_perimeter") != "general government": raise ValueError("General-government inputs required; federal-only data rejected") if data.get("interest_measure") != "net interest": raise ValueError("Source-consistent NET interest required") rows, countries = data["jurisdictions"], data["country_rows"] if len(rows) != 2 or {r["code"] for r in rows} != {"USA", "EU27"}: raise ValueError("Exactly USA and EU27 required") if len(countries) != 27 or {r["code"] for r in countries} != EU_CODES: raise ValueError("Complete EU-27 membership required; UK excluded") fields = ("debt_pct_gdp", "revenue_pct_gdp", "overall_balance_pct_gdp", "primary_balance_pct_gdp", "net_interest_pct_gdp") for country in countries: if country["year"] != START_YEAR or country["nominal_gdp_usd_billions"] <= 0: raise ValueError("Same-year positive GDP weights required") if any(not isinstance(country[f], (int, float)) or not math.isfinite(country[f]) for f in fields): raise ValueError("Missing country fiscal inputs") total_gdp = sum(c["nominal_gdp_usd_billions"] for c in countries) eu = next(r for r in rows if r["code"] == "EU27") for field in fields: weighted = sum(c[field] * c["nominal_gdp_usd_billions"] / total_gdp for c in countries) if not math.isclose(eu[field], weighted, abs_tol=1e-8): raise ValueError("EU aggregate does not reconcile to frozen GDP-weighted country inputs") for row in rows: if row["year"] != START_YEAR or row["government_perimeter"] != "general government": raise ValueError("Same 2025 general-government baseline required") if any(not isinstance(row[f], (int, float)) or not math.isfinite(row[f]) for f in fields): raise ValueError("Missing or non-finite fiscal inputs") if row["debt_pct_gdp"] <= 0 or row["revenue_pct_gdp"] <= 0: raise ValueError("Debt and revenue must be positive") if not math.isclose(row["primary_balance_pct_gdp"] - row["overall_balance_pct_gdp"], row["net_interest_pct_gdp"], abs_tol=1e-8): raise ValueError("Net interest must equal primary minus overall balance") return data def parameters(row): return dict(name=row["name"], code=row["code"], d0=row["debt_pct_gdp"] / 100, i0=row["net_interest_pct_gdp"] / 100, rev=row["revenue_pct_gdp"] / 100, pb0=row["primary_balance_pct_gdp"] / 100, g=NOMINAL_GROWTH, r0=row["net_interest_pct_gdp"] / row["debt_pct_gdp"]) def path(p, extra): d = p["d0"] rows = [dict(year=START_YEAR, debt=d, rate=p["r0"], interest=p["i0"], interest_revenue=p["i0"] / p["rev"], primary_balance=p["pb0"], prior_debt=None, additional_deficit=0.0)] for t in range(1, HORIZON + 1): r = p["r0"] + NET_COST_INCREASE * (1 - math.exp(-t / TAU)) pb, prior = p["pb0"] - extra, d interest = r * prior / (1 + p["g"]) d = prior / (1 + p["g"]) + interest - pb if not math.isfinite(d) or d <= 0: raise ValueError("Scenario leaves positive-debt domain") rows.append(dict(year=START_YEAR + t, debt=d, rate=r, interest=interest, interest_revenue=interest / p["rev"], primary_balance=pb, prior_debt=prior, additional_deficit=extra)) return rows def crossing(rows, threshold=0.25): return next((r["year"] for r in rows if r["interest_revenue"] >= threshold), None) def write_csv(filename, rows): with Path(filename).open("w", newline="", encoding="utf-8") as handle: writer = csv.DictWriter(handle, fieldnames=list(rows[0])) writer.writeheader() writer.writerows(rows) def calculate(data): out, annual = [], [] for row in data["jurisdictions"]: p = parameters(row) for name, extra in SCENARIOS: rows = path(p, extra) head, last = rows[0], rows[-1] pb_star = (last["rate"] - p["g"]) / (1 + p["g"]) * last["debt"] out.append(dict(jurisdiction=p["name"], scenario=name, interest_revenue_2025=round(head["interest_revenue"] * 100, 1), year_crossing_25pct=crossing(rows) or "", interest_revenue_2050=round(last["interest_revenue"] * 100, 1), debt_2050=round(last["debt"] * 100, 1), pb_star_2050=round(pb_star * 100, 1), adjustment_2050=round((pb_star - last["primary_balance"]) * 100, 1))) for r in rows: annual.append(dict(jurisdiction=p["name"], scenario=name, year=r["year"], debt_pct_gdp=r["debt"] * 100, net_interest_pct_gdp=r["interest"] * 100, net_interest_revenue_pct=r["interest_revenue"] * 100, primary_balance_pct_gdp=r["primary_balance"] * 100, effective_net_cost_pct=r["rate"] * 100, nominal_growth_pct=p["g"] * 100, additional_deficit_pp_gdp=r["additional_deficit"] * 100)) return out, annual def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--inputs", type=Path, default=INPUT_PATH) parser.add_argument("--output-dir", type=Path, default=Path(__file__).parent) args = parser.parse_args() summary, annual = calculate(load_inputs(args.inputs)) args.output_dir.mkdir(parents=True, exist_ok=True) write_csv(args.output_dir / "cxv-debt-paths-output.csv", summary) write_csv(args.output_dir / "cxv-general-government-paths.csv", annual) print("GENERAL GOVERNMENT / NET INTEREST — conditional sensitivities, not forecasts") print(json.dumps(summary, ensure_ascii=False, indent=2)) print("Wrote six summary rows and 156 annual observations") if __name__ == "__main__": main()