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,12 +26,22 @@ 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"]
|
||||||
|
|
||||||
tools = [
|
config = get_config()
|
||||||
get_fundamentals,
|
market = config.get("market", "US") if config else "US"
|
||||||
get_balance_sheet,
|
|
||||||
get_cashflow,
|
if market == "KRX":
|
||||||
get_income_statement,
|
tools = [
|
||||||
]
|
get_krx_fundamentals,
|
||||||
|
get_dart_financials,
|
||||||
|
get_dart_shareholders,
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
tools = [
|
||||||
|
get_fundamentals,
|
||||||
|
get_balance_sheet,
|
||||||
|
get_cashflow,
|
||||||
|
get_income_statement,
|
||||||
|
]
|
||||||
|
|
||||||
system_message = (
|
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."
|
"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."
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,22 @@ 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"]
|
||||||
|
|
||||||
tools = [
|
config = get_config()
|
||||||
get_stock_data,
|
market = config.get("market", "US") if config else "US"
|
||||||
get_indicators,
|
|
||||||
]
|
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 = (
|
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:
|
"""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:
|
||||||
|
|
|
||||||
|
|
@ -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,10 +22,20 @@ 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"]
|
||||||
|
|
||||||
tools = [
|
config = get_config()
|
||||||
get_news,
|
market = config.get("market", "US") if config else "US"
|
||||||
get_global_news,
|
|
||||||
]
|
if market == "KRX":
|
||||||
|
tools = [
|
||||||
|
get_korean_news,
|
||||||
|
get_korean_global_news,
|
||||||
|
get_dart_disclosures,
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
tools = [
|
||||||
|
get_news,
|
||||||
|
get_global_news,
|
||||||
|
]
|
||||||
|
|
||||||
system_message = (
|
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."
|
"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."
|
||||||
|
|
|
||||||
|
|
@ -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