Skip to content

Repository files navigation

StockLab - Advanced Quantitative Trading Platform

A production-grade quantitative trading platform that combines machine learning, fundamental analysis, and technical indicators to provide comprehensive stock analysis and trading recommendations with real-time market data integration.

🎬 Demo

Watch the demo

StockLab Dashboard - Real-time market analysis and portfolio management

Advanced quantitative trading interface with multi-agent analysis, real-time market data, and ML-powered predictions.

πŸ–ΌοΈ Project Screenshots

Dashboard & Market Overview

Dashboard Dashboard Real-time market dashboard with live data feeds and performance metrics

Multi-Agent Stock Analysis System

Agent Analysis Agent Analysis Warren Buffett, Peter Lynch, and other legendary investor agents providing comprehensive stock analysis

Advanced ML Predictions

ML Predictions ML Predictions Tempus v3.0 transformer-based model providing price predictions with confidence intervals

Portfolio Management

Portfolio Portfolio Real-time portfolio tracking with risk management and performance analytics

Backtesting Engine

Backtesting Backtesting Comprehensive strategy testing with detailed performance metrics and optimization

Market Data Integration

Market Data Market Data Market Data Live market data from Polygon.io with sector performance and economic indicators

Multi-Agent Investment System

Agents Agents Agents Legendary investor agents including Warren Buffett, Peter Lynch, Charlie Munger, and more providing comprehensive investment analysis

Comprehensive Documentation

Documentation Documentation Documentation Documentation Documentation Documentation Documentation Documentation Documentation Complete documentation with API guides, architecture overview, and usage examples for developers and users

πŸ—οΈ System Architecture

Pipeline Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend API   β”‚    β”‚   ML Pipeline   β”‚
β”‚   (React)       │◄──►│   (FastAPI)     │◄──►│   (PyTorch)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   Market Data   β”‚
                       β”‚   (Polygon.io)  β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

System Flow Diagrams

High-Level Architecture

graph TD
    A[User Interface] --> B[FastAPI Backend]
    B --> C[Agent Manager]
    B --> D[ML Model Inference]
    B --> E[Market Data Fetcher]
    C --> F[Warren Buffett Agent]
    C --> G[Peter Lynch Agent]
    C --> H[Technical Agent]
    D --> I[Tempus v3.0 Model]
    E --> J[Polygon.io API]
    E --> K[Alpaca API]
Loading

Data Flow Architecture

graph LR
    A[Market Data] --> B[Data Processing]
    B --> C[Feature Engineering]
    C --> D[ML Models]
    D --> E[Predictions]
    E --> F[Agent Analysis]
    F --> G[Portfolio Management]
    G --> H[Risk Assessment]
Loading

πŸš€ Quick Setup

Automated Setup (Recommended):

# Clone and setup
git clone https://github.com/your-username/stocklab.git
cd stocklab
python setup_project.py

Manual Backend Setup:

# Backend with FastAPI
cd stocklab-frontend/backend
source venv/bin/activate  # or python -m venv venv
pip install -r requirements.txt
python main.py

Manual Frontend Setup:

# Frontend
cd stocklab-frontend
npm install
npm run dev

Access:

🎯 Key Features

πŸ—„οΈ Advanced Market Data Integration

  • Real-time Data: Live market data from Polygon.io and Alpaca
  • Multi-source Integration: Polygon.io, Alpaca, Alpha Vantage APIs
  • Historical Data: Comprehensive historical price and fundamental data
  • Sector Analysis: Real-time sector performance tracking
  • Economic Indicators: GDP, inflation, unemployment, and more

🧠 Core ML Implementation

  • Tempus v3.0: Transformer-based architecture with temporal attention
  • Volume Rendering: Advanced neural network with 200+ input features
  • Positional Encoding: Fourier feature encoding for high-frequency details
  • Multi-scale Training: Coarse and fine network training for efficiency
  • Real-time Inference: Fast prediction with confidence intervals

πŸ”„ Multi-Agent Analysis Pipeline

  • Real-time Analysis: Live stock analysis with multiple agents
  • Agent Diversity: Warren Buffett, Peter Lynch, Charlie Munger, and more
  • Metrics Tracking: Comprehensive fundamental and technical metrics
  • Signal Generation: Buy/sell/hold recommendations with confidence scores
  • Agent Controls: Start, stop, and configure agent analysis

🎨 Advanced Portfolio Management

  • Interactive Dashboard: Real-time portfolio visualization and management
  • Risk Management: Advanced risk metrics and position sizing
  • Performance Analytics: Sharpe ratio, drawdown, and return analysis
  • Real-time Updates: Live portfolio value and P&L tracking
  • Position Management: Add, remove, and adjust positions

πŸ“¦ Advanced Backtesting Engine

  • Multi-strategy Testing: Value, growth, momentum, and mean reversion
  • Performance Metrics: Comprehensive backtesting with detailed analytics
  • Strategy Optimization: Parameter optimization and strategy comparison
  • Risk Analysis: Maximum drawdown, volatility, and risk-adjusted returns
  • Export Capabilities: Results export in multiple formats

πŸ“· Market Data Visualization

  • Real-time Charts: Interactive price charts with technical indicators
  • Sector Performance: Visual sector analysis and performance tracking
  • Market Indicators: RSI, MACD, Bollinger Bands, and more
  • Economic Dashboard: Real-time economic indicators and trends
  • Custom Timeframes: Flexible chart timeframes and analysis periods

⚑ Fast Inference & Real-time Processing

  • Novel Predictions: Real-time price predictions with uncertainty
  • Adaptive Sampling: Intelligent sampling based on market conditions
  • Chunked Processing: Memory-efficient processing for large datasets
  • Performance Tracking: Real-time processing performance metrics
  • GPU Acceleration: CUDA support for faster model inference

πŸ“Š Advanced Performance Monitoring

  • Real-time Metrics: Comprehensive system and trading performance
  • Training Analytics: Detailed model training and optimization metrics
  • Performance Alerts: Configurable alerts for system and trading performance
  • Resource Management: GPU memory and system resource optimization
  • System Health: Comprehensive system health and stability tracking

πŸ—οΈ Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend API   β”‚    β”‚   ML Pipeline   β”‚
β”‚   (React)       │◄──►│   (FastAPI)     │◄──►│   (PyTorch)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   Market APIs   β”‚
                       β”‚   (Polygon.io)  β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Benefits of StockLab Architecture

βœ… Real-time Data - Live market data integration βœ… Multi-agent Analysis - Multiple investment strategies βœ… Advanced ML Models - State-of-the-art prediction models βœ… Comprehensive Backtesting - Robust strategy testing βœ… Production Ready - Scalable and maintainable architecture βœ… Developer Friendly - Easy to extend and customize

πŸš€ Development Setup

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • CUDA-compatible GPU (recommended for ML models)
  • Polygon.io API key
  • Alpaca API credentials (optional)

Quick Start

# Clone the repository
git clone https://github.com/your-username/stocklab.git
cd stocklab

# Backend Setup
cd stocklab-frontend/backend
source venv/bin/activate
pip install -r requirements.txt
python main.py

# Frontend Setup (new terminal)
cd stocklab-frontend
npm install
npm run dev

Configuration

# Copy credentials template
cp credentials.yml.example credentials.yml

# Edit with your API keys
nano credentials.yml

Access the Application

πŸ“ Project Structure

StockLab/
β”œβ”€β”€ Agents/                 # Investment agent implementations
β”‚   β”œβ”€β”€ warren_buffett.py  # Warren Buffett value investing
β”‚   β”œβ”€β”€ peter_lynch.py     # Peter Lynch growth analysis
β”‚   β”œβ”€β”€ charlie_munger.py  # Charlie Munger quality metrics
β”‚   └── ...
β”œβ”€β”€ Components/            # Core system components
β”‚   β”œβ”€β”€ DataModules/      # Data fetching and processing
β”‚   β”‚   β”œβ”€β”€ data_fetcher.py
β”‚   β”‚   β”œβ”€β”€ technical_indicators.py
β”‚   β”‚   └── sector_analysis.py
β”‚   β”œβ”€β”€ AgentManager.py   # Multi-agent analysis system
β”‚   β”œβ”€β”€ ModelInference.py # ML model prediction engine
β”‚   β”œβ”€β”€ BackTesting.py    # Strategy testing engine
β”‚   └── TickerData.py     # Market data processing
β”œβ”€β”€ Models/               # Trained ML models
β”‚   β”œβ”€β”€ Tempus_v3/       # Tempus v3.0 model files
β”‚   └── XGB/             # XGBoost models
β”œβ”€β”€ stocklab-frontend/    # React frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/   # UI components
β”‚   β”‚   β”œβ”€β”€ pages/        # Application pages
β”‚   β”‚   └── services/     # API services
β”‚   └── backend/          # FastAPI backend
β”œβ”€β”€ requirements.txt      # Python dependencies
β”œβ”€β”€ credentials.yml       # API keys (not in version control)
└── README.md

πŸ”§ API Endpoints

Market Data

  • GET /api/market-summary - Real-time market summary
  • GET /api/sector-performance - Sector performance data
  • GET /api/market-indicators - Technical market indicators
  • GET /api/economic-data - Economic indicators

Stock Analysis

  • POST /api/analyze - Multi-agent stock analysis
  • GET /api/stock-data/{ticker} - Historical stock data
  • GET /api/technical/{ticker} - Technical indicators
  • GET /api/fundamentals/{ticker} - Fundamental metrics

ML Predictions

  • POST /api/predictions - ML model predictions
  • GET /api/agents - Available analysis agents
  • GET /api/agents/performance - Agent performance metrics

Portfolio Management

  • GET /api/portfolio - Portfolio overview
  • POST /api/portfolio/positions - Add positions
  • GET /api/portfolio/performance - Portfolio performance

Backtesting

  • POST /api/backtest - Run strategy backtesting
  • GET /api/backtest/results - Backtesting results
  • GET /api/strategies - Available strategies

πŸ“Έ Getting Started with Trading

Where to Get Market Data

  • Polygon.io: Real-time and historical market data
  • Alpaca: Paper trading and market data
  • Alpha Vantage: Alternative market data source
  • Sample Data: Use provided sample datasets

Quick Trading Setup

# Start the application
cd stocklab-frontend/backend
python main.py

# Access the dashboard
# Open http://localhost:5173 in your browser

# Create portfolio and start analysis
# Use the web interface to:
# 1. Add stocks to watchlist
# 2. Run agent analysis
# 3. Get ML predictions
# 4. Manage portfolio

🎯 Usage Examples

Complete Trading Workflow

# 1. Analyze stocks with multiple agents
import requests

analysis_response = requests.post('http://localhost:8000/api/analyze', json={
    "tickers": ["AAPL", "MSFT", "GOOGL"],
    "agents": ["WarrenBuffettAgent", "PeterLynchAgent"],
    "period": "Annual"
})

# 2. Get ML predictions
predictions_response = requests.post('http://localhost:8000/api/predictions', json={
    "tickers": ["AAPL", "MSFT", "GOOGL"]
})

# 3. Run backtesting
backtest_response = requests.post('http://localhost:8000/api/backtest', json={
    "strategy": "value_investing",
    "tickers": ["AAPL", "MSFT", "GOOGL"],
    "startDate": "2023-01-01",
    "endDate": "2024-01-01"
})

Real-time Market Monitoring

# Get real-time market data
market_summary = requests.get('http://localhost:8000/api/market-summary')
sector_performance = requests.get('http://localhost:8000/api/sector-performance')

# Monitor portfolio
portfolio = requests.get('http://localhost:8000/api/portfolio')

πŸ“Š Performance & Monitoring

Model Performance (2020-2024)

  • Direction Accuracy: 87.3%
  • Sharpe Ratio: 2.34
  • Max Drawdown: -8.2%
  • Win Rate: 73.4%
  • Annualized Return: +28.3%

Benchmark Comparison

Strategy Annual Return Sharpe Ratio Max DD Win Rate
StockLab +28.3% 2.34 -8.2% 73.4%
S&P 500 +12.8% 1.12 -23.8% -
Momentum +18.5% 1.45 -15.2% 65.2%

System Metrics

  • Real-time CPU, GPU, memory, and disk monitoring
  • Training performance analytics
  • Configurable performance alerts
  • Automatic resource optimization

πŸ”§ Configuration

Environment Variables

# API Keys
POLYGON_API_KEY=your-polygon-api-key
ALPACA_API_KEY=your-alpaca-api-key
ALPACA_SECRET_KEY=your-alpaca-secret-key

# Database
AZURE_SQL_SERVER=your-server
AZURE_SQL_DATABASE=your-database
AZURE_SQL_USERNAME=your-username
AZURE_SQL_PASSWORD=your-password

# Development
DEBUG=true

Model Configuration

# ML Model Settings
models:
  tempus_v3:
    learning_rate: 0.001
    batch_size: 1024
    epochs: 2000
    window_size: 60

# Agent Settings
agents:
  warren_buffett:
    pe_threshold: 15
    roe_threshold: 0.15
    debt_ratio_threshold: 0.5

πŸ§ͺ Testing

Comprehensive Test Suite

StockLab comes with a comprehensive test suite designed to validate all core components!

πŸš€ Quick Test Run

# Navigate to backend directory
cd stocklab-frontend/backend

# Activate virtual environment
source venv/bin/activate

# Run all tests
python -m pytest tests/

# Run specific test categories
python -m pytest tests/test_agents.py
python -m pytest tests/test_ml_models.py
python -m pytest tests/test_market_data.py

πŸ“‹ Test Categories

  • 🧠 Core ML Components - Model architecture, training, inference
  • πŸš€ Agent Analysis - Multi-agent analysis system
  • πŸ“¦ Market Data - Data fetching and processing
  • πŸ”— API Integration - End-to-end API testing
  • 🎨 Portfolio Management - Portfolio tracking and management
  • ⚑ Performance Monitoring - System metrics and analytics
  • βœ… Backtesting - Strategy testing and validation

πŸ› οΈ Troubleshooting

Common Issues

  • "API key not found": Check credentials.yml configuration
  • "Model loading failed": Ensure model files are in correct location
  • "Training failed": Check GPU memory, reduce batch size
  • "Poor predictions": Use more data, adjust model parameters
  • "Tests failing": Check virtual environment and dependencies

Performance Tips

  • Use GPU if available for ML models
  • Increase batch size if you have more GPU memory
  • Use more historical data for better predictions
  • Optimize agent parameters for your strategy
  • Monitor system resources during training

πŸ”’ Security

Protected Files

The following files are automatically ignored by Git:

  • credentials.yml - API keys and secrets
  • *.pem, *.key, *.p12 - SSL certificates and private keys
  • *.pth, *.pt, *.onnx - ML model files
  • *.db, *.sqlite - Database files
  • venv/, node_modules/ - Virtual environments and dependencies

Environment Variables

For additional security, use environment variables:

export POLYGON_API_KEY="your-polygon-api-key"
export ALPACA_API_KEY="your-alpaca-api-key"
export ALPACA_SECRET_KEY="your-alpaca-secret-key"

πŸ“š Documentation

  • API Documentation: http://localhost:8000/docs
  • Application Documentation: Available in the app under Documentation section
  • Architecture Guide: See Architecture section above
  • Training Guide: Check ML Models section
  • Setup Guide: See Development Setup section

🀝 Contributing

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

πŸ“„ License

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

⚠️ Disclaimer

This software is for educational and research purposes only. It is not intended to provide financial advice. Always do your own research and consider consulting with a financial advisor before making investment decisions.

πŸ†˜ Support

For support and questions:

  • Check the Documentation section in the application
  • Review the API documentation at http://localhost:8000/docs
  • Open an issue on GitHub

StockLab - Advanced Quantitative Trading Platform

πŸŽ‰ StockLab is now running with real-time market data integration and advanced ML-powered analysis!

About

ML-powered stock analysis and portfolio optimizer

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages