Skip to content

Commit b7da03d

Browse files
committed
Add scheduled theme momentum refresh
1 parent 2b33312 commit b7da03d

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Theme Momentum Snapshot
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
as_of:
7+
description: "Optional YYYY-MM-DD cutoff. Empty uses latest available/downloaded price date."
8+
required: false
9+
type: string
10+
prices_path:
11+
description: "Optional local price CSV path. Empty downloads Yahoo chart data as a temporary fallback."
12+
required: false
13+
default: ""
14+
type: string
15+
strict_downloads:
16+
description: "Fail if any downloaded symbol is unavailable."
17+
required: false
18+
default: "false"
19+
type: choice
20+
options:
21+
- "false"
22+
- "true"
23+
commit_outputs:
24+
description: "Commit generated theme_momentum_snapshot.json back to data/output."
25+
required: false
26+
default: "false"
27+
type: choice
28+
options:
29+
- "false"
30+
- "true"
31+
schedule:
32+
# Refresh before the advisory publication workflow. The script records data
33+
# source and hash metadata; downstream use remains research-only.
34+
- cron: "45 11 * * 6"
35+
36+
permissions:
37+
contents: write
38+
39+
jobs:
40+
build-theme-momentum:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v6
44+
- uses: actions/setup-python@v6
45+
with:
46+
python-version: "3.11"
47+
- name: Install package
48+
run: python -m pip install -e .
49+
- name: Build theme momentum snapshot
50+
env:
51+
INPUT_AS_OF: ${{ github.event.inputs.as_of || '' }}
52+
PRICES_PATH: ${{ github.event.inputs.prices_path || '' }}
53+
STRICT_DOWNLOADS: ${{ github.event.inputs.strict_downloads || 'false' }}
54+
run: |
55+
set -euo pipefail
56+
mkdir -p data/output
57+
ARGS=(--output data/output/theme_momentum_snapshot.json)
58+
if [ -n "${INPUT_AS_OF}" ]; then
59+
ARGS+=(--as-of "${INPUT_AS_OF}")
60+
fi
61+
if [ -n "${PRICES_PATH}" ]; then
62+
ARGS+=(--prices "${PRICES_PATH}")
63+
fi
64+
if [ "${STRICT_DOWNLOADS}" = "true" ]; then
65+
ARGS+=(--strict-downloads)
66+
fi
67+
python scripts/build_theme_momentum_snapshot.py "${ARGS[@]}" | tee /tmp/theme_momentum_summary.json
68+
{
69+
echo "## Theme momentum snapshot"
70+
echo ""
71+
echo '```json'
72+
cat /tmp/theme_momentum_summary.json
73+
echo '```'
74+
} >> "$GITHUB_STEP_SUMMARY"
75+
- name: Commit snapshot
76+
env:
77+
COMMIT_OUTPUTS: ${{ github.event_name == 'schedule' && 'true' || github.event.inputs.commit_outputs || 'false' }}
78+
run: |
79+
set -euo pipefail
80+
if [ "${COMMIT_OUTPUTS}" != "true" ]; then
81+
echo "Snapshot commit disabled."
82+
exit 0
83+
fi
84+
git config user.name "github-actions[bot]"
85+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
86+
git add data/output/theme_momentum_snapshot.json
87+
if git diff --cached --quiet; then
88+
echo "No theme momentum changes to commit."
89+
else
90+
git commit -m "Update theme momentum snapshot [skip ci]"
91+
git push
92+
fi
93+
- name: Upload theme momentum artifact
94+
uses: actions/upload-artifact@v7
95+
with:
96+
name: theme-momentum-snapshot
97+
path: data/output/theme_momentum_snapshot.json
98+
if-no-files-found: error

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,19 @@ Theme membership is research context, not a hot-list override. Monthly context
230230
bundles embed `theme_context`; downstream use remains shadow-only and must replay
231231
saved artifacts rather than regenerating historical AI judgments.
232232

233+
## Scheduled Theme Momentum Refresh
234+
235+
`.github/workflows/theme_momentum_snapshot.yml` runs weekly before the advisor
236+
publication workflow. It builds `data/output/theme_momentum_snapshot.json` and,
237+
on scheduled runs, commits the changed snapshot back to the repository so
238+
`QuantAdvisorResearch` can consume a point-in-time artifact. Manual runs can pass
239+
`prices_path` to use an audited local CSV instead of Yahoo chart downloads.
240+
241+
Yahoo chart downloads remain a temporary fallback only. The snapshot records
242+
source metadata and file hashes when a local price CSV is used. Random free proxy
243+
pools should not be used in this stable pipeline because they make replay, data
244+
quality, and compliance review harder.
245+
233246
## Theme Momentum Snapshot
234247

235248
The static taxonomy only defines long-horizon theme membership. Ranking is done

README.zh-CN.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ config/symbol_theme_exposure.csv
190190

191191
这些配置是长期研究上下文,不是热点追涨列表。月度 context bundle 会把主题暴露写入 `theme_context`,供 AI shadow review 使用;任何推荐或回测仍必须基于已保存 artifact,不能在回测时重新生成历史判断。
192192

193+
## 主题动量定时刷新
194+
195+
`.github/workflows/theme_momentum_snapshot.yml` 每周在 Advisor 发布前运行,生成 `data/output/theme_momentum_snapshot.json`。定时运行时如果快照有变化,会提交回仓库,供 `QuantAdvisorResearch` 读取点时 artifact。手工运行可以传 `prices_path`,使用可审计的本地价格 CSV,而不是临时下载。
196+
197+
Yahoo chart 下载仍然只是临时 fallback。使用本地价格 CSV 时,快照会记录来源和文件 hash。随机免费代理 IP 池不应进入稳定链路,因为它会增加 replay、数据质量和合规复核难度。
198+
193199
## 主题动量快照
194200

195201
跨板块主题 taxonomy 只是定义“股票属于哪些长期主题”。真正的排序由独立的主题动量快照完成,避免因为近期热门标的临时改 universe 或权重。

0 commit comments

Comments
 (0)