Skip to content

kongwen686/alpha-pilot-quant

Repository files navigation

AlphaPilot Quant

AlphaPilot Quant is an open-source AI quant trading workbench. It combines market data ingestion, factor research, signal-based stock selection, simulated auto trading, portfolio rebalancing, and risk monitoring in a local React + TypeScript application.

The project is built for research, demos, education, and controlled prototype validation. It defaults to PaperBroker simulated trading. The release gate intentionally blocks live arming because a real broker order protocol is not included.

中文说明

AlphaPilot Quant 是一个开源的 AI 量化研究与模拟交易工作台,覆盖从数据采集、因子研究、策略开发、回测分析、信号选股到订单执行、持仓核对和风险监控的完整流程。项目采用 React、TypeScript 和 Node.js 构建,默认在本地运行,适合量化研究、功能演示、教学实验和交易系统原型验证。

核心能力

  • 数据中心:支持腾讯证券、Yahoo Finance,以及可选的 AkShare、TuShare 数据适配器;提供数据源配置、订阅调度、连接测试、自动同步、质量检查和聚合分析。
  • 本地数仓:真实采集数据按 Bronze、Silver、Gold 三层写入 data/warehouse/,保留交易时间、采集时间、分区、文件大小和数据血缘。
  • 因子与策略研究:支持因子公式、参数、权重和股票池配置,保存逐标的因子值与排名;策略更新会生成独立版本,可结合回测结果进行调优。
  • MiroFish 推演:提供群体智能场景推演适配流程,可将推演结果转换为另类因子,但不内置或复制 MiroFish 源代码。
  • 真实本地回测:读取本地日 K 数据执行回测,计入手续费和滑点,保存净值曲线、收益、回撤、Sharpe、Sortino、Calmar、交易次数和费用。
  • 信号选股:综合行情、因子、流动性、持仓约束和 TradingAgents 多代理审议,输出候选标的、信号评分、目标权重、止损止盈及决策依据。
  • 模拟自动交易:PaperBroker 支持订单创建、提交、部分成交、成交、拒绝和撤单事件,并同步更新现金、持仓、费用、购买力与账户净资产。
  • 风险管理:基于持久化收益序列计算历史 VaR 和 ES,同时监控最大回撤、杠杆率、持仓集中度、风控规则和风险快照。
  • 系统运维:支持可选 API Token、后端 RBAC、密钥配置状态、追加式审计日志、原子状态写入、备份恢复、健康检查、运行指标和 GitHub Actions CI。

业务流程

真实数据源 -> 自动同步 -> 分层仓储 -> 数据质量检查 -> 因子计算
          -> 策略版本 -> 本地回测 -> 信号选股 -> 风控预检
          -> PaperBroker 模拟执行 -> 订单/成交/持仓/资金核对 -> 风险刷新

快速运行

npm install
npm run dev

启动后访问:

  • 工作台:http://localhost:5173/
  • API:http://localhost:8787/
  • 健康检查:http://localhost:8787/api/health
  • 发布门禁:http://localhost:8787/api/release/readiness

运行完整测试与生产构建:

npm run check

交易安全边界

项目默认使用 PaperBroker 模拟交易,不会向真实券商发送订单。当前版本仅提供 IBKR TCP 连通诊断,尚未实现真实券商的下单、撤单和成交回报协议,因此实盘发布门禁会保持阻断,不能通过普通系统配置绕过。接入实盘前必须完成真实券商适配、凭证保护、合规审批、沙箱连续运行、每日对账和故障演练。

本项目不构成任何投资建议,也不是已经通过生产实盘认证的交易基础设施。市场数据可能存在延迟、缺失或错误,使用者应自行评估风险。

Features

  • Data center: Tencent, Yahoo, optional AkShare and TuShare adapters; scheduled sync; Bronze/Silver/Gold JSONL storage; lineage; subscriptions; quality checks; and aggregation insights.
  • Research workspace: quote-derived factor runs, ranked outputs, versioned strategies, optimization records, and MiroFish-style market scenario simulation adapter.
  • Signal selection: ranks tradable A-share and ETF quotes with factor bias, momentum, liquidity, and position constraints.
  • Auto trading loop: generates PaperBroker orders from signals, handles stop-loss, take-profit, overweight trimming, fees, slippage, partial fills, event reports, positions, cash, account reconciliation, and emergency stop.
  • Trading calendar guard: exposes the current A-share trading session, holiday reason, next open time, and blocks mock fills outside continuous auction sessions.
  • Backtesting and analytics: local daily-K execution with transaction costs, persisted equity curves, Sharpe/Sortino/Calmar, attribution, and failure reporting.
  • Risk management: historical VaR/ES from persisted returns, drawdown, leverage, concentration, risk snapshots, rules, and append-only request audit hashes.
  • One-click workflow: runs data sync, quality checks, factor calculation, MiroFish simulation, strategy optimization, backtesting, signal selection, auto trading, and risk refresh.
  • Operations: optional token authentication, backend RBAC, atomic state writes with backup, real health/metrics endpoints, CI, release readiness, and recovery runbook.

Tech Stack

  • React 18
  • TypeScript
  • Vite
  • Node HTTP server
  • Local JSON persistence
  • lucide-react icons

Quick Start

npm install
npm run dev

Default URLs:

  • Web app: http://localhost:5173/
  • API: http://localhost:8787/

Test and build:

npm run check

Environment

Use .env.example as a variable reference. Export variables in the shell or configure them in the process supervisor; the Node server does not load .env automatically.

Useful variables:

  • API_PORT: API server port. Default: 8787.
  • AUTO_TRADER_INTERVAL_MS: interval for scheduled auto trading. Default: 0, disabled.
  • AUTO_DATA_SYNC_INTERVAL_MS: interval for scheduled data crawling and sync. Default: 0, disabled.
  • AUTO_TRADER_SYNC_MARKET: set to false to skip market sync in scheduled runs.
  • QUANT_API_TOKEN / VITE_QUANT_API_TOKEN: matching API and web tokens for protected deployments.
  • TUSHARE_TOKEN: optional TuShare adapter token.
  • IBKR_HOST, IBKR_PORT, IBKR_ACCOUNT: IBKR connectivity diagnostics only.

Example:

AUTO_TRADER_INTERVAL_MS=60000 npm run api

API Overview

Read endpoints:

  • GET /api/state
  • GET /api/data-sources
  • GET /api/data-provider-configs
  • GET /api/data-subscriptions
  • GET /api/data-sync-runs
  • GET /api/data-aggregate-insights
  • GET /api/data-warehouse
  • GET /api/factors
  • GET /api/factor-configs
  • GET /api/mirofish/config
  • GET /api/mirofish/scenarios
  • GET /api/strategies
  • GET /api/strategy-optimizations
  • GET /api/backtests
  • GET /api/backtest-results
  • GET /api/market-quotes
  • GET /api/trading/session
  • GET /api/stock-signals
  • GET /api/auto-trade-runs
  • GET /api/orders
  • GET /api/positions
  • GET /api/risk-indicators
  • GET /api/logs
  • GET /api/health
  • GET /api/metrics
  • GET /api/release/readiness
  • GET /api/secrets/status

Action endpoints:

  • POST /api/data/pipeline
  • POST /api/data/quality-check
  • POST /api/data-warehouse/refresh
  • POST /api/data-warehouse/compact
  • POST /api/data-provider-configs
  • PATCH /api/data-provider-configs/:id/toggle
  • POST /api/data-subscriptions
  • PATCH /api/data-subscriptions/:id/toggle
  • PATCH /api/data-sources/:id/subscription
  • POST /api/factors/compute
  • POST /api/factors
  • PATCH /api/factors/:id/toggle
  • POST /api/factor-configs
  • PATCH /api/factor-configs/:id/toggle
  • POST /api/mirofish/config
  • POST /api/mirofish/scenarios
  • POST /api/mirofish/advance
  • POST /api/mirofish/scenarios/:id/publish-factor
  • POST /api/strategies
  • PATCH /api/strategies/:id/toggle
  • POST /api/strategies/optimize
  • POST /api/backtests
  • POST /api/backtests/advance
  • POST /api/backtests/:id/run
  • POST /api/signals/select
  • POST /api/trading/auto
  • POST /api/orders
  • POST /api/orders/execute
  • PATCH /api/orders/:id/cancel
  • PATCH /api/positions/:id/rebalance
  • POST /api/risk/refresh
  • POST /api/risk-rules
  • PATCH /api/risk-rules/:id/toggle
  • POST /api/workflow/run
  • POST /api/system-config
  • POST /api/broker/reconcile
  • POST /api/broker/test
  • POST /api/trading/kill-switch
  • POST /api/system/recover-state
  • POST /api/release/arm-live (currently fails closed until a reviewed real order adapter exists)

Auto trading request example:

{
  "strategyId": "s-1",
  "execute": true,
  "minScore": 68,
  "maxOrders": 3
}

Project Structure

server/            Local REST API and market data ingestion
src/               React app and quant engine
data/state.json    Local runtime state, ignored by git
data/warehouse/    Local JSONL warehouse snapshots, ignored by git
data/audit/        Append-only runtime audit records, ignored by git
dist/              Production build output, ignored by git

MiroFish Adapter

AlphaPilot Quant includes an adapter-style workflow inspired by MiroFish market scenario simulation. It does not copy or vendor MiroFish source code. If you connect a full external MiroFish service, review its AGPL-3.0 license obligations separately.

Safety Notice

This project is not investment advice. Market data can be delayed, unavailable, or inaccurate. Automatic execution is simulated. Live trading stays blocked until a separately reviewed broker order adapter, credentials, compliance approval, sandbox evidence, and incident procedures exist.

Contributing

Contributions are welcome. See CONTRIBUTING.md for the development workflow.

Security

Please do not open public issues for sensitive security reports. See SECURITY.md.

License

MIT. See LICENSE.

About

Open-source AI quant trading workbench for signals, simulated auto trading, and risk controls.

Resources

License

Code of conduct

Contributing

Security policy

Stars

16 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors