Skip to content

Repository files navigation

QuantLab - Backend Service

QuantLab Backend is a modular, structured API built with FastAPI. It handles quantitative strategy design, statistical analysis, backtesting, and real-time paper trading simulations.

This repository is optimized for deployment on Render, while the frontend repository (QuantLab_Frontend) is designed to be deployed on Vercel.


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).
  • 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.
  • main.py: FastAPI entrypoint hosting the REST API endpoints.
  • run_pipeline.py: CLI pipeline to run strategies locally.

Local Setup & Run

  1. Install dependencies:

    pip install -r requirements.txt
  2. Run the API locally:

    uvicorn main:app --reload --port 8000

    The interactive Swagger documentation will be available at http://127.0.0.1:8000/docs.

  3. Run a local backtest CLI:

    python run_pipeline.py

Deployment to Render (Backend)

You can deploy this API to Render either as a native Python Web Service or using the included Dockerfile.

Option 1: Native Python Web Service (Recommended)

  1. Sign in to Render and click New > Web Service.
  2. Connect this repository (QuantLab_Backend).
  3. Set the following configuration details:
    • Runtime: Python 3 (or choose Python matching your workspace)
    • Build Command: pip install -r requirements.txt
    • Start Command: uvicorn main:app --host 0.0.0.0 --port $PORT
  4. Add the following Environment Variables (under the "Env" tab) if you want custom paths:
    • DATA_CACHE_DIR: data
    • PAPER_TRADING_LOG: paper_trading.log

Option 2: Dockerized Web Service

  1. Create a New > Web Service on Render.
  2. Connect this repository and set:
    • Runtime: Docker
  3. Render will automatically build the container using the root Dockerfile and expose the port.

Connecting with QuantLab_Frontend (Vercel)

When deploying your frontend QuantLab_Frontend to Vercel:

  1. Copy your Backend URL from the Render dashboard (e.g., https://quantlab-backend.onrender.com).
  2. In your frontend repository, configure the environment variable or configuration file to point to this URL.
    • For example, if using React/Vite, set:
      VITE_API_BASE_URL=https://quantlab-backend.onrender.com
    • Ensure the frontend fetch calls point to ${VITE_API_BASE_URL}/api/backtest and other endpoints.
  3. Note: The backend has CORS enabled for all origins (*) by default in main.py, making it ready to receive requests from your Vercel URL.

About

FastAPI backend and backtesting engine for QuantLab quantitative trading strategies.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages