Add global market context to morning analysis
- fetch_global_data(): Yahoo Finance로 나스닥/S&P500/다우/SOX/달러원/WTI/미국10년물 수집 - morning.py --print 출력에 global_raw 포함 - morning.md: global_score·global_risk 산출 기준 및 섹터 힌트 매핑 추가 - daily_context.json에 global_context 블록 추가 (domestic_score와 분리) - sentiment_score = domestic_score×0.6 + global_score×0.4 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+50
-3
@@ -84,6 +84,49 @@ RSS_FEEDS = [
|
||||
]
|
||||
|
||||
|
||||
# ── 글로벌 지표 수집 ──────────────────────────────────────────────────────────
|
||||
|
||||
def fetch_global_data() -> dict:
|
||||
"""Yahoo Finance로 미국 주요 지수·환율·원자재 전일 종가 및 등락률 수집"""
|
||||
try:
|
||||
import yfinance as yf
|
||||
except ImportError:
|
||||
logger.warning("yfinance 미설치 — 글로벌 데이터 스킵")
|
||||
return {}
|
||||
|
||||
SYMBOLS = {
|
||||
"nasdaq": "^IXIC",
|
||||
"sp500": "^GSPC",
|
||||
"dow": "^DJI",
|
||||
"sox": "^SOX",
|
||||
"usdkrw": "KRW=X",
|
||||
"wti": "CL=F",
|
||||
"us10y": "^TNX",
|
||||
}
|
||||
|
||||
result: dict = {}
|
||||
for name, sym in SYMBOLS.items():
|
||||
try:
|
||||
hist = yf.Ticker(sym).history(period="2d")
|
||||
if len(hist) >= 2:
|
||||
prev = float(hist["Close"].iloc[-2])
|
||||
last = float(hist["Close"].iloc[-1])
|
||||
result[name] = {
|
||||
"price": round(last, 2),
|
||||
"change_pct": round((last - prev) / prev * 100, 2),
|
||||
}
|
||||
elif len(hist) == 1:
|
||||
result[name] = {
|
||||
"price": round(float(hist["Close"].iloc[-1]), 2),
|
||||
"change_pct": None,
|
||||
}
|
||||
except Exception as e:
|
||||
logger.warning(f"글로벌 데이터 실패 [{name}/{sym}]: {e}")
|
||||
|
||||
logger.info(f"글로벌 데이터 수집: {list(result.keys())}")
|
||||
return result
|
||||
|
||||
|
||||
# ── RSS 뉴스 수집 ─────────────────────────────────────────────────────────────
|
||||
|
||||
async def fetch_rss_news() -> list[str]:
|
||||
@@ -223,10 +266,13 @@ async def main(print_mode: bool = False):
|
||||
for d in ["data/news", "data/market"]:
|
||||
os.makedirs(d, exist_ok=True)
|
||||
|
||||
# 1. RSS 뉴스 수집 (4개 언론사)
|
||||
# 1. 글로벌 지표 수집 (Yahoo Finance — 동기, 블로킹 짧음)
|
||||
global_data = fetch_global_data()
|
||||
|
||||
# 2. RSS 뉴스 수집 (4개 언론사)
|
||||
news = await fetch_rss_news()
|
||||
|
||||
# 2. KIS 시장 데이터 — 데이터 수집 전용이므로 실거래 API 사용 (주문 없음)
|
||||
# 3. KIS 시장 데이터 — 데이터 수집 전용이므로 실거래 API 사용 (주문 없음)
|
||||
_orig_mock = os.environ.get("KIS_MOCK", "true")
|
||||
os.environ["KIS_MOCK"] = "false"
|
||||
kis = KISClient()
|
||||
@@ -238,7 +284,7 @@ async def main(print_mode: bool = False):
|
||||
except Exception as e:
|
||||
logger.warning(f"KIS 수집 실패: {e}")
|
||||
|
||||
# 3. 네이버 종목별 뉴스 (거래량 상위 20종목)
|
||||
# 4. 네이버 종목별 뉴스 (거래량 상위 20종목)
|
||||
stock_news = await fetch_stock_news_naver(market["volume_rank"])
|
||||
|
||||
# 파일 저장
|
||||
@@ -257,6 +303,7 @@ async def main(print_mode: bool = False):
|
||||
print(json.dumps(
|
||||
{
|
||||
"date": TODAY,
|
||||
"global_raw": global_data, # 미국 지수·환율·원자재
|
||||
"news_headlines": news, # RSS 전체 (~80건)
|
||||
"volume_rank": market["volume_rank"][:20],
|
||||
"foreign_buy_top10": market["foreign_buy"],
|
||||
|
||||
Reference in New Issue
Block a user