fix: HK stocks store HKD, calc_total_assets converts to CNY at aggregation
This commit is contained in:
+15
-7
@@ -33,8 +33,10 @@ for h in pf.get('holdings', []):
|
||||
is_hk = is_hk_stock(code)
|
||||
flag = 'HK' if is_hk else 'A '
|
||||
|
||||
# 检查币种
|
||||
if is_hk and curr != 'CNY':
|
||||
# 检查币种:港股应为 HKD,A股应为 CNY
|
||||
if is_hk and curr != 'HKD':
|
||||
hk_cny_issues.append(f"{code} {name}: currency={curr} (应为HKD)")
|
||||
if not is_hk and curr != 'CNY':
|
||||
hk_cny_issues.append(f"{code} {name}: currency={curr} (应为CNY)")
|
||||
|
||||
# 检查 cost=0 的股票
|
||||
@@ -55,8 +57,11 @@ print(f" stored cash: {pf.get('cash')}")
|
||||
print(f" stored frozen_cash: {pf.get('frozen_cash')}")
|
||||
print(f" stored total_pnl: {pf.get('total_pnl')}")
|
||||
|
||||
calc_ta = total_mv + (pf.get('cash') or 0) + (pf.get('frozen_cash') or 0)
|
||||
print(f" calculated total_assets: {calc_ta:.2f}")
|
||||
# 用 mo_models 计算(已处理 HKD→CNY)
|
||||
calc_ta = calc_total_assets(pf)
|
||||
calc_mv = calc_total_mv(pf.get('holdings', []))
|
||||
print(f" calculated total_mv (CNY): {calc_mv:.2f}")
|
||||
print(f" calculated total_assets (CNY): {calc_ta:.2f}")
|
||||
|
||||
if abs((pf.get('total_assets') or 0) - calc_ta) > 1:
|
||||
errors.append(f"total_assets mismatch: stored={pf.get('total_assets')} vs calc={calc_ta:.2f}")
|
||||
@@ -68,12 +73,15 @@ hkds = 0
|
||||
none_curr = 0
|
||||
for d in dec.get('decisions', []):
|
||||
c = d.get('currency', '')
|
||||
code = d.get('code', '')
|
||||
if c == 'CNY': cnys += 1
|
||||
elif c == 'HKD': hkds += 1
|
||||
else: none_curr += 1
|
||||
print(f" CNY: {cnys} HKD: {hkds} None: {none_curr}")
|
||||
if hkds > 0:
|
||||
errors.append(f"Decisions: {hkds} entries still have currency=HKD")
|
||||
# 港股应标 HKD,A 股应标 CNY
|
||||
if is_hk_stock(str(code)) and c != 'HKD':
|
||||
errors.append(f"决策 {code} currency={c} (应为HKD)")
|
||||
elif not is_hk_stock(str(code)) and c != 'CNY':
|
||||
errors.append(f"决策 {code} currency={c} (应为CNY)")
|
||||
|
||||
# ── 4. 错误汇总 ──
|
||||
print(f"\n{'='*40}")
|
||||
|
||||
Reference in New Issue
Block a user