搭建期货量化管理后台 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
View File
+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}"
+33
View File
@@ -0,0 +1,33 @@
"""振幅锁仓策略计算引擎"""
def compute_amp_5d(diffs: list[float]) -> float:
"""近5日均振幅 = round(mean of 5 diffs)"""
if len(diffs) < 5:
return 0.0
return round(sum(diffs[-5:]) / 5)
def check_stop_profit(
active_profits: list[float],
locked_losses: list[float],
daily_hands: int,
amp_threshold: float,
) -> bool:
"""止盈条件: total_floating_profit >= N * A"""
total = sum(active_profits) + sum(locked_losses)
return total >= daily_hands * amp_threshold
def check_lock(
open_price: float,
current_price: float,
lock_threshold: float,
) -> bool:
"""锁仓条件: 空单亏损 >= 开仓时的振幅阈值"""
return (current_price - open_price) >= lock_threshold
def should_meltdown(lock_count: int) -> bool:
"""3锁熔断"""
return lock_count >= 3