Stock Prediction Service

AI-Powered Real-time Stock Analysis

DEMO AI/ML REAL-TIME

AI-powered stock prediction system using real-time news sentiment analysis. Aggregates news from multiple sources (Reddit, NewsAPI, RSS feeds), analyzes sentiment with a local LLM (Ollama), and generates multi-timeframe predictions with confidence scores.

📊 Quick Stats

80+ Supported Stocks
3 News Sources
12h Cache Duration
30s Avg Response

âœĻ Key Features

  • Real-time News Analysis - Aggregates from Reddit, NewsAPI, and RSS feeds (CNBC, MarketWatch, Reuters)
  • Local AI Processing - Ollama LLM (Llama 3.2 3B) running on M2 Mac with Neural Engine
  • Multi-timeframe Predictions - Short-term, mid-term, and long-term recommendations
  • Interactive Charts - 30-day price history visualization with Chart.js
  • Discussion Board - Community insights and discussions per stock ticker
  • Real-time Chat - Stock-specific chat rooms using Socket.IO
  • Activity Analytics - User behavior tracking and session analysis
  • Force Update - Bypass cache to get fresh predictions on demand

ðŸ’ŧ Tech Stack

Component Technology
Frontend HTML5, CSS3, JavaScript (ES6+), jQuery, Chart.js, Socket.IO client
Backend Flask, Python 3.12, Flask-SocketIO, Flask-CORS
AI/ML Ollama (Llama 3.2 3B) / OpenAI GPT-3.5-turbo
Data Sources Reddit API (praw), NewsAPI, RSS feeds (feedparser), yfinance
Storage JSON (discussions), Pickle (cache), JSONL (activity logs)
Deployment GitHub Pages (frontend) + ngrok tunnel (backend)
Hardware MacBook Air M2 (24GB RAM, 10-core GPU)

🏗ïļ System Architecture

Data Flow

GitHub Pages (Frontend) ↓ HTTPS Ngrok Tunnel (carpedkm.jp.ngrok.io) ↓ localhost:5001 MacBook Air M2 (Flask Backend) ↓ ├── News Aggregator │ ├── Reddit API (r/wallstreetbets, r/stocks, r/investing) │ ├── NewsAPI (global financial news) │ └── RSS Feeds (CNBC, MarketWatch, Reuters) │ ├── Sentiment Analyzer │ └── Ollama LLM (Llama 3.2 3B) │ ├── Price Data │ └── yfinance (historical & real-time) │ └── Storage ├── JSON (discussion board) ├── Pickle (prediction cache) └── JSONL (activity logs)

🔌 API Endpoints

# Authentication POST /api/login # User login POST /api/logout # User logout GET /api/check-auth # Check auth status # Stock Data GET /api/stocks # List supported stocks GET /api/search-stock?q={query} # Search stock by name/ticker GET /api/stock/{ticker}/predict # Get prediction (queued) GET /api/stock/{ticker}/price # Get price data GET /api/stock/{ticker}/news # Get recent news # Market Overview GET /api/market-overview # Get market indices GET /api/trending # Get trending stocks # Discussion Board GET /api/discussions/{ticker} # Get posts POST /api/discussions/{ticker} # Create post GET /api/discussions/post/{post_id} # Get post with comments POST /api/discussions/post/{post_id}/comment # Add comment POST /api/discussions/post/{post_id}/like # Like post DELETE /api/discussions/post/{post_id} # Delete post # Analytics POST /api/log-activity # Log user activity # System GET /api/health # Health check GET /api/status # Server status

📰 News Sources

Reddit

  • r/wallstreetbets - High-volume retail trader discussions
  • r/stocks - General stock market discussion
  • r/investing - Long-term investment strategies
  • r/StockMarket - Market news and analysis

NewsAPI

Global financial news aggregator with 100 requests/day limit on free tier.

RSS Feeds

  • CNBC - Breaking financial news
  • MarketWatch - Market data and analysis
  • Reuters - Global business news

ðŸĪ– AI Configuration

Installation

# Install Ollama brew install ollama # Start Ollama service ollama serve # Pull Llama 3.2 3B model ollama pull llama3.2:3b

Model Performance

Metric Value
Model Llama 3.2 3B
Memory Usage ~2GB RAM
Speed ~1-2s per news article on M2
Hardware Acceleration M2 Neural Engine (16-core, 15.8 TOPS)
Cost Free (local processing)

ðŸ’ŧ Hardware Specifications

Component Specification
Model MacBook Air M2 (2022)
CPU Apple M2 (8-core: 4 performance + 4 efficiency)
GPU 10-core GPU (integrated)
RAM 24GB Unified Memory
Neural Engine 16-core (15.8 trillion ops/sec)
Storage 512GB SSD

⚠ïļ Limitations

  • Prediction Time: 30-60s due to sequential LLM inference for sentiment analysis
  • Concurrent Users: 1-3 max (single MacBook server, no load balancing)
  • Uptime: Requires MacBook to be powered on and ngrok tunnel active
  • Rate Limits: NewsAPI 100 req/day (free tier), Reddit API 60 req/min
  • Cache: 12-hour prediction cache, may show stale data during volatile markets
  • Market Coverage: Limited to 80+ major stocks and Korean KOSPI stocks

ðŸ”Ū Future Enhancements

  • Batch Processing: Parallel LLM inference for faster predictions
  • Redis Caching: Distributed cache layer for better performance
  • Cloud Deployment: 24/7 availability on AWS/GCP with autoscaling
  • Expanded Coverage: Full S&P 500 and international markets
  • Accuracy Tracking: Historical performance metrics and backtesting
  • WebSocket Updates: Real-time prediction progress without polling
  • Advanced Charts: Technical indicators (RSI, MACD, Bollinger Bands)
  • Portfolio Tracking: User watchlists and personalized alerts

ðŸ‘Ļ‍ðŸ’ŧ Author & Developer

Daneul Kim

Graduate Student in Computer Science & Engineering

Seoul National University

carpedkm@snu.ac.kr

carpedkm.github.io

This project was developed as a demonstration of AI-powered financial analysis using locally-run LLMs. The system showcases real-time data aggregation, sentiment analysis, and predictive modeling in a production-ready web application.