1ed7b72aca
根因: daily_dir mixed-adjust(hfq bulk+akshare raw tail)致3-30 -94%假跌。 方案(Linus三问简化单raw, 除权留分期项#3): - datareader read_parquet_daily/15min 加 dir_key 参数 - data_source iter_bars/fetch_day: adjust=raw→raw_dir(缺配置报错防混源), qfq→daily_dir - engine PaperEngine 默认 adjust=raw - config 加 raw_dir; scripts/raw_redownload.py 新浪源adjust='' 直连+单线程限速 - 验证: 浦发606行close 6.5/14.6 mean10.08 0跳变, 撮合成交价9.71-10.25真实 - 测试9/9+trader全量108/108通过
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""raw 双源回放验证(容器内跑,task #79 Phase C)。
|
|
|
|
确认 engine.adjust=raw → iter_bars 路由 raw_dir → 撮合在真实价上跑(无 mixed 假跌)。
|
|
用法(容器内):python3 /app/scripts/verify_raw_replay.py
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, "/app")
|
|
|
|
from sanguo_data.config import find_config_path, load_config
|
|
from sanguo_data.datareader import guess_exchange
|
|
from sanguo_trader.account import Account
|
|
from sanguo_trader.cta_adapter import PaperCtaEngine
|
|
from sanguo_trader.engine import PaperEngine
|
|
from sanguo_trader.models import AccountConfig
|
|
from sanguo_trader.persistence import init_db, list_daily_balance, list_trades, save_account
|
|
from sanguo_trader.strategy_runner import StrategyRunner
|
|
from sanguo_api.routes_paper import _DataSourceWrapper
|
|
from sanguo_api.strategy_registry import get_strategy_class
|
|
from vnpy.trader.utility import ArrayManager
|
|
|
|
|
|
def main(symbol="600000", start="2026-01-01", end="2026-07-07"):
|
|
cfg = load_config(find_config_path())
|
|
db = "/tmp/raw_verify.db"
|
|
if os.path.exists(db):
|
|
os.remove(db)
|
|
init_db(db)
|
|
aid = save_account(db, {"name": "raw_verify", "initial_capital": 1_000_000})
|
|
|
|
cls = get_strategy_class("DoubleMaStrategy")
|
|
cta = PaperCtaEngine("s1", match_session="next_open", listing_days=0, size=100)
|
|
vt_symbol = symbol + "." + guess_exchange(symbol).value
|
|
strat = cls(cta, "s1", vt_symbol, {"fast_window": 5, "slow_window": 10})
|
|
strat.trading = True
|
|
strat.am = ArrayManager(20)
|
|
cta.set_strategy(strat)
|
|
runner = StrategyRunner("s1", strategy=strat, paper_cta_engine=cta, symbol=symbol)
|
|
|
|
pe = PaperEngine(
|
|
Account(1_000_000), [runner], _DataSourceWrapper(cfg),
|
|
AccountConfig(initial_capital=1_000_000),
|
|
db, aid, [symbol], start, end, "d",
|
|
)
|
|
print("engine.adjust =", pe.adjust)
|
|
pe.run()
|
|
|
|
trades = [t for t in list_trades(db, aid) if not t["rejected"]]
|
|
print("fills:", len(trades))
|
|
for t in trades[:8]:
|
|
print(" ", t["bar_date"], t["direction"], "@", t["price"], "vol", t["volume"])
|
|
|
|
bal = list_daily_balance(db, aid)
|
|
if bal:
|
|
print("净值点数:", len(bal), "首:", round(bal[0]["equity"]), "末:", round(bal[-1]["equity"]))
|
|
|
|
prices = [t["price"] for t in trades]
|
|
if prices:
|
|
print("成交价 min/max:", min(prices), max(prices),
|
|
"→", "REAL ✓" if max(prices) < 20 else "MIXED!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|