-
Notifications
You must be signed in to change notification settings - Fork 5k
Macro analyst #244
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
base: main
Are you sure you want to change the base?
Macro analyst #244
Conversation
Summary of ChangesHello @bmigette, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the TradingAgents system by integrating macroeconomic analysis capabilities through the Federal Reserve Economic Data (FRED) API. It introduces a new 'Macro Analyst' agent that can be optionally included in the trading graph, providing comprehensive reports on economic indicators, treasury yield curves, and Federal Reserve policy. This expansion allows for a more holistic market analysis by incorporating crucial economic context without introducing breaking changes or new external dependencies. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new Macro Analyst agent, integrating FRED API for macroeconomic data. The implementation is well-structured and follows the existing design patterns of the project. The changes are mostly additive and well-documented. My review focuses on the new macro_utils.py file, where I've identified a few areas for improvement, including an incorrect calculation, a misleading function name, and some code cleanup opportunities related to exception handling and unused imports. Addressing these points will enhance the correctness and maintainability of the new functionality.
| """Get FRED API key from config or environment""" | ||
| try: | ||
| api_key = get_api_key("fred_api_key", "FRED_API_KEY") | ||
| except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a bare except: is a bad practice as it catches all exceptions, including system-exiting ones like SystemExit or KeyboardInterrupt, which can hide bugs and make debugging difficult. It's better to catch a more specific exception, or at least Exception.
| except: | |
| except Exception: |
| spread = ten_year["yield"] - two_year["yield"] | ||
| result += f"- **2Y-10Y Spread**: {spread:.2f} basis points\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation for the yield spread is incorrect. The result is used with the unit 'basis points', but the calculation ten_year["yield"] - two_year["yield"] gives the spread in percentage points. To convert to basis points, you should multiply the result by 100. The subsequent check spread < 50 also implies that the value is expected in basis points.
| spread = ten_year["yield"] - two_year["yield"] | |
| result += f"- **2Y-10Y Spread**: {spread:.2f} basis points\n" | |
| spread = (ten_year["yield"] - two_year["yield"]) * 100 | |
| result += f"- **2Y-10Y Spread**: {spread:.2f} basis points\n" |
| def get_fed_calendar_and_minutes(curr_date: str) -> str: | ||
| """ | ||
| Get Federal Reserve meeting calendar and recent minutes | ||
|
|
||
| Args: | ||
| curr_date: Current date in YYYY-MM-DD format | ||
|
|
||
| Returns: | ||
| Formatted string with Fed calendar information | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function get_fed_calendar_and_minutes and its docstring are misleading. They claim to retrieve the Federal Reserve meeting calendar and minutes, but the implementation only fetches and displays the recent history of the Federal Funds Rate. The function should either be renamed to reflect its actual behavior (e.g., get_fed_funds_rate_history) or be implemented to actually fetch calendar/minutes data.
| import time | ||
| import json | ||
| from tradingagents.agents.utils.agent_utils import get_economic_indicators, get_yield_curve, get_fed_calendar | ||
| from tradingagents.dataflows.config import get_config | ||
|
|
||
|
|
||
| def create_macro_analyst(llm): | ||
| def macro_analyst_node(state): | ||
| current_date = state["trade_date"] | ||
| ticker = state["company_of_interest"] | ||
| company_name = state["company_of_interest"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several unused imports and an unused variable in this file. To improve code cleanliness and maintainability, it's best to remove them.
time(line 2) is imported but not used.json(line 3) is imported but not used.get_config(line 5) is imported but not used.- The variable
company_name(line 12) is assigned but never used.
| import json | ||
| from datetime import datetime, timedelta | ||
| from typing import Annotated, Dict, List, Optional | ||
| from .config import get_api_key, DATA_DIR | ||
| import os | ||
| import pandas as pd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| # Calculate year-over-year change for inflation indicators | ||
| if config.get("yoy") and len(valid_obs) >= 12: | ||
| year_ago = valid_obs[11] if len(valid_obs) > 11 else valid_obs[-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to get the year-ago observation can be simplified. Since you've already checked len(valid_obs) >= 12 on the line above, the condition len(valid_obs) > 11 in the ternary operator will always be true. The else part is therefore dead code.
| year_ago = valid_obs[11] if len(valid_obs) > 11 else valid_obs[-1] | |
| year_ago = valid_obs[11] |
FRED Macro Analyst Integration - Complete Summary
Overview
Successfully added FRED (Federal Reserve Economic Data) API support to TradingAgents, including a complete Macro Analyst agent that can be selected alongside existing analysts.
Changes Made
New Files Created (3 files)
tradingagents/dataflows/macro_utils.py(461 lines)get_fred_data(),get_economic_indicators_report(),get_treasury_yield_curve(),get_fed_calendar_and_minutes(),get_macro_economic_summary()tradingagents/agents/analysts/macro_analyst.py(73 lines)tradingagents/agents/utils/macro_data_tools.py(80 lines)get_economic_indicators(),get_yield_curve(),get_fed_calendar()Files Modified (6 files)
tradingagents/dataflows/interface.pyfrom .macro_utils import ...(1 line)"fred"toVENDOR_LIST(1 line)"macro_data"category toTOOLS_CATEGORIES(8 lines)VENDOR_METHODS(12 lines)tradingagents/agents/__init__.pyfrom .analysts.macro_analyst import create_macro_analyst(1 line)"create_macro_analyst"to__all__(1 line)tradingagents/agents/utils/agent_utils.pytradingagents/graph/setup.py"macro"to docstring (1 line)tradingagents/graph/trading_graph.py"macro"tool node with 3 tools (8 lines)FRED_MACRO_INTEGRATION.md(Updated documentation)How to Use
1. Set FRED API Key
Get a free key from: https://fred.stlouisfed.org/
2. Enable Macro Analyst
3. Access Macro Report
Available Analysts
After this update, TradingAgents now supports:
Macro Analyst Capabilities
The macro analyst provides analysis of:
Economic Indicators
Treasury Yield Curve
Fed Calendar & Policy
Vendor Routing Integration
The macro tools are integrated into the vendor routing system:
Vendor configuration (if needed):
Code Quality
All files pass Python syntax validation:
PR Compatibility ✅
selected_analystsTesting Checklist
Next Steps for PR
Files Summary
New Files (3):
tradingagents/dataflows/macro_utils.pytradingagents/agents/analysts/macro_analyst.pytradingagents/agents/utils/macro_data_tools.pyModified Files (6):
tradingagents/dataflows/interface.py(+22 lines)tradingagents/agents/__init__.py(+2 lines)tradingagents/agents/utils/agent_utils.py(+4 lines)tradingagents/graph/setup.py(+8 lines)tradingagents/graph/trading_graph.py(+11 lines)FRED_MACRO_INTEGRATION.md(updated)Total Lines Added: ~47 lines to existing files, ~614 lines in new files