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/
42 lines
878 B
Python
42 lines
878 B
Python
"""
|
|
策略基类定义
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any
|
|
|
|
|
|
class Strategy(ABC):
|
|
"""策略抽象基类"""
|
|
|
|
def __init__(self, name: str, config: dict = None):
|
|
self.name = name
|
|
self.config = config or {}
|
|
|
|
@abstractmethod
|
|
def run(self, **kwargs) -> Any:
|
|
"""执行策略"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_signals(self, **kwargs) -> Any:
|
|
"""获取当前信号"""
|
|
pass
|
|
|
|
|
|
class BacktestStrategy(Strategy):
|
|
"""回测策略基类"""
|
|
|
|
def __init__(self, name: str, config: dict = None):
|
|
super().__init__(name, config)
|
|
self.results = None
|
|
|
|
@abstractmethod
|
|
def run_backtest(self, **kwargs) -> dict:
|
|
"""执行回测,返回绩效指标"""
|
|
pass
|
|
|
|
def get_results(self) -> dict:
|
|
"""获取回测结果"""
|
|
return self.results
|