feat(strategy): finalize global rotation system with advanced risk controls
Summary of updates: 1. Core Logic (engine.py): Added 'score > 0' filtering to support automatic cash positions during market downturns. 2. Experimental Analysis: Added scripts/analyze_negative_scores.py, scripts/test_select_num.py, and scripts/ab_test_iterations.py. 3. Documentation: Created docs/strategy_evolution_report.md detailing the evolution from benchmark to the final 47% CAGR version. 4. Configuration: Finalized rotation.yaml with 11 core assets and optimal risk parameters.
This commit is contained in:
@@ -97,27 +97,27 @@ class RotationStrategy(BacktestStrategy):
|
||||
|
||||
if not diversified:
|
||||
if select_num == 1:
|
||||
daily_target = (
|
||||
result[score_cols]
|
||||
.idxmax(axis=1)
|
||||
.str.replace("得分_", "", regex=False)
|
||||
)
|
||||
def top_1_filter(row):
|
||||
scores = pd.to_numeric(row[score_cols], errors="coerce").dropna()
|
||||
if scores.empty: return ""
|
||||
best_code = scores.idxmax()
|
||||
if scores[best_code] <= 0: return "" # 强制过滤负分
|
||||
return best_code.replace("得分_", "")
|
||||
daily_target = result.apply(top_1_filter, axis=1)
|
||||
else:
|
||||
def top_n_codes(row):
|
||||
scores = pd.to_numeric(row[score_cols], errors="coerce")
|
||||
scores = scores.dropna()
|
||||
if len(scores) == 0:
|
||||
return ""
|
||||
scores = pd.to_numeric(row[score_cols], errors="coerce").dropna()
|
||||
scores = scores[scores > 0] # 强制只保留正分标的
|
||||
if scores.empty: return ""
|
||||
top = scores.nlargest(min(select_num, len(scores))).index.tolist()
|
||||
return ",".join([c.replace("得分_", "") for c in top])
|
||||
daily_target = result.apply(top_n_codes, axis=1)
|
||||
else:
|
||||
# 强制分散化:每个大类只选 Top 1
|
||||
def top_n_diversified(row):
|
||||
scores = pd.to_numeric(row[score_cols], errors="coerce")
|
||||
scores = scores.dropna()
|
||||
if len(scores) == 0:
|
||||
return ""
|
||||
scores = pd.to_numeric(row[score_cols], errors="coerce").dropna()
|
||||
scores = scores[scores > 0] # 强制只保留正分标的
|
||||
if scores.empty: return ""
|
||||
|
||||
# 建立 category -> (code, score) 的映射
|
||||
cat_best = {}
|
||||
|
||||
Reference in New Issue
Block a user