AI-powered stock analysis agent that provides investment recommendations for NASDAQ stocks using Claude AI.
The NASDAQ Stock Agent is an intelligent AI system that analyzes stocks and provides investment recommendations. It uses:
- Claude AI (Anthropic) for intelligent analysis
- Real-time market data from yfinance
- Technical analysis (RSI, MACD, Moving Averages)
- Fundamental analysis (P/E ratios, EPS, Revenue)
- Natural language processing to understand your questions
- Analyze any NASDAQ stock by ticker symbol (e.g., "AAPL", "TSLA")
- Answer questions in plain English (e.g., "Should I buy Apple stock?")
- Provide BUY/HOLD/SELL recommendations with confidence scores
- Explain the reasoning behind each recommendation
- Track analysis history in a database
You ask: "What do you think about Apple stock?"
Agent responds:
{
"symbol": "AAPL",
"recommendation": "BUY",
"confidence": 85,
"current_price": 178.45,
"reasoning": "Strong technical indicators with price above key moving averages.",
"key_factors": [
"Price above 50-day and 200-day moving averages",
"Strong revenue growth of 8.5%",
"Solid balance sheet"
],
"risks": [
"High valuation at 28.5x P/E ratio",
"Potential regulatory headwinds"
]
}- Docker and Docker Compose installed
- Anthropic API key (Get one here)
- 2GB+ RAM available
1. Clone the repository
git clone https://github.com/YOUR_USERNAME/nasdaq-stock-agent.git
cd nasdaq-stock-agent2. Configure environment
# Copy the template
cp .env.example .env
# Edit and add your API key
nano .envUpdate this line in .env:
ANTHROPIC_API_KEY=your_actual_api_key_here3. Start the application
docker-compose up -d4. Test it
# Check if it's running
curl http://localhost:8000/
# Analyze a stock
curl -X POST http://localhost:8000/api/v1/analyze \
-H "Content-Type: application/json" \
-d '{"query": "AAPL"}'5. View API documentation
Open in your browser: http://localhost:8000/docs
That's it! Your agent is running on http://localhost:8000
docker-compose downThe startup.sh script automatically detects your public IP and configures NEST:
# For development
./startup.sh
# For production (AWS EC2)
./startup.sh prodWhat it does:
- Detects public IP from AWS EC2 metadata or external services
- Updates
NEST_PUBLIC_URLin.envautomatically - Optionally starts Docker services
- Shows configuration summary
- AWS account with EC2 access
- SSH key pair for EC2
- Anthropic API key
1. Launch EC2 Instance
In AWS Console:
- Go to EC2 Dashboard β Launch Instance
- Name: nasdaq-stock-agent
- AMI: Ubuntu Server 22.04 LTS
- Instance Type: t3.medium (2 vCPU, 4GB RAM)
- Key Pair: Select or create new
- Storage: 20GB gp3
- Security Group: Create with these rules:
- SSH (22) - Your IP
- HTTP (80) - 0.0.0.0/0
- Custom TCP (8000) - 0.0.0.0/0
- Custom TCP (6000) - 0.0.0.0/0
2. Connect to EC2
# Set key permissions
chmod 400 your-key.pem
# SSH into instance
ssh -i your-key.pem ubuntu@YOUR_EC2_PUBLIC_IP3. Install Docker
# Update system
sudo apt-get update && sudo apt-get upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker ubuntu
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Verify installations
docker --version
docker-compose --version4. Deploy Application
# Clone repository
git clone https://github.com/YOUR_USERNAME/nasdaq-stock-agent.git
cd nasdaq-stock-agent
# Configure environment
cp .env.example .env
nano .envUpdate these values in .env:
ANTHROPIC_API_KEY=your_actual_api_key_here
MONGO_ROOT_PASSWORD=your_secure_password_here
MONGO_PASSWORD=your_secure_password_here
# Note: NEST_PUBLIC_URL will be auto-detected by startup script5. Start Services (Automatic IP Detection)
Option A: Quick Deploy (Easiest)
# One command deployment - handles everything
./quick-deploy.sh
# This will:
# 1. Create .env from template (if needed)
# 2. Detect your EC2 public IP automatically
# 3. Update NEST_PUBLIC_URL in .env
# 4. Start services in production modeOption B: Using Startup Script
# If you already have .env configured
./startup.sh prod
# This will:
# 1. Detect your EC2 public IP
# 2. Update NEST_PUBLIC_URL in .env
# 3. Start services in production modeOption B: Manual Start
# Manually update NEST_PUBLIC_URL with your EC2 IP
# Get your public IP
curl http://169.254.169.254/latest/meta-data/public-ipv4
# Update .env file
nano .env
# Set: NEST_PUBLIC_URL=http://YOUR_EC2_IP:6000
# Start with production configuration
docker-compose -f docker-compose.prod.yml up -d
# Check status
docker-compose -f docker-compose.prod.yml ps
# View logs
docker-compose -f docker-compose.prod.yml logs -f6. Test Deployment
# From your local machine
curl http://YOUR_EC2_PUBLIC_IP:8000/
# Analyze a stock
curl -X POST http://YOUR_EC2_PUBLIC_IP:8000/api/v1/analyze \
-H "Content-Type: application/json" \
-d '{"query": "AAPL"}'7. Access API Documentation
Open in browser: http://YOUR_EC2_PUBLIC_IP:8000/docs
# View logs
docker-compose -f docker-compose.prod.yml logs -f
# Restart services
docker-compose -f docker-compose.prod.yml restart
# Stop services
docker-compose -f docker-compose.prod.yml down
# Update application
git pull
docker-compose -f docker-compose.prod.yml up -d --build# Analyze by ticker
curl -X POST http://localhost:8000/api/v1/analyze \
-H "Content-Type: application/json" \
-d '{"query": "AAPL"}'
# Natural language
curl -X POST http://localhost:8000/api/v1/analyze \
-H "Content-Type: application/json" \
-d '{"query": "Should I buy Tesla stock?"}'import requests
response = requests.post(
"http://localhost:8000/api/v1/analyze",
json={"query": "AAPL"}
)
result = response.json()
print(f"Recommendation: {result['recommendation']}")
print(f"Confidence: {result['confidence']}%")fetch('http://localhost:8000/api/v1/analyze', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: 'AAPL' })
})
.then(res => res.json())
.then(data => console.log(data));This project includes two Docker Compose configurations:
- Use for: Local development and testing
- MongoDB: No authentication (simpler setup)
- Nginx: Not included (direct access to port 8000)
- Command:
docker-compose up -d - Best for: Quick local testing and development
- Use for: Production deployments on AWS EC2 or other servers
- MongoDB: Authentication required (secure)
- Nginx: Included as reverse proxy (ports 80/443)
- Resource Limits: CPU and memory limits configured
- Command:
docker-compose -f docker-compose.prod.yml up -d - Best for: Production environments requiring security and scalability
Key Differences:
| Feature | docker-compose.yml | docker-compose.prod.yml |
|---|---|---|
| MongoDB Auth | β No | β Yes (secure) |
| Nginx Proxy | β No | β Yes |
| Resource Limits | β No | β Yes |
| SSL Support | β No | β Yes |
| Restart Policy | unless-stopped | always |
| Use Case | Local Dev | Production |
# Anthropic API (Required)
ANTHROPIC_API_KEY=your_api_key_here
ANTHROPIC_MODEL=claude-3-haiku-20240307
# MongoDB (Required)
MONGODB_URL=mongodb://mongodb:27017/
MONGODB_DATABASE=nasdaq_stock_agent# MongoDB Authentication (Required for docker-compose.prod.yml)
MONGO_ROOT_PASSWORD=your_secure_password
MONGO_PASSWORD=your_secure_password
# NEST Integration (Optional)
NEST_ENABLED=true
NEST_PUBLIC_URL=http://YOUR_EC2_PUBLIC_IP:6000See .env.example for all available configuration options.
βββββββββββββββ
β Client β (Browser, curl, API calls)
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β Nginx β Port 80/443 (Production only)
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββ
β FastAPI β Port 8000 (Main API)
β Agent β
ββββββββ¬βββββββ
β
ββββββββββββ¬βββββββββββ¬βββββββββββ
βΌ βΌ βΌ βΌ
ββββββββββ ββββββββββ ββββββββββ ββββββββββ
βMongoDB β βClaude β βyfinanceβ β NEST β
βDatabaseβ β AI β β Market β β (A2A) β
ββββββββββ ββββββββββ ββββββββββ ββββββββββ
# Check logs
docker-compose logs nasdaq-agent
# Verify API key is set
docker exec nasdaq-stock-agent env | grep ANTHROPIC
# Restart
docker-compose restart nasdaq-agent# Check MongoDB is running
docker-compose ps mongodb
# Restart MongoDB
docker-compose restart mongodb# Check what's using port 8000
lsof -i :8000
# Stop the process or change PORT in .env# Add swap space
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfileGET /- Health checkGET /docs- Interactive API documentationPOST /api/v1/analyze- Analyze stockGET /api/v1/status- System statusGET /health- Health check
- Never commit
.envfile to Git (already in.gitignore) - Use strong passwords for MongoDB in production
- Restrict EC2 security group to your IP for SSH
- Consider enabling SSL/TLS for production (update
nginx.conf) - Rotate API keys regularly
- API Documentation: http://localhost:8000/docs
- Issues: Open a GitHub issue
- Logs:
docker-compose logs -f nasdaq-agent
This project is licensed under the MIT License.
Using Claude AI Model, FastAPI, and Docker