feat(selection): 迁移知行B1选股策略
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""Offline golden checks for fixed, non-legacy selection fixtures."""
|
||||
|
||||
import csv
|
||||
import json
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
from zhixing_server.modules.selection.domain.models import SelectionBar, StockHistory
|
||||
from zhixing_server.modules.selection.domain.zhixing_b1 import ZhixingB1Strategy
|
||||
|
||||
FIXTURE_ROOT = Path(__file__).parents[1] / "fixtures" / "selection" / "zhixing_b1"
|
||||
|
||||
|
||||
def _read_history(path: Path, ts_code: str) -> StockHistory:
|
||||
with path.open(newline="") as file:
|
||||
bars = tuple(
|
||||
SelectionBar(
|
||||
trade_date=date.fromisoformat(row["trade_date"]),
|
||||
open=float(row["open"]),
|
||||
high=float(row["high"]),
|
||||
low=float(row["low"]),
|
||||
close=float(row["close"]),
|
||||
volume=float(row["volume"]),
|
||||
)
|
||||
for row in csv.DictReader(file)
|
||||
)
|
||||
return StockHistory(ts_code=ts_code, name="fixture", bars=bars)
|
||||
|
||||
|
||||
def test_fixed_ordinary_and_wide_limit_goldens_are_reproducible() -> None:
|
||||
with (FIXTURE_ROOT / "golden.json").open() as file:
|
||||
golden = json.load(file)
|
||||
|
||||
strategy = ZhixingB1Strategy()
|
||||
for key in ("ordinary", "wide_limit"):
|
||||
expected = golden[key]
|
||||
history = _read_history(FIXTURE_ROOT / expected["file"], expected["ts_code"])
|
||||
target = date.fromisoformat(expected["target_trade_date"])
|
||||
result = strategy.evaluate(history, target)
|
||||
assert result.status == expected["status"]
|
||||
assert [signal.category.value for signal in result.signals] == expected["categories"]
|
||||
Reference in New Issue
Block a user