Spaces:
Sleeping
Sleeping
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,13 +1,145 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: QuantAgent OS - Autonomous Quant Trading & Self-Improving Alpha Discovery
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.42.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# ποΈ QuantAgent OS: Autonomous Quantitative Trading System
|
| 14 |
+
### *Self-Improving Multi-Agent Quantitative Architecture based on arXiv:2402.03755*
|
| 15 |
+
|
| 16 |
+

|
| 17 |
+

|
| 18 |
+

|
| 19 |
+

|
| 20 |
+
|
| 21 |
+
QuantAgent OS is an institutional-grade, self-improving quantitative investment system powered by agentic AI. It implements the two-layer loop architecture pioneered in the research paper:
|
| 22 |
+
|
| 23 |
+
> **QuantAgent: Seeking Holy Grail in Trading by Self-Improving Large Language Model**
|
| 24 |
+
> *Saizhuo Wang, Hang Yuan, Lionel M. Ni, Jian Guo (HKUST & IDEA Research)*
|
| 25 |
+
> [arXiv:2402.03755](https://arxiv.org/abs/2402.03755)
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## ποΈ System Architecture
|
| 30 |
+
|
| 31 |
+
QuantAgent OS solves the core bottleneck of domain-specific financial AI: **how to autonomously discover, test, and accumulate quantitative trading signals (alphas) without manual human data curation.**
|
| 32 |
+
|
| 33 |
+
```
|
| 34 |
+
+---------------------------------------+
|
| 35 |
+
| Outer Feedback Loop |
|
| 36 |
+
| (Slow / Real-World Backtest Oracle) |
|
| 37 |
+
+---------------------------------------+
|
| 38 |
+
| ^
|
| 39 |
+
Submit Alpha | | Ground-truth Metrics
|
| 40 |
+
for Backtest v | & Qualitative Review
|
| 41 |
+
+--------------------+ |
|
| 42 |
+
| Real Environment |-----------+
|
| 43 |
+
| (Backtesting Eng) |
|
| 44 |
+
+--------------------+
|
| 45 |
+
|
|
| 46 |
+
Updates KB v
|
| 47 |
+
+---------------------------------------------------------------------------------+
|
| 48 |
+
| Inner Reasoning Loop (Fast Simulation) |
|
| 49 |
+
| |
|
| 50 |
+
| +------------------------------------------------------------------+ |
|
| 51 |
+
| | Shared Context Buffer (ctx) | |
|
| 52 |
+
| +------------------------------------------------------------------+ |
|
| 53 |
+
| | ^ | ^ |
|
| 54 |
+
| 1. Query | 2. Writer Hint | 3. Generated | 4. Judge | 5. Review |
|
| 55 |
+
| v | Alpha Code v Hint | & Score |
|
| 56 |
+
| +---------------+ +---------------+ +---------------+ | |
|
| 57 |
+
| | KnowledgeBase | | Writer LLM | | Judge LLM |---+ |
|
| 58 |
+
| | (KB) | +---------------+ +---------------+ |
|
| 59 |
+
| +---------------+ |
|
| 60 |
+
+---------------------------------------------------------------------------------+
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### 1. The Inner Reasoning Loop (Fast Heuristic Simulation)
|
| 64 |
+
- **Shared Context Buffer**: Holds task descriptions, retrieved knowledge hints, generated factor code, and mentor feedback.
|
| 65 |
+
- **Quant Alpha Writer**: Translates qualitative trading ideas into vectorized, lookahead-free Python factor code inheriting from the standardized `Factor` base class.
|
| 66 |
+
- **Quant Mentor Judge**: Evaluates candidate signals against 6 quantitative criteria:
|
| 67 |
+
1. *Vectorization efficiency* (no single-asset Python loops)
|
| 68 |
+
2. *Lookahead bias prevention* (no `shift(-1)` or future leakage)
|
| 69 |
+
3. *Continuous nuance* (smooth tanh / z-score scaling into `[-1.0, 1.0]`)
|
| 70 |
+
4. *Numerical stability* (`.clip()`, `.fillna()`, zero-division protection)
|
| 71 |
+
5. *Code validity*
|
| 72 |
+
6. *Economic intuition alignment*
|
| 73 |
+
- **Iterative Dialogue**: The Writer and Judge iterate for up to $T$ rounds until the candidate meets approval score $\beta$.
|
| 74 |
+
|
| 75 |
+
### 2. The Outer Feedback Loop (Real Backtesting Oracle)
|
| 76 |
+
- Submits the approved alpha code to the vectorized backtesting engine against historical market cross-sections.
|
| 77 |
+
- Calculates empirical metrics:
|
| 78 |
+
- **Information Coefficient (IC)**: Cross-sectional Pearson correlation between signal and forward returns.
|
| 79 |
+
- **IC Information Ratio (IC_IR)**: $\text{Mean}(IC) / \text{Std}(IC)$.
|
| 80 |
+
- **Long-Short Sharpe Ratio, Max Drawdown, and Turnover Rate**.
|
| 81 |
+
- **Autonomous Knowledge Base (KB)**: Retains both successful and failed alphas (with failure diagnosis) to enable *pessimistic value updates*.
|
| 82 |
+
|
| 83 |
+
### 3. Downstream XGBoost Alpha Ensemble (Paper Figure 5)
|
| 84 |
+
- Automatically pools all valid alphas from the KB as feature columns.
|
| 85 |
+
- Trains an XGBoost cross-validated non-linear regression model to predict cross-sectional asset returns, demonstrating how prediction Mean Squared Error (MSE) monotonically decreases as the KB accumulates more diverse alphas.
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## π Free Public Data Sources Integrated
|
| 90 |
+
|
| 91 |
+
| Source | Description | Authentication |
|
| 92 |
+
| :--- | :--- | :--- |
|
| 93 |
+
| **Yahoo Finance** | Live & historical OHLCV, volume, dividends, valuation metrics, beta, market cap | 100% Free (Built-in browser session) |
|
| 94 |
+
| **SEC EDGAR API** | Official regulatory 10-K and 10-Q XBRL financial facts: Revenue, Net Income, Total Assets, Liabilities, Debt/Equity | 100% Free (Official SEC endpoint) |
|
| 95 |
+
| **FRED / Market Proxies** | 10Y Treasury, 3M T-bill, Yield Curve Slope, VIX Volatility Index, Crude Oil, USD Index | 100% Free (FRED key optional) |
|
| 96 |
+
| **Yahoo RSS & Finnhub** | Live news headlines, company announcements, financial sentiment polarity scoring | 100% Free (Finnhub key optional) |
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## π How to Run Locally
|
| 101 |
+
|
| 102 |
+
```bash
|
| 103 |
+
# 1. Clone the repository
|
| 104 |
+
git clone https://github.com/your-username/quantagent-os.git
|
| 105 |
+
cd quantagent-os
|
| 106 |
+
|
| 107 |
+
# 2. Install dependencies
|
| 108 |
+
pip install -r requirements.txt
|
| 109 |
+
|
| 110 |
+
# 3. Launch the application
|
| 111 |
+
python app.py
|
| 112 |
+
```
|
| 113 |
+
Open your browser at `http://localhost:7860` to access the interactive dashboard.
|
| 114 |
+
|
| 115 |
+
---
|
| 116 |
+
|
| 117 |
+
## βοΈ Deploying to Hugging Face Spaces
|
| 118 |
+
|
| 119 |
+
You can deploy this Space in one of two ways:
|
| 120 |
+
|
| 121 |
+
### Method 1: Directly from the Web UI (Tab 6)
|
| 122 |
+
1. Open the application locally or on your server.
|
| 123 |
+
2. Navigate to **Tab 6: Hugging Face Deployment & Settings**.
|
| 124 |
+
3. Enter your Hugging Face API Token (with `write` permission) and target Space ID (`username/quantagent-os`).
|
| 125 |
+
4. Click **Deploy to Hugging Face Spaces**.
|
| 126 |
+
|
| 127 |
+
### Method 2: Via Git
|
| 128 |
+
```bash
|
| 129 |
+
git remote add space https://huggingface.co/spaces/your-username/quantagent-os
|
| 130 |
+
git push space main
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
---
|
| 134 |
+
|
| 135 |
+
## π Mathematical Formulation & Regret Guarantees
|
| 136 |
+
|
| 137 |
+
The framework formulates alpha mining as an Information-State Markov Decision Process $(S, A, \mathcal{T}, r, \gamma)$:
|
| 138 |
+
- **Inner Loop**: Under implicit Bayesian inference by the LLM (Assumption 4.1), Bayesian regret is sublinear in inner iterations $T$.
|
| 139 |
+
- **Outer Loop**: Grounded in Pessimistic Value Iteration (PEVI, Jin et al. 2021), epistemic uncertainty between simulated KB and real-world environment decays with outer iterations $K$.
|
| 140 |
+
- **Overall Regret**: Total Bayesian regret $R(TK)$ decomposes into four bounded terms and is proven **sublinear in $KT$** (Theorem 4.6).
|
| 141 |
+
|
| 142 |
+
---
|
| 143 |
+
|
| 144 |
+
## βοΈ License
|
| 145 |
+
Released under the MIT License. Educational and quantitative research use only.
|