NicolasBohn/NexQuant
GitHub: NicolasBohn/NexQuant
NexQuant 是一个基于多代理框架构建的量化策略自主研究系统,通过高速回测引擎和多种自动化发现方法帮助用户快速搜索并验证可盈利的交易策略。
Stars: 4 | Forks: 0
# NexQuant
高速策略发现框架
## 概述 **NexQuant** 通过高速搜索发现可盈利的交易策略 —— 无需 LLM。核心引擎:Numba JIT 编译的回测速度达到 **7.35 亿根 K 线/秒**(比 pandas 快 245 倍)。四种发现方法在连续循环中运行: | 方法 | 频率 | 描述 | |--------|-----------|-------------| | **Explore** | 30% 的迭代 | 基于 17 种 TA-Lib 指标在不同时间周期下的随机策略 | | **Exploit** | 70% 的迭代 | 对已知最佳策略进行变异(更改参数、指标或时间周期) | | **Optuna** | 每 500 次迭代 | 对当前最佳策略进行 20 次试验的超参数优化 | | **LightGBM** | 每 2000 次迭代 | 基于 SOTA 指标信号训练的 ML 分类器,用于预测方向 | **当前最佳策略**:MACD(3,10,3) 4 时间周期 (TF),采用 2/4 多数投票 —— **+32.0%/月** (Numba),**+24.3%/月**(经独立回测验证),0/75 个负收益月。 ## 快速开始 ``` # 先决条件 conda create -n nexquant python=3.10 -y && conda activate nexquant pip install -e . # 确保 OHLCV 数据存在:git_ignore_folder/intraday_pv_all.h5 # Strategy Discovery Loop (10,000 次迭代,约 1 小时) python scripts/nexquant_rd_loop.py --iterations 10000 # Price-Action Indicator Loop (grid search 所有 TA-Lib 指标) python scripts/nexquant_priceaction_loop.py # Top strategies 报告 python nexquant.py best -n 20 -m monthly_return --min-trades 30 ``` ## 策略发现 ### R&D 循环 (`scripts/nexquant_rd_loop.py`) ``` ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ Explore │ ──→ │ Exploit │ ──→ │ Optuna │ ──→ │ LightGBM │ │ (Random) │ │ (Mutate) │ │ (Tuning) │ │ (ML) │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ 30% 70% /500 iter /2000 iter ``` **17 种 TA-Lib 指标**:MACD, RSI, Donchian, SAR, ADX, BBANDS, CCI, WCLPRICE, MFI, OBV, STOCH, ROC, AROON, AROONOSC, MOM, ULTOSC, WILLR **4 种时间周期**:15 分钟,30 分钟,1 小时,4 小时 **3 种策略类型**:单时间周期,多时间周期(多数投票),投资组合(指标集成) **发现示例**(50,000 次迭代): ``` random → SAR(+65) → MACD(+73) → MACD-mutated(+102.75, +32%/month) ↓ Optuna tuned params ↓ LightGBM ensemble ``` ### 网格搜索 (`scripts/nexquant_priceaction_loop.py`) 在所有 17 种指标上进行确定性参数网格搜索。发现 MACD(3,10,3) 为最优。 ### 投资组合优化器 (`scripts/nexquant_portfolio_optimizer.py`) 从已发现的策略中进行考虑相关性的贪婪选择。 ## 实盘交易 闭源模块位于 `git_ignore_folder/nexquant_live_trader.py`。架构如下: ``` MACD(3,10,3) Signal → cTrader OpenAPI → Live Account 4-TF 2/4 Votes (WebSocket+Protobuf) ↓ Paper Mode ``` 集成:cTrader WebSocket `live.ctraderapi.com:5035`,OAuth2 身份验证,Protobuf 消息编码,FIX 协议。 ## 功能 ### ⚡ Numba 回测 - 7.35 亿根 K 线/秒(处理 226 万根 K 线仅需 0.003 秒) - JIT 编译的利润/回撤/夏普比率计算 - 通过 pandas resample + TA-Lib 构建信号(约 0.4 秒)是性能瓶颈 ### 🔍 四种发现方法 - **Explore**:随机指标 + 时间周期 + 参数 - **Exploit**:对排名前 5 的 SOTA 策略进行变异(参数微调、指标替换、时间周期更改) - **Optuna**:对最佳策略进行 20 次试验的 TPE 超参数优化 - **LightGBM**:基于 SOTA 指标信号的 ML 分类器(80/20 训练/测试集划分) ### 📊 TA-Lib 集成 - 17 种指标,具有完整的参数范围 - 自动防范错误参数(会导致 TA-Lib 崩溃的负值或零值) - 具有可配置阈值的多时间周期投票 ### 🔒 安全与质量 - 0 个 Dependabot 告警,0 个 CodeScan 告警 - git 历史记录中无专有术语 - 闭源检测 CI ## 项目结构 ``` nexquant/ ├── scripts/ # Strategy discovery & trading │ ├── nexquant_rd_loop.py # High-speed R&D loop (Numba + Optuna + ML) │ ├── nexquant_priceaction_loop.py # TA-Lib grid search loop │ ├── nexquant_portfolio_optimizer.py # Correlation-aware portfolio selection │ ├── nexquant_gridsearch.py # Deterministic parameter grid search │ ├── nexquant_daily_strategies.py # Daily Kronos + factor combinations │ ├── nexquant_gen_strategies_real_bt.py # LLM-based strategy generation │ ├── nexquant_autopilot.py # 24/7 continuous generator │ └── nexquant_parallel.py # Multi-instance parallel runs ├── rdagent/ # Core framework (LLM-based, see note below) │ ├── app/ # CLI and scenario apps │ ├── components/ # Backtest engine, protections, coders │ ├── core/ # Core abstractions │ ├── scenarios/ # Domain-specific scenarios │ └── utils/ # Utilities ├── git_ignore_folder/ # Closed-source (never committed) │ ├── nexquant_live_trader.py # cTrader live trading │ ├── nexquant_fix_trader.py # FIX protocol trader │ ├── intraday_pv_all.h5 # OHLCV data │ ├── gbpusdt_1min.h5 # GBP/USD data │ └── btc_1min.h5 # BTC data ├── test/ # 1,125+ collected tests ├── data_config.yaml # Walk-forward split configuration ├── requirements.txt # Dependencies └── AGENTS.md # Agent configuration & workflow guide ``` ## 安装说明 ### 前置条件 - **Conda** (Miniconda 或 Anaconda) - **TA-Lib** 系统库(`apt install ta-lib` 或 `brew install ta-lib`) - **Linux** (Ubuntu 22.04+) ### 安装 ``` git clone https://github.com/TPTBusiness/NexQuant && cd NexQuant conda create -n nexquant python=3.10 -y && conda activate nexquant pip install -e . ``` ### 数据 将 OHLCV HDF5 数据放置在 `git_ignore_folder/intraday_pv_all.h5`: ``` # 格式:MultiIndex (datetime, instrument),columns:$open $close $high $low $volume df.to_hdf('git_ignore_folder/intraday_pv_all.h5', key='data') ``` ## 许可证 **GNU Affero General Public License v3.0 (AGPL-3.0)**。详见 [`LICENSE`](LICENSE)。 ## 免责声明 NexQuant 仅用于**研究和教育目的**。过去的业绩并不代表未来的结果。用户需自行承担所有责任。标签:逆向工具