"""전세/매수 예산·규제 판정 (순수 함수, 외부 호출 없음).""" from . import finance_rules_config as cfg def region_regulation(dong: str) -> dict: d = (dong or "").strip() is_toheo = d in cfg.TOHEO_DONGS is_regulated = d in cfg.REGULATED_DONGS or is_toheo notes = [] if is_toheo: notes.append("토지거래허가구역 — 매수 시 실거주 의무(2년)+허가 필요, 갭투자 금지") if is_regulated: notes.append("규제지역 — LTV 강화") notes.append("토허/규제 여부는 서울시 최신 고시로 확인 필요") return {"is_toheo": is_toheo, "is_regulated": is_regulated, "notes": " · ".join(notes)} def _dsr_max_loan(annual_income: int) -> int: """DSR 한도 내 대출 원금 근사(만원). 원리금균등, 가정 금리·만기.""" if not annual_income or annual_income <= 0: return 0 annual_pay_cap = annual_income * cfg.DSR_LIMIT_PCT / 100.0 # 연 상환 가능액 r = cfg.ASSUMED_RATE_PCT / 100.0 / 12 n = cfg.ASSUMED_TERM_YEARS * 12 monthly_cap = annual_pay_cap / 12.0 if r == 0: return int(monthly_cap * n) # PV = PMT * (1-(1+r)^-n)/r pv = monthly_cap * (1 - (1 + r) ** (-n)) / r return int(pv) def estimate_jeonse_budget(equity: int, annual_income: int, jeonse_loan_ratio: float = None) -> dict: equity = equity or 0 ratio = jeonse_loan_ratio if jeonse_loan_ratio is not None else cfg.JEONSE_LOAN_RATIO # 전세대출 한도 = min(보증기관 절대상한, DSR 한도). 보증금 비례는 매물별로 matcher에서 재확인. loan_limit = min(cfg.JEONSE_LOAN_CAP, _dsr_max_loan(annual_income) or cfg.JEONSE_LOAN_CAP) max_deposit = equity + loan_limit return { "loan_limit": loan_limit, "max_deposit": max_deposit, "notes": f"전세대출 한도≈{loan_limit}만(보증기관·DSR 근사, 보증금 대비 {int(ratio*100)}% 이내). {cfg.DISCLAIMER}", } def estimate_purchase_budget(equity: int, annual_income: int, region_flags: dict, is_first_home: bool, is_homeless: bool) -> dict: equity = equity or 0 reg = "regulated" if (region_flags or {}).get("is_regulated") else "normal" first = "first" if is_first_home else "normal" ltv_pct = cfg.LTV_TABLE[(reg, first)] # 대출가능액 = min(수도권 한도, DSR 한도). LTV는 매매가에 따라 matcher에서 상한 재확인. dsr_cap = _dsr_max_loan(annual_income) loan_cap = min(cfg.SUDOGWON_MORTGAGE_CAP, dsr_cap) if dsr_cap else cfg.SUDOGWON_MORTGAGE_CAP max_price = equity + loan_cap flags = [] if (region_flags or {}).get("is_toheo"): flags.append("토허") if (region_flags or {}).get("is_regulated"): flags.append("규제지역") return { "ltv_pct": ltv_pct, "loan_cap": loan_cap, "max_price": max_price, "dsr_note": f"DSR {cfg.DSR_LIMIT_PCT}% 한도 근사(금리{cfg.ASSUMED_RATE_PCT}%·{cfg.ASSUMED_TERM_YEARS}년)", "regulation_flags": flags, }