quant-ai / README.md
Ypeng12's picture
Enhance README.md with Alpaca Live/Paper Trading and HF deployment documentation
3245e3f
|
Raw
History Blame Contribute Delete
8.11 kB
metadata
title: Quant AI - Advanced Quant Trading Engine & Backtest Simulator
emoji: πŸ“ˆ
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false

πŸ“ˆ Quant.ai β€” Institutional Alpha Research & Live/Paper Trading Platform

Hugging Face Space GitHub Repository Python Version FastAPI Alpaca Trading Docker Ready

πŸš€ Interactive Terminal Demo: Experience the deployed terminal live on Hugging Face Spaces πŸ‘‰ huggingface.co/spaces/Ypeng12/quant-ai

Quant.ai is an end-to-end, Point-in-Time Consistent Quantitative Trading & Paper/Live Execution Platform. Designed following Hudson River Trading (HRT) and Quantitative Hedge Fund engineering standards, it bridges the gap between rigorous signal research, microstructure execution, and real-time broker integration (Alpaca API).


πŸ”₯ Key Platform Highlights

⚑ 1. Real-Time Live & Paper Trading (Alpaca Integration)

  • Direct Broker Connectivity: Seamless REST & WebSocket integration with Alpaca Markets for real-time order routing, position tracking, and market streaming.
  • Paper & Live Mode Switch: Flexible environment toggling (https://paper-api.alpaca.markets for risk-free simulation vs. live brokerage execution).
  • Execution Algorithmic Suite: Smart order routing with TWAP, VWAP, and Implementation Shortfall (IS) execution algorithms.
  • Dynamic Portfolio Risk Controls:
    • Real-time position tracking and ledger recording.
    • Trailing stop-loss triggers and volatility-based position sizing.
    • Drawdown-contingent risk multipliers & consecutive loss protections.

πŸ”¬ 2. HRT-Standard Alpha Research Engine

  • Point-in-Time Data Hygiene: Strict timestamp truncation at date $t$ to eliminate lookahead bias across U.S. Equity & ETF universes.
  • Purged Walk-Forward Cross Validation + Embargo: Eliminates overlap leakage across rolling 3-year train / 6-month validation / 6-month OOS test windows with a 5-day embargo.
  • Novel Risk-Adjusted Signals:
    • Sortino Momentum: $\text{Return}{20d} / \text{DownsideVol}{20d}$
    • Residual Momentum: 60-day rolling OLS stripping SPY Market Beta: $R_i(\tau) = \alpha_i + \beta_i R_{\text{SPY}}(\tau) + \epsilon_i(\tau)$
    • Robust Z-Score Normalization: Cross-sectional Median/MAD standardization.
  • Multiple Testing Correction: Deflated Sharpe Ratio (DSR) and Stationary Bootstrap 95% Confidence Intervals.

πŸ“Š 3. Microstructure & Orderbook Engine

  • Order Flow Imbalance (OFI): Real-time L2/L3 orderbook imbalance calculation for high-frequency price impact prediction.
  • Friction & Shortfall Modeling: Multi-tiered transaction cost models with 2–15 bps slippage sensitivity checks.
  • Low-Latency Engine Core: C++ accelerated order matching engine headers (orderbook.hpp).

πŸ€– 4. Natural Language Alpha Hypothesis Parser

  • LLM-assisted hypothesis compilation translating natural language ideas into validated, executable Pydantic model configurations.

🎯 Core Research Hypothesis

"Can volatility-adjusted and market-beta-residualized cross-sectional momentum signals across liquid U.S. ETFs predict short-term excess returns after transaction costs and execution friction?"


⚑ Quick Start & Setup

1. Clone & Install Dependencies

git clone https://github.com/ypeng12/Quant.ai.git
cd Quant.ai

# Install Python requirements
pip install -r requirements.txt

2. Configure Environment & Alpaca Credentials

Create a .env file in the project root:

# Alpaca Broker Credentials (Use Paper Trading for risk-free testing)
ALPACA_API_KEY=your_alpaca_paper_key
ALPACA_SECRET_KEY=your_alpaca_paper_secret
ALPACA_BASE_URL=https://paper-api.alpaca.markets

# Server Configuration
PORT=7860

3. Run Unit Tests (Zero Future Leakage Verification)

python -m pytest tests/ -v

4. Execute Out-of-Sample Alpha Experiment (make oos)

python run_experiment.py

Outputs: ```text

QUANT.AI OUT-OF-SAMPLE EXPERIMENT RUNNER Hypothesis: Volatility-Adjusted Momentum across Liquid U.S. ETFs Lookback: 20d | Holding: 5d | Transaction Cost: 5.0 bps

--> Raw_Momentum_Baseline | OOS Rank IC: -0.0182 | Net Sharpe: 0.33 | MaxDD: -55.2% --> Vol_Adj_Momentum_Baseline | OOS Rank IC: -0.0196 | Net Sharpe: 0.33 | MaxDD: -59.4% --> Ridge_Linear | OOS Rank IC: 0.0102 | Net Sharpe: 1.58 | MaxDD: -23.5%


### 5. Launch Local Dashboard / FastAPI Backend
```bash
# Launch FastAPI Backend
uvicorn backend.app.main:app --host 0.0.0.0 --port 7860 --reload

Navigate to http://localhost:7860 in your browser.


πŸ“ Repository Architecture

Quant.ai/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── sync_to_hf.yml        # CI/CD GitHub Action auto-syncing to Hugging Face
β”œβ”€β”€ backend/
β”‚   └── app/
β”‚       β”œβ”€β”€ trading_engine.py     # Live/Paper Trading Engine & Portfolio Risk Control
β”‚       β”œβ”€β”€ simulator.py          # Execution Simulator & Implementation Shortfall Model
β”‚       β”œβ”€β”€ orderbook_ofi.py      # Microstructure Order Flow Imbalance (OFI) Engine
β”‚       β”œβ”€β”€ execution_algo.py     # TWAP / VWAP Order Execution Algorithms
β”‚       β”œβ”€β”€ low_latency_engine.py # High-Frequency Matching Engine Adapter
β”‚       └── cpp_engine/           # C++ Orderbook & Level-2 Matching Headers
β”œβ”€β”€ frontend/                     # React / TypeScript Institutional Dashboard UI
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ features/
β”‚   β”œβ”€β”€ labels/
β”‚   β”œβ”€β”€ validation/
β”‚   β”œβ”€β”€ models/
β”‚   └── portfolio/
β”œβ”€β”€ tests/                        # Zero Future Leak & Purged CV Unit Tests
β”œβ”€β”€ Dockerfile                    # Hugging Face Space Docker Deployment spec
β”œβ”€β”€ run_experiment.py             # One-command OOS research executable
└── requirements.txt              # Production Python dependencies

πŸ”„ CI/CD & Hugging Face Auto-Sync Workflow

This repository features automated GitHub Actions CI/CD (.github/workflows/sync_to_hf.yml).

Whenever changes are merged into the main branch, GitHub automatically mirrors and deploys the latest codebase directly to the Hugging Face Space, guaranteeing 24/7 live deployment without manual intervention.


🀝 Collaborative Development & Branching Model

To ensure platform stability:

  • Feature Branches: Developers work on dedicated feature branches (e.g. ypeng12, lxc).
  • Pull Requests (PR): Code is tested locally and submitted via PRs to main.
  • Deployment Trigger: Merging to main automatically triggers Hugging Face live deployment.

Developed with ❀️ for Quantitative Finance, Machine Learning, and Automated Execution Research.