Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: start-date parsing in market_data.py #41

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/agents/market_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from tools.api import search_line_items, get_financial_metrics, get_insider_trades, get_market_cap, get_prices

from datetime import datetime
import calendar

llm = ChatOpenAI(model="gpt-4o")

Expand All @@ -16,11 +17,20 @@ def market_data_agent(state: AgentState):
# Set default dates
end_date = data["end_date"] or datetime.now().strftime('%Y-%m-%d')
if not data["start_date"]:
# Calculate 3 months before end_date
end_date_obj = datetime.strptime(end_date, '%Y-%m-%d')
start_date = end_date_obj.replace(month=end_date_obj.month - 3) if end_date_obj.month > 3 else \
end_date_obj.replace(year=end_date_obj.year - 1, month=end_date_obj.month + 9)
start_date = start_date.strftime('%Y-%m-%d')

# Calculate 3 months before end_date
new_month = (end_date_obj.month - 3) % 12 or 12
new_year = end_date_obj.year - 1 if end_date_obj.month <= 3 else end_date_obj.year
# Get the last day of the new month to handle edge cases like December 31
last_day_of_month = calendar.monthrange(new_year, new_month)[1]
new_day = min(end_date_obj.day, last_day_of_month)

# Create the new date
start_date_obj = end_date_obj.replace(year=new_year, month=new_month, day=new_day)

# Format the start_date as a string
start_date = start_date_obj.strftime('%Y-%m-%d')
else:
start_date = data["start_date"]

Expand Down Expand Up @@ -71,4 +81,4 @@ def market_data_agent(state: AgentState):
"market_cap": market_cap,
"financial_line_items": financial_line_items,
}
}
}