Add sovereign_debt_py package + comprehensive READMEs for both packages#4
Conversation
Co-authored-by: zachessesjohnson <168567202+zachessesjohnson@users.noreply.github.com>
Co-authored-by: zachessesjohnson <168567202+zachessesjohnson@users.noreply.github.com>
…les with tests Co-authored-by: zachessesjohnson <168567202+zachessesjohnson@users.noreply.github.com>
… imf_framework Co-authored-by: zachessesjohnson <168567202+zachessesjohnson@users.noreply.github.com>
Creates sovereign_debt_py/ directory containing a complete, pip-installable Python package that mirrors sovereign_debt_xl with all @xl_func decorators and PyXLL imports removed. All 18 modules are converted; 73 public functions are importable. Package includes pyproject.toml and README.md so it can be directly dropped into a new GitHub repo. Co-authored-by: zachessesjohnson <168567202+zachessesjohnson@users.noreply.github.com>
…_debt_py Both READMEs now document every function (73 total across 18 modules) with: - Full description of what the function does and the underlying methodology - Parameter table (name, type, description) - Return value description - Concrete usage example (Excel formula syntax for xl; Python code for py) - sovereign_debt_xl README also covers installation, PyXLL setup, array formula guidance, and error handling - sovereign_debt_py README also covers installation, quick start, and how return types work Co-authored-by: zachessesjohnson <168567202+zachessesjohnson@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a PyXLL-based sovereign_debt_xl package plus a PyXLL-free mirror package (sovereign_debt_py) and expands documentation/testing so the same sovereign-debt analytics can be used from both Excel and standard Python environments.
Changes:
- Introduces
sovereign_debt_pyas a standalone pure-Python mirror of the Excel functions. - Adds/organizes the
sovereign_debt_xlpackage modules and a broad pytest suite covering many functions. - Updates CI packaging/install flow to run tests via editable install + requirements.
Reviewed changes
Copilot reviewed 55 out of 62 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Expanded top-level documentation (function-level usage/methodology). |
| requirements.txt | Pins runtime/test dependencies for CI and local runs. |
| pyproject.toml | Defines sovereign-debt-xl packaging metadata and dependencies. |
| conftest.py | Stubs pyxll.xl_func as a pass-through decorator for tests. |
| .github/workflows/pytest.yml | Installs deps + editable package install before running pytest. |
| init.py | Removes old root-level exports (package now lives under sovereign_debt_xl/). |
| test_amortization.py | Adds tests for amortization/redemption-wall utilities. |
| test_contagion.py | Adds tests for contagion and linkage analytics. |
| test_credit_risk.py | Adds tests for CDS/Merton/z-score/spread decomposition functions. |
| test_debt_composition.py | Adds tests for debt composition/transparency/collateral flags. |
| test_event_studies.py | Adds tests for event studies, EWS, restructuring comparables. |
| test_fiscal.py | Adds tests for debt dynamics and fiscal reaction/metrics. |
| test_imf_framework.py | Adds tests for IMF-framework utilities (DSA replication, etc.). |
| test_indexing.py | Makes xl_index_to_base assertion robust to float comparisons. |
| test_macro_financial.py | Adds tests for macro-financial risk scoring functions. |
| test_market_microstructure.py | Adds tests for liquidity/basis/auction/investor-base functions. |
| test_political_esg.py | Adds tests for political risk, ESG, and sanctions exposure. |
| test_reserves.py | Adds tests for reserve adequacy, BoP gap, FX misalignment. |
| test_stress.py | Adds tests for stress/fan chart and shock calculators. |
| test_yield_curve.py | Adds tests for Nelson–Siegel, z-spread, carry/rolldown, ASW. |
| sovereign_debt_xl/init.py | Re-exports package modules for Excel-facing usage. |
| sovereign_debt_xl/_coerce.py | Shared coercion/helpers for Excel-style inputs and error formatting. |
| sovereign_debt_xl/amortization.py | Excel functions for redemption wall, WAM, gross financing need. |
| sovereign_debt_xl/averaging.py | Excel functions for weighted/rolling/trimmed stats + describe table. |
| sovereign_debt_xl/contagion.py | Excel functions for contagion betas, DCC proxy, Granger, trade matrix. |
| sovereign_debt_xl/credit_risk.py | Excel functions for Merton, CDS PDs, z-score, spread decomposition. |
| sovereign_debt_xl/debt_composition.py | Excel functions for original sin, hidden debt, transparency, collateral flags. |
| sovereign_debt_xl/event_studies.py | Excel functions for restructuring comparables, event study, EWS table. |
| sovereign_debt_xl/fiscal.py | Excel functions for debt trajectory, fiscal reaction, implicit rate, stabilizing PB. |
| sovereign_debt_xl/forecasting.py | Excel functions for simple forecasting + seasonal decomposition outputs. |
| sovereign_debt_xl/imf_framework.py | Excel functions implementing IMF-framework style analytics. |
| sovereign_debt_xl/indexing.py | Excel functions for ranking, z-score, minmax scaling, rebasing. |
| sovereign_debt_xl/macro_financial.py | Excel functions for bank nexus, monetization risk, r–g, dollarization. |
| sovereign_debt_xl/market_microstructure.py | Excel functions for liquidity score, basis, auction tails, HHI concentration. |
| sovereign_debt_xl/modeling.py | Excel functions for regression, correlation matrix, Monte Carlo, scenario table. |
| sovereign_debt_xl/political_esg.py | Excel functions for political risk, ESG scoring, sanctions exposure. |
| sovereign_debt_xl/reserves.py | Excel functions for reserve adequacy, BoP gap, BEER misalignment regression. |
| sovereign_debt_xl/stress.py | Excel functions for fan chart simulation + liability/FX shock calculators. |
| sovereign_debt_xl/utils.py | Excel debugging/helpers (shape/flatten/business-day diff). |
| sovereign_debt_xl/yield_curve.py | Excel yield-curve tools (Nelson–Siegel, z-spread, carry/rolldown, ASW). |
| sovereign_debt_py/README.md | Python-package README with full function documentation and examples. |
| sovereign_debt_py/pyproject.toml | Defines sovereign-debt-py packaging metadata and dependencies. |
| sovereign_debt_py/sovereign_debt_py/init.py | Re-exports modules for Python usage parity with the XL package. |
| sovereign_debt_py/sovereign_debt_py/_coerce.py | Python mirror of coercion/helpers. |
| sovereign_debt_py/sovereign_debt_py/amortization.py | Python mirror of amortization utilities. |
| sovereign_debt_py/sovereign_debt_py/averaging.py | Python mirror of averaging/stat utilities. |
| sovereign_debt_py/sovereign_debt_py/contagion.py | Python mirror of contagion/linkage analytics. |
| sovereign_debt_py/sovereign_debt_py/credit_risk.py | Python mirror of credit risk analytics. |
| sovereign_debt_py/sovereign_debt_py/debt_composition.py | Python mirror of debt composition/transparency tools. |
| sovereign_debt_py/sovereign_debt_py/event_studies.py | Python mirror of event-study/EWS tools. |
| sovereign_debt_py/sovereign_debt_py/fiscal.py | Python mirror of fiscal/debt-dynamics tools. |
| sovereign_debt_py/sovereign_debt_py/forecasting.py | Python mirror of forecasting helpers. |
| sovereign_debt_py/sovereign_debt_py/imf_framework.py | Python mirror of IMF-framework style analytics. |
| sovereign_debt_py/sovereign_debt_py/indexing.py | Python mirror of indexing helpers. |
| sovereign_debt_py/sovereign_debt_py/macro_financial.py | Python mirror of macro-financial risk scoring. |
| sovereign_debt_py/sovereign_debt_py/market_microstructure.py | Python mirror of market microstructure analytics. |
| sovereign_debt_py/sovereign_debt_py/modeling.py | Python mirror of regression/correlation/MC/scenario tools. |
| sovereign_debt_py/sovereign_debt_py/political_esg.py | Python mirror of political/ESG/sanctions scoring. |
| sovereign_debt_py/sovereign_debt_py/reserves.py | Python mirror of reserves and FX misalignment regression. |
| sovereign_debt_py/sovereign_debt_py/stress.py | Python mirror of stress testing utilities. |
| sovereign_debt_py/sovereign_debt_py/utils.py | Python mirror of helper utilities. |
| sovereign_debt_py/sovereign_debt_py/yield_curve.py | Python mirror of yield curve tools. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| redemption = profile[yr] | ||
| flag = "HIGH" if redemption > 0.25 * total else "" | ||
| out.append([yr, round(redemption, 4), flag]) |
There was a problem hiding this comment.
The docstring says the concentration flag should trigger at "25 % or more" of total redemptions, but the implementation uses a strict > comparison. This will miss the edge case where a year is exactly 25% of total. Align the code and doc by using >= or updating the wording in the docstring.
| for yr in sorted(profile.keys()): | ||
| redemption = profile[yr] | ||
| flag = "HIGH" if redemption > 0.25 * total else "" | ||
| out.append([yr, round(redemption, 4), flag]) |
There was a problem hiding this comment.
The docstring says the concentration flag should trigger at "25 % or more" of total redemptions, but the implementation uses a strict > comparison. This will miss the edge case where a year is exactly 25% of total. Align the code and doc by using >= or updating the wording in the docstring.
| reserves_usd: float, | ||
| short_term_debt: float, | ||
| monthly_imports: float, | ||
| broad_money: float, | ||
| gdp: float, |
There was a problem hiding this comment.
gdp is part of the public function signature but is unused in the computation and not referenced in the docstring. This is confusing for callers and makes the API harder to understand/maintain. Either remove it (if safe), use it (if intended), or explicitly document it as reserved/unused (and consider renaming to _gdp to signal that).
| debt_gdp: float, | ||
| spread_bps: float, | ||
| reserves_months: float, | ||
| haircut_comparables: float, | ||
| ) -> list[list[Any]] | str: |
There was a problem hiding this comment.
haircut_comparables is accepted as an input but never used (the function always relies on the embedded episodes data). This is misleading for users and suggests the function isn’t doing what its signature implies. Either use haircut_comparables (e.g., to override/extend the dataset), remove it from the signature, or rename it to _haircut_comparables and document that it’s currently unused.
| debt_gdp: float, | ||
| spread_bps: float, | ||
| reserves_months: float, | ||
| haircut_comparables: float, | ||
| ) -> list[list[Any]] | str: |
There was a problem hiding this comment.
haircut_comparables is accepted as an input but never used (the function always relies on the embedded episodes data). This is misleading for users and suggests the function isn’t doing what its signature implies. Either use haircut_comparables (e.g., to override/extend the dataset), remove it from the signature, or rename it to _haircut_comparables and document that it’s currently unused.
| from .averaging import * # noqa: F401,F403 | ||
| from .indexing import * # noqa: F401,F403 | ||
| from .forecasting import * # noqa: F401,F403 | ||
| from .modeling import * # noqa: F401,F403 | ||
| from .utils import * # noqa: F401,F403 |
There was a problem hiding this comment.
The PR introduces a new standalone sovereign_debt_py package, but there are currently no tests that import or exercise it (all tests target sovereign_debt_xl). Adding at least a smoke test (import + a couple of representative function calls) or a parity test against sovereign_debt_xl would reduce the risk of the two packages drifting or packaging/import issues going unnoticed.
| reserves_usd: float, | ||
| short_term_debt: float, | ||
| monthly_imports: float, | ||
| broad_money: float, | ||
| gdp: float, |
There was a problem hiding this comment.
gdp is part of the public function signature but is unused in the computation and not referenced in the docstring. This is confusing for callers and makes the API harder to understand/maintain. Either remove it (if safe), use it (if intended), or explicitly document it as reserved/unused (and consider renaming to _gdp to signal that).
| def xl_array_shape(range: Any) -> list[list[Any]] | str: | ||
| """Returns rows x cols of a range (debugging helper).""" | ||
| try: |
There was a problem hiding this comment.
Using range as a parameter name shadows Python’s built-in range, which can make debugging harder and confuses readers. Rename the parameter (e.g., range_/data_range) for clarity.
|
@copilot apply changes based on the comments in this thread |
Adds a standalone, PyXLL-free Python mirror of
sovereign_debt_xland replaces both packages' minimal READMEs with full function-level documentation.sovereign_debt_py (new package)
sovereign_debt_py/is a pip-installable package (pip install sovereign-debt-py) containing all 18 modules and 73 functions fromsovereign_debt_xlwith@xl_funcdecorators andfrom pyxll import xl_funcstripped — business logic is identicalREADMEs
Both READMEs now document every function with: methodology explanation, parameter table (name / type / description), return value layout, and a concrete usage example.
README.md(sovereign_debt_xl) — adds PyXLL/pyxll.cfgsetup, Excel array-formula guidance, and Excel formula examples (=SOV_DEBT_TRAJECTORY(...)) for all 73 functions.sovereign_debt_py/README.md— adds Python installation, return-type conventions (scalar /list[float]/ 2D table), and runnable Python snippets for all 73 functions.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.