update krx function

This commit is contained in:
hyejwon 2026-03-12 15:55:51 +09:00
parent d066820307
commit 692a55dfd5
5 changed files with 84 additions and 29 deletions

View File

@ -1,6 +0,0 @@
# LLM Providers (set the one you use)
OPENAI_API_KEY=
GOOGLE_API_KEY=
ANTHROPIC_API_KEY=
XAI_API_KEY=
OPENROUTER_API_KEY=

View File

@ -1,7 +1,16 @@
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
import time
import json
from tradingagents.agents.utils.agent_utils import get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement, get_insider_transactions
from tradingagents.agents.utils.agent_utils import (
get_fundamentals,
get_balance_sheet,
get_cashflow,
get_income_statement,
get_insider_transactions,
get_krx_fundamentals,
get_dart_financials,
get_dart_shareholders,
)
from tradingagents.agents.utils.korean_prompt import (
KOREAN_INVESTOR_GUIDE,
KOREAN_REPORT_FORMAT_GUIDE,
@ -17,12 +26,22 @@ def create_fundamentals_analyst(llm):
ticker = state["company_of_interest"]
company_name = state["company_of_interest"]
tools = [
get_fundamentals,
get_balance_sheet,
get_cashflow,
get_income_statement,
]
config = get_config()
market = config.get("market", "US") if config else "US"
if market == "KRX":
tools = [
get_krx_fundamentals,
get_dart_financials,
get_dart_shareholders,
]
else:
tools = [
get_fundamentals,
get_balance_sheet,
get_cashflow,
get_income_statement,
]
system_message = (
"You are a researcher tasked with analyzing fundamental information over the past week about a company. Please write a comprehensive report of the company's fundamental information such as financial documents, company profile, basic company financials, and company financial history to gain a full view of the company's fundamental information to inform traders. Make sure to include as much detail as possible. Do not simply state the trends are mixed, provide detailed and finegrained analysis and insights that may help traders make decisions."

View File

@ -26,10 +26,22 @@ def create_market_analyst(llm):
ticker = state["company_of_interest"]
company_name = state["company_of_interest"]
tools = [
get_stock_data,
get_indicators,
]
config = get_config()
market = config.get("market", "US") if config else "US"
if market == "KRX":
tools = [
get_krx_stock_data,
get_krx_indicators,
get_exchange_rate,
get_korea_index,
get_investor_trading,
]
else:
tools = [
get_stock_data,
get_indicators,
]
system_message = (
"""You are a trading assistant tasked with analyzing financial markets. Your role is to select the **most relevant indicators** for a given market condition or trading strategy from the following list. The goal is to choose up to **8 indicators** that provide complementary insights without redundancy. Categories and each category's indicators are:

View File

@ -1,7 +1,13 @@
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
import time
import json
from tradingagents.agents.utils.agent_utils import get_news, get_global_news
from tradingagents.agents.utils.agent_utils import (
get_news,
get_global_news,
get_korean_news,
get_korean_global_news,
get_dart_disclosures,
)
from tradingagents.agents.utils.korean_prompt import (
KOREAN_INVESTOR_GUIDE,
KOREAN_REPORT_FORMAT_GUIDE,
@ -16,10 +22,20 @@ def create_news_analyst(llm):
current_date = state["trade_date"]
ticker = state["company_of_interest"]
tools = [
get_news,
get_global_news,
]
config = get_config()
market = config.get("market", "US") if config else "US"
if market == "KRX":
tools = [
get_korean_news,
get_korean_global_news,
get_dart_disclosures,
]
else:
tools = [
get_news,
get_global_news,
]
system_message = (
"You are a news researcher tasked with analyzing recent news and trends over the past week. Please write a comprehensive report of the current state of the world that is relevant for trading and macroeconomics. Use the available tools: get_news(query, start_date, end_date) for company-specific or targeted news searches, and get_global_news(curr_date, look_back_days, limit) for broader macroeconomic news. Do not simply state the trends are mixed, provide detailed and finegrained analysis and insights that may help traders make decisions."

View File

@ -189,14 +189,25 @@ def get_bulk_ohlcv(
if market == "KRX":
try:
import FinanceDataReader as fdr
from pykrx import stock as krx_stock
except ImportError:
raise ImportError("FinanceDataReader required for KRX data")
raise ImportError("pykrx required for KRX data: pip install pykrx")
# pykrx uses YYYYMMDD format
start_fmt = start_date.replace("-", "")
end_fmt = end_date.replace("-", "")
for ticker in tickers:
try:
data = fdr.DataReader(ticker, start_date, end_date)
ticker_padded = ticker.zfill(6)
data = krx_stock.get_market_ohlcv(start_fmt, end_fmt, ticker_padded)
if data is not None and not data.empty:
# Normalize column names to match expected format
col_map = {
"시가": "Open", "고가": "High", "저가": "Low",
"종가": "Close", "거래량": "Volume",
}
data = data.rename(columns=col_map)
result[ticker] = data
except Exception as e:
logger.warning(f"Failed to get OHLCV for {ticker}: {e}")
@ -263,9 +274,12 @@ def compute_screening_indicators(df: pd.DataFrame) -> dict:
# Volume analysis
if volume is not None and len(volume) >= 20:
indicators["volume_current"] = volume.iloc[-1]
indicators["volume_avg_20"] = volume.rolling(20).mean().iloc[-1]
vol_ratio = volume.iloc[-1] / volume.rolling(20).mean().iloc[-1]
indicators["volume_ratio"] = vol_ratio
vol_avg_20 = volume.rolling(20).mean().iloc[-1]
indicators["volume_avg_20"] = vol_avg_20
if vol_avg_20 and vol_avg_20 > 0:
indicators["volume_ratio"] = volume.iloc[-1] / vol_avg_20
else:
indicators["volume_ratio"] = 0.0
# Bollinger Bands
if len(close) >= 20:
@ -370,7 +384,7 @@ def _get_naver_krx_universe(
if not code_match:
continue
code = code_match.group(1)
code = code_match.group(1).zfill(6)
name = link.text.strip()
# Parse numeric values (remove commas)