c2a89d01a4
spec §14 方案A 数据层迁移完成 + E2E 验证(read_db_daily: 在市/退市治偏差/ETF 全OK):
- dbbardata('d') 1826万含退市(治回测幸存者偏差, INSERT OR REPLACE staging迁移, WHERE OHLC NOT NULL+COALESCE)
- constituent_unified 7110行/9指数(300/500/50 baostock全集 + 深证4指 akshare cni union + 中证1000/2000 snapshot)
- pe/pb 不进DB -> valuation_baostock/<year>.parquet 按年宽表(2003-2026)
- 废弃 daily_baostock_full/bs_index_constituent(rename _old 保留); 旧4 schtask disabled
- 新 schtask sanguo-bs-eod 18:05(baostock个股日线+15min+拆pe/pb DAILY_LIMIT 48000) + sanguo-xt-eod 18:40(ETF/基金xtata)
- 权威源: baostock个股日线+估值+15min+复权+300/500/50 / xtata ETF+基金+当天实时 / akshare三表+事件+深证中证成份股
- 全程备份+staging+_old保留可回滚; 脚本 audit/probe/migrate/merge/cleanup/fix_config/verify/bs_eod/xt_eod/wrapper/register_schtasks
- 待办(spec §6 使用层): LocalParquetProvider 接 constituent_unified+valuation_baostock + 实时拼接
33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""merge_constituent.py — 单元3 合并: staging -> constituent_unified, bs_index_constituent -> _old。
|
|
|
|
前提: migrate_constituent.py 已建 constituent_unified_staging (验证通过)。
|
|
- constituent_unified_staging RENAME constituent_unified (正式表)
|
|
- bs_index_constituent RENAME bs_index_constituent_old (保留 988 时点精度, 不删)
|
|
- 建索引 (index_code, code) 加速 get_index_stocks 查询
|
|
回滚: rename 反向 (constituent_unified->staging, _old->bs_index_constituent)
|
|
"""
|
|
import sqlite3
|
|
|
|
DB = r"C:\sanguo_vnpy_v2\data\quant_trading.db"
|
|
c = sqlite3.connect(DB, timeout=60)
|
|
c.execute("PRAGMA busy_timeout = 60000")
|
|
|
|
c.execute("ALTER TABLE constituent_unified_staging RENAME TO constituent_unified")
|
|
print("renamed constituent_unified_staging -> constituent_unified")
|
|
|
|
c.execute("ALTER TABLE bs_index_constituent RENAME TO bs_index_constituent_old")
|
|
print("renamed bs_index_constituent -> bs_index_constituent_old (时点精度保留)")
|
|
|
|
c.execute("CREATE INDEX IF NOT EXISTS idx_constituent_unified "
|
|
"ON constituent_unified(index_code, code)")
|
|
c.commit()
|
|
|
|
print("constituent_unified rows:", c.execute(
|
|
"SELECT COUNT(*) FROM constituent_unified").fetchone()[0])
|
|
print("bs_index_constituent_old rows:", c.execute(
|
|
"SELECT COUNT(*) FROM bs_index_constituent_old").fetchone()[0])
|
|
c.close()
|
|
print("MERGE DONE")
|