Skip to content

Commit 57aee0c

Browse files
committed
수정: US 검색 openable 게이트 손익신호로 확대 — 은행·REIT 수백 종목 복구
매출(sales) 단독 게이트가 금융·REIT(매출=이자/리스수익이라 sales 태그 빔) 및 일부 제조사를 부당 제외. 손익신호(sales OR net_profit)로 확대. 실측 +2,094 종목 openable(은행239·제조331·holding208·credit44 등, 2,067/2,094 자산보유=실회사). revenue 는 랭킹용 sales 유지(net_profit-only 은 0 하단). 손익 전무는 제외.
1 parent 6df7a4a commit 57aee0c

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

‎.github/scripts/prebuild/buildSearchIndexUs.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ def build(tickersPath: Path, scanPath: Path, out: Path) -> int:
4747
print(f"[search-us] scan 스키마 부적합: {scan.columns}", flush=True)
4848
return 0
4949

50-
# 회사별 최신 fy 1행 (sales/sector) — 다년 패널이면 latest 슬라이스, 단년이면 그대로.
50+
# 회사별 최신 fy 1행 (sales/net_profit/sector). 다년 패널이면 latest 슬라이스, 단년이면 그대로.
51+
# openable 게이트는 sales 단독이 아니라 손익신호(sales OR net_profit). 금융·REIT 는 매출이
52+
# 이자/리스수익이라 sales 태그가 비어도 net_profit 으로 열 수 있어야 한다(매출 only 게이트가
53+
# AAON 류 외에 금융·REIT 수백 종목도 부당 제외했음). revenue 는 랭킹용으로만 sales 사용.
5154
sel = (
5255
["stockCode", "sales"]
56+
+ (["net_profit"] if "net_profit" in scan.columns else [])
5357
+ (["sector"] if "sector" in scan.columns else [])
5458
+ (["fy"] if "fy" in scan.columns else [])
5559
)
@@ -59,6 +63,7 @@ def build(tickersPath: Path, scanPath: Path, out: Path) -> int:
5963

6064
sectorMap: dict[str, str] = {}
6165
revMap: dict[str, float] = {}
66+
openSet: set[str] = set() # 손익신호(sales OR net_profit) 있는 종목 = openable
6267
for r in scan.iter_rows(named=True):
6368
code = str(r["stockCode"]).strip().upper()
6469
if not code:
@@ -71,19 +76,21 @@ def build(tickersPath: Path, scanPath: Path, out: Path) -> int:
7176
revMap[code] = round(float(sales) / 1_000_000_000_000, 4)
7277
except (ValueError, TypeError):
7378
pass
79+
if sales is not None or r.get("net_profit") is not None:
80+
openSet.add(code)
7481

7582
rows: list[dict] = []
7683
for r in tk.iter_rows(named=True):
7784
ticker = str(r["ticker"]).strip().upper()
78-
if not ticker or ticker not in revMap: # 재무 없는 티커 제외 (검색돼도 못 여니까)
85+
if not ticker or ticker not in openSet: # 손익신호 없는 티커 제외 (열어도 빈 패널이라)
7986
continue
8087
rows.append(
8188
{
8289
"stockCode": ticker,
8390
"corpName": str(r["title"]).strip() if r["title"] else ticker,
8491
"industry": sectorMap.get(ticker) or (str(r["exchange"]).strip() if r["exchange"] else "US"),
8592
"market": "US",
86-
"revenue": revMap[ticker],
93+
"revenue": revMap.get(ticker, 0.0), # net_profit-only(금융·REIT) 은 매출 0(랭킹 하단)
8794
}
8895
)
8996
# 매출 내림차순 (검색 랭킹 대형주 우선)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""buildSearchIndexUs openable 게이트. 손익신호(sales OR net_profit)면 검색에 포함.
2+
3+
금융·REIT 는 매출(sales) 태그가 비고 net_profit 만 있어도 열려야 한다(매출 only 게이트가
4+
은행·REIT 수백 종목을 부당 제외하던 회귀 가드). 합성 parquet, 네트워크/OOM 무관.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
import importlib.util
10+
import json
11+
from pathlib import Path
12+
13+
import polars as pl
14+
import pytest
15+
16+
pytestmark = pytest.mark.unit
17+
18+
_SCRIPT = Path(__file__).resolve().parents[2] / ".github" / "scripts" / "prebuild" / "buildSearchIndexUs.py"
19+
20+
21+
def _loadBuild():
22+
"""buildSearchIndexUs.build 함수 로드(스크립트라 importlib 경유)."""
23+
spec = importlib.util.spec_from_file_location("buildSearchIndexUsForTest", _SCRIPT)
24+
module = importlib.util.module_from_spec(spec)
25+
spec.loader.exec_module(module)
26+
return module.build
27+
28+
29+
def test_gate_includes_net_profit_only_company(tmp_path):
30+
"""net_profit 만 있고 sales 없는 종목(은행·REIT)도 검색 포함, 매출 0 랭킹 하단."""
31+
build = _loadBuild()
32+
scanPath = tmp_path / "finance.parquet"
33+
tickersPath = tmp_path / "tickers.parquet"
34+
out = tmp_path / "search-index-us.json"
35+
36+
pl.DataFrame(
37+
{
38+
"stockCode": ["MFG", "BANK", "SHELL"],
39+
"sales": [1_000_000_000.0, None, None], # MFG 매출, BANK·SHELL 없음
40+
"net_profit": [50_000_000.0, 80_000_000.0, None], # BANK 순이익만, SHELL 둘 다 없음
41+
"sector": ["manufacturing", "banks", None],
42+
"fy": [2024, 2024, 2024],
43+
}
44+
).write_parquet(scanPath)
45+
pl.DataFrame(
46+
{
47+
"ticker": ["MFG", "BANK", "SHELL"],
48+
"title": ["Maker Inc", "Big Bank", "Empty Shell"],
49+
"exchange": ["NYSE", "NYSE", "NYSE"],
50+
}
51+
).write_parquet(tickersPath)
52+
53+
n = build(tickersPath, scanPath, out)
54+
rows = {r["stockCode"]: r for r in json.loads(out.read_text(encoding="utf-8"))}
55+
assert "MFG" in rows # 매출 있음
56+
assert "BANK" in rows # 순이익만 있어도 포함(회귀 가드 핵심)
57+
assert "SHELL" not in rows # 손익신호 전무 제외
58+
assert rows["BANK"]["revenue"] == 0.0 # 매출 없으니 랭킹용 0
59+
assert rows["MFG"]["revenue"] > 0
60+
assert n == 2

0 commit comments

Comments
 (0)