feat(factors/engine): 添加性能分析器支持 debug 模式
- 新增 PerformanceProfiler 组件,与 FactorEngine 解耦 - 支持上下文管理器用法,安全计时处理异常 - 为 DataRouter/ComputeEngine/FactorEngine 添加 debug 参数
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
|
||||
使用方法:
|
||||
uv run python src/experiment/probe_selection/run_probe_selection_all_factors.py
|
||||
uv run python src/experiment/probe_selection/run_probe_selection_all_factors.py --debug
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -180,15 +182,26 @@ def apply_preprocessing_for_probe(
|
||||
return data
|
||||
|
||||
|
||||
def run_probe_feature_selection_with_all_factors():
|
||||
"""执行探针法因子筛选(使用 FactorManager 中所有因子)"""
|
||||
def run_probe_feature_selection_with_all_factors(debug: bool = True):
|
||||
"""执行探针法因子筛选(使用 FactorManager 中所有因子)
|
||||
|
||||
Args:
|
||||
debug: 是否启用 debug 模式,显示详细的性能统计信息
|
||||
|
||||
Returns:
|
||||
筛选后的特征列表
|
||||
"""
|
||||
print("\n" + "=" * 80)
|
||||
print("增强探针法因子筛选 - 使用 FactorManager 全部因子")
|
||||
if debug:
|
||||
print("[DEBUG] 性能监控模式已启用")
|
||||
print("=" * 80)
|
||||
|
||||
# 1. 创建 FactorEngine
|
||||
print("\n[1] 创建 FactorEngine")
|
||||
engine = FactorEngine()
|
||||
if debug:
|
||||
print("[DEBUG] 启用性能监控模式")
|
||||
engine = FactorEngine(debug=debug)
|
||||
|
||||
# 2. 从 FactorManager 注册所有因子
|
||||
print("\n[2] 从 FactorManager 注册所有因子")
|
||||
@@ -203,6 +216,11 @@ def run_probe_feature_selection_with_all_factors():
|
||||
end_date=VAL_END, # 包含验证集,增加样本量
|
||||
)
|
||||
|
||||
# 3.5. 打印性能报告(如果启用了 debug 模式)
|
||||
if debug:
|
||||
print("\n[DEBUG] 生成性能报告")
|
||||
engine.profiler.print_report()
|
||||
|
||||
# 4. 股票池筛选
|
||||
print("\n[4] 执行股票池筛选")
|
||||
pool_manager = StockPoolManager(
|
||||
@@ -309,5 +327,23 @@ def run_probe_feature_selection_with_all_factors():
|
||||
return selected_features
|
||||
|
||||
|
||||
def main():
|
||||
"""主入口函数,支持命令行参数"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="探针法因子筛选 - 使用 FactorManager 中所有因子"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
"-d",
|
||||
action="store_true",
|
||||
help="启用 debug 模式,显示详细的性能统计信息",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
selected = run_probe_feature_selection_with_all_factors(debug=args.debug)
|
||||
return selected
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
selected = run_probe_feature_selection_with_all_factors()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user