Skip to content

Commit

Permalink
Move financial_metrics out of market_data agent
Browse files Browse the repository at this point in the history
  • Loading branch information
virattt committed Jan 3, 2025
1 parent 3dccd07 commit 0e66e81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
15 changes: 14 additions & 1 deletion src/agents/fundamentals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
12 changes: 1 addition & 11 deletions src/agents/market_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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"],
Expand All @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions src/agents/valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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%}"
Expand Down

0 comments on commit 0e66e81

Please sign in to comment.