Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .planning/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- [x] `portfolio_daily_margin()` 已支持多笔持仓逐日合并盯市与保证金监控。
- [x] `check_portfolio_constraints()` 已提供组合级保证金占用与回撤门控。
- [x] `financing_cost_estimate()` 已支持保证金资金成本估算。
- [x] `position_pnl_estimate()` 已输出扣减资金成本后的净 P&L。
- [ ] 在完整组合资金引擎中接入融资/资金费率与更多组合约束。
- [x] T+1 close 执行近似已加入 `backtest --t1-close`(仍非 open/settle,真实缺口待合约数据接入)。
- [x] `summarize_roll_costs()` 已提供合约级可量化换月 gap 成本统计。
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
- `run_daily_position_mark()`:单笔持仓逐日盯市与保证金占用估算;
- `portfolio_daily_margin()`:多笔持仓逐日合并盯市与保证金监控;
- `check_portfolio_constraints()`:组合级保证金占用与回撤风控门控;
- `financing_cost_estimate()`:保证金资金成本估算。
- `financing_cost_estimate()`:保证金资金成本估算;
- `position_pnl_estimate()` 增加资金成本与净 P&L 估算。
Comment on lines +53 to +54

## [0.1.0-rc1] - 2026-09-02

Expand Down
10 changes: 10 additions & 0 deletions src/goratio/margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,20 @@ def position_pnl_estimate(
"GC" if instrument == "gold" else "CL", 0.1
)
margin = notional * rate
holding_days = max(0, (exit_date - entry_date).days)
financing = financing_cost_estimate(margin, holding_days)
Comment on lines +100 to +101
roll_return = roll_aware_contract_return(
records,
instrument=instrument,
entry_date=entry_date,
exit_date=exit_date,
)
pnl = notional * roll_return * direction if roll_return is not None else None
net_pnl = (
pnl - financing
if pnl is not None
else None
)
Comment on lines +109 to +113
return {
"instrument": instrument,
"direction": direction,
Expand All @@ -112,7 +119,10 @@ def position_pnl_estimate(
"roll_aware_return": roll_return,
"notional": notional,
"margin_estimate": margin,
"holding_days": holding_days,
"financing_cost_estimate": financing,
"pnl_estimate": pnl,
"net_pnl_estimate": net_pnl,
"note": "研究性持仓估算,不构成交易建议",
}

Expand Down
2 changes: 2 additions & 0 deletions tests/test_margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def test_position_pnl_estimate_uses_roll_aware_return(self) -> None:
result["pnl_estimate"], 2000 * 100 * expected_return
)
self.assertGreater(result["margin_estimate"], 0)
self.assertGreater(result["holding_days"], 0)
self.assertIsNotNone(result["net_pnl_estimate"])
Comment on lines +73 to +74


def test_run_position_simulation_batch(self) -> None:
Expand Down