feat(phase9): add real corporate bond pipeline and fix rate mapping

This commit is contained in:
variet-worker
2026-04-03 22:46:56 +09:00
parent f777a0d2a9
commit b691324685
47 changed files with 6587 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
---
phase: 9-real-bond-data
task: 5
total_tasks: 6
status: paused
last_updated: 2026-04-03T13:43:26.520Z
---
<current_state>
We have successfully implemented the "Real Corporate Bond Data Fetching Pipeline" (Phase 9) using an open-source Naver Finance scraper, substituted fake benchmark mappings with actual realistic ISINs (e.g. KR600538012C Hyundai Motor), and excluded `Rate` (SOFR/CD91D) from default simulations. We also fixed a fatal bug where empty Equity shock frames crashed the sqlite generation which 500'd the API. We are pausing to consolidate progress.
</current_state>
<completed_work>
- Task 1: Built `bond_data_fetcher.py` and decoupled `Rate` classification. - Done
- Task 2: Adjusted `create_security_master.py` to employ realistic ISINs (Samsung, Hyundai, KB, KTB). - Done
- Task 3: Modified `market_risk_engine.py` to execute accurately over mixed asset types. - Done
- Task 4: Solved API Internal Server Error caused by sqlite missing dataset. - Done
</completed_work>
<remaining_work>
- Task 5: Push documentation to Gitea Wiki (currently blocked by git remote auth, drafted locally instead).
</remaining_work>
<decisions_made>
- Decided to use hardcoded real ISINs linked to Naver Finance proxy representations because `pykrx` bond endpoints were broken, and generating/scraping raw issuance reports from DART/Seibro needs API Keys and is heavily captcha-gated.
</decisions_made>
<blockers>
- Gitea Wiki Clone: Failed due to network remote reading error. Workaround: Formatted the progress summary into `docs/Wiki_Summary_Phase9.md` so the user can manually transfer or push it.
</blockers>
<context>
The DB is fresh and valid. The FastAPI works locally at `:8000/api/matrix/baseline`. Data maps successfully.
</context>
<next_action>
Start with: Reviewing the UI to ensure the user is completely satisfied with the ISIN bond rendering, then proceed to any remaining UI polishing or back-testing tasks.
</next_action>

View File

@@ -0,0 +1,27 @@
# Title: ISDA Quantitative Engine Mathematical & Data Overhaul
## Goal
Transform the climate risk engine from a heuristic-based approximation model into a mathematically rigorous, ISDA-compliant valuation framework. Eliminate theoretical "fudging", correct NGFS data scaling errors, and ensure that all market scenarios accurately map to formal reference data and baseline dataset snapshots instead of arbitrary values.
## Proposed Steps
### 1. Data Governance & Entity Relational Mapping
- **Create `firm_reference_data` table:** Implement a Security Master mechanism (SQLite or CSV) mapping `asset_code` to specific ISDA Firmographics (`gics_sector`, `credit_rating`, `ksic_code`).
- **Load Firmographic Reference Data**: Implement logic in `base_market_data_loader.py` to join against this robust catalog, replacing all previous Python `lambda` arbitrary sector mapping.
### 2. Market Data Integration (ISDA Baseline)
- **JSONB Parsing**: Extract the pre-evaluated market dataset snapshot (`spots` & `vols`) from the `eval_datasets` Postgres table.
- **Bind True Starting State ($V_0$ & $\sigma_0$)**: Substitute all uniformly hardcoded constants ($V_{base} = 100.0, \sigma_V = 0.20$) with actual market prices and observed implied volatilities for precise baseline setting (e.g., Samsung Electronics `56300`).
### 3. Quantitative Formulation Overhaul
- **Merton Model Rectification**: Halt arbitrary scalar amplifications of Firm Asset Volatility ($\sigma_V$). Restore $\sigma_V$ as an invariant across normal & stressed environments so equity spread amplification triggers organically via capital structural leverage ($V/E \cdot N(d_1)$).
- **Hull-White 1-Factor Correct Pricing Formula**: Replace simplistic Beta curve increments. Implement the precise Affine Term Structure $B(0, T)$ Zero Rate formulation factoring mean reversion (`hw_kappa`).
- **NGFS Percentage Recalibration**: Divide structural NGFS policy inputs by 100 to map them into formal decimal yield configurations (`0.0525` instead of `5.25`), aligning seamlessly with HW mathematical bounds.
### 4. UI & Presentation Integration
- Extend existing frontend (`App.jsx`) and API serialization (`main.py`) to expose accurate curve `Tenor` fields explicitly.
- Render accurate HW mathematical formulas on the guidance panels corresponding to the reformed backend physics.
## Testing & Verification
- Manually review `engine_results` and JSON API outputs to verify newly produced PVs and Deltas align with expected Quant characteristics.
- Ensure the UI adequately parses `Tenor` without exceptions.