trader-cloud-backtest
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloud backtest / train (neural-trader on a Managed Agent)
云端回测/训练(基于Managed Agent的neural-trader)
Dispatch a heavy job to an Anthropic Claude Managed Agent (cloud container) instead of running it locally. See project ADR-117 (recipe + cost rules) and ADR-115 (the runtime).
neural-tradermanaged_agent_*将大型任务分发至Anthropic Claude Managed Agent(云端容器)运行,而非本地执行。详情请参考项目ADR-117(方案及成本规则)和ADR-115(运行时)。
neural-tradermanaged_agent_*When to use this vs trader-backtest
(local)
trader-backtest何时使用本方案 vs trader-backtest
(本地版)
trader-backtest| Job | Runtime |
|---|---|
| Quick sanity check; one short backtest (< ~1 min) | local — use the |
| Multi-year walk-forward, big Monte-Carlo count, parameter sweep over a grid, or model training (LSTM/Transformer/N-BEATS) | cloud — this skill |
Prereq: (or ) + Managed Agents beta access. If returns "needs ANTHROPIC_API_KEY", fall back to the local skill.
ANTHROPIC_API_KEYCLAUDE_API_KEYmanaged_agent_*trader-backtest| 任务类型 | 运行环境 |
|---|---|
| 快速sanity check;单次短时间回测(<约1分钟) | 本地 — 使用 |
| 多年滚动回测、大规模蒙特卡洛模拟次数、基于网格的参数寻优,或模型训练(LSTM/Transformer/N-BEATS) | 云端 — 本技能 |
前置条件:(或)+ Managed Agents测试版访问权限。若返回"needs ANTHROPIC_API_KEY",则fallback到本地技能。
ANTHROPIC_API_KEYCLAUDE_API_KEYmanaged_agent_*trader-backtestSteps
步骤
-
Estimate first. From the job size, print an estimated cost (≈ container-minutes × rate + tokens) — a long sweep is a deliberate choice, not a default.
-
Provision (or reuse) the container — install neural-trader at container start so the agent doesn't reinstall mid-run:
managed_agent_create({ name: "nt-cloud", model: "claude-haiku-4-5-20251001", // orchestration only — the compute is the Rust engine, not the LM (ADR-026) system: "You operate the `neural-trader` CLI in this container. Run exactly the commands asked, report the metrics, write requested artifacts, then stop.", networking: "unrestricted", // or "restricted" pinned to your data host packages: { npm: ["neural-trader"] }, // add apt:["build-essential"] ONLY if there's no prebuilt NAPI binary for the arch (neural-trader ships prebuilds → usually omit) initScript: "npm install -g --ignore-scripts neural-trader >/dev/null 2>&1 || npx -y neural-trader --version >/dev/null 2>&1 || true" }) → { sessionId, agentId, environmentId }For a sweep: create the environment once, run all configs in one(one container), not N sessions.managed_agent_prompt -
Pre-flight cheap. Before a 1000-path / multi-year run, do a tiny smoke first (1 MC path, ~3 months) — catches a bad strategy name / symbol in seconds:
managed_agent_prompt({ sessionId, message: "Run `npx neural-trader --backtest --strategy <name> --symbol <TICKER> --period <last 3 months> --mc-paths 1`. Just confirm it ran and report the Sharpe. Then stop.", maxWaitMs: 60000 })If that fails, fix the args before the real run (and).managed_agent_terminate -
Run the real job:
managed_agent_prompt({ sessionId, message: "Run `npx neural-trader --backtest --strategy <name> --symbol <TICKER> --period <range> --walk-forward --mc-paths <N>` (for training: `npx neural-trader --train --model <lstm|transformer|nbeats> --symbol <TICKER> --period <range>`; for a sweep: loop the configs and run each). Report: total return, annualized return, Sharpe, Sortino, max drawdown, win rate, profit factor, # trades, 95% CVaR. Write the equity curve to /tmp/equity.csv and the trade log to /tmp/trades.csv. Then stop.", maxWaitMs: <generous — minutes> }) → { finished, status, stopReason, assistantText (the metrics), toolUses }If, follow up withfinished:falseuntil idle.managed_agent_events({ sessionId }) -
Pull artifacts (if needed):or
managed_agent_prompt({ sessionId, message: "cat /tmp/equity.csv" })and read the tool_result.managed_agent_events -
Ingest locally:
memory_store({ key: "backtest-<strategy>-<ts>", value: <metrics+params JSON>, namespace: "trading-backtests" })- If Sharpe > 1.5:
agentdb_pattern-store({ pattern: "profitable-<strategy-type>", data: "<params + results>" }) - Record the run's container time + token cost to the namespace (per ADR-117 — cloud sessions bill until terminated).
cost-tracking
-
Terminate immediately — results in hand:
managed_agent_terminate({ sessionId, environmentId }) → { sessionDeleted: true, environmentDeleted: true }Never leave an idle billing container. (/ GC catches orphans — #1931.)ruflo doctor
-
先估算成本。根据任务规模,打印预估成本(≈容器分钟数 × 费率 + 令牌消耗)——长周期参数寻优是主动选择,而非默认选项。
-
创建(或复用)容器——在容器启动时安装neural-trader,避免代理在运行中途重新安装:
managed_agent_create({ name: "nt-cloud", model: "claude-haiku-4-5-20251001", // 仅用于编排——计算由Rust引擎执行,而非大语言模型(ADR-026) system: "You operate the `neural-trader` CLI in this container. Run exactly the commands asked, report the metrics, write requested artifacts, then stop.", networking: "unrestricted", // 或设置为"restricted"并固定到你的数据主机 packages: { npm: ["neural-trader"] }, // 仅当对应架构没有预构建NAPI二进制文件时才添加apt:["build-essential"](neural-trader已提供预构建版本→通常无需添加) initScript: "npm install -g --ignore-scripts neural-trader >/dev/null 2>&1 || npx -y neural-trader --version >/dev/null 2>&1 || true" }) → { sessionId, agentId, environmentId }对于参数寻优:只需创建一次环境,在同一个(同一个容器)中运行所有配置,而非N个会话。managed_agent_prompt -
低成本预校验。在运行1000路径/多年任务前,先执行一次小型冒烟测试(1次蒙特卡洛路径,约3个月)——可在数秒内发现错误的策略名称/交易代码:
managed_agent_prompt({ sessionId, message: "Run `npx neural-trader --backtest --strategy <name> --symbol <TICKER> --period <last 3 months> --mc-paths 1`. Just confirm it ran and report the Sharpe. Then stop.", maxWaitMs: 60000 })如果测试失败,在正式运行前修复参数(并执行终止容器)。managed_agent_terminate -
运行正式任务:
managed_agent_prompt({ sessionId, message: "Run `npx neural-trader --backtest --strategy <name> --symbol <TICKER> --period <range> --walk-forward --mc-paths <N>`(训练任务使用:`npx neural-trader --train --model <lstm|transformer|nbeats> --symbol <TICKER> --period <range>`;参数寻优任务使用:循环遍历所有配置并逐一运行)。需报告:总收益、年化收益、夏普比率(Sharpe)、索提诺比率(Sortino)、最大回撤、胜率、盈利因子、交易次数、95%条件风险价值(CVaR)。将权益曲线写入/tmp/equity.csv,交易日志写入/tmp/trades.csv。完成后停止。", maxWaitMs: <充足时长 — 以分钟为单位> }) → { finished, status, stopReason, assistantText (指标结果), toolUses }若,后续执行finished:false直到容器处于空闲状态。managed_agent_events({ sessionId }) -
拉取产物(如需):执行或通过
managed_agent_prompt({ sessionId, message: "cat /tmp/equity.csv" })读取tool_result。managed_agent_events -
本地存储:
memory_store({ key: "backtest-<strategy>-<ts>", value: <指标+参数JSON>, namespace: "trading-backtests" })- 若夏普比率>1.5:
agentdb_pattern-store({ pattern: "profitable-<strategy-type>", data: "<params + results>" }) - 将本次运行的容器时长+令牌消耗记录到命名空间(遵循ADR-117——云端会话在终止前持续计费)。
cost-tracking
-
立即终止容器——获取结果后:
managed_agent_terminate({ sessionId, environmentId }) → { sessionDeleted: true, environmentDeleted: true }切勿让计费容器处于空闲状态。(/垃圾回收机制会清理孤立容器——#1931。)ruflo doctor
Cost rules (don't skip)
成本规则(请勿跳过)
- Install once (), reuse the environment, batch sweeps into one prompt, pre-flight cheap, terminate eagerly, use Haiku/Sonnet for the agent loop, estimate before kicking off. (ADR-117 §"Cost optimization".)
initScript - A cloud backtest that runs for an hour costs an hour of container time + the agent-loop tokens. Be deliberate.
- 仅安装一次(通过),复用环境,将参数寻优任务批量放入同一个prompt,执行低成本预校验,及时终止容器,使用Haiku/Sonnet作为代理循环模型,启动前先估算成本。(ADR-117 §"成本优化"章节)
initScript - 运行1小时的云端回测将产生1小时的容器时长费用+代理循环令牌消耗。请谨慎操作。
Quick example
快速示例
managed_agent_create { "name":"nt-cloud", "model":"claude-haiku-4-5-20251001", "packages":{"npm":["neural-trader"]}, "initScript":"npm install -g --ignore-scripts neural-trader >/dev/null 2>&1 || true" }
→ { sessionId:"sesn_…", environmentId:"env_…" }
managed_agent_prompt { "sessionId":"sesn_…", "message":"Run `npx neural-trader --backtest --strategy multi-indicator --symbol SPY --period 2020-2024 --walk-forward --mc-paths 1000`. Report Sharpe/Sortino/max-DD/win-rate/CVaR; write /tmp/equity.csv. Then stop.", "maxWaitMs":600000 }
→ { finished:true, status:"idle", assistantText:"<metrics>", toolUses:[{bash:"npx neural-trader --backtest …"}] }managed_agent_create { "name":"nt-cloud", "model":"claude-haiku-4-5-20251001", "packages":{"npm":["neural-trader"]}, "initScript":"npm install -g --ignore-scripts neural-trader >/dev/null 2>&1 || true" }
→ { sessionId:"sesn_…", environmentId:"env_…" }
managed_agent_prompt { "sessionId":"sesn_…", "message":"Run `npx neural-trader --backtest --strategy multi-indicator --symbol SPY --period 2020-2024 --walk-forward --mc-paths 1000`. Report Sharpe/Sortino/max-DD/win-rate/CVaR; write /tmp/equity.csv. Then stop.", "maxWaitMs":600000 }
→ { finished:true, status:"idle", assistantText:"<metrics>", toolUses:[{bash:"npx neural-trader --backtest …"}] }… memory_store the metrics, agentdb_pattern-store if Sharpe>1.5, record cost …
… 将指标存入memory_store,若夏普比率>1.5则存入agentdb_pattern-store,记录成本 …
managed_agent_terminate { "sessionId":"sesn_…", "environmentId":"env_…" }
undefinedmanaged_agent_terminate { "sessionId":"sesn_…", "environmentId":"env_…" }
undefined