multi-factor-strategy
Guide users to create multi-factor stock selection strategies and generate independent YAML configuration files
Guide users to create multi-factor stock selection strategies and generate independent YAML configuration files
Real data. Real impact.
Emerging
Developers
Per week
Open source
Skills give you superpowers. Install in 30 seconds.
{"homepage":"https://gitcode.com/datavoid/quantcli","user-invocable":true}
Guide you to create multi-factor stock selection strategies and generate independent YAML configuration files.
# Install from PyPI (recommended) pip install quantcliOr install from source
git clone https://gitcode.com/datavoid/quantcli.git cd quantcli pip install -e .
Verify installation:
quantcli --help
A complete multi-factor stock selection strategy YAML example:
name: Value-Growth Hybrid Strategy version: 1.0.0 description: ROE + Momentum factor stock selectionscreening: fundamental_conditions: # Stage 1: Financial condition screening - "roe > 0.10" # ROE > 10% - "pe_ttm < 30" # P/E < 30 - "pe_ttm > 0" # Exclude losses daily_conditions: # Stage 2: Price condition screening - "close > ma10" # Above 10-day MA limit: 100 # Keep at most 100 stocks
Factor configuration (supports two methods, factors at top level)
factors:
Method 1: Inline factor definition
- name: ma10_deviation expr: "(close - ma(close, 10)) / ma(close, 10)" direction: negative description: "10-day MA deviation"
Method 2: External reference (reference factor files in factors/ directory, include .yaml suffix)
- factors/alpha_001.yaml
- factors/alpha_008.yaml
ranking: weights: # Weight fusion ma10_deviation: 0.20 # Inline factor factors/alpha_001.yaml: 0.40 # External reference factor factors/alpha_008.yaml: 0.40 normalize: zscore # Normalization method
output: limit: 30 # Output top 30 stocks columns: [symbol, name, score, roe, pe_ttm, close, ma10_deviation]
Factor configuration supports two methods (can be mixed):
| Method | Type | Example | Description |
|---|---|---|---|
| Inline | | | Define expression directly in YAML |
| External | | | Load factor file from directory |
Example: Mixed usage
factors: # Inline: Custom factor - name: custom_momentum expr: "close / delay(close, 20) - 1" direction: positiveExternal: Alpha101 factor library (include .yaml suffix)
- factors/alpha_001.yaml
- factors/alpha_005.yaml
- factors/alpha_009.yaml
ranking: weights: custom_momentum: 0.3 factors/alpha_001.yaml: 0.3 factors/alpha_005.yaml: 0.2 factors/alpha_009.yaml: 0.2
Run strategy:
quantcli filter run -f your_strategy.yaml
/multi-factor-strategy
| Function | Usage | Description |
|---|---|---|
| delay | | Lag n periods |
| ma | | Simple moving average |
| ema | | Exponential moving average |
| rolling_sum | | Rolling sum |
| rolling_std | | Rolling standard deviation |
| Function | Usage | Description |
|---|---|---|
| rsi | | Relative strength index |
| correlation | | Correlation coefficient |
| cross_up | | Golden cross (a crosses above b) |
| cross_down | | Death cross (a crosses below b) |
| Function | Usage | Description |
|---|---|---|
| rank | | Cross-sectional ranking (0-1) |
| zscore | | Standardization |
| sign | | Sign function |
| clamp | | Clipping function |
| Function | Usage | Description |
|---|---|---|
| where | | Conditional selection |
| if | | Conditional selection (alias) |
| Field | Description |
|---|---|
| open, high, low, close | OHLC prices |
| volume | Trading volume |
| pe, pb | P/E ratio, P/B ratio |
| roe | Return on equity |
| netprofitmargin | Net profit margin |
I will first understand your strategy needs:
Based on your strategy goals, recommend suitable factor combinations:
Common Fundamental Factors:
| Factor | Expression | Direction | Description |
|---|---|---|---|
| roe | | positive | Return on equity |
| pe | | negative | Lower P/E is better |
| pb | | negative | Price-to-book ratio |
| netprofitmargin | | positive | Net profit margin |
| revenue_growth | | positive | Revenue growth rate |
Common Technical Factors:
| Factor | Expression | Direction | Description |
|---|---|---|---|
| momentum | | positive | N-day momentum |
| ma_deviation | | negative | MA deviation |
| ma_slope | | positive | MA slope |
| volume_ratio | | negative | Volume ratio |
Alpha101 Built-in Factors (can reference
{baseDir}/alpha101/alpha_XXX):
QuantCLI includes 40 WorldQuant Alpha101 factors that can be directly referenced:
| Factor | Category | Description |
|---|---|---|
| Reversal | 20-day new high then decline |
| Reversal | Down volume bottom |
| Volatility | Low volatility stability |
| Capital Flow | Net capital inflow |
| Trend | Uptrend |
| Capital Flow | Capital inflow |
| Momentum | Long-term momentum |
| Reversal | MA deviation reversal |
~ | Extended | Volatility, momentum, price-volume factors |
~ | Extended | Price-volume, trend, strength factors |
~ | Extended | Position, volatility, capital factors |
View all built-in factors:
quantcli factors list
Usage Example:
factors: - alpha101/alpha_001 # Reversal factor - alpha101/alpha_008 # Capital inflow - alpha101/alpha_029 # 5-day momentum ranking: weights: alpha101/alpha_001: 0.4 alpha101/alpha_008: 0.3 alpha101/alpha_029: 0.3
Screening Conditions Example:
screening: conditions: - "roe > 0.10" # ROE > 10% - "netprofitmargin > 0.05" # Net profit margin > 5%
Allocate weights based on factor importance, 0 means only for screening, not scoring:
ranking: weights: # Fundamental factors roe: 0.30 pe: 0.20 # Technical factors ma_deviation: 0.30 momentum: 0.20 normalize: zscore
I will generate a complete strategy YAML file for you:
name: Your Strategy Name version: 1.0.0 description: Strategy descriptionStage 1: Fundamental screening
screening: conditions: - "roe > 0.10" - "pe < 30" limit: 200
Stage 2: Technical ranking
ranking: weights: roe: 0.30 pe: 0.20 ma_deviation: 0.30 momentum: 0.20 normalize: zscore
output: columns: [symbol, score, rank, roe, pe, momentum] limit: 30
Run strategy:
quantcli filter run -f your_strategy.yaml --top 30
Evaluation points:
Q: How to allocate factor weights? A: Core factors 0.3-0.4, auxiliary factors 0.1-0.2, ensure weights sum close to 1
Q: Screening conditions too strict resulting in empty results? A: Gradually relax conditions, first see how many stocks meet each condition
Q: What expression syntax is supported? A: Supports 40+ built-in functions:
ma(), ema(), delay(), rolling_sum(), rsi(), rank(), zscore(), etc.No automatic installation available. Please visit the source repository for installation instructions.
View Installation Instructions1,500+ AI skills, agents & workflows. Install in 30 seconds. Part of the Torly.ai family.
© 2026 Torly.ai. All rights reserved.