From 2b94cc802d059320147f2c34da48f64bbc5b317b Mon Sep 17 00:00:00 2001 From: Variet Agent Date: Wed, 11 Mar 2026 16:00:07 +0900 Subject: [PATCH] feat(pipeline): update transition_matrices and config for 7x7 Zt estimation --- config.yaml | 4 ++-- data/transition_matrices.py | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/config.yaml b/config.yaml index 125a330..843c981 100644 --- a/config.yaml +++ b/config.yaml @@ -18,14 +18,14 @@ ecos: # 전이행렬 데이터 소스 data: transition_source: "real" # "real" (3사 실제) | "builtin" (내장 샘플) - transition_dir: null # null이면 기본 data/real/ + transition_dir: null # null이면 기본 data/real_v2/ # 모형 파라미터 model: # 자산상관계수 (Basel IRB 기준 0.12~0.24, 기업 평균 ~0.20) rho: 0.20 # 신용등급 체계 (한국 3사 공통) - rating_grades: ["AAA", "AA", "A", "BBB", "BB", "B", "CCC", "D"] + rating_grades: ["AAA", "AA", "A", "BBB", "BB", "B", "D"] # 7x7 (CCC제외, Zt추정용) # 시나리오 설정 scenarios: diff --git a/data/transition_matrices.py b/data/transition_matrices.py index ab1f255..c6a7b3e 100644 --- a/data/transition_matrices.py +++ b/data/transition_matrices.py @@ -15,8 +15,12 @@ from pathlib import Path from typing import Dict, List, Optional, Tuple -# 등급 레이블 -RATING_GRADES = ["AAA", "AA", "A", "BBB", "BB", "B", "CCC", "D"] +# Rating grade labels +RATING_GRADES_8 = ["AAA", "AA", "A", "BBB", "BB", "B", "CCC", "D"] +RATING_GRADES_7 = ["AAA", "AA", "A", "BBB", "BB", "B", "D"] + +# Default: 7x7 (CCC excluded for Zt estimation) +RATING_GRADES = RATING_GRADES_7 N_GRADES = len(RATING_GRADES) @@ -205,7 +209,7 @@ def _load_real_matrices(data_dir: Optional[str] = None) -> Dict[int, np.ndarray] parse_pdf_matrices.py 로 생성된 3사 평균 CSV 사용. """ if data_dir is None: - data_dir = str(Path(__file__).parent / "real") + data_dir = str(Path(__file__).parent / "real_v2") real_dir = Path(data_dir) if not real_dir.exists(): @@ -320,7 +324,11 @@ def get_default_rates(matrices: Dict[int, np.ndarray]) -> pd.DataFrame: index=연도, columns=등급, values=연간 PD """ years = sorted(matrices.keys()) - grades = RATING_GRADES[:-1] # D 제외 + n = list(matrices.values())[0].shape[0] + if n == 7: + grades = RATING_GRADES_7[:-1] # AAA~B (D 제외) + else: + grades = RATING_GRADES_8[:-1] # AAA~CCC (D 제외) data = {} for year in years: @@ -332,10 +340,15 @@ def get_default_rates(matrices: Dict[int, np.ndarray]) -> pd.DataFrame: def display_matrix(tm: np.ndarray, title: str = "전이행렬") -> str: """전이행렬을 보기 좋게 포매팅""" + n = tm.shape[0] + if n == 7: + grades = RATING_GRADES_7 + else: + grades = RATING_GRADES_8 df = pd.DataFrame( tm, - index=RATING_GRADES, - columns=RATING_GRADES + index=grades, + columns=grades ) # 백분율 표시 df_pct = df * 100