diff --git a/test_setup.py b/test_setup.py index 6b1a436..1c393b4 100644 --- a/test_setup.py +++ b/test_setup.py @@ -1,68 +1,44 @@ -"""Quick test: Merton model + Vikunja connectivity""" -import sys -sys.path.insert(0, ".") +"""DART finstate test — stock code vs corp_code""" +import OpenDartReader +import time -# Test 1: Merton model -print("=== Test 1: Merton Model ===") -from src.models.merton import solve_merton, calculate_dd, calculate_edf, dd_to_rating +dart = OpenDartReader("ef6deb100be436aed88051fd4914dbdb58ff2e94") -E = 10_000_000_000_000 # 10조 -sigma_E = 0.30 -D = 5_000_000_000_000 # 5조 -r = 0.035 +# Test: finstate with stock code directly +print("=== DART finstate with stock code directly ===") +for code, name in [("005930", "삼성전자"), ("000660", "SK하이닉스"), ("036720", "한볼트")]: + try: + fs = dart.finstate(code, 2024) + time.sleep(0.5) + n = len(fs) if fs is not None else 0 + print(f" {code} {name}: {n} rows") + except Exception as e: + print(f" {code} {name}: ERROR {e}") -sol = solve_merton(E, sigma_E, D, r) -DD = calculate_dd(sol['V'], sol['sigma_V'], D, r=r) -EDF = calculate_edf(DD) -rating = dd_to_rating(DD) - -print(f" V = {sol['V']/1e12:.2f}조") -print(f" sigma_V = {sol['sigma_V']:.4f}") -print(f" DD = {DD:.4f}") -print(f" EDF = {EDF:.6f} ({EDF*100:.4f}%)") -print(f" Rating = {rating}") -print(f" Converged: {sol['converged']}, Method: {sol['method']}") - -# Test 2: Vikunja -print("\n=== Test 2: Vikunja Connectivity ===") +# Test: finstate_all — bulk download per corp_code +print("\n=== DART finstate_all (삼성전자 00126380) ===") try: - import urllib.request - import json - headers = { - "Authorization": "Bearer tk_070f8e0b715e818bb7178c3815ed5389040eddca", - "Content-Type": "application/json", - } - req = urllib.request.Request( - "https://plan.variet.net/api/v1/projects/11/tasks?per_page=5", - headers=headers - ) - with urllib.request.urlopen(req) as resp: - tasks = json.loads(resp.read().decode("utf-8")) - print(f" Vikunja connected! {len(tasks)} tasks found") - for t in tasks: - status = "done" if t["done"] else "todo" - print(f" #{t['id']} [{status}] {t['title']}") + fs = dart.finstate_all("00126380", 2024) + time.sleep(0.5) + n = len(fs) if fs is not None else 0 + print(f" 삼성전자 finstate_all: {n} rows") except Exception as e: - print(f" Vikunja error: {e}") + print(f" ERROR: {e}") -# Test 3: pykrx -print("\n=== Test 3: pykrx ===") -try: - from pykrx import stock - tickers = stock.get_market_ticker_list("20260310", market="KOSPI") - print(f" pykrx connected! KOSPI tickers: {len(tickers)}") -except Exception as e: - print(f" pykrx error: {e}") - -# Test 4: DART -print("\n=== Test 4: DART API ===") -try: - import OpenDartReader - dart = OpenDartReader("ef6deb100be436aed88051fd4914dbdb58ff2e94") - corp_list = dart.corp_codes - listed = corp_list[corp_list["stock_code"].notna() & (corp_list["stock_code"] != " ")] - print(f" DART connected! Listed companies: {len(listed)}") -except Exception as e: - print(f" DART error: {e}") - -print("\n=== All tests complete ===") +# Test: KOSPI major — find their corp_codes and try finstate +print("\n=== DART finstate loop with known-good corp_codes ===") +corp_codes = dart.corp_codes +for ticker in ["005930", "000660", "005380", "036720", "040130"]: + match = corp_codes[corp_codes["stock_code"] == ticker] + if len(match) > 0: + cc = match.iloc[0]["corp_code"] + cn = match.iloc[0]["corp_name"] + try: + fs = dart.finstate(cc, 2024) + time.sleep(0.5) + n = len(fs) if fs is not None else 0 + print(f" {ticker} {cn} (corp={cc}): {n} rows") + except Exception as e: + print(f" {ticker} {cn}: ERROR {e}") + else: + print(f" {ticker}: Not found in corp_codes")