# index_monthly_wrapper.ps1 — sanguo-index schtask wrapper (monthly 16号 19:50 成份股刷新) # STEP0: parse_csindex_announce (csindex 调整公告 -> announce_union, 治幸存者偏差全集, 2026-07-23 新增) # STEP1: index_const_hist_download --parts A B (深证 A adjust_cni + 中证 B snapshot) akshare parquet 刷新 # STEP2: migrate_constituent 重建 staging (baostock _old 全集 + 深证 union + 中证 announce_union 全集) # STEP3: merge_constituent staging -> constituent_unified (幂等 DROP+CREATE) # 不碰 baostock online (全集已在 _old, migrate 读它); 不跑 C 新浪 (baostock 权威) # STEP0 失败不阻塞 (csindex 网络抖动时 migrate 回退 snapshot, 治偏差降级但 pipeline 不死) $env:http_proxy = '' $env:https_proxy = '' $env:all_proxy = '' $env:PYTHONIOENCODING = 'utf-8' $env:INDEX_HIST_OUT_DIR = 'C:\sanguo_vnpy_v2\data\index_const_hist' $env:CSINDEX_CACHE = 'C:\sanguo_vnpy_v2\data\csindex_raw' Set-Location C:\sanguo_vnpy_v2 $ts = Get-Date -Format 'yyyyMMdd_HHmmss' $logDir = 'C:\sanguo_vnpy_v2\data\migration_logs' if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null } $log = Join-Path $logDir "index_monthly_$ts.txt" $py = 'C:\Python310\python.exe' $dir = 'C:\sanguo_vnpy_v2\scripts\data_platform' "[$ts] STEP0 parse_csindex_announce --only both (csindex 公告 -> announce_union, 治偏差全集)" | Out-File $log -Encoding UTF8 & $py -X utf8 "$dir\parse_csindex_announce.py" --only both *>> $log "[$ts] STEP0 done exit=$LASTEXITCODE (失败不阻塞, migrate 回退 snapshot)" | Out-File $log -Append -Encoding UTF8 # STEP0b: 中证一级行业指数系列 (000928-000937) 治偏差 - 独立第二次调用 # 原因: main() 里 --indices 与 --only 互斥 (line ~683 早 return), 必须独立调用。 # 不加 --max-notices-per-index: process_generic_index 每月从零重建 announce_union, 需保 was_removed 全历史。 # 失败不阻塞 (旧 parquet 兜底, migrate 用现存 announce_union)。 "[$ts] STEP0b parse_csindex_announce --indices 000928..000937 (中证行业指数系列, 独立调用)" | Out-File $log -Append -Encoding UTF8 & $py -X utf8 "$dir\parse_csindex_announce.py" --indices 000928,000929,000930,000931,000932,000933,000934,000935,000936,000937 *>> $log "[$ts] STEP0b done exit=$LASTEXITCODE (失败不阻塞, 旧 parquet 兜底)" | Out-File $log -Append -Encoding UTF8 "[$ts] STEP1 index_const_hist_download --parts A B (深证 adjust + 中证 snapshot)" | Out-File $log -Append -Encoding UTF8 & $py -X utf8 "$dir\index_const_hist_download.py" --parts A B *>> $log "[$ts] STEP1 done exit=$LASTEXITCODE" | Out-File $log -Append -Encoding UTF8 "[$ts] STEP2 migrate_constituent (rebuild staging from _old + parquet + announce_union)" | Out-File $log -Append -Encoding UTF8 & $py -X utf8 "$dir\migrate_constituent.py" *>> $log "[$ts] STEP2 done exit=$LASTEXITCODE" | Out-File $log -Append -Encoding UTF8 "[$ts] STEP3 merge_constituent (staging -> constituent_unified, idempotent)" | Out-File $log -Append -Encoding UTF8 & $py -X utf8 "$dir\merge_constituent.py" *>> $log $final = $LASTEXITCODE "[$ts] STEP3 done exit=$final" | Out-File $log -Append -Encoding UTF8 exit $final