Skip to content

feat: portfolio risk constraint gates - #21

Merged
XucroYuri merged 4 commits into
mainfrom
goratio-dev-portfolio-constraints
Sep 3, 2026
Merged

feat: portfolio risk constraint gates#21
XucroYuri merged 4 commits into
mainfrom
goratio-dev-portfolio-constraints

Conversation

@XucroYuri

Copy link
Copy Markdown
Owner

新增 check_portfolio_constraints,输出保证金占用与回撤风控门控。

Copilot AI lite review requested due to automatic review settings September 3, 2026 00:16
@XucroYuri
XucroYuri merged commit e80446c into main Sep 3, 2026
11 checks passed
@XucroYuri
XucroYuri deleted the goratio-dev-portfolio-constraints branch September 3, 2026 00:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

check_portfolio_constraints() 对回撤值的度量单位与同模块现有摘要输出不一致且缺少 initial_capital 校验,可能导致门控结果错误或触发除零异常。

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

此 PR 在 goratio.margin 中新增组合级风控门控函数 check_portfolio_constraints(),用于输出保证金占用率与回撤相关的风控 gate 结果,并补齐对应单元测试与文档记录,方便在组合研究/回测摘要上做约束检查。

Changes:

  • 新增 check_portfolio_constraints():计算保证金占用率与回撤门控结果并返回结构化 gate 信息
  • 新增对应单测 test_check_portfolio_constraints
  • 更新 CHANGELOG.md.planning/ROADMAP.md 记录新增能力与测试数
File summaries
File Description
src/goratio/margin.py 新增组合级约束检查函数,输出保证金占用与回撤门控结果
tests/test_margin.py 增加 check_portfolio_constraints() 的单元测试覆盖
CHANGELOG.md 在变更日志中补充新增 API 记录
.planning/ROADMAP.md Roadmap 勾选新增功能并更新测试通过数量
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 thread src/goratio/margin.py
Comment on lines +369 to +391
"""组合级风控门控:保证金占用率与回撤上限。"""
daily_rows = portfolio_summary.get("daily_rows", [])
if daily_rows:
max_margin = max(
row["total_margin"] / portfolio_summary.get("initial_capital", 1)
for row in daily_rows
)
else:
max_margin = None
drawdown = portfolio_summary.get("max_drawdown")
return {
"max_margin_utilization": max_margin,
"max_margin_utilization_threshold": max_margin_utilization,
"margin_utilization_passed": bool(
max_margin is not None and max_margin <= max_margin_utilization
),
"max_drawdown": drawdown,
"max_drawdown_threshold": max_drawdown,
"drawdown_passed": bool(
drawdown is not None and drawdown <= max_drawdown
),
"note": "组合风控门控研究,不构成投资建议",
}
Comment thread tests/test_margin.py
Comment on lines +249 to +252
gates = check_portfolio_constraints(summary)

self.assertTrue(gates["margin_utilization_passed"])
self.assertTrue(gates["drawdown_passed"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants