Files
etf/archive/framework_v2/scripts/export_backtest_detail.py
aszerW c905230a40 refactor(archive): move unused modules to archive/
Archive legacy framework and utility modules that are no longer
referenced by the active core (datasource/ and rotation/):

- framework/ -> archive/framework/
- framework_v2/ -> archive/framework_v2/
- strategies/ -> archive/strategies/
- config/ -> archive/config/
- visualization/ -> archive/visualization/
- scripts/ -> archive/scripts/
- tests/ -> archive/tests/
- run_rotation.py, run_us_rotation.py -> archive/single_files/
- compare_*.py, test_api_dates.py -> archive/single_files/
2026-06-03 23:41:46 +08:00

63 lines
1.8 KiB
Python
Raw Permalink 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.

#!/usr/bin/env python3
"""
导出 V2 框架回测逐日明细到 JSON简化版
现在直接调用 strategy.run(export_detail=True)
不再重复执行策略逻辑
用法:
python framework_v2/scripts/export_backtest_detail.py
"""
import sys
from pathlib import Path
project_root = Path(__file__).parent.parent.parent
sys.path.insert(0, str(project_root))
from dotenv import load_dotenv
load_dotenv()
from framework_v2.config import load_config
from framework_v2.strategies.rotation.rotation import GlobalRotationStrategy
def main():
print("=" * 80)
print(" V2 回测逐日明细导出GlobalRotationStrategy")
print("=" * 80)
# 1. 加载配置
config_file = project_root / 'framework_v2' / 'strategies' / 'rotation' / 'config_simple.yaml'
print(f"\n[1] 加载配置: {config_file}")
config = load_config(str(config_file))
# 2. 初始化策略
print("[2] 初始化策略...")
strategy = GlobalRotationStrategy(config)
# 3. 运行策略并导出明细
output_path = project_root / 'framework_v2' / 'results' / 'backtest_detail_v2.json'
print("[3] 运行策略并导出明细...")
result = strategy.run(
export_detail=True,
detail_path=str(output_path)
)
# 4. 打印汇总
print("\n" + "=" * 80)
print(" 回测汇总")
print("=" * 80)
print(f" 总收益: {result['metrics']['total_return'] * 100:.2f}%")
print(f" 年化收益: {result['metrics']['annual_return'] * 100:.2f}%")
print(f" 最大回撤: {result['metrics']['max_drawdown'] * 100:.2f}%")
print(f" 夏普比率: {result['metrics']['sharpe_ratio']:.2f}")
print(f" 调仓次数: {result['metrics']['rebalance_count']}")
print(f" 交易天数: {result['metrics']['n_days']}")
print(f" 输出文件: {output_path}")
if __name__ == '__main__':
main()