fix(live): 恒等式逐票对账补负向幻影——09-04 收盘联检实证:002633买缺100(正向孤儿,已列)+002836卖缺300(负向幻影,漏列),旧代码unattr_positions只遍历snap_pos.items(),快照没有的票永不被遍历到,单看票单会把修账做成半拉子(只补孤儿不补幻影);修=双端键并集sorted(set(snap_pos)|set(inst_pos)),正向孤儿/负向幻影都入列(002836当日在报告里只有MV差对不上数才现形);残差拆腿同步定性:-1535=100×002633收盘15.35-300×002836收盘10.23,100%来自两笔引擎未报成交,修账后应归零;TDD 1新测先红后绿+21全过 [vps]
This commit is contained in:
@@ -264,12 +264,14 @@ def build_identity_report(db: str, date: Optional[str] = None) -> Dict[str, Any]
|
||||
"WHERE account_id=?", (inst["id"],)):
|
||||
inst_pos[_norm_symbol(r[0])] = inst_pos.get(
|
||||
_norm_symbol(r[0]), 0.0) + float(r[1] or 0)
|
||||
# 双端键并集:快照独有=正向孤儿(遗留/手动仓),实例独有=负向幻影
|
||||
# (09-04 002836 实证:只遍历快照会漏幻影,导致修账只补一半)
|
||||
unattr_positions = [
|
||||
{"symbol": s, "snapshot_volume": v,
|
||||
{"symbol": s, "snapshot_volume": snap_pos.get(s, 0.0),
|
||||
"instance_volume": inst_pos.get(s, 0.0),
|
||||
"diff": v - inst_pos.get(s, 0.0)}
|
||||
for s, v in sorted(snap_pos.items())
|
||||
if abs(v - inst_pos.get(s, 0.0)) > 0.5
|
||||
"diff": snap_pos.get(s, 0.0) - inst_pos.get(s, 0.0)}
|
||||
for s in sorted(set(snap_pos) | set(inst_pos))
|
||||
if abs(snap_pos.get(s, 0.0) - inst_pos.get(s, 0.0)) > 0.5
|
||||
]
|
||||
if snap is None:
|
||||
status = "snapshot_missing"
|
||||
|
||||
@@ -380,6 +380,23 @@ def test_identity_unattributed_position_listed(db):
|
||||
assert r["identity_passed"] is False
|
||||
|
||||
|
||||
def test_identity_phantom_position_listed(db):
|
||||
"""实例账本有快照没有的票(幻影仓,如卖出迟到未记账)→ 负差票单列(09-04 002836 实证)。"""
|
||||
_add_live_account(db, aid=5)
|
||||
_seed_snapshot(db, mv=1_000_000, positions=[
|
||||
{"symbol": "600036.SH", "volume": 1000, "can_use": 1000,
|
||||
"avg_price": 38, "mv": 38000}])
|
||||
_seed_inst_mv(db, 5, mv=997_000,
|
||||
positions={"600036.XSHG": 1000, "002836.XSHE": 300}) # 幻影 300 股
|
||||
r = build_identity_report(db)
|
||||
row = r["rows"][0]
|
||||
unattr = row["unattributed_positions"]
|
||||
assert [p["symbol"] for p in unattr] == ["002836"]
|
||||
assert unattr[0]["snapshot_volume"] == 0
|
||||
assert unattr[0]["instance_volume"] == 300
|
||||
assert unattr[0]["diff"] == -300
|
||||
|
||||
|
||||
def test_identity_instance_over_snapshot_negative(db):
|
||||
"""Σ实例>快照(旧全账户行叠加期)→ 未归因为负,如实呈现 FAIL。"""
|
||||
_add_live_account(db, aid=5)
|
||||
|
||||
Reference in New Issue
Block a user