diff --git a/src/agents/fundamentals.py b/src/agents/fundamentals.py index 65a0b73..a4fa3d7 100644 --- a/src/agents/fundamentals.py +++ b/src/agents/fundamentals.py @@ -4,12 +4,25 @@ import json +from tools.api import get_financial_metrics + ##### Fundamental Agent ##### def fundamentals_agent(state: AgentState): """Analyzes fundamental data and generates trading signals.""" show_reasoning = state["metadata"]["show_reasoning"] data = state["data"] - metrics = data["financial_metrics"][0] + end_date = data["end_date"] + + # Get the financial metrics + financial_metrics = get_financial_metrics( + ticker=data["ticker"], + report_period=end_date, + period='ttm', + limit=1, + ) + + # Pull the most recent financial metrics + metrics = financial_metrics[0] # Initialize signals list for different fundamental aspects signals = [] diff --git a/src/agents/market_data.py b/src/agents/market_data.py index 09d6a84..442f584 100644 --- a/src/agents/market_data.py +++ b/src/agents/market_data.py @@ -2,9 +2,8 @@ from langchain_openai.chat_models import ChatOpenAI from agents.state import AgentState -from tools.api import search_line_items, get_financial_metrics, get_insider_trades, get_market_cap, get_prices +from tools.api import search_line_items, get_insider_trades, get_market_cap -from datetime import datetime llm = ChatOpenAI(model="gpt-4o") @@ -15,14 +14,6 @@ def market_data_agent(state: AgentState): start_date = data["start_date"] end_date = data["end_date"] - # Get the financial metrics - financial_metrics = get_financial_metrics( - ticker=data["ticker"], - report_period=end_date, - period='ttm', - limit=1, - ) - # Get the insider trades insider_trades = get_insider_trades( ticker=data["ticker"], @@ -49,7 +40,6 @@ def market_data_agent(state: AgentState): **data, "start_date": start_date, "end_date": end_date, - "financial_metrics": financial_metrics, "insider_trades": insider_trades, "market_cap": market_cap, "financial_line_items": financial_line_items, diff --git a/src/agents/valuation.py b/src/agents/valuation.py index 4a63e3b..e7974ba 100644 --- a/src/agents/valuation.py +++ b/src/agents/valuation.py @@ -2,16 +2,27 @@ from agents.state import AgentState, show_agent_reasoning import json +from tools.api import get_financial_metrics + def valuation_agent(state: AgentState): """Performs detailed valuation analysis using multiple methodologies.""" show_reasoning = state["metadata"]["show_reasoning"] data = state["data"] - metrics = data["financial_metrics"][0] current_financial_line_item = data["financial_line_items"][0] previous_financial_line_item = data["financial_line_items"][1] market_cap = data["market_cap"] + end_date = data["end_date"] + + # Get the financial metrics + financial_metrics = get_financial_metrics( + ticker=data["ticker"], + report_period=end_date, + period='ttm', + limit=1, + ) - reasoning = {} + # Pull the most recent financial metrics + metrics = financial_metrics[0] # Calculate working capital change working_capital_change = (current_financial_line_item.get('working_capital') or 0) - (previous_financial_line_item.get('working_capital') or 0) @@ -48,6 +59,8 @@ def valuation_agent(state: AgentState): else: signal = 'neutral' + # Create the reasoning + reasoning = {} reasoning["dcf_analysis"] = { "signal": "bullish" if dcf_gap > 0.15 else "bearish" if dcf_gap < -0.15 else "neutral", "details": f"Intrinsic Value: ${dcf_value:,.2f}, Market Cap: ${market_cap:,.2f}, Gap: {dcf_gap:.1%}"