Stock Market Analysis with CrewAI

ravidorairajcrewai, ai9 months ago33 Views

I built a self-hosted stock market assistant that fetches real-time market data, computes technical indicators, and uses AI agents to generate actionable analysis. It runs as a single Docker container with a built-in web dashboard. The code is open source.

GitHub: github.com/crewwithravi/stockbot

What is StockBot?

StockBot is a personal research project I built to explore multi-agent AI architectures applied to financial data. The idea is simple:

  1. You ask — “Analyze QQQ” (via the API or web dashboard)
  2. StockBot fetches — Real-time price, 11 technical indicators, and the latest news from Yahoo Finance
  3. AI interprets — A CrewAI agent reads all the data and produces a human-readable analysis
  4. You receive — Structured JSON with verified market data and an AI-generated buy/hold/sell recommendation

The key design principle: the numbers are always real. The AI interprets — it never fabricates data.

Why I Built It

As someone working in enterprise application development within financial services — and currently pursuing a Master’s in Data Science — I wanted a project that sits at the intersection of production engineering and applied AI.

Most AI demos treat the model as a black box that generates everything. I wanted the opposite: a system where all data is fetched from real APIs, computed locally, and the AI layer is strictly limited to interpretation. If the AI hallucinates, the raw data is still there for the user to verify.

Key Features

FeatureDescription
Stock AnalysisDeep-dive into any ticker with price, technicals, news, and an AI recommendation
Morning BriefingAI-generated summary for your entire watchlist in a single request
Portfolio TrackingTrack holdings with real-time P&L calculations and AI commentary
Price AlertsSet price targets and check for triggered conditions
Quick QuoteInstant data endpoint with zero AI latency
Web DashboardBuilt-in dark-themed UI with watchlist, analysis, portfolio, alerts, and briefing tabs
Multi-LLM SupportSwitch between Ollama (local), Google Gemini, OpenAI, or Anthropic with one env variable

Architecture: Data-First Design

This is the part I’m most intentional about. StockBot follows a data-first architecture — all market data is fetched directly from external APIs and computed locally. The AI layer receives verified data and is responsible only for interpretation.

Step 1  Fetch real-time data           → yfinance (prices, volume, 52-week range)
Step 2  Compute technical indicators   → ta library (RSI, MACD, SMA, Bollinger, ATR)
Step 3  Gather news headlines          → yfinance news feed (real headlines with sources)
Step 4  AI interpretation              → LLM reads verified data and writes analysis
Step 5  Structured response            → JSON with raw data fields + AI summary

Every API response separates verified data (price, change_pct, technicals) from AI output (ai_analysis, ai_recommendation). Users can trust the numbers independently of whatever the model says.

Tech Stack

ComponentTechnologyPurpose
API ServerFastAPI + GunicornProduction-grade async API with OpenAPI docs
AI AgentsCrewAI + LiteLLMMulti-agent orchestration with provider-agnostic LLM support
Market DatayfinanceReal-time prices, company fundamentals, and news
Technical Analysista (Python)RSI, MACD, SMA, Bollinger Bands, ATR computation
DatabaseSQLite (WAL mode)Persistent storage for portfolio, watchlist, alerts
Web DashboardHTML + Tailwind CSS + JSBuilt-in UI served by FastAPI — zero build step
ContainerizationDocker ComposeSingle-command deployment with volume persistence
Reverse ProxyCaddy (optional)Auto-HTTPS with Let’s Encrypt

The Web Dashboard

StockBot ships with a built-in web dashboard — no separate frontend build required. It features:

  • Dark theme with glass-morphism design
  • Live watchlist cards with prices and signal summaries
  • Full AI analysis with color-coded BUY / HOLD / SELL badges
  • Portfolio table with real-time P&L tracking
  • Price alerts with one-click condition checking
  • AI morning briefing for your entire watchlist
  • Keyboard shortcuts — Enter for quick quote, Shift+Enter for AI analysis

The frontend is pure HTML, JavaScript, and CSS served directly by FastAPI. Zero build step, zero npm.

API Endpoints

MethodEndpointDescription
GET/healthHealth check — LLM connection status and provider info
GET/quote/{symbol}Quick quote — price, technicals, news (instant, no AI)
GET/analyze/{symbol}Full AI analysis with buy/hold/sell recommendation
POST/briefingMorning briefing for all watchlist symbols
GET/portfolioPortfolio overview with AI summary
POST / DELETE/portfolioAdd or remove holdings
GET / POST / DELETE/watchlistManage watchlist symbols
GET / POST/alertsCreate and check price alerts

Interactive API documentation is auto-generated at /docs (Swagger UI) and /redoc.

Running It Yourself

The quickest way to try StockBot locally:

git clone https://github.com/crewwithravi/stockbot.git
cd stockbot
pip install -r requirements.txt

LLM_PROVIDER=gemini \
LLM_MODEL=gemini-2.0-flash \
GEMINI_API_KEY=your-api-key \
STOCKBOT_DB_PATH=/tmp/stockbot.db \
PYTHONPATH=app \
uvicorn main:app --host 0.0.0.0 --port 5050

Then open http://localhost:5050 in your browser.

For Docker deployment, production configuration, and all LLM provider options, check the full documentation on GitHub.

Technical Indicators

StockBot computes the following indicators from historical OHLCV data:

IndicatorParametersSignal
RSI14-periodOverbought (> 70), Oversold (< 30), Neutral
MACD12, 26, 9Bullish when MACD crosses above signal line
SMA 20 / 50 / 20020, 50, 200-dayShort, medium, and long-term trend direction
Golden / Death CrossSMA 50 vs 200Golden cross (bullish), Death cross (bearish)
Bollinger Bands20-period, 2 std devOverextended at upper band, oversold at lower
ATR14-periodAverage daily range — measures volatility

What’s Next

  • Scheduled alert scanning on configurable intervals
  • Push notifications via Telegram and n8n
  • Historical backtesting to evaluate signal accuracy
  • Interactive charting in the dashboard

Disclaimer

StockBot is an educational project for learning and demonstration purposes. It is not financial advice. AI-generated recommendations are produced by a language model and should never be interpreted as professional financial guidance. Market data is sourced from Yahoo Finance and may be delayed or incomplete. Always consult a qualified financial advisor before making investment decisions. Use at your own risk.

Full source code, deployment guide, and API docs:
github.com/crewwithravi/stockbot

Licensed under MIT · Built with CrewAI, FastAPI, and yfinance

Leave a reply

Previous Post

Next Post

Loading Next Post...
Search
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...

Cart
Cart updating

ShopYour cart is currently is empty. You could visit our shop and start shopping.