feat(selection): 迁移知行B1选股策略
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Selection application use cases."""
|
||||
@@ -0,0 +1,46 @@
|
||||
"""Application use case for one-stock historical Zhixing B1 evaluation."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
|
||||
from ..domain.models import SelectionEvaluation, StockHistory
|
||||
from ..domain.ports import MarketDataReader, MarketDataReaderError
|
||||
from ..domain.zhixing_b1 import ZhixingB1Strategy
|
||||
|
||||
|
||||
class EvaluateZhixingB1:
|
||||
"""Read one history, evaluate the pure strategy, and map read failures."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
reader: MarketDataReader,
|
||||
strategy: ZhixingB1Strategy | None = None,
|
||||
) -> None:
|
||||
"""Inject the market-data port and optionally a strategy instance."""
|
||||
|
||||
self.reader = reader
|
||||
self.strategy = strategy or ZhixingB1Strategy()
|
||||
|
||||
def execute(self, ts_code: str, target_trade_date: date) -> SelectionEvaluation:
|
||||
"""Evaluate ``ts_code`` on the exact requested trading date."""
|
||||
|
||||
try:
|
||||
history = self.reader.load_history(ts_code, target_trade_date)
|
||||
except MarketDataReaderError as exc:
|
||||
return SelectionEvaluation(
|
||||
ts_code=ts_code,
|
||||
target_trade_date=target_trade_date,
|
||||
status="data_error",
|
||||
reason=str(exc),
|
||||
)
|
||||
return self.strategy.evaluate(history, target_trade_date)
|
||||
|
||||
def execute_history(
|
||||
self,
|
||||
history: StockHistory,
|
||||
target_trade_date: date,
|
||||
) -> SelectionEvaluation:
|
||||
"""Evaluate an already loaded history for deterministic unit tests."""
|
||||
|
||||
return self.strategy.evaluate(history, target_trade_date)
|
||||
Reference in New Issue
Block a user