mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-05-01 14:33:10 +03:00
feat: add yfinance support to accommodate community request for stability and quota
This commit is contained in:
10
main.py
10
main.py
@@ -12,12 +12,12 @@ config["deep_think_llm"] = "gpt-5-mini" # Use a different model
|
|||||||
config["quick_think_llm"] = "gpt-5-mini" # Use a different model
|
config["quick_think_llm"] = "gpt-5-mini" # Use a different model
|
||||||
config["max_debate_rounds"] = 1 # Increase debate rounds
|
config["max_debate_rounds"] = 1 # Increase debate rounds
|
||||||
|
|
||||||
# Configure data vendors (default uses yfinance and alpha_vantage)
|
# Configure data vendors (default uses yfinance, no extra API keys needed)
|
||||||
config["data_vendors"] = {
|
config["data_vendors"] = {
|
||||||
"core_stock_apis": "yfinance", # Options: yfinance, alpha_vantage, local
|
"core_stock_apis": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
"technical_indicators": "yfinance", # Options: yfinance, alpha_vantage, local
|
"technical_indicators": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
"fundamental_data": "alpha_vantage", # Options: openai, alpha_vantage, local
|
"fundamental_data": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
"news_data": "alpha_vantage", # Options: openai, alpha_vantage, google, local
|
"news_data": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialize with custom config
|
# Initialize with custom config
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from typing import Annotated
|
|||||||
from .y_finance import (
|
from .y_finance import (
|
||||||
get_YFin_data_online,
|
get_YFin_data_online,
|
||||||
get_stock_stats_indicators_window,
|
get_stock_stats_indicators_window,
|
||||||
|
get_fundamentals as get_yfinance_fundamentals,
|
||||||
get_balance_sheet as get_yfinance_balance_sheet,
|
get_balance_sheet as get_yfinance_balance_sheet,
|
||||||
get_cashflow as get_yfinance_cashflow,
|
get_cashflow as get_yfinance_cashflow,
|
||||||
get_income_statement as get_yfinance_income_statement,
|
get_income_statement as get_yfinance_income_statement,
|
||||||
@@ -78,6 +79,7 @@ VENDOR_METHODS = {
|
|||||||
# fundamental_data
|
# fundamental_data
|
||||||
"get_fundamentals": {
|
"get_fundamentals": {
|
||||||
"alpha_vantage": get_alpha_vantage_fundamentals,
|
"alpha_vantage": get_alpha_vantage_fundamentals,
|
||||||
|
"yfinance": get_yfinance_fundamentals,
|
||||||
},
|
},
|
||||||
"get_balance_sheet": {
|
"get_balance_sheet": {
|
||||||
"alpha_vantage": get_alpha_vantage_balance_sheet,
|
"alpha_vantage": get_alpha_vantage_balance_sheet,
|
||||||
|
|||||||
@@ -293,6 +293,63 @@ def get_stockstats_indicator(
|
|||||||
return str(indicator_value)
|
return str(indicator_value)
|
||||||
|
|
||||||
|
|
||||||
|
def get_fundamentals(
|
||||||
|
ticker: Annotated[str, "ticker symbol of the company"],
|
||||||
|
curr_date: Annotated[str, "current date (not used for yfinance)"] = None
|
||||||
|
):
|
||||||
|
"""Get company fundamentals overview from yfinance."""
|
||||||
|
try:
|
||||||
|
ticker_obj = yf.Ticker(ticker.upper())
|
||||||
|
info = ticker_obj.info
|
||||||
|
|
||||||
|
if not info:
|
||||||
|
return f"No fundamentals data found for symbol '{ticker}'"
|
||||||
|
|
||||||
|
fields = [
|
||||||
|
("Name", info.get("longName")),
|
||||||
|
("Sector", info.get("sector")),
|
||||||
|
("Industry", info.get("industry")),
|
||||||
|
("Market Cap", info.get("marketCap")),
|
||||||
|
("PE Ratio (TTM)", info.get("trailingPE")),
|
||||||
|
("Forward PE", info.get("forwardPE")),
|
||||||
|
("PEG Ratio", info.get("pegRatio")),
|
||||||
|
("Price to Book", info.get("priceToBook")),
|
||||||
|
("EPS (TTM)", info.get("trailingEps")),
|
||||||
|
("Forward EPS", info.get("forwardEps")),
|
||||||
|
("Dividend Yield", info.get("dividendYield")),
|
||||||
|
("Beta", info.get("beta")),
|
||||||
|
("52 Week High", info.get("fiftyTwoWeekHigh")),
|
||||||
|
("52 Week Low", info.get("fiftyTwoWeekLow")),
|
||||||
|
("50 Day Average", info.get("fiftyDayAverage")),
|
||||||
|
("200 Day Average", info.get("twoHundredDayAverage")),
|
||||||
|
("Revenue (TTM)", info.get("totalRevenue")),
|
||||||
|
("Gross Profit", info.get("grossProfits")),
|
||||||
|
("EBITDA", info.get("ebitda")),
|
||||||
|
("Net Income", info.get("netIncomeToCommon")),
|
||||||
|
("Profit Margin", info.get("profitMargins")),
|
||||||
|
("Operating Margin", info.get("operatingMargins")),
|
||||||
|
("Return on Equity", info.get("returnOnEquity")),
|
||||||
|
("Return on Assets", info.get("returnOnAssets")),
|
||||||
|
("Debt to Equity", info.get("debtToEquity")),
|
||||||
|
("Current Ratio", info.get("currentRatio")),
|
||||||
|
("Book Value", info.get("bookValue")),
|
||||||
|
("Free Cash Flow", info.get("freeCashflow")),
|
||||||
|
]
|
||||||
|
|
||||||
|
lines = []
|
||||||
|
for label, value in fields:
|
||||||
|
if value is not None:
|
||||||
|
lines.append(f"{label}: {value}")
|
||||||
|
|
||||||
|
header = f"# Company Fundamentals for {ticker.upper()}\n"
|
||||||
|
header += f"# Data retrieved on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
|
||||||
|
|
||||||
|
return header + "\n".join(lines)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return f"Error retrieving fundamentals for {ticker}: {str(e)}"
|
||||||
|
|
||||||
|
|
||||||
def get_balance_sheet(
|
def get_balance_sheet(
|
||||||
ticker: Annotated[str, "ticker symbol of the company"],
|
ticker: Annotated[str, "ticker symbol of the company"],
|
||||||
freq: Annotated[str, "frequency of data: 'annual' or 'quarterly'"] = "quarterly",
|
freq: Annotated[str, "frequency of data: 'annual' or 'quarterly'"] = "quarterly",
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ DEFAULT_CONFIG = {
|
|||||||
# Data vendor configuration
|
# Data vendor configuration
|
||||||
# Category-level configuration (default for all tools in category)
|
# Category-level configuration (default for all tools in category)
|
||||||
"data_vendors": {
|
"data_vendors": {
|
||||||
"core_stock_apis": "yfinance", # Options: yfinance, alpha_vantage
|
"core_stock_apis": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
"technical_indicators": "yfinance", # Options: yfinance, alpha_vantage
|
"technical_indicators": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
"fundamental_data": "alpha_vantage", # Options: alpha_vantage, yfinance
|
"fundamental_data": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
"news_data": "yfinance", # Options: yfinance, alpha_vantage
|
"news_data": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
},
|
},
|
||||||
# Tool-level configuration (takes precedence over category-level)
|
# Tool-level configuration (takes precedence over category-level)
|
||||||
"tool_vendors": {
|
"tool_vendors": {
|
||||||
|
|||||||
Reference in New Issue
Block a user