feat: 筹码S/R集成到reassess_strategy
- calc_chip_sr(): 从筹码分布计算支撑/阻力
- reassess_strategy新增筹码S/R输出+共振检测
- 止损用枢轴(短期),目标参考筹码(中线)
- 两者差距<3%时标记共振⚡
This commit is contained in:
@@ -51,6 +51,55 @@ def calc_atr(code, period=14):
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def calc_chip_sr(code, price):
|
||||
"""从筹码分布计算支撑/阻力位。
|
||||
|
||||
返回: {"chip_ss": 筹码强支撑, "chip_sr": 筹码强阻力} 或 None
|
||||
筹码强支撑 = 当前价下方成交量最大的价格区间
|
||||
筹码强阻力 = 当前价上方成交量最大的价格区间
|
||||
|
||||
用法:
|
||||
sr = calc_chip_sr("600519", 1193)
|
||||
if sr:
|
||||
print(f"筹码支撑{sr['chip_ss']} 筹码阻力{sr['chip_sr']}")
|
||||
"""
|
||||
if not price or price <= 0:
|
||||
return None
|
||||
try:
|
||||
# 复用chip_factors的筹码分布构建
|
||||
import sys as _sys
|
||||
_sys.path.insert(0, "/home/hmo/MoFin/scripts")
|
||||
from chip_factors import ChipFactors
|
||||
cf = ChipFactors()
|
||||
chip = cf._build_chip_distribution(code)
|
||||
if not chip:
|
||||
return None
|
||||
total = sum(chip.values())
|
||||
if total <= 0:
|
||||
return None
|
||||
# 2%区间聚合
|
||||
step = max(round(price * 0.02, 2), 1.0)
|
||||
bins = {}
|
||||
for p, v in chip.items():
|
||||
k = round(p / step) * step
|
||||
bins[k] = bins.get(k, 0) + v
|
||||
sb = sorted(bins.items())
|
||||
below = [(p, v) for p, v in sb if p < price]
|
||||
above = [(p, v) for p, v in sb if p >= price]
|
||||
if not below or not above:
|
||||
return None
|
||||
|
||||
# 支撑 = 下方成交量最大的密集区
|
||||
chip_ss = max(below, key=lambda x: x[1])[0]
|
||||
# 阻力 = 上方成交量最大的密集区
|
||||
chip_sr = max(above, key=lambda x: x[1])[0]
|
||||
|
||||
return {"chip_ss": chip_ss, "chip_sr": chip_sr}
|
||||
except Exception as e:
|
||||
print(f" ⚠️ 筹码S/R计算失败: {e}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
# 提示词版本追踪
|
||||
try:
|
||||
from prompt_manager.tracking import record_strategy_generation
|
||||
@@ -542,6 +591,25 @@ def reassess_strategy(code, name, price, cost, shares, current_action,
|
||||
except Exception as e:
|
||||
print(f" 多周期分析失败: {e}", file=sys.stderr)
|
||||
|
||||
# ----- 筹码分布支撑/阻力(中长线参考) -----
|
||||
chip_sr = None
|
||||
try:
|
||||
chip_sr = calc_chip_sr(code, price)
|
||||
if chip_sr:
|
||||
print(f" 筹码: 强撑={chip_sr['chip_ss']} 强压={chip_sr['chip_sr']}")
|
||||
# 与枢轴点对比,判断共振/分歧
|
||||
if ss and ws and pivot:
|
||||
chip_ss_pct = (price - chip_sr['chip_ss']) / price * 100 if chip_sr['chip_ss'] > 0 else 0
|
||||
chip_sr_pct = (chip_sr['chip_sr'] - price) / price * 100 if chip_sr['chip_sr'] > 0 else 0
|
||||
pivot_ss_pct = (price - ss) / price * 100 if ss > 0 else 0
|
||||
pivot_sr_pct = (sr_resist - price) / price * 100 if sr_resist > 0 else 0
|
||||
if abs(chip_ss_pct - pivot_ss_pct) < 3:
|
||||
print(f" ⚡ 支撑共振: 筹码+枢轴均指向{chip_sr['chip_ss']:.0f}附近")
|
||||
if abs(chip_sr_pct - pivot_sr_pct) < 3:
|
||||
print(f" ⚡ 阻力共振: 筹码+枢轴均指向{chip_sr['chip_sr']:.0f}附近")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
profit_pct = (price - cost) / cost * 100 if cost else 0
|
||||
is_new_entry = (cost == 0) or (shares == 0)
|
||||
is_deep_loss = profit_pct < -20
|
||||
|
||||
Reference in New Issue
Block a user