Available in
Marketplaces, most starred first
Tags
Add to README
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
By quantskillsIn 1 marketplace
Discover causal alpha factors from OHLCV data using causal discovery (PC + LiNGAM + NOTEARS), build Structural Causal Models, construct regime-invariant factor expressions, and validate through backtesting. Produces OHLCV-only alpha factors whose predictive power is grounded in causal mechanisms rather than spurious correlations. Use when an agent needs to discover stable alpha factors that survive regime changes, test whether existing factors are causal or merely correlational, or generate alpha factors with formal invariance guarantees on portable agent platforms such as Claude Code, Codex, or Codex-style skill systems.
Claude hands work to one, or you mention it with @.
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
简体中文 | English
基于因果发现(PC + LiNGAM + NOTEARS)从 OHLCV 数据中挖掘具有因果不变性的 alpha 因子。与传统的相关性因子挖掘不同,因果发现识别的是 OHLCV 衍生量之间 导致未来收益的结构性关系——产生的因子在跨市场体制下保持稳定。
本技能仅用于研究流程,不构成投资建议。
传统因子挖掘回答的问题是:
"历史上这个 OHLCV 模式出现时,收益如何表现?"
这是相关性推理。问题在于:金融市场是非平稳的,任何模式与未来收益 之间的相关性都可能(且确实会)随市场体制而变化。
因果发现回答一个根本不同的问题:
"这个 OHLCV 衍生量是否通过稳定的结构机制导致未来收益?"
如果答案是肯定的,那么这种关系是不变的——无论牛市、熊市、震荡市、 高波动市,它都成立。
# 1. 安装依赖
pip install -r requirements.txt
# 2.(可选)配置 PandaData —— 用于获取 A 股实时数据
cp .env.example .env
# 编辑 .env,填入 PANDA_AI_USERNAME 和 PANDA_AI_PASSWORD
训练/测试期间通过 config.json 中的 data_split 配置(默认:训练 2015–2020,测试 2021–2025)。因子复杂度通过 max_components 控制(默认 3)。
# Step 1: 生成训练期特征(因 API 5 年限制需拆分)
python scripts/generate_features.py --use-pandadata --start-date 20150101 --end-date 20191231 --indicator 000300 --output output/run_001/features_2015_2019.csv
python scripts/generate_features.py --use-pandadata --start-date 20200101 --end-date 20201231 --indicator 000300 --output output/run_001/features_2020.csv
# 合并后添加 forward_return_5d 目标
# Step 2: 因果发现(默认 rank-IC 选择)
python scripts/causal_discovery.py --features output/run_001/features.csv --target forward_return_5d --method ic_selection --output output/run_001/causal_graph.json
# Step 3: 构建因果 alpha(默认最多 3 个成分)
python scripts/build_causal_alpha.py --graph output/run_001/causal_graph.json --features output/run_001/features.csv --output output/run_001/causal_factor.csv --expression-output output/run_001/causal_alpha_expression.json --max-components 3
# Step 4: 生成测试期特征 & 计算测试期因子值
python scripts/generate_features.py --use-pandadata --start-date 20210101 --end-date 20251231 --indicator 000300 --output output/run_001/features_test.csv
python scripts/build_causal_alpha.py --graph output/run_001/causal_graph.json --features output/run_001/features_test.csv --output output/run_001/causal_factor_test.csv --max-components 3
# Step 5: 不变性检验 + 回测(测试期)
python scripts/invariance_test.py --factor output/run_001/causal_factor_test.csv --data-root ../backtest/market_data_2020_2025/ --output output/run_001/invariance_report.json
python scripts/integrate_backtest.py --factor output/run_001/causal_factor_test.csv --factor-column causal_alpha --use-pandadata --start-date 20210101 --end-date 20251231 --indicator 000300 --output-dir output/run_001/
# Step 6: 生成综合分析报告
python scripts/generate_report.py --run-dir output/run_001/ --output output/run_001/causal_analysis.md
# Step 1: 从本地 Parquet 数据生成特征池
python scripts/generate_features.py \
--data-root ../backtest/market_data_2015_2019/ \
--output output/run_001/features.csv
# Step 2–4 同上 ...
# Step 5: 回测验证(本地数据 + 时间范围过滤)
python scripts/integrate_backtest.py \
--factor output/run_001/causal_factor.csv \
--factor-column causal_alpha \
--data-root ../backtest/market_data_2020_2025/ \
--timespan 20200101 20251231 \
--output-dir output/run_001/
# 指定不同的股票池
python scripts/generate_features.py \
--use-pandadata --start-date 20200101 --end-date 20251231 \
--indicator 000905 \ # CSI 500
--output output/run_002/features.csv
# 回测时自定义参数
python scripts/integrate_backtest.py \
--factor output/run_001/causal_factor_test.csv \
--factor-column causal_alpha \
--use-pandadata --start-date 20210101 --end-date 20251231 \
--indicator 000300 \
--holding-days 10 \ # 每 10 个交易日调仓
--n-long 100 \ # 持有 100 只股票
--cost-bps 3 \ # 交易成本 3bps
--output-dir output/run_001/
| 代码 | 指数 |
|---|---|
000300 | 沪深300 |
000905 | 中证500 |
000016 | 上证50 |
000852 | 中证1000 |
| 文件 | 内容 |
|---|---|
causal_graph.json | 发现的因果 DAG(边、ATE) |
causal_alpha_expression.json | OHLCV 因子表达式 + 成分分解 |
causal_factor.csv / causal_factor_test.csv | 每日因子得分(训练/测试期) |
invariance_report.json | 跨体制不变性检验(含每体制 ATE 和日期范围) |
causal_backtest_summary.json | 回测指标(Sharpe、IC、MDD) |
causal_analysis.md | 综合分析报告(18 节,含 Mermaid 图) |
ICs.csv | 每日多周期 Rank IC 序列 |
stats.csv | 组合模拟日频净值 |
ic_summary.csv | 多周期 IC 汇总(1d/5d/10d/20d) |
* (1 - rank(vol)) 门控Built from public signals: copy clicks on this site, GitHub stars and activity, the README and the manifest. Not a security audit or an endorsement.
causal-alpha-discovery@quantskills is listed by quantskills/registry — review the source before installing
npx claudepluginhub quantskills/registry --plugin causal-alpha-discoveryPlugins from other owners that cover similar ground