feat: contracts net-backtest CLI - #31
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
新增命令路径存在可避免的重复 CSV 解析开销且测试未覆盖 settle/文本输出分支,建议补齐后再合并。
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
本 PR 为 goratio contracts 增加 net-backtest 子命令,使用户可以从合约 CSV 直接运行基于 T+1 open/settle 净收益口径 的 episode 回测摘要输出(支持 JSON 或文本)。
Changes:
- 在 CLI 中新增
contracts net-backtest子命令与参数(horizon/cost-bps/execution/json)。 - 增加对应 CLI 单测,验证从合约 CSV 运行并产出可解析的 JSON。
- 更新 README/CHANGELOG/ROADMAP 文档,补充命令用法与版本记录。
File summaries
| File | Description |
|---|---|
| tests/test_cli.py | 新增 contracts net-backtest 的 CLI 回归测试用例。 |
| src/goratio/cli.py | 增加 contracts net-backtest 子命令解析与执行逻辑,并接入 run_contract_episode_net_backtest。 |
| README.md | 补充 contracts net-backtest 的示例用法。 |
| CHANGELOG.md | 记录新增 CLI 能力的变更条目。 |
| .planning/ROADMAP.md | 更新 roadmap 勾选项与测试数量统计。 |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+466
to
+468
| records = read_contract_csv(args.csv) | ||
| raw = contract_csv_to_raw_market_data(args.csv) | ||
| prepared = prepare_market_data( |
Comment on lines
+411
to
+425
| output = io.StringIO() | ||
| exit_code = main( | ||
| [ | ||
| "contracts", "net-backtest", "--csv", str(csv_path), | ||
| "--horizon", "63", "--json", | ||
| ], | ||
| today=lambda: date(2024, 1, 4), | ||
| stdout=output, | ||
| stderr=io.StringIO(), | ||
| ) | ||
|
|
||
| payload = json.loads(output.getvalue()) | ||
| self.assertEqual(exit_code, 0) | ||
| self.assertEqual(payload["execution"], "open") | ||
| self.assertEqual(payload["episode_count"], 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
新增 contracts net-backtest,从合约 CSV 运行 T+1 open/settle 净收益回测。