update krx function
This commit is contained in:
parent
d066820307
commit
692a55dfd5
|
|
@ -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=
|
|
||||||
|
|
@ -1,7 +1,16 @@
|
||||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||||
import time
|
import time
|
||||||
import json
|
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 (
|
from tradingagents.agents.utils.korean_prompt import (
|
||||||
KOREAN_INVESTOR_GUIDE,
|
KOREAN_INVESTOR_GUIDE,
|
||||||
KOREAN_REPORT_FORMAT_GUIDE,
|
KOREAN_REPORT_FORMAT_GUIDE,
|
||||||
|
|
@ -17,6 +26,16 @@ def create_fundamentals_analyst(llm):
|
||||||
ticker = state["company_of_interest"]
|
ticker = state["company_of_interest"]
|
||||||
company_name = state["company_of_interest"]
|
company_name = state["company_of_interest"]
|
||||||
|
|
||||||
|
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 = [
|
tools = [
|
||||||
get_fundamentals,
|
get_fundamentals,
|
||||||
get_balance_sheet,
|
get_balance_sheet,
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,18 @@ def create_market_analyst(llm):
|
||||||
ticker = state["company_of_interest"]
|
ticker = state["company_of_interest"]
|
||||||
company_name = state["company_of_interest"]
|
company_name = state["company_of_interest"]
|
||||||
|
|
||||||
|
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 = [
|
tools = [
|
||||||
get_stock_data,
|
get_stock_data,
|
||||||
get_indicators,
|
get_indicators,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||||
import time
|
import time
|
||||||
import json
|
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 (
|
from tradingagents.agents.utils.korean_prompt import (
|
||||||
KOREAN_INVESTOR_GUIDE,
|
KOREAN_INVESTOR_GUIDE,
|
||||||
KOREAN_REPORT_FORMAT_GUIDE,
|
KOREAN_REPORT_FORMAT_GUIDE,
|
||||||
|
|
@ -16,6 +22,16 @@ def create_news_analyst(llm):
|
||||||
current_date = state["trade_date"]
|
current_date = state["trade_date"]
|
||||||
ticker = state["company_of_interest"]
|
ticker = state["company_of_interest"]
|
||||||
|
|
||||||
|
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 = [
|
tools = [
|
||||||
get_news,
|
get_news,
|
||||||
get_global_news,
|
get_global_news,
|
||||||
|
|
|
||||||
|
|
@ -189,14 +189,25 @@ def get_bulk_ohlcv(
|
||||||
|
|
||||||
if market == "KRX":
|
if market == "KRX":
|
||||||
try:
|
try:
|
||||||
import FinanceDataReader as fdr
|
from pykrx import stock as krx_stock
|
||||||
except ImportError:
|
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:
|
for ticker in tickers:
|
||||||
try:
|
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:
|
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
|
result[ticker] = data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to get OHLCV for {ticker}: {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
|
# Volume analysis
|
||||||
if volume is not None and len(volume) >= 20:
|
if volume is not None and len(volume) >= 20:
|
||||||
indicators["volume_current"] = volume.iloc[-1]
|
indicators["volume_current"] = volume.iloc[-1]
|
||||||
indicators["volume_avg_20"] = volume.rolling(20).mean().iloc[-1]
|
vol_avg_20 = volume.rolling(20).mean().iloc[-1]
|
||||||
vol_ratio = volume.iloc[-1] / volume.rolling(20).mean().iloc[-1]
|
indicators["volume_avg_20"] = vol_avg_20
|
||||||
indicators["volume_ratio"] = vol_ratio
|
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
|
# Bollinger Bands
|
||||||
if len(close) >= 20:
|
if len(close) >= 20:
|
||||||
|
|
@ -370,7 +384,7 @@ def _get_naver_krx_universe(
|
||||||
if not code_match:
|
if not code_match:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
code = code_match.group(1)
|
code = code_match.group(1).zfill(6)
|
||||||
name = link.text.strip()
|
name = link.text.strip()
|
||||||
|
|
||||||
# Parse numeric values (remove commas)
|
# Parse numeric values (remove commas)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue