搭建期货量化管理后台 MVP,支持行情查看、博弈分析、持仓录入、品种合约管理

This commit is contained in:
2026-07-24 21:38:40 +08:00
parent d06ed06f01
commit 1ff2aa17e8
22 changed files with 1486 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
"""博弈分析计算引擎"""
def net_position(long_pos: int, short_pos: int) -> int:
"""净持仓 = 多单 - 空单。正=净多, 负=净空"""
return long_pos - short_pos
def net_pnl(net_pos: int, avg_cost: float, current_price: float) -> float:
"""净盈亏 = 净持仓 × (现价 - 成本均价) × 20"""
return net_pos * (current_price - avg_cost) * 20
def cost_delta(old_cost: float, new_cost: float) -> float:
"""成本变化 = 新均价 - 旧均价"""
return round(new_cost - old_cost, 2)
def format_pnl(pnl_yuan: float) -> str:
"""格式化盈亏为亿/万"""
yi = abs(pnl_yuan) / 1e8
if yi >= 0.01:
sign = "+" if pnl_yuan >= 0 else "-"
return f"{sign}{yi:.2f}亿"
wan = abs(pnl_yuan) / 1e4
return f"{'+' if pnl_yuan >= 0 else '-'}{wan:.1f}"