feat: daily position mark-to-market - #18
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
run_daily_position_mark() 目前存在输入校验与返回结构一致性问题(无数据/日期区间边界与 margin_rate 判定),需要先修正以避免调用方在边界条件下出现不一致或隐式错误。
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
新增 run_daily_position_mark(),用于基于真实主力合约链输出单笔持仓的逐日盯市 P&L 与保证金占用估算,并补充相应单元测试与文档记录,完善保证金/换月研究工具链。
Changes:
- 在
margin.py新增run_daily_position_mark(),逐日输出 realized/unrealized/cumulative P&L 与保证金估算,并在换月时按旧合约结算、按新合约重开仓。 - 新增单测覆盖换月场景下的 P&L 计算与保证金字段输出。
- 更新
CHANGELOG与ROADMAP记录新增能力与测试数量。
File summaries
| File | Description |
|---|---|
| tests/test_margin.py | 增加逐日盯市换月场景的单元测试用例 |
| src/goratio/margin.py | 新增 run_daily_position_mark() 逐日盯市与保证金估算逻辑 |
| CHANGELOG.md | 记录新增 run_daily_position_mark() 能力 |
| .planning/ROADMAP.md | 更新路线图条目与当前测试数量 |
Review details
- Files reviewed: 4/4 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
+243
to
+250
| calendar = report["series"][instrument]["calendar"] | ||
| daily = [ | ||
| point | ||
| for point in calendar | ||
| if entry_date <= date.fromisoformat(point["date"]) <= exit_date | ||
| ] | ||
| if not daily: | ||
| return {"rows": [], "final_pnl": None} |
Comment on lines
+251
to
+254
| multiplier = 100 if instrument == "gold" else 1000 | ||
| rate = margin_rate or DEFAULT_MARGIN_RATES.get( | ||
| "GC" if instrument == "gold" else "CL", 0.1 | ||
| ) |
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_daily_position_mark,输出逐日盯市 P&L 与保证金占用。