Skip to content

DataTalesByAgos/QuantLab

Repository files navigation

QuantLab

QuantLab is a modular, structured environment for the design, statistical analysis, backtesting, and real-time simulation (Paper Trading) of quantitative trading strategies.

This project serves as a professional portfolio demonstrating the application of mathematical rigor and software engineering principles to quantitative finance.

Live Deployment: https://quantlab-liard-delta.vercel.app/


System Architecture

QuantLab System Architecture

The QuantLab platform consists of:

  • Frontend Dashboard: A responsive, modern UI built with HTML5, CSS3, and Vanilla JavaScript, deployed live on Vercel.
  • FastAPI Backend Server: Exposes REST APIs and WebSockets for real-time market data streaming and simulation control, designed to run in Docker containerized environments.
  • Quantitative Engine: Contains modules for backtesting, custom strategy implementations, data pipeline (fetching from Yahoo Finance API), risk metrics, and live/paper trading.

Directory Structure

  • 01_backtesting_engine/: Event-driven simulation engine with full portfolio accounting, commissions, and slippage.
  • 02_strategies/: Concrete strategy implementations (Mean Reversion, Momentum, Pairs Trading, Multi-Factor), documenting mathematical hypotheses and practical limitations.
  • 03_data_pipeline/: Robust data download (yfinance), cleaning, and feature engineering pipeline.
  • 04_research_notebooks/: Statistical tests (ADF, Cointegration) and pre-development experimentation.
  • 05_risk_metrics/: Risk-adjusted performance metrics (Sharpe, Sortino, Drawdown, position sizing).
  • 06_live_or_paper/: Real-time simulated execution module with structured logging system.

Implemented Strategies

1. Bollinger Mean Reversion

  • Hypothesis: Prices revert to their historical mean after extreme deviations.
  • Key Limitation: Sensitive to strong trend regimes (prolonged bull/bear markets) where price "walks the band", generating accumulated losses.

2. EMA Crossover Momentum

  • Hypothesis: Price direction persists after confirmation of fast/slow EMA crossovers.
  • Key Limitation: Generates consecutive false signals (whipsaws) in sideways-ranging markets.

3. Pairs Trading (Cointegration)

  • Hypothesis: Two cointegrated assets maintain a stationary spread over the long term.
  • Key Limitation: Loss of structural cointegration due to changes in corporate fundamentals.

Initial Backtest Results (Period: 2021–2023)

Using the unified execution script run_pipeline.py to simulate the Bollinger Mean Reversion strategy on asset KO:

  • Total Return: ~9.52% (relative to initial capital of $100,000.00).
  • Sharpe Ratio: ~0.45.
  • Max Drawdown: ~12.30%.
  • Slippage & Commissions: Incorporated (0.1% commission and 0.05% slippage per trade).

Getting Started & Local Installation

This project is fully containerized with Docker to easily run both the frontend and backend in unified environments.

Prerequisites

Make sure you have Docker and Docker Compose installed on your machine.

Running with Docker (Recommended)

To spin up the entire application (FastAPI backend + Nginx-served frontend), run the following command in the root directory:

docker compose up --build

Alternative: Local Development Installation (No Docker)

If you prefer to run the components manually, install the dependencies and follow these steps:

pip install -r requirements.txt
python run_pipeline.py

Running the Full Dashboard Manually

  1. Start the FastAPI backend:

    cd backend
    uvicorn main:app --reload --port 8000
  2. Open the frontend:

    Open index.html directly in your browser, or serve it with any static file server:

    # Using Python's built-in server (from the project root)
    python -m http.server 3000

    Then navigate to http://localhost:3000.


Roadmap & Next Steps

  1. Parameter Optimization: Add Bayesian optimization in the research step to calibrate thresholds and rolling windows while avoiding overfitting.
  2. MetaTrader 5 / Interactive Brokers API Integration: Connect the 06_live_or_paper module to real brokers for live order transmission and execution, or paper trading on demo accounts.
  3. Machine Learning Module: Implement a simple XGBoost classifier in the factors section to filter false signals based on market regime detection.

About

A modular quantitative trading environment for designing, backtesting, and simulating strategies (Mean Reversion, Momentum, Pairs Trading) in real-time. Features an event-driven backtesting engine, statistical research notebooks, a FastAPI backend, a dynamic frontend dashboard, and full Docker containerization.

Topics

Resources

Stars

Watchers

Forks

Contributors