Files
myquant/CLAUDE-ml.md
T
simonandClaude Opus 4.7 271a9343a5 Initial commit: cc-cursor 全链路量化研究平台
7 Sprints 全部完成:
  Sprint 0: 基础设施 (DataManager + MariaDB)
  Sprint 1: 因子引擎 (34因子/12分类)
  Sprint 2: VectorBT 回测 (5策略+截面)
  Sprint 3: Optuna 优化 (+Walk-Forward)
  Sprint 4: ML 模型 (LightGBM+CatBoost)
  Sprint 5: Qwen 情绪因子 (三源新闻+日期对齐)
  Sprint 6: Agent 系统 (4Agent+日报.md/.html)

生产加固 (15项): Tushare双源fallback, SSH自动恢复, pool_pre_ping,
  save_daily先删后插, load_dotenv绝对路径, 日报5d/20d修复,
  RiskAgent改上证指数, 昨日对比+数据截止, mac_report utf8mb4,
  CLAUDE-*.md 9条已知Bug, demo全参数化, djapi数据源归一化,
  indexDatas API修正

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-07 15:59:05 +08:00

46 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CLAUDE-ml.md — ML 模型层
## FeatureEngine (`finance/models/features.py`)
因子 → 特征矩阵 + 标签。防前视偏差。
```python
from models.features import FeatureEngine
fe = FeatureEngine(lookahead=5, label_type="regression")
X, y = fe.build(factor_df, price_df, fit=True)
# fit=True: Winsorize(1%/99%) → ffill → median fill → RobustScaler.fit → 标签计算
# fit=False: 复用训练时的 scaler + 有效特征
```
## LightGBM (`finance/models/lightgbm/model.py`)
```python
from models.lightgbm.model import LightGBMModel
model = LightGBMModel(params={"n_estimators": 200, "learning_rate": 0.03}, eval_ratio=0.2)
model.fit(X_train, y_train) # val>=50 行才启用早停
pred = model.predict(X_test)
imp = model.get_feature_importance() # → DataFrame
cv = model.cv_evaluate(X, y, n_folds=5) # TimeSeriesSplit
```
## CatBoost (`finance/models/catboost/model.py`)
同接口。`get_feature_importance()` / `cv_evaluate()`
## ML 策略 (`finance/models/backtest_integration.py`)
```python
from models.backtest_integration import MLStrategy, MLBenchmark
strategy = MLStrategy(model, fe, buy_quantile=0.7, sell_quantile=0.3, rebalance_freq=5)
# 预测值分位 → 动态阈值 → 交易信号
benchmark = MLBenchmark([lgb, cb], fe, price_df, factor_df)
result = benchmark.run() # → DataFrame: model × (IC, return, sharpe, win_rate, trades)
```
## 重要约束
- lookahead 固定,不输入模型(防目标泄露)
- 单股票 IC≈0 是正常现象(噪声主导),多股票截面才是 ML 发挥价值的地方
- 特征工程严禁使用未来数据(RobustScaler fit 在训练集,transform 在测试集)
- 交叉验证用 TimeSeriesSplit(不 shuffle