"""振幅锁仓策略计算引擎""" 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, max_locks: int = 3) -> bool: """锁仓次数达到上限时熔断""" return lock_count >= max_locks