A multi-agent system that analyzes stocks, visualizes financial data, and provides investment recommendations.
The Financial Research Assistant is an intelligent system built using LangGraph that automates the stock analysis process. It combines financial data retrieval, technical analysis, visualization, and investment recommendations in a seamless workflow powered by multiple specialized agents.
The Financial Research Assistant is capable of:
-
Data Collection:
- Fetches comprehensive financial data for any stock using yfinance
- Gets historical prices, company information, financial statements
- Calculates technical indicators like moving averages
-
Financial Analysis:
- Performs technical analysis (moving averages, RSI)
- Calculates performance metrics (price changes, volatility)
- Analyzes valuation metrics (P/E ratio, dividend yield)
-
Visualization:
- Creates price charts with moving averages
- Generates daily returns distribution visualization
- Displays trading volume over time
-
Investment Advising:
- Provides actionable investment recommendations (Buy, Hold, Sell)
- Explains reasoning for recommendations
- Includes risk disclaimers and context
The system utilizes a LangGraph workflow with four specialized agents:
-
Data Collector Agent: Fetches financial data using yfinance
- Retrieves historical prices, company info, and financial statements
- Calculates technical indicators (moving averages, volatility)
-
Analyst Agent: Analyzes financial metrics and historical data
- Performs technical analysis (trend identification, RSI calculation)
- Evaluates performance metrics and valuation indicators
-
Visualization Agent: Creates charts and graphs of the data
- Generates price charts with moving averages
- Creates distributions of daily returns
- Visualizes trading volume
-
Advisor Agent: Provides investment recommendations
- Uses a scoring system based on technical and fundamental factors
- Generates Buy/Hold/Sell recommendations with explanations
- Includes contextual information about the company
The agents communicate through a shared state that maintains the analysis context. If any agent encounters an error, the workflow stops gracefully, preventing incomplete or inaccurate analysis.
- Custom yfinance Tool: The system leverages a custom tool built around the yfinance API to fetch comprehensive financial data
- Multi-Agent Architecture: Different specialized agents handle specific parts of the analysis process
- Visualization Generation: Creates professional-grade visualizations for better decision making
- Investment Scoring System: Uses a weighted scoring system to generate recommendations based on multiple factors
- Error Handling: Robust error handling prevents the system from crashing if data is unavailable
- Conditional Workflow: The graph structure ensures that analysis only proceeds when valid data is available
To use this system:
# Import the system
from financial_research_assistant import run_financial_research
# Analyze Tesla stock over a 6-month period
result = run_financial_research("TSLA", "6mo")
# Get the recommendation
print(result["recommendation"])
# View agent conversation
for message in result["messages"]:
print(message.content)
# Access generated visualizations
print(result["visualization_paths"])The system supports various timeframes for analysis:
1d: 1 day5d: 5 days1mo: 1 month3mo: 3 months6mo: 6 months1y: 1 year2y: 2 years5y: 5 years10y: 10 yearsytd: Year to datemax: Maximum available data
- Clone the repository
- Install the required dependencies:
pip install yfinance pandas matplotlib seaborn langgraph langchain-core
- Python 3.8+
- yfinance
- pandas
- matplotlib
- seaborn
- langgraph
- langchain-core
This tool is for informational purposes only. The investment recommendations should be considered alongside your own research and risk tolerance. Past performance does not guarantee future results.