Skip to content

Latest commit

 

History

History
270 lines (215 loc) · 8.65 KB

File metadata and controls

270 lines (215 loc) · 8.65 KB

Q24 Quantitative Trading System

A production-grade quantitative trading platform for the Quantiacs Q24 competition. This system provides a comprehensive ecosystem for developing, backtesting, analyzing, and managing algorithmic trading strategies across equities and cryptocurrencies.

Features

  • Multi-Strategy Portfolio Management - Run and compare 11+ strategies with individual isolation
  • Advanced Factor Library - 32+ factors across 12 categories (momentum, value, quality, etc.)
  • Professional Dashboard - 20+ analytical pages with real-time performance monitoring
  • Risk Analytics - Comprehensive risk attribution, Brinson analysis, and ex-ante risk forecasting
  • What-If Analysis - Scenario exploration with parameter surfaces
  • Smart Data Caching - TTL-based caching to optimize API usage
  • Regime Detection - Market regime classification with regime-aware metrics

Tech Stack

  • Python 3.7+
  • Streamlit - Interactive web dashboard
  • xarray - N-dimensional array computing
  • pandas / numpy - Data manipulation and numerical computing
  • Quantiacs API (qnt) - Market data access and backtesting
  • Plotly / Matplotlib - Visualization
  • scikit-learn / scipy - Machine learning and scientific computing

Project Structure

Q24_QUANT_SYSTEM/
├── src/Q24/
│   ├── strategies/           # Strategy implementations
│   │   ├── base.py           # Abstract base class
│   │   ├── registry.py       # Strategy discovery & registry
│   │   ├── ou_v1/            # Ornstein-Uhlenbeck mean-reversion
│   │   ├── glft_v1/          # Global Long-Short Tactical
│   │   ├── gtp51max/         # Optimized for max Sharpe
│   │   ├── q24_crypto_v*/    # Neural Crypto Alpha variants
│   │   └── benchmarks/       # Benchmark implementations
│   │
│   ├── strategy/             # Core strategy engine
│   │   ├── engine.py         # Execution orchestrator
│   │   ├── data_loader.py    # Market data with caching
│   │   ├── factors.py        # Factor library (32+ factors)
│   │   ├── portfolio.py      # Portfolio construction
│   │   ├── ic_weighting.py   # Information coefficient weighting
│   │   └── risk_overlays.py  # Risk management
│   │
│   ├── dashboard/            # Streamlit dashboard
│   │   ├── app.py            # Main entry point
│   │   ├── _pages/           # 20+ dashboard pages
│   │   ├── components/       # Reusable UI components
│   │   └── analytics/        # Analytics modules
│   │
│   └── shared/               # Shared utilities
│
├── outputs/                  # Strategy output directories
├── data-cache/               # Smart data caching
├── run_strategy.py           # Strategy execution entry point
├── run_dashboard.py          # Dashboard launcher
├── Run_Q24.command           # macOS combined runner
└── .env                      # Configuration

Getting Started

Prerequisites

  • Python 3.7+
  • Quantiacs API key (obtain from Quantiacs)
  • Conda (recommended) or pip

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd Q24_QUANT_SYSTEM
  2. Create and activate environment:

    conda create -n q24 python=3.10
    conda activate q24
  3. Install dependencies:

    pip install streamlit pandas numpy xarray plotly matplotlib scikit-learn scipy
    pip install qnt  # Quantiacs toolbox
  4. Configure environment variables in .env:

    API_KEY=your-quantiacs-api-key
    Q24_TAG=2025-12-22          # Optional: tag for outputs
    Q24_FORCE_RERUN=false       # Force re-run regardless of freshness
    Q24_AUTO_RUN_BENCHMARKS=true

Usage

Running Strategies

Execute all enabled strategies:

python run_strategy.py

This will:

  • Load enabled strategies from enabled_strategies.json
  • Skip strategies already run today (unless Q24_FORCE_RERUN=true)
  • Execute each strategy and save results to outputs/<strategy_id>/
  • Auto-run benchmark strategies after regular strategies

Launching Dashboard

Start the interactive portfolio management dashboard:

python run_dashboard.py

The dashboard provides:

  • Overview - KPI dashboard with performance charts
  • Performance - Sharpe, Sortino, Calmar, drawdown metrics
  • Weights - Portfolio composition over time
  • Factors - Factor IC analysis and contribution
  • Attribution - Factor and stock attribution
  • Risk Analytics - Risk decomposition and ex-ante forecasting
  • Elite Analytics - Regime, tail risk, convexity analysis
  • Strategy Comparison - Multi-strategy performance comparison
  • What-If Analysis - Scenario exploration

Combined Runner (macOS)

./Run_Q24.command

Runs diagnostics, executes strategies, and launches the dashboard.

Strategy Framework

Creating a New Strategy

  1. Create a new directory in src/Q24/strategies/:

    src/Q24/strategies/my_strategy/
    ├── __init__.py
    ├── config.py      # Strategy configuration
    ├── engine.py      # Strategy implementation
    └── factors.py     # Custom factors (optional)
    
  2. Implement the strategy by inheriting from StrategyBase:

    from src.Q24.strategies.base import StrategyBase, StrategyConfig
    from src.Q24.strategies.registry import StrategyRegistry
    
    @StrategyRegistry.register
    class MyStrategy(StrategyBase):
        @classmethod
        def get_id(cls) -> str:
            return "my_strategy"
    
        @classmethod
        def get_display_name(cls) -> str:
            return "My Custom Strategy"
    
        def run(self):
            # Strategy implementation
            pass
  3. Enable the strategy in enabled_strategies.json:

    {
      "enabled": {
        "my_strategy": true
      }
    }

Available Strategies

Strategy Type Description
ou_v1 Mean-Reversion Ornstein-Uhlenbeck process with 24 factors
glft_v1 Tactical Global Long-Short Tactical
gtp51max Optimized Maximum Sharpe optimization
q24_crypto_v5 Crypto Neural Crypto Alpha (28 factors)
q24_crypto_v10x Crypto Neural Crypto Alpha (12 factors)
q24_crypto_v11x Crypto Neural Crypto Alpha (10 curated factors)
q23_composer_v1 Ensemble 32-factor ensemble strategy
benchmarks/* Benchmark Equal-weight and market-cap benchmarks

Configuration

Environment Variables

Variable Description Default
API_KEY Quantiacs API key Required
Q24_TAG Tag for output directories Current date
Q24_FORCE_RERUN Force re-run all strategies false
Q24_AUTO_RUN_BENCHMARKS Auto-run benchmarks after strategies true
Q24_SKIP_BENCHMARKS Skip benchmark execution false
Q24_DEBUG_RUNS Enable debug mode false

Strategy Configuration

Configure which strategies to run in src/Q24/strategies/enabled_strategies.json:

{
  "enabled": {
    "ou_v1": true,
    "glft_v1": false,
    "benchmark_nas_ew": true
  }
}

Dashboard Pages

Core Analytics

  • Overview - KPI dashboard with portfolio snapshot
  • Performance - Comprehensive performance metrics
  • Weights - Long/short portfolio composition
  • Factors - Factor IC analysis
  • Attribution - Factor/stock attribution

Elite Analytics

  • Regime Analysis - Market regime detection
  • Tail Risk - CVaR clustering and extreme risk
  • Convexity - Gain decomposition analysis
  • Alpha Decay - Signal freshness estimation
  • Capacity - Portfolio scalability analysis

Risk Analytics

  • Risk Attribution - Factor risk contribution
  • Brinson Attribution - Active return decomposition
  • Ex-Ante Risk - Forward risk projection
  • Correlation Analysis - Rolling correlations

Management

  • Strategy Warehouse - Enable/disable strategies
  • Strategy Comparison - Multi-strategy comparison
  • What-If Analysis - Scenario exploration
  • Diagnostics - System health monitoring

Output Structure

Strategy results are saved to outputs/<strategy_id>/:

outputs/ou_v1/
├── _wide_weights_2025-12-22.csv    # Portfolio weights
├── _ic_2025-12-22.csv              # Information coefficients
├── _factor_weights_2025-12-22.csv  # Factor contributions
└── diagnostics.json                # Performance metrics

License

Proprietary - All rights reserved.

Support

For issues and feature requests, please open an issue in the repository.