An AI-powered autonomous agent that automates financial data analysis and generates investment insights using LangChain, Python, and multi-agent orchestration.
Features β’ Architecture β’ Installation β’ Usage β’ API Reference β’ Contributing
- Overview
- Case Study Details
- Features
- Architecture
- Installation
- Configuration
- Usage
- API Reference
- Agent Capabilities
- Sample Analysis
- Testing
- Deployment
- Contributing
- License
The Financial Research Analyst Agent is an end-to-end AI solution designed to automate financial data analysis and insight generation. Built with LangChain and Python, this agent leverages multiple specialized sub-agents to:
- π Analyze financial data from multiple sources
- π Generate investment insights with detailed reasoning
- π Perform market research autonomously
- π Create comprehensive reports with actionable recommendations
- β‘ Enhance decision-making speed through automation
| Attribute | Description |
|---|---|
| Objective | Leverage AI agent capabilities to automate data analysis and insight generation, enhancing the speed and quality of investment decision-making |
| Domain | Finance, Investment Analysis, Automation |
| Skills | AI Agents, Data Analysis, Investment Decision-Making, LangChain, Python |
| Complexity | Advanced |
| Duration | 4-6 weeks implementation |
Traditional financial research is:
- Time-consuming: Analysts spend 60-80% of time on data gathering
- Error-prone: Manual analysis leads to inconsistencies
- Limited in scope: Human capacity limits coverage
- Reactive: Difficulty in real-time market monitoring
This AI agent system addresses these challenges by:
- Automating data collection from multiple financial APIs
- Performing real-time analysis using advanced NLP and ML
- Generating actionable insights with confidence scores
- Creating structured reports for decision-makers
| Feature | Description |
|---|---|
| π€ Multi-Agent Architecture | Specialized agents for different analysis tasks |
| π Real-time Data Analysis | Live market data processing and analysis |
| π Technical Analysis | Automated chart pattern and indicator analysis |
| π° News Sentiment Analysis | NLP-powered news and social media analysis |
| π― Thematic Investing Analysis | Group stocks by investment themes (AI, EV, Green Energy, etc.) |
| π₯ Peer Group Comparison | Compare stocks against industry peers with real-time metrics |
| π Report Generation | Automated investment research reports |
| π Alert System | Configurable alerts for market conditions |
| π API Integration | REST API for external system integration |
| π± Web Dashboard | Interactive visualization dashboard |
- Data Collector Agent: Gathers financial data from multiple sources
- Technical Analyst Agent: Performs technical analysis on price data
- Fundamental Analyst Agent: Analyzes company financials and metrics
- Sentiment Analyst Agent: Processes news and social media sentiment
- Risk Analyst Agent: Performs risk assessment and VaR calculations
- Thematic Analyst Agent: Analyzes stocks grouped by investment themes and megatrends
- Report Generator Agent: Compiles insights into structured reports
- Orchestrator Agent: Coordinates all agents and manages workflow
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FINANCIAL RESEARCH ANALYST AGENT β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β ORCHESTRATOR AGENT β β
β β β’ Task Planning & Decomposition β’ Agent Coordination β’ Aggregation β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββ¬ββββββββββββΌββββββββββββ¬ββββββββββββββββ β
β β β β β β β
β ββββββββββΌββββββββ βββββββΌββββββ βββββΌββββ ββββββΌβββββ ββββββββββΌββββββββ β
β β DATA COLLECTOR β β TECHNICAL β β FUNDA β β SENTI- β β RISK β β
β β AGENT β β ANALYST β β MENTALβ β MENT β β ANALYST AGENT β β
β β β β AGENT β β AGENT β β AGENT β β β β
β β β’ Yahoo Financeβ β β’ RSI β β β’ P/E β β β’ News β β β’ VaR Calc β β
β β β’ Alpha Vantageβ β β’ MACD β β β’ EPS β β β’ Socialβ β β’ Volatility β β
β β β’ News APIs β β β’ SMA/EMA β β β’ ROE β β β’ Trend β β β’ Correlation β β
β ββββββββββββββββββ βββββββββββββ βββββββββ βββββββββββ ββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββ β
β β THEMATIC ANALYST AGENT β β REPORT GENERATOR AGENT β β
β β β β β β
β β β’ Theme-to-Ticker Mapping β β β’ PDF / Markdown / JSON Reports β β
β β β’ Multi-Horizon Performance β β β’ Actionable Recommendations β β
β β β’ Momentum & Health Scoring β β β’ Executive Summaries β β
β β β’ Correlation & Diversification β β β β
β β β’ Sector Overlap Analysis β β β β
β βββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββ β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β DATA LAYER β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ ββββββββββββββ ββββββββββββ β
β β Vector Store β β Cache Layer β β Database β β File Store β β Theme β β
β β (ChromaDB) β β (Redis) β β (PostgreSQL) β β (S3/Local) β β Config β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ ββββββββββββββ ββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Component | Technology |
|---|---|
| AI Framework | LangChain, LangGraph |
| LLM | Ollama (Llama 4, Mistral) / Groq / LM Studio |
| Embeddings | Sentence Transformers / HuggingFace / Ollama |
| Vector Store | ChromaDB / Qdrant / Milvus / Weaviate |
| Backend | FastAPI, Python 3.14+ |
| Data Processing | Pandas, NumPy |
| Visualization | Plotly, Matplotlib |
| Frontend | HTML5, CSS3, JavaScript |
| Database | PostgreSQL / SQLite |
| Caching | Redis |
- Python 3.14 or higher
- pip or conda package manager
- OpenAI API key (or other LLM provider)
- Alpha Vantage API key (optional, for live data)
# Clone the repository
git clone https://github.com/gsaini/financial-research-analyst-agent.git
cd financial-research-analyst-agent
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your API keys
# Run the application
python -m src.main# Build the Docker image
docker build -t financial-analyst-agent .
# Run the container
docker run -p 8000:8000 --env-file .env financial-analyst-agentCreate a .env file in the root directory:
# LLM Configuration (Open Source by Default)
LLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=llama4:latest
LLM_TEMPERATURE=0.1
# Embedding Configuration (Open Source)
EMBEDDING_PROVIDER=sentence-transformers
SENTENCE_TRANSFORMER_MODEL=all-MiniLM-L6-v2
# Financial Data APIs (Yahoo Finance is free, others optional)
USE_YFINANCE=true
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_key # Optional
NEWS_API_KEY=your_news_api_key # Optional
# Database Configuration
DATABASE_URL=sqlite:///./data/financial_agent.db
REDIS_URL=redis://localhost:6379
# Vector Store (Open Source)
VECTOR_STORE_PROVIDER=chroma
CHROMA_PERSIST_DIR=./data/chroma
# Application Settings
DEBUG=false
LOG_LEVEL=INFO
API_HOST=0.0.0.0
API_PORT=8000Edit config/agents.yaml to customize agent behavior:
orchestrator:
max_iterations: 10
timeout_seconds: 300
technical_analyst:
indicators:
- RSI
- MACD
- SMA
- EMA
- Bollinger Bands
lookback_periods: [14, 30, 50, 200]
sentiment_analyst:
sources:
- news
- twitter
- reddit
sentiment_threshold: 0.3from src.agents import FinancialResearchAgent
# Initialize the agent
agent = FinancialResearchAgent()
# Analyze a single stock
result = agent.analyze("AAPL")
print(result.summary)
print(result.recommendation)
print(result.confidence_score)
# Analyze multiple stocks
portfolio = ["AAPL", "GOOGL", "MSFT", "AMZN"]
portfolio_analysis = agent.analyze_portfolio(portfolio)
# Generate a research report
report = agent.generate_report(
symbols=["AAPL"],
include_technical=True,
include_fundamental=True,
include_sentiment=True,
format="pdf"
)# Analyze a stock
curl -X POST "http://localhost:8000/api/v1/analyze" \
-H "Content-Type: application/json" \
-d '{"symbol": "AAPL", "analysis_type": "comprehensive"}'
# Get technical analysis
curl "http://localhost:8000/api/v1/technical/AAPL"
# Generate report
curl -X POST "http://localhost:8000/api/v1/reports" \
-H "Content-Type: application/json" \
-d '{"symbols": ["AAPL", "GOOGL"], "format": "pdf"}'
# List available investment themes
curl "http://localhost:8000/api/v1/themes"
# Analyze an investment theme
curl -X POST "http://localhost:8000/api/v1/theme/ai_machine_learning" \
-H "Content-Type: application/json" \
-d '{"theme_id": "ai_machine_learning", "include_narrative": false}'
# Compare multiple themes
curl -X POST "http://localhost:8000/api/v1/themes/compare" \
-H "Content-Type: application/json" \
-d '{"theme_ids": ["ai_machine_learning", "cybersecurity", "electric_vehicles"]}'# Quick analysis
python -m src.cli analyze AAPL
# Portfolio analysis
python -m src.cli portfolio AAPL GOOGL MSFT --output report.pdf
# Start web dashboard
python -m src.cli dashboard --port 8080| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/analyze |
Analyze a stock symbol |
GET |
/api/v1/technical/{symbol} |
Get technical analysis |
GET |
/api/v1/fundamental/{symbol} |
Get fundamental analysis |
GET |
/api/v1/sentiment/{symbol} |
Get sentiment analysis |
POST |
/api/v1/portfolio |
Analyze a portfolio |
POST |
/api/v1/reports |
Generate a report |
GET |
/api/v1/market/summary |
Get market summary |
GET |
/api/v1/themes |
List all available investment themes |
POST |
/api/v1/theme/{theme_id} |
Analyze an investment theme |
POST |
/api/v1/themes/compare |
Compare multiple themes side by side |
GET |
/api/v1/peers/{symbol} |
Get peer comparison (auto-discovery) |
POST |
/api/v1/peers/compare |
Compare stock against specific peers |
WebSocket |
/ws/alerts |
Real-time alerts |
{
"symbol": "AAPL",
"analysis_date": "2024-01-15T10:30:00Z",
"technical": {
"trend": "bullish",
"signals": [...],
"indicators": {...}
},
"fundamental": {
"valuation": "fairly_valued",
"metrics": {...},
"growth_score": 8.5
},
"sentiment": {
"overall": "positive",
"score": 0.72,
"sources": {...}
},
"recommendation": {
"action": "BUY",
"confidence": 0.85,
"reasoning": "...",
"target_price": 195.00,
"stop_loss": 175.00
}
}Capabilities:
- Fetch real-time stock prices
- Historical data retrieval
- Financial statements download
- News article collection
- Social media data gatheringIndicators Supported:
- RSI (Relative Strength Index)
- MACD (Moving Average Convergence Divergence)
- SMA/EMA (Simple/Exponential Moving Averages)
- Bollinger Bands
- Fibonacci Retracements
- Volume Analysis
- Support/Resistance LevelsMetrics Analyzed:
- P/E Ratio, P/B Ratio, P/S Ratio
- EPS and Revenue Growth
- ROE, ROA, ROIC
- Debt-to-Equity Ratio
- Free Cash Flow
- Dividend Yield and Payout Ratio
- Competitive AnalysisSources:
- Financial news articles
- SEC filings and earnings calls
- Social media (Twitter, Reddit)
- Analyst ratings
- Insider trading activityCapabilities:
- Analyze stocks grouped by investment themes (AI, EV, Green Energy, etc.)
- Multi-horizon performance tracking (1W, 1M, 3M, 6M, 1Y, YTD)
- Intra-theme correlation and diversification scoring
- Momentum scoring (0-100) with configurable weights
- Theme health scoring (0-100) combining performance, momentum, risk
- Sector overlap breakdown
- Top performer and laggard identification
- LLM-generated narrative outlook (optional)
Available Themes:
- AI & Machine Learning - Electric Vehicles
- Green Energy & Clean Tech - Cybersecurity
- Aging Population & Healthcare - Cloud Computing & SaaS
- Fintech & Digital Payments - Space Economy & Aerospace
- Digital Entertainment & Gaming - Blockchain & Web3================================================================================
FINANCIAL RESEARCH ANALYST REPORT
Apple Inc. (AAPL)
Generated: 2024-01-15
================================================================================
EXECUTIVE SUMMARY
-----------------
Apple Inc. demonstrates strong fundamentals with continued growth in services
revenue and a robust product ecosystem. Technical indicators suggest a bullish
trend, while sentiment analysis reveals positive market perception.
TECHNICAL ANALYSIS
------------------
Trend: BULLISH
RSI (14): 58.3 (Neutral)
MACD: Bullish crossover detected
Support: $175.00
Resistance: $195.00
FUNDAMENTAL ANALYSIS
--------------------
P/E Ratio: 28.5 (Industry Avg: 25.2)
Revenue Growth: 8.2% YoY
EPS Growth: 12.1% YoY
Debt/Equity: 1.52
ROE: 147.3%
SENTIMENT ANALYSIS
------------------
Overall Sentiment: POSITIVE (Score: 0.72)
News Sentiment: 0.68
Social Media: 0.75
Analyst Consensus: 0.82
RECOMMENDATION
--------------
Action: BUY
Confidence: 85%
Target Price: $195.00
Stop Loss: $175.00
Reasoning: Strong fundamentals combined with positive technical signals and
favorable market sentiment suggest upside potential. The services segment
continues to grow, providing recurring revenue stability.
================================================================================
# Run all tests
pytest tests/ -v
# Run specific test suite
pytest tests/test_agents.py -v
# Run thematic investing tests
pytest tests/test_thematic.py -v
# Run with coverage
pytest tests/ --cov=src --cov-report=html
# Run integration tests (requires network access for yfinance)
pytest tests/ -v -m integrationversion: "3.8"
services:
api:
build: .
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/financial_agent
- REDIS_URL=redis://redis:6379
depends_on:
- db
- redis
db:
image: postgres:15
environment:
POSTGRES_DB: financial_agent
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Set in .env file
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7
volumes:
- redis_data:/data
volumes:
postgres_data:
redis_data:See k8s/ directory for Kubernetes deployment manifests.
financial-research-analyst-agent/
βββ src/
β βββ __init__.py
β βββ main.py # Application entry point
β βββ config.py # Configuration management
β βββ agents/
β β βββ __init__.py
β β βββ base.py # Base agent class
β β βββ orchestrator.py # Main orchestrator agent
β β βββ data_collector.py # Data collection agent
β β βββ technical.py # Technical analysis agent
β β βββ fundamental.py # Fundamental analysis agent
β β βββ sentiment.py # Sentiment analysis agent
β β βββ risk.py # Risk analysis agent
β β βββ thematic.py # Thematic investing analysis agent β¨
β β βββ report_generator.py # Report generation agent
β βββ tools/
β β βββ __init__.py
β β βββ market_data.py # Market data fetching tools
β β βββ news_fetcher.py # News fetching tools
β β βββ technical_indicators.py
β β βββ financial_metrics.py
β β βββ peer_comparison.py # Peer discovery & comparison tools β¨
β β βββ theme_mapper.py # Theme-to-ticker mapping & analysis tools β¨
β βββ models/
β β βββ __init__.py
β β βββ analysis.py # Analysis data models
β β βββ report.py # Report data models
β βββ api/
β β βββ __init__.py
β β βββ routes.py # API routes (incl. thematic endpoints)
β β βββ schemas.py # Pydantic schemas (incl. theme schemas)
β βββ utils/
β βββ __init__.py
β βββ logger.py # Logging utility
β βββ helpers.py # Helper functions
βββ tests/
β βββ __init__.py
β βββ test_agents.py
β βββ test_tools.py
β βββ test_api.py
β βββ test_peer_comparison.py # Peer comparison tests β¨
β βββ test_thematic.py # Thematic investing tests β¨
βββ data/
β βββ sample_data.csv
βββ docs/
β βββ architecture.md
β βββ api_reference.md # API reference (incl. peer comparison endpoints)
β βββ SCOPE.md # Feature scope & enhancement roadmap
βββ notebooks/
β βββ exploration.ipynb
βββ static/
β βββ dashboard/
βββ config/
β βββ agents.yaml # Agent configuration
β βββ themes.yaml # Investment theme definitions β¨
βββ .env.example
βββ requirements.txt
βββ Dockerfile
βββ docker-compose.yml
βββ README.md
Contributions are welcome! Please read our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- LangChain - AI Agent Framework
- OpenAI - Language Models
- Alpha Vantage - Financial Data API
- Yahoo Finance - Market Data
Created by π€ Antigravity AI (Google DeepMind)
Author: Gopal Saini
Part of the AI Agents Case Studies Collection