fix(portfolio): P1.2 stop_loss去1m依赖—昨日涨停分支改get_limit_status_batch日线口径(原get_price frequency=1m,数据层无1m表→分支静默失效);_intraday_high_low→_limit_status(getattr降级同small_cap等三策略);3新测试(涨停打开卖/仍涨停持有/异常跳过) [vps]
CI/CD / test (push) Successful in 15s
CI/CD / nas-deploy (push) Successful in 36s
CI/CD / nas-verify (push) Successful in 20s

This commit is contained in:
2026-08-14 22:57:26 +08:00
parent 86a13ede42
commit fbd0c39c6c
+19 -27
View File
@@ -173,19 +173,15 @@ class AllWeatherStrategy:
for stock in self.yesterday_hl_list:
if stock not in positions:
continue
row = self._intraday_high_low(stock, now_time)
if row is None:
status = self._limit_status(stock, now_time)
if status is None:
continue
close = row.get("close")
high_limit = row.get("high_limit")
if close is None or high_limit is None:
continue
if close < high_limit:
if status.get("is_limit_up"):
logger.info("[%s]涨停,继续持有", stock)
else:
logger.info("[%s]涨停打开,卖出", stock)
self._close_position(stock)
num_sold += 1
else:
logger.info("[%s]涨停,继续持有", stock)
# 2) 止损 -8%
remaining: List[str] = []
@@ -456,27 +452,23 @@ class AllWeatherStrategy:
arr = np.nan_to_num(change.to_numpy())
return float(np.mean(arr))
def _intraday_high_low(self, stock: str, now_time: Any) -> Optional[Dict[str, Any]]:
"""当日 1m close + high_limit(聚宽 stop_loss 用)。"""
def _limit_status(self, stock: str, now_time: Any) -> Optional[Dict[str, Any]]:
"""当日涨跌停/停牌状态(P1.2 去 1m 依赖)。
原实现取 1m close+high_limit,但数据层无 1m 表(仅 d/15m)→ 该分支在
日线路径静默失效。改用 get_limit_status_batch(日线 prev_close×板块
幅度精确算涨跌停价,与 filters/其他策略同源)。provider 未实现/异常
→ None(跳过该股,等价原失效行为)。
"""
fn = getattr(self.provider, "get_limit_status_batch", None)
if fn is None:
return None
try:
df = self.provider.get_price(
stock,
end_date=now_time,
frequency="1m",
fields=["close", "high_limit"],
skip_paused=False,
fq="pre",
count=1,
panel=False,
fill_paused=True,
)
result = fn([stock], now_time) or {}
except Exception as exc:
logger.debug("intraday_high_low 失败 %s: %s", stock, exc)
logger.warning("get_limit_status_batch 失败 %s: %s", stock, exc)
return None
if df is None or len(df) == 0:
return None
row = df.iloc[0]
return {"close": row.get("close"), "high_limit": row.get("high_limit")}
return result.get(stock)
# ======================== context 适配 ========================