Skip to content

Your Personal Assistant for Financial Markets - Analyze, Invest. Trade using the knowledge base and reasoning powered by SoTA LLMs

Notifications You must be signed in to change notification settings

hellonish/Finassistant

Repository files navigation

πŸ“Š Financial Assistant - AI-Powered Financial Analysis Platform

Python FastAPI React LangChain Docker License

An intelligent multi-agent financial analysis system powered by LangChain and Google's Gemini AI, providing real-time market insights, SEC filing analysis, and comprehensive financial reports.

Financial Assistant Demo

🎯 Overview

Financial Assistant is a production-ready AI platform that combines advanced LLM capabilities with real-time financial data to deliver professional-grade financial analysis. The system features a sophisticated multi-agent architecture that can process complex queries, analyze SEC filings, perform quantitative analysis, and generate comprehensive investment reports.

Key Highlights

  • πŸ€– Dual-Mode AI System: Chat mode for quick queries, Think mode for deep analysis
  • πŸ“ˆ Real-Time Market Data: Integration with Yahoo Finance, Alpha Vantage, and News APIs
  • πŸ“„ SEC Filing Analysis: RAG-enhanced semantic search across 10-K, 10-Q, 8-K filings
  • 🌐 Multi-Agent Architecture: Planner β†’ Financial Analyst β†’ Publisher workflow
  • πŸ’¬ Conversational Memory: MongoDB-backed chat history with session management
  • πŸš€ Production-Ready: Dockerized, fully documented, AWS deployment guides included

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Frontend (React)                         β”‚
β”‚    - Modern UI with Tailwind CSS                                β”‚
β”‚    - Real-time WebSocket streaming                              β”‚
β”‚    - Session management & chat history                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    API Layer (FastAPI)                           β”‚
β”‚    - RESTful endpoints (/api/chat, /api/think)                  β”‚
β”‚    - WebSocket support for streaming                            β”‚
β”‚    - MongoDB integration for persistence                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Multi-Agent System (LangGraph)                  β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚   Planner    │───▢│  Financial   │───▢│  Publisher   β”‚     β”‚
β”‚  β”‚    Agent     β”‚    β”‚    Agent     β”‚    β”‚    Agent     β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚         β”‚                    β”‚                    β”‚             β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
β”‚                              β”‚                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                     β”‚                     β”‚
         β–Ό                     β–Ό                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Financial Tools β”‚  β”‚   News & Web    β”‚  β”‚   SEC Filings   β”‚
β”‚                 β”‚  β”‚     Search      β”‚  β”‚   (RAG + LLM)   β”‚
β”‚ - yfinance      β”‚  β”‚ - NewsAPI       β”‚  β”‚ - ChromaDB      β”‚
β”‚ - Metrics       β”‚  β”‚ - DuckDuckGo    β”‚  β”‚ - Embeddings    β”‚
β”‚ - Comparisons   β”‚  β”‚ - Summarization β”‚  β”‚ - Chunking      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

🎯 Core Capabilities

1. Dual-Mode Analysis

  • Chat Mode: Fast, conversational responses (2-4 LLM calls)

    • Quick metrics lookups (P/E ratio, market cap, etc.)
    • Stock price summaries
    • Analyst recommendations
    • Conversational follow-ups with memory
  • Think Mode: Comprehensive analysis (10+ LLM calls, structured workflow)

    • Multi-agent planning and execution
    • Deep financial analysis with multiple data sources
    • Structured investment reports
    • Comparative analysis across companies

2. Financial Analysis Tools (18+ Built-in Tools)

Quantitative Analysis:

  • Valuation metrics (P/E, P/B, EV/EBITDA, etc.)
  • Profitability metrics (ROE, ROA, margins)
  • Historical growth analysis
  • Stock price summaries
  • Analyst recommendations
  • Multi-company comparisons

News & Market Intelligence:

  • Stock-specific news aggregation
  • Market-wide news monitoring
  • Full article content extraction
  • News summarization

SEC Filing Analysis (RAG-Enhanced):

  • 10-K, 10-Q, 8-K filing downloads
  • Semantic search across documents
  • Multi-document comparative analysis
  • Financial data extraction
  • Smart chunking and embeddings

Web Search:

  • Real-time market searches
  • Financial web search
  • Search + summarization pipeline

3. Conversation Management

  • MongoDB-backed chat history
  • Session persistence across queries
  • Multi-user support
  • Automatic session continuation
  • Message metadata tracking

4. Production Features

  • API: RESTful + WebSocket endpoints
  • Authentication: Ready for JWT/OAuth integration
  • Monitoring: Health checks, logging
  • Error Handling: Comprehensive error responses
  • CORS: Configurable for frontend integration
  • Docker: Single-command deployment

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • Docker & Docker Compose
  • API Keys (see .env.example)

1. Clone Repository

git clone https://github.com/yourusername/Finassistant.git
cd Finassistant

2. Setup Environment

# Copy environment template
cp .env.example .env

# Edit .env and add your API keys
nano .env

Required API keys:

  • GOOGLE_API_KEY - Google Gemini AI
  • NEWS_API_KEY - NewsAPI.org
  • MONGODB_URL - MongoDB Atlas connection string
  • (Optional) OPENAI_API_KEY, GROQ_API_KEY, ALPHA_VANTAGE_API_KEY

3. Run with Docker (Recommended)

# Build and start backend
docker-compose up -d

# View logs
docker-compose logs -f backend

# Test API
curl http://localhost:8000/api/health

4. Run Frontend (Development)

cd frontend
npm install
npm run dev
# Visit http://localhost:5173

5. Test the System

Chat Mode (Quick queries):

curl -X POST "http://localhost:8000/api/chat?query=What%20is%20Apple%27s%20P/E%20ratio?"

Think Mode (Comprehensive analysis):

curl -X POST "http://localhost:8000/api/think?query=Analyze%20Tesla%27s%20financial%20health&verbose=true"

πŸ“ Project Structure

Finassistant/
β”œβ”€β”€ agent/                      # AI Agent System
β”‚   β”œβ”€β”€ agent.py               # Main agent runner
β”‚   β”œβ”€β”€ graph/                 # LangGraph workflows
β”‚   β”‚   β”œβ”€β”€ single_agent_graph.py  # Chat mode
β”‚   β”‚   └── multi_agent_graph.py   # Think mode
β”‚   β”œβ”€β”€ nodes/                 # Agent nodes
β”‚   β”œβ”€β”€ subagents/             # Specialized agents
β”‚   β”‚   β”œβ”€β”€ planner_agent.py
β”‚   β”‚   β”œβ”€β”€ financial_agent.py
β”‚   β”‚   └── publisher_agent.py
β”‚   β”œβ”€β”€ tools/                 # Tool implementations
β”‚   β”‚   β”œβ”€β”€ quant/            # Financial metrics
β”‚   β”‚   β”œβ”€β”€ news/             # News aggregation
β”‚   β”‚   β”œβ”€β”€ sec_filing/       # SEC filings
β”‚   β”‚   β”œβ”€β”€ rag/              # RAG system
β”‚   β”‚   └── search/           # Web search
β”‚   └── states/               # State management
β”‚
β”œβ”€β”€ api/                       # FastAPI Backend
β”‚   β”œβ”€β”€ app.py                # Main API application
β”‚   β”œβ”€β”€ database.py           # MongoDB connection
β”‚   β”œβ”€β”€ chat_history.py       # Session management
β”‚   β”œβ”€β”€ models.py             # Pydantic models
β”‚   └── websocket_handler.py  # WebSocket streaming
β”‚
β”œβ”€β”€ frontend/                  # React Frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/       # React components
β”‚   β”‚   β”œβ”€β”€ services/         # API client
β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom React hooks
β”‚   β”‚   └── App.jsx          # Main app
β”‚   └── package.json
β”‚
β”œβ”€β”€ Dockerfile                 # Backend container
β”œβ”€β”€ docker-compose.yml         # Orchestration
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ DEPLOYMENT_BACKEND.md      # EC2 deployment guide
β”œβ”€β”€ DEPLOYMENT_FRONTEND.md     # S3 + CloudFront guide
└── README.md                  # This file

πŸ› οΈ Technology Stack

Backend

Technology Purpose
Python 3.11 Core language
FastAPI REST API framework
LangChain LLM orchestration
LangGraph Multi-agent workflows
Google Gemini Primary LLM (Gemini 1.5 Flash)
ChromaDB Vector database for RAG
MongoDB Chat history & sessions
yfinance Stock market data
NewsAPI News aggregation
BeautifulSoup Web scraping

Frontend

Technology Purpose
React 18 UI framework
Vite Build tool
Tailwind CSS Styling
Axios HTTP client
React Markdown Markdown rendering
Lucide React Icons

Infrastructure

  • Docker - Containerization
  • AWS EC2 - Backend hosting
  • AWS S3 + CloudFront - Frontend CDN
  • Nginx - Reverse proxy
  • Let's Encrypt - SSL certificates

πŸ“š API Documentation

Core Endpoints

Health Check

GET /api/health

Response:

{
  "status": "healthy",
  "timestamp": "2024-01-15T10:30:00Z",
  "version": "1.0.0"
}

Chat Mode (Quick Responses)

POST /api/chat?query=<your_query>&session_id=<optional>&user_id=<optional>

Example:

curl -X POST "http://localhost:8000/api/chat?query=What%27s%20Apple%27s%20market%20cap%3F"

Response:

{
  "success": true,
  "query": "What's Apple's market cap?",
  "query_type": "chat",
  "result": "Apple (AAPL) has a market capitalization of approximately $2.8 trillion...",
  "timestamp": "2024-01-15T10:30:00Z",
  "metadata": {
    "execution_time_seconds": 3.2,
    "session_id": "abc123..."
  }
}

Think Mode (Comprehensive Analysis)

POST /api/think?query=<your_query>&verbose=<true|false>

Example:

curl -X POST "http://localhost:8000/api/think?query=Analyze%20Tesla%27s%20financial%20health&verbose=true"

Session Management

GET    /api/sessions?user_id=<user_id>              # List sessions
POST   /api/sessions                                 # Create session
GET    /api/sessions/<session_id>                    # Get session with messages
DELETE /api/sessions/<session_id>                    # Delete session
PATCH  /api/sessions/<session_id>                    # Update session

WebSocket Streaming

const ws = new WebSocket('ws://localhost:8000/ws/chat?user_id=user123');

ws.send(JSON.stringify({
  query: "Analyze Apple",
  mode: "think",
  session_id: "abc123",
  save_history: true
}));

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log(data.type, data.data);
};

Full API Docs: Visit http://localhost:8000/docs after starting the server.


πŸŽ“ Usage Examples

Example 1: Quick Stock Query (Chat Mode)

from agent.agent import run_agent

result = run_agent(
    query="What's Microsoft's P/E ratio?",
    mode="chat"
)
print(result)
# Output: "Microsoft (MSFT) has a P/E ratio of 32.5..."

Example 2: Comprehensive Analysis (Think Mode)

result = run_agent(
    query="Compare the financial health of Tesla and Ford",
    mode="think",
    verbose=True
)
print(result)
# Output: Detailed multi-page report with metrics, analysis, and recommendations

Example 3: With Conversation History

history = [
    {"role": "user", "content": "Tell me about Apple"},
    {"role": "assistant", "content": "Apple Inc. is..."}
]

result = run_agent(
    query="What about their latest earnings?",
    mode="chat",
    conversation_history=history
)

Example 4: CLI Usage

# Interactive mode
python -m agent.agent

# Direct query
python -m agent.agent chat "What's NVDA's current price?"
python -m agent.agent think "Analyze Amazon's Q4 performance"

🚒 Deployment

Docker Compose Files

  • docker-compose.yml - Full stack (local development with FE + BE)
  • docker-compose.backend.yml - Backend only (for EC2 deployment)
  • docker-compose.frontend.yml - Frontend only (for testing before S3)

See DOCKER_DEPLOYMENT.md for detailed usage.

Backend Deployment (AWS EC2)

Complete step-by-step guide: DEPLOYMENT_BACKEND.md

Quick Deploy:

# On EC2 instance
git clone https://github.com/yourusername/Finassistant.git
cd Finassistant
cp .env.example .env
# Edit .env with your API keys
docker-compose -f docker-compose.backend.yml up -d

Features:

  • Docker containerization (backend only)
  • Direct port exposure (8000)
  • Optional: Nginx reverse proxy
  • Optional: SSL with Let's Encrypt
  • Systemd service management
  • CloudWatch monitoring

Frontend Deployment (AWS S3 + CloudFront)

Complete step-by-step guide: DEPLOYMENT_FRONTEND.md

Quick Deploy:

cd frontend
npm run build
aws s3 sync dist/ s3://your-bucket --delete
aws cloudfront create-invalidation --distribution-id XXX --paths "/*"

Features:

  • Static hosting on S3
  • CloudFront CDN distribution
  • Custom domain with SSL
  • Automated deployment script
  • CI/CD with GitHub Actions

πŸ”§ Configuration

Environment Variables

Variable Description Required
GOOGLE_API_KEY Google Gemini API key βœ… Yes
NEWS_API_KEY NewsAPI.org API key βœ… Yes
MONGODB_URL MongoDB connection string βœ… Yes
OPENAI_API_KEY OpenAI API key (optional) βšͺ No
GROQ_API_KEY Groq API key (optional) βšͺ No
ALPHA_VANTAGE_API_KEY Alpha Vantage key (optional) βšͺ No
PINECONE_API_KEY Pinecone vector DB (optional) βšͺ No

MongoDB Setup

  1. Create free cluster at MongoDB Atlas
  2. Create database user
  3. Whitelist your IP (or 0.0.0.0/0 for development)
  4. Get connection string and add to .env

API Keys


🎯 Areas for Improvement

The following enhancements are planned or recommended for future development:

1. News Sentiment Analysis Model

  • Current State: News articles are fetched and summarized, but sentiment is not quantitatively analyzed
  • Improvement:
    • Implement a fine-tuned sentiment analysis model (e.g., FinBERT)
    • Score news sentiment on a scale (-1 to +1)
    • Aggregate sentiment scores over time windows
    • Visualize sentiment trends in frontend

Business Impact: More accurate assessment of market sentiment, better decision-making signals

2. News-to-Price Prediction Model

  • Current State: News and price data are shown separately
  • Improvement:
    • Build ML model correlating news sentiment with stock price movements
    • Features: sentiment scores, article volume, source credibility, historical patterns
    • Predict short-term price movements (1-day, 7-day, 30-day)
    • Backtesting framework to validate predictions

Technical Approach:

  • Feature engineering: sentiment scores, trading volume, price history
  • Models to explore: LSTM, Transformer-based architectures, XGBoost
  • Training data: Historical news + stock prices (2018-2024)

Business Impact: Predictive insights for traders, enhanced investment recommendations

3. Frontend + Backend + System Improvements

Frontend UX/UI:

  • Dark/light mode toggle
  • Advanced charting (Plotly.js, TradingView widgets)
  • Comparison dashboards (side-by-side company views)
  • Sentiment visualization (gauge charts, trend lines)
  • Export reports to PDF
  • Saved queries and favorites
  • Real-time streaming indicators (typing animation, progress bars)
  • Mobile-responsive design improvements

Backend Performance:

  • Caching layer (Redis) for frequently requested data
  • Rate limiting per user/API key
  • Async batch processing for multi-company queries
  • Database indexing optimization
  • API response compression (gzip)
  • Websocket connection pooling

System Architecture:

  • Microservices architecture (separate services for tools, agents, API)
  • Message queue (RabbitMQ/SQS) for long-running tasks
  • Horizontal scaling with load balancer
  • Kubernetes deployment manifests
  • Prometheus + Grafana monitoring
  • Distributed tracing (OpenTelemetry)

Integration & Testing:

  • Comprehensive unit tests (pytest, >80% coverage)
  • Integration tests for API endpoints
  • End-to-end tests (Playwright/Selenium)
  • CI/CD pipeline (GitHub Actions)
  • Automated security scanning (Snyk, Dependabot)
  • Performance benchmarking suite

Security:

  • JWT authentication
  • Role-based access control (RBAC)
  • API key management
  • Secrets management (AWS Secrets Manager)
  • Input validation and sanitization
  • Rate limiting and DDoS protection

🀝 Contributing

Contributions are welcome! This project is actively maintained.

How to Contribute

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Setup

# Install dependencies
pip install -r requirements.txt
cd frontend && npm install

# Run tests
pytest
npm test

# Format code
black agent/ api/
prettier --write frontend/src

πŸ“Š Performance Metrics

Metric Value
Chat Mode Latency 2-4 seconds (avg)
Think Mode Latency 15-30 seconds (avg)
API Throughput 50+ req/sec (single instance)
Tool Accuracy 95%+ (financial data)
LLM Calls (Chat) 2-4 calls
LLM Calls (Think) 10-15 calls
Database Queries <100ms (MongoDB)
Vector Search <200ms (ChromaDB)

πŸ› Troubleshooting

Common Issues

1. MongoDB Connection Failed

# Check connection string in .env
# Verify IP whitelist in MongoDB Atlas
# Test connection:
mongosh "your-mongodb-url"

2. API Keys Not Working

# Ensure .env file exists and is loaded
# Verify API key validity
# Check API quota limits

3. Docker Build Fails

# Clear Docker cache
docker-compose down -v
docker system prune -a
docker-compose build --no-cache

4. Frontend Can't Connect to Backend

# Check CORS settings in api/app.py
# Verify API URL in frontend/.env.production
# Check backend is running: curl http://localhost:8000/api/health

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Nishant


πŸ™ Acknowledgments

  • LangChain - For the amazing LLM framework
  • Google Gemini - For powerful AI capabilities
  • FastAPI - For the excellent Python web framework
  • MongoDB - For reliable data persistence
  • Open Source Community - For countless libraries and tools

πŸ“ž Support

For questions, issues, or feature requests:


⭐ Star History

If you find this project useful, please consider giving it a star! ⭐


Built with ❀️ using AI and modern web technologies

🌟 Star this repo β€’ πŸ› Report Bug β€’ ✨ Request Feature

About

Your Personal Assistant for Financial Markets - Analyze, Invest. Trade using the knowledge base and reasoning powered by SoTA LLMs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published