fix: 组合循环缩进修复+单条件门槛0.5pp+4-6因子叠加
This commit is contained in:
+18
-17
@@ -65,26 +65,27 @@ def scan_big(market, regime, panel, min_n=500):
|
||||
if len(m) < 200:
|
||||
continue
|
||||
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.sort(key=lambda x: -x[3])
|
||||
print(" 单条件:", single[:5])
|
||||
print(" 单条件:", single[:6])
|
||||
|
||||
# 三因子组合(从单条件提升>基线*1.3 里取 6 个)
|
||||
pool = [s[0] for s in single if s[3] > br * 0.3][:6]
|
||||
# 4-6 因子组合(从单条件提升>0.5pp 里取 8 个,测 4/5/6 组合)
|
||||
pool = [s[0] for s in single if s[3] > 0.5][:8]
|
||||
results = []
|
||||
for combo in combinations(pool, 3):
|
||||
cond = pd.Series(True, index=sub.index)
|
||||
for feat in combo:
|
||||
op, val = factor_defs[feat]
|
||||
cond &= (sub[feat] < val) if op == "<" else (sub[feat] > val)
|
||||
m = sub[cond]
|
||||
if len(m) < 200:
|
||||
continue
|
||||
rate = m["is_big"].mean() * 100
|
||||
avg = m["fwd_ret60"].mean()
|
||||
results.append(({f: factor_defs[f] for f in combo}, len(m), round(rate, 1),
|
||||
round(avg, 1), round(rate - br, 1)))
|
||||
for k in [4, 5, 6]:
|
||||
for combo in combinations(pool, k):
|
||||
cond = pd.Series(True, index=sub.index)
|
||||
for feat in combo:
|
||||
op, val = factor_defs[feat]
|
||||
cond &= (sub[feat] < val) if op == "<" else (sub[feat] > val)
|
||||
m = sub[cond]
|
||||
if len(m) < 200:
|
||||
continue
|
||||
rate = m["is_big"].mean() * 100
|
||||
avg = m["fwd_ret60"].mean()
|
||||
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])
|
||||
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": []}
|
||||
for rg in regimes:
|
||||
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)
|
||||
for feat, (op, val) in cond.items():
|
||||
if feat not in panel.columns:
|
||||
|
||||
Reference in New Issue
Block a user