fix: 组合循环缩进修复+单条件门槛0.5pp+4-6因子叠加

This commit is contained in:
xxm
2026-08-16 17:49:08 +08:00
parent 084c4d9f8e
commit 64db8a1ca5
+18 -17
View File
@@ -65,26 +65,27 @@ def scan_big(market, regime, panel, min_n=500):
if len(m) < 200: if len(m) < 200:
continue continue
rate = m["is_big"].mean() * 100 rate = m["is_big"].mean() * 100
if rate > br * 1.3: # 大涨率比基线高30% if rate > br + 0.5: # 单条件提升>0.5pp 进组合池(多因子叠加才有大提升)
single.append((feat, round(rate, 1), len(m), round(rate - br, 1))) single.append((feat, round(rate, 1), len(m), round(rate - br, 1)))
single.sort(key=lambda x: -x[3]) single.sort(key=lambda x: -x[3])
print(" 单条件:", single[:5]) print(" 单条件:", single[:6])
# 因子组合(从单条件提升>基线*1.3 里取 6 个 # 4-6 因子组合(从单条件提升>0.5pp 里取 8 个,测 4/5/6 组合
pool = [s[0] for s in single if s[3] > br * 0.3][:6] pool = [s[0] for s in single if s[3] > 0.5][:8]
results = [] results = []
for combo in combinations(pool, 3): for k in [4, 5, 6]:
cond = pd.Series(True, index=sub.index) for combo in combinations(pool, k):
for feat in combo: cond = pd.Series(True, index=sub.index)
op, val = factor_defs[feat] for feat in combo:
cond &= (sub[feat] < val) if op == "<" else (sub[feat] > val) op, val = factor_defs[feat]
m = sub[cond] cond &= (sub[feat] < val) if op == "<" else (sub[feat] > val)
if len(m) < 200: m = sub[cond]
continue if len(m) < 200:
rate = m["is_big"].mean() * 100 continue
avg = m["fwd_ret60"].mean() rate = m["is_big"].mean() * 100
results.append(({f: factor_defs[f] for f in combo}, len(m), round(rate, 1), avg = m["fwd_ret60"].mean()
round(avg, 1), round(rate - br, 1))) results.append(({f: factor_defs[f] for f in combo}, len(m), round(rate, 1),
round(avg, 1), round(rate - br, 1), len(combo)))
results.sort(key=lambda x: -x[4]) results.sort(key=lambda x: -x[4])
return results[:5] return results[:5]
@@ -140,7 +141,7 @@ def mine(market="a", regimes=None):
out = {"market": market, "mined_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "candidates": []} out = {"market": market, "mined_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "candidates": []}
for rg in regimes: for rg in regimes:
combos = scan_big(market, rg, panel) combos = scan_big(market, rg, panel)
for cond, n, rate, avg, extra in combos[:3]: for cond, n, rate, avg, extra, nf in combos[:3]:
c = pd.Series(True, index=panel.index) c = pd.Series(True, index=panel.index)
for feat, (op, val) in cond.items(): for feat, (op, val) in cond.items():
if feat not in panel.columns: if feat not in panel.columns: