Aby — A 股可视化博弈沙盘
A local, self-use research sandbox that replays an A-share trading day (510300 / 沪深300 ETF) with ~30 heterogeneous agents — retail, hot money, quant, institutional, northbound arbitrage — and visualizes their game in a web panel. It can also run as a DSH (DeepSeek Harness) plugin embedded in the right sidebar.
English abstract. Aby is a deterministic, loopback-only multi-agent simulation of one A-share trading day at 5-minute resolution. Agents follow rule-based psychology kernels (disposition effect, sentiment temperature, order-flow impact); a few key roles may optionally call an LLM through the host. The panel shows intraday price, per-stratum money flow, sentiment contagion, decision streams, next-day and 5-day probabilistic forecasts, and a comparison against the real historical outcome. News injection and sentiment-temperature knobs create counterfactual branches. Everything is simulated or fixture data; nothing here is investment advice, and no broker orders are ever placed.

定位与边界
- 自用研究工具:本地
127.0.0.1+ 一次性 ticket,无外部服务、无券商下单。 - 所有数字标注「模拟」或「fixture」;真实数据刷新失败时保留旧快照并告警,不填 0、不伪造。
- 历史回放仅用 2026 年数据,并与真实结果对照评分(Brier / ECE / 基线)。
快速开始
要求:Node.js ≥ 24.9、npm;Python 3.11+ 仅数据侧车需要。
npm ci
npm run fixture # 生成单日 fixture 快照(data/ 不入库,见 data/README.md)
npx tsx scripts/make-series.ts 20 # 补齐 20 日序列(泄漏探针等测试需要)
npm run build # 构建 web 面板与 host bundle
# 终端 1:起面板(loopback + ephemeral port,打印带 ticket 的 URL)
npx tsx scripts/serve-panel.ts
# 终端 2(可选):headless Chrome 实测 UI(360/1440 响应式 + UX 不变量)
node scripts/verify-ui.mjs
打开终端 1 打印的 http://127.0.0.1:<port>/?ticket=… 即可。批量回放用 npm run replay:batch。
测试与硬门槛
npm run typecheck # tsc --noEmit,硬门槛
npm test # vitest(引擎/评分/数据/契约/Host/UI/对抗测试)
python3 -m venv python/.venv
python/.venv/bin/pip install -e 'python[dev]'
PYTHONPATH=python python/.venv/bin/python -m pytest python/tests
作为 DSH 插件安装
examples/profile/ 提供 web profile 的 patch 层与 package.json 模板({{ABY_ROOT}} 替换为仓库绝对路径):
npm run build:host
dsh plugin --profile <name> add -w link:$(pwd)/packages/host
# 将 examples/profile/cordis.patch.yml 放入 $DSH_HOME/profiles/<name>/,替换 {{ABY_ROOT}}
要点:
- 插件默认路径取自
process.cwd(),patch 里必须钉死runStorePath/schedulerPath/llmCachePath等绝对路径。 - web profile 需显式
ui-sidebar-browser disabled: false,否则侧栏浏览器 tab 类型不存在。 - 真实 LLM 调用需在 patch 里显式设置
llmProvider/llmModel与 profile 实际配置一致;未配置时关键角色走规则降级(面板会标注)。
冒烟:node scripts/dsh-smoke.mjs(一次性 DSH_HOME,20 项断言)。
架构
| 目录 | 职责 |
|---|---|
packages/contracts |
类型与 API 契约 |
packages/engine |
Agent 心理内核、撮合、评分、集成运行 |
packages/data |
快照读写、fixture 生成、未来数据隔离 |
packages/host |
面板 HTTP 服务、DSH 插件 host/client |
packages/web |
前端面板(响应式、色盲模式、术语表) |
python/aby_data |
数据侧车:baostock/akshare 适配、清洗、readiness |
scripts/ |
构建、fixture/序列生成、回放、冒烟、UI 验证 |
docs/ |
ODD 设计文档、spec、ADR、tickets |
设计细节见 docs/ODD.md,术语见 CONTEXT.md,决策记录见 docs/adr/。
数据
仓库不携带行情快照与回放报告(体积与来源许可原因)。fixture 可一键再生;真实数据经 Python 侧车从免费公开源刷新,持仓/散户情绪用代理指标并显式标注 proxy / degraded。详见 data/README.md。
免责声明
本项目仅供个人研究与教学演示。所有输出均为模拟结果,不构成任何投资建议;使用真实行情数据时请遵守数据源的服务条款。
No comments yet. Be the first to write one.