|
| 1 | +# QuantStrategyLab Developer Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +QuantStrategyLab is a multi-market quantitative trading platform spanning 28 repositories. This guide helps new developers understand the system and start contributing. |
| 6 | + |
| 7 | +## Repository Map |
| 8 | + |
| 9 | +### Layer 1: Shared Foundation |
| 10 | +| Repo | Purpose | |
| 11 | +|------|---------| |
| 12 | +| **QuantPlatformKit** | Core shared library: domain models, broker adapters, cloud abstraction, notifications, risk, backtest, data versioning | |
| 13 | +| **QuantRuntimeSettings** | Runtime configuration center: JSON Schema, strategy switch console (JS/Cloudflare Workers) | |
| 14 | + |
| 15 | +### Layer 2: Strategy Packages |
| 16 | +| Repo | Market | Strategies | |
| 17 | +|------|--------|-----------| |
| 18 | +| **UsEquityStrategies** | US Equity | ETF rotation, Smart DCA, leader rotation, leveraged combos | |
| 19 | +| **HkEquityStrategies** | HK Equity | Global ETF rotation, dividend quality, combo | |
| 20 | +| **CnEquityStrategies** | CN A-shares | Industry ETF rotation, dividend quality, combo | |
| 21 | +| **CryptoStrategies** | Crypto | BTC DCA, trend rotation, live pool rotation, combo | |
| 22 | + |
| 23 | +### Layer 3: Data Pipelines |
| 24 | +| Repo | Produces | |
| 25 | +|------|----------| |
| 26 | +| **UsEquitySnapshotPipelines** | Feature snapshots, rankings, backtest summaries for US equity strategies | |
| 27 | +| **HkEquitySnapshotPipelines** | Factor snapshots, live-enablement evidence for HK strategies | |
| 28 | +| **CnEquitySnapshotPipelines** | A-share factor snapshots via AkShare | |
| 29 | +| **CryptoLivePoolPipelines** | Monthly live pool selection with ML ranking | |
| 30 | +| **MarketSignalSources** | BTC cycle indicators, daily technicals, US equity context | |
| 31 | +| **ResearchSignalContextPipelines** | Research-grade market context artifacts | |
| 32 | + |
| 33 | +### Layer 4: Execution Platforms |
| 34 | +| Repo | Broker | Deployment | |
| 35 | +|------|--------|-----------| |
| 36 | +| **InteractiveBrokersPlatform** | IBKR | Cloud Run (Flask) | |
| 37 | +| **LongBridgePlatform** | LongBridge | Cloud Run (Flask) | |
| 38 | +| **CharlesSchwabPlatform** | Schwab | Cloud Run (Flask) | |
| 39 | +| **FirstradePlatform** | Firstrade | Cloud Run (Flask) | |
| 40 | +| **BinancePlatform** | Binance | VPS (CLI) | |
| 41 | +| **QmtPlatform** | QMT (paper) | Cloud Run (Flask) | |
| 42 | + |
| 43 | +### Layer 5: Operations & Research |
| 44 | +| Repo | Purpose | |
| 45 | +|------|---------| |
| 46 | +| **IBKRGatewayManager** | IBKR gateway VM lifecycle (Docker + TOTP) | |
| 47 | +| **SchwabTokenAutoRefresher** | Schwab OAuth token refresh (Playwright) | |
| 48 | +| **CodexAuditBridge** | AI audit gateway (Claude/GPT/Codex) | |
| 49 | +| **QuantStrategyPlugins** | Sidecar risk plugins (regime, crisis, macro) | |
| 50 | +| **QuantAdvisorResearch** | Advisory research publishing | |
| 51 | +| **PoliticalEventTrackingResearch** | Political event RSS tracking | |
| 52 | + |
| 53 | +## Development Workflow |
| 54 | + |
| 55 | +1. **Create feature branch**: `git checkout -b feat/description` |
| 56 | +2. **Make changes**: Follow existing code patterns |
| 57 | +3. **Run checks**: `ruff check . && pytest tests/ -q` |
| 58 | +4. **Commit**: `type(scope): description` format |
| 59 | +5. **Push and create PR**: CI must pass before merge |
| 60 | +6. **Merge**: PR merged with `admin` flag, branch deleted |
| 61 | + |
| 62 | +## Key Patterns |
| 63 | + |
| 64 | +### Strategy Interface |
| 65 | +All strategies expose: |
| 66 | +```python |
| 67 | +PROFILE_NAME: str |
| 68 | +build_target_weights(...) → (weights_dict, ranked_frame, metadata) |
| 69 | +compute_signals(...) → (weights, signal_desc, is_emergency, status_desc, diagnostics) |
| 70 | +extract_managed_symbols(...) → tuple[str, ...] |
| 71 | +``` |
| 72 | + |
| 73 | +### Catalog Pattern |
| 74 | +Every strategy package has a `catalog.py` with standardized accessor functions: |
| 75 | +`get_strategy_definitions()`, `get_strategy_catalog()`, `get_runtime_enabled_profiles()` |
| 76 | + |
| 77 | +### Broker Adapter |
| 78 | +Platform repos implement broker-specific adapters conforming to QPK's `MarketDataPort`, `PortfolioPort`, `ExecutionPort` protocols. |
| 79 | + |
| 80 | +### Dependency Pinning |
| 81 | +All repos pin QPK via `QPK_PIN`. Run `python scripts/check_qpk_pin_consistency.py` to verify. |
0 commit comments