refactor: 配置文件迁移到策略目录(模块自包含)
迁移内容: - config/strategies/rotation.yaml → strategies/rotation/config.yaml 路径更新(核心文件): - strategies/rotation/strategy.py(注释示例) - scripts/generate_legacy_report.py(config_path) - run_rotation.py(注释和默认参数) - datasource/hybrid_source.py(from_yaml示例和fetch_rotation_data) 保留: - config/strategies/cci.yaml(无对应策略目录,暂保留) 设计原则:策略模块自包含,配置与实现同目录,方便移植和复制 验证:策略加载成功(候选池11只,回测区间2019-01-01 ~ 2026-05-12)
This commit is contained in:
@@ -26,7 +26,7 @@ class HybridDataSource:
|
||||
使用方式:
|
||||
from datasource import HybridDataSource
|
||||
|
||||
source = HybridDataSource.from_yaml('config/strategies/rotation.yaml')
|
||||
source = HybridDataSource.from_yaml('strategies/rotation/config.yaml')
|
||||
result = source.fetch_all()
|
||||
"""
|
||||
|
||||
@@ -259,7 +259,7 @@ class HybridDataSource:
|
||||
|
||||
|
||||
# 简化接口
|
||||
def fetch_rotation_data(config_path: str = "config/strategies/rotation.yaml") -> dict:
|
||||
def fetch_rotation_data(config_path: str = "strategies/rotation/config.yaml") -> dict:
|
||||
"""
|
||||
获取轮动策略数据(简化接口)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ ETF轮动策略回测入口
|
||||
|
||||
用法:
|
||||
python run_rotation.py
|
||||
python run_rotation.py --config config/strategies/rotation.yaml
|
||||
python run_rotation.py --config strategies/rotation/config.yaml
|
||||
python run_rotation.py --save-path results/my_rotation
|
||||
"""
|
||||
|
||||
@@ -20,7 +20,7 @@ def main():
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
type=str,
|
||||
default="config/strategies/rotation.yaml",
|
||||
default="strategies/rotation/config.yaml",
|
||||
help="配置文件路径",
|
||||
)
|
||||
parser.add_argument(
|
||||
|
||||
@@ -34,7 +34,7 @@ def run_with_legacy_report():
|
||||
"""运行新框架回测并生成原引擎格式报告"""
|
||||
|
||||
# 加载配置
|
||||
config_path = 'config/strategies/rotation.yaml'
|
||||
config_path = 'strategies/rotation/config.yaml'
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class RotationStrategy(StrategyBase):
|
||||
|
||||
使用方式:
|
||||
from strategies.rotation.strategy import RotationStrategy
|
||||
strategy = RotationStrategy.from_yaml('config/strategies/rotation.yaml')
|
||||
strategy = RotationStrategy.from_yaml('strategies/rotation/config.yaml')
|
||||
result = strategy.run_backtest()
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user