feat: T+1 net episode backtest summary - #30
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
新增 backtest 摘要的测试断言与分支覆盖不足,且返回字段/文档与错误信息需补强以避免 API 使用歧义。
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
该 PR 新增合约 episode 的“净收益(T+1 open/settle 执行缺口)+ 成本”回测摘要入口,用于在合约 CSV 数据上快速汇总净收益表现,配合现有 contract_episode_return_summary() 的口径输出。
Changes:
- 新增
run_contract_episode_net_backtest():按 execution=open/settle 选择净收益口径并扣减成本后汇总统计。 - 新增对应单元测试用例,并更新 Changelog/Roadmap 记录。
File summaries
| File | Description |
|---|---|
| tests/test_contracts.py | 增加 run_contract_episode_net_backtest() 的基础用例覆盖 |
| src/goratio/contracts.py | 新增净收益回测摘要函数(基于 episode summary 的 open/settle 口径) |
| CHANGELOG.md | 记录新增 backtest 摘要入口 |
| .planning/ROADMAP.md | Roadmap 勾选完成项并更新测试数 |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 4
- 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
+347
to
+354
| result = run_contract_episode_net_backtest( | ||
| records, [episode], execution="open", cost_bps=10.0 | ||
| ) | ||
|
|
||
| self.assertEqual(result["execution"], "open") | ||
| self.assertEqual(result["episode_count"], 1) | ||
| self.assertIsNotNone(result["mean_net_after_cost_return"]) | ||
|
|
Comment on lines
+541
to
+545
| """基于合约 CSV 的 episode 净收益回测摘要(T+1 open/settle 默认成交模型)。 | ||
|
|
||
| execution="open" 使用扣减 T+1 open gap 后的真实换月净收益; | ||
| execution="settle" 使用扣减 T+1 settle gap 后的真实换月净收益。 | ||
| """ |
Comment on lines
+546
to
+547
| if execution not in ("open", "settle"): | ||
| raise ValueError("execution 必须是 open 或 settle") |
Comment on lines
+569
to
+576
| return { | ||
| "method": "contract_episode_net_backtest", | ||
| "execution": execution, | ||
| "cost_bps": cost_bps, | ||
| "episode_count": len(net_rows), | ||
| "mean_net_after_cost_return": ( | ||
| sum(returns) / len(returns) if returns else None | ||
| ), |
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.
新增 run_contract_episode_net_backtest,基于 T+1 open/settle 净收益与成本。