feat(data): 恢复双源(task#79)—撮合raw+策略qfq, 分红除权准确
用户要模拟=回测准确: raw除权缺口致MA假信号, 必须双源。
- data_source: qfq→qfq_dir(干净qfq), raw→raw_dir; _check_adjust_cfg(cfg提供才校验)
- engine 双bar流: step(raw_bars,qfq_bars)撮合/盯市raw+策略on_bar qfq; run zip(raw,qfq)
- live_orchestrator: warmup用qfq(信号am); 去adjust参数(双源固定)
- raw_redownload --adjust(''raw/'qfq'); config qfq_dir
- 113/113通过
This commit is contained in:
@@ -34,7 +34,7 @@ def test_iter_bars_cross_section_multi_symbol(monkeypatch):
|
||||
assert len(sections) == 1
|
||||
_date, d = sections[0]
|
||||
assert d["600000"].close_price == 10.5
|
||||
assert all(k == "daily_dir" for k in seen) # 默认 qfq → daily_dir
|
||||
assert all(k == "qfq_dir" for k in seen) # 默认 qfq → qfq_dir(双源)
|
||||
|
||||
|
||||
def test_iter_bars_raw_uses_raw_dir(monkeypatch, caplog):
|
||||
@@ -90,4 +90,4 @@ def test_fetch_day_returns_last_bar(monkeypatch):
|
||||
monkeypatch.setattr("sanguo_trader.data_source._read_fn", lambda iv: mock_read)
|
||||
bar = fetch_day("600000", "2024-01-02", "d")
|
||||
assert bar.close_price == 10.5 # 取最后一个
|
||||
assert seen == ["daily_dir"]
|
||||
assert seen == ["qfq_dir"] # 默认 qfq → qfq_dir(双源)
|
||||
|
||||
@@ -101,12 +101,12 @@ def test_engine_step_single_bar_advances(tmp_path):
|
||||
]
|
||||
pe, db, aid, account, runner = _build(tmp_path, sections)
|
||||
# day1 step:_AlwaysBuyStrategy 买单(NEXT_OPEN)→ 进 pending,当根不撮合
|
||||
pending, closes = pe.step("2024-01-01", sections[0][1], {}, [])
|
||||
pending, closes = pe.step("2024-01-01", sections[0][1], sections[0][1], {}, [])
|
||||
assert len(pending) == 1
|
||||
assert account.positions.get("600000") is None
|
||||
assert closes["600000"] == 10.0
|
||||
# day2 step:撮合 day1 pending @ open 10.5;策略 on_bar(day2) 又发单进 pending 等 day3
|
||||
pending2, closes2 = pe.step("2024-01-02", sections[1][1], closes, pending)
|
||||
pending2, closes2 = pe.step("2024-01-02", sections[1][1], sections[1][1], closes, pending)
|
||||
assert len(pending2) == 1 # day2 新信号(无 day3 不撮合)
|
||||
assert account.positions["600000"].volume == 100 # day1 单 day2 open 10.5 撮合 100 股
|
||||
# step 入库(day1+day2 各一条余额)
|
||||
|
||||
Reference in New Issue
Block a user