Alpha-R1 is a reasoning-enhanced LLM for quantitative alpha selection, trained with GRPO reinforcement learning on top of Qwen3-8B. This repository is the companion implementation of the paper Alpha-R1: Alpha Screening with LLM Reasoning via Reinforcement Learning.
Alpha-R1 screens a candidate pool of Alpha101 factors. Instead of treating alphas as bare time series, it reasons over semantic factor descriptions — how each factor works, when it works, and when it fails — and activates the factors that fit current market conditions:
qlib single-factor backtest (P_i) ─┐
├─→ LLM factor descriptions α_des (OpenRouter)
market memory (M_global) ──────────┘ │
↓
Alpha-R1 inference (FinStep/Alpha-R1)
↓
parsed selections (selections.json)
↓
end-to-end strategy backtest (NAV, AR/SR/MDD)
- Single-factor backtesting (paper §3.1.3): each Alpha101 factor is evaluated on qlib — factor values, IC/RankIC, and a top-k portfolio — and saved as a performance vector
P_i. - Factor description generation (§3.1.2/§3.2.1): an LLM (via OpenRouter) iteratively aggregates daily price/news text into a global market memory
M_global, then mapsM_global + P_iinto a structured descriptionα_desper factor. - Alpha-R1 inference (§3.3): descriptions are concatenated into the decision-context prompt; the model outputs the selected factors in
<alpha_list>...</alpha_list>. - Output parsing: responses are validated and parsed into
selections.json/summary.csv. - Strategy backtest (§3.3, Appendix F): a fixed linear model scores stocks with the selected factors, and the paper's execution protocol (slot rotation, VWAP fills, fees) produces the NAV curve and metrics.
pip install -e . # core (transformers inference + generation + parsing)
pip install -e .[vllm] # optional high-throughput inference backend
pip install -e .[qlib] # optional backtesting (pyqlib)API keys (see .env.example):
export OPENROUTER_API_KEY=... # description generation
export HF_TOKEN=... # optional (e.g. for gated/private mirrors)All steps read their defaults from configs/.
python scripts/prepare_qlib_data.py --csv-dir data/stock_data --qlib-dir ~/.qlib/qlib_data/alpha_r1
python scripts/run_factor_backtest.py --alphas allWrites result/alpha_backtest/alphaNNN.json per factor. See data/README.md for data layout conventions.
python scripts/build_market_memory.py --start-date 2023-01-01 --end-date 2024-12-31
python scripts/generate_descriptions.py --model "anthropic/claude-3.7-sonnet" --alphas allThe OpenRouter model id is intentionally left blank in configs/generation.yaml — set it there or pass --model. Writes data/market_memory/M_global.txt and result/alpha_des/alphaNNN.txt.
python scripts/run_inference.py \
--factor-des-dir result/alpha_des \
--start-date 2025-01-01 --end-date 2025-12-31Loads FinStep/Alpha-R1 via from_pretrained (default hf backend; set backend: vllm in configs/inference.yaml to switch to vLLM). Decoding defaults to temperature=0, top_p=0.7 as in the paper. Writes result/alpha_select/result_YYYYMMDD.json. A minimal smoke run without real data works with --factor-des-dir examples/factor_descriptions.
Decision days default to weekdays in the given range (a trading-calendar approximation); pass --market-state-dir to restrict to days that actually have market data.
python scripts/parse_outputs.py --result-dir result/alpha_selectWrites selections.json (date → factor list) and summary.csv, and reports format-invalid days.
# estimate the fixed linear model on the historical window (paper: 2020-2023)
python scripts/train_linear_model.py --alphas all
# backtest the selections with the paper's execution protocol (slot rotation, VWAP, 10 bps)
python scripts/run_strategy_backtest.py \
--selections result/alpha_select/parsed/selections.json \
--betas result/linear_model/betas.csvTurns parsed selections into a tradable top-10 equal-weight portfolio: capital rotates through holding_days slots (one slot rebalanced per day), fills use daily $vwap (falling back to $close), fees are 10 bps per side, idle cash earns the risk-free rate, and decision day t scores stocks with factor values of t-1. Writes metrics JSON (AR / excess SR / MDD / Sortino / Calmar / IR vs benchmark) and a daily NAV CSV to configs/strategy.yaml: output_dir. Passing a directory of per-round selections files as --selections additionally writes the multi-round average. Limit-lock filtering is available but off by default (daily data carries no limit flags; see configs/strategy.yaml).
Main experiment results (paper Table 1; 12-month out-of-sample testing period 2025-01-01 to 2025-12-31). AR = annualized return, SR = excess Sharpe ratio, MDD = max drawdown.
| Type | Method | S&P 500 | CSI 300 | ||||
|---|---|---|---|---|---|---|---|
| AR (%) | SR | MDD (%) | AR (%) | SR | MDD (%) | ||
| Non-LLM | Buy & Hold | 19.34 | 0.80 | 18.75 | 22.16 | 1.31 | 10.49 |
| PCA | 7.98 | 0.27 | 17.30 | 2.93 | 0.17 | 14.46 | |
| XGBoost | 3.49 | 0.03 | 18.45 | 8.99 | 0.50 | 16.26 | |
| LightGBM | -5.42 | -0.43 | 20.93 | 18.44 | 1.05 | 14.92 | |
| A2C | 10.82 | 0.40 | 17.70 | 22.96 | 1.20 | 14.86 | |
| PPO | 7.68 | 0.25 | 14.97 | 14.96 | 0.81 | 12.95 | |
| DDPG | 2.53 | -0.02 | 15.04 | 1.97 | 0.12 | 16.54 | |
| TD3 | 5.54 | 0.14 | 16.58 | 8.66 | 0.52 | 10.26 | |
| SAC | 37.60 | 1.44 | 15.18 | 9.77 | 0.56 | 11.68 | |
| LLM | Gemini 2.5 Pro | 14.23 | 0.55 | 17.01 | 16.29 | 0.90 | 14.01 |
| Claude 3.7 Sonnet | 10.92 | 0.40 | 18.88 | 10.13 | 0.57 | 14.49 | |
| DeepSeek‑R1 | 21.94 | 0.93 | 14.36 | 14.66 | 0.81 | 14.60 | |
| Qwen3‑8B | 12.85 | 0.47 | 19.52 | 15.44 | 0.79 | 14.38 | |
| Alpha‑R1 (Ours) | 47.87 | 1.62 | 16.91 | 40.57 | 2.23 | 6.58 | |
On out-of-domain universes without retraining, Alpha-R1 reaches 80.54% AR (SR 2.46) on Russell 2000 and 73.52% AR (SR 2.80) on CSI 1000 (paper Table 2).
Alpha-R1 is trained with GRPO on Qwen3-8B using verl and a market-feedback reward (paper Section 3.4). training/ contains the training configuration (configs/grpo_alpha_r1.yaml) and a simplified reference implementation of the reward (reward.py), pluggable via verl's custom_reward_function mechanism. See training/README.md for details.
src/alpha_r1/
├── factors/ Alpha101 formula library + description loading/concatenation
├── backtest/ qlib data conversion, Alpha101→qlib expressions, single-factor
│ backtest, linear model, slot-rotation strategy backtest
├── generation/ OpenRouter client, market memory, description generation
├── inference/ transformers / vLLM backends, prompt builder, selection loop
└── parsing/ <alpha_list> extraction and validation
scripts/ CLI entry points for each pipeline step
configs/ YAML configs for backtest / generation / inference / strategy
training/ GRPO training config + reference reward (verl)
data/ raw data lives here (gitignored, see data/README.md)
examples/ minimal example inputs
@article{jiang2025alphar1,
title={Alpha-R1: Alpha Screening with LLM Reasoning via Reinforcement Learning},
author={Jiang, Zuoyou and Zhao, Li and Sun, Rui and Sun, Ruohan and Li, Zhongjian and Li, Jing and Jiang, Daxin and Bai, Zuo and Hua, Cheng},
journal={arXiv preprint arXiv:2512.23515},
year={2025}
}This project is released under the MIT License.
- [2025.12] 📄 Paper released on arXiv.
- [2026.09] 🧩 Code release: qlib single-factor backtests, factor description generation (OpenRouter), Alpha-R1 inference, output parsing, end-to-end strategy backtest, and the GRPO training config + reference reward.
- ✅ Inference code (Alpha Screening Pipeline)
- ✅ Model weights (
FinStep/Alpha-R1)
Please ⭐ Star this repo to stay updated!



