multi-factor
What it does
This skill scores a group of stocks on several measures and picks the highest-ranked ones. It is for investors who build portfolios from many stocks at once.
When to use it
- ✓When you want to pick the top stocks from a group using several measures together.
- ✓When you want to compare stocks on momentum, volatility, and volume at the same time.
- ✓When you want to build an equal-weight portfolio of your highest-ranked names.
Skill link
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/multi-factor/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Rank these 50 stocks by momentum and volatility, and show me the top 10.”
5 new skills a week. 1 minute to read.
How it works
It scores each stock on each factor, standardizes the scores so they compare fairly, and adds them together. The top-scoring stocks go into the portfolio with equal weights.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Multi-Factor Cross-Sectional Stock Ranking
Purpose
On the same time cross-section, compute multiple factor values for many stocks, standardize them, combine them into a composite score, and select the top-ranked stocks to build a portfolio.
Signal Logic
- Factor calculation: calculate N factors for each stock (such as momentum, value, and quality)
- Cross-sectional standardization: standardize each factor on the cross-section with Z-score normalization (subtract mean, divide by standard deviation)
- Composite scoring: sum the factors with equal weights (or custom weights) to obtain a composite score
- Rank and select: go long the TopN names, with weight = 1/N for each
Built-In Factors
| Factor Name | Calculation Method | Direction |
|---|---|---|
| momentum | Return over the past N days | Positive (higher is better) |
| reversal | Return over the past 5 days | Negative (lower is better) |
| volatility | Standard deviation of returns over the past N days | Negative (lower is better) |
| volume_ratio | Today's volume / N-day average volume | Positive |
If extra_fields are available (China A-shares), you can also add:
pe_factor: 1/PE (the larger, the cheaper)pb_factor: 1/PBroe_factor: ROE (the larger, the better)
Parameters
| Parameter | Default | Description |
|---|---|---|
| momentum_window | 20 | Momentum lookback window |
| vol_window | 20 | Volatility lookback window |
| top_n | 3 | Number of selected stocks |
| rebalance_freq | 20 | Rebalancing frequency (trading days) |
Common Pitfalls
- Cross-sectional standardization requires at least 3 stocks, otherwise Z-scores are meaningless
- Keep the previous signal unchanged between rebalance dates (do not rerank every day)
- Factors have different directions: momentum is positively sorted, volatility is negatively sorted, so directions must be aligned before standardization
- Portfolio weights must be normalized: each TopN stock gets 1/N, all others get 0
Dependencies
pip install pandas numpy
Signal Convention
1/N= selected into TopN (equal-weight long),0= not selected
Zoo Signal Engine (new in 0.1.8)
When the user wants to compose 1-N alphas drawn from the Alpha Zoo (450+ pre-built factors) into a multi-factor strategy, use ZooSignalEngine.from_zoo(...) from zoo_signal_engine.py instead of the old per-symbol example_signal_engine.py. The new engine operates on wide-panel dict[str, pd.DataFrame] inputs (the same shape the registry's Alpha.compute(panel) contract uses), redistributes weights when any alpha fails or is skipped, and supports long-only (top_n), short-only (bottom_n), and long-short (top_n + bottom_n) signal modes. It also exposes a generate(data_map) adapter so it drops straight into the existing run_backtest pipelines.
from src.factors.registry import Registry
from zoo_signal_engine import ZooSignalEngine
registry = Registry()
# Browse candidates with registry.list(theme="momentum") -- see the alpha-zoo skill.
alpha_ids = ["alpha101_001", "alpha101_012", "guotai_191_003"]
engine = ZooSignalEngine.from_zoo(alpha_ids, top_n=10, bottom_n=10, standardize=True)
# Feed into a panel-aware backtest, or via .generate(data_map) into the bundled engines.
signal_panel = engine.compute_signal(panel) # DataFrame, same shape as panel["close"]
Cross-references:
- See the
alpha-zooskill for browsing the alpha catalogue, filtering bytheme/universe, and inspecting__alpha_meta__records. example_signal_engine.pyis kept for legacy per-symbol workflows that compute factors directly from raw OHLCV; new code should preferzoo_signal_engine.pyso it benefits from the 450+ zoo alphas, registry-level NaN/inf guardrails, and per-alpha skip isolation.
FAQ
What is a factor?
A factor is a measurable trait of a stock, such as its recent return or how much its price swings.
Can I change the weights?
Yes. The skill allows equal weights or custom weights for each factor.
Which factors come built in?
It includes momentum, reversal, volatility, and volume ratio, and adds value factors when that data is available.
Details
Original description by the author
Multi-factor cross-sectional stock ranking. Combines factor standardization, equal-weight or IC-weighted scoring, and TopN portfolio construction. Suitable for multi-instrument portfolio strategies.
repo: HKUDS/Vibe-Trading
Popularity
- GitHub stars
- 37k
- Ranking position
- #7534
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
vibe-trading
37kGives your agent a full finance research toolkit, covering backtests, factor analysis, options pricing and market data across many markets.
adr-hshare
37kShows your agent how to compare the price of a Chinese company listed in several markets, such as a US ADR and a Hong Kong share.
akshare
37kLets your agent pull free market data for Chinese and global stocks, futures, forex and economic indicators, with no API key needed.
alpha-zoo
37kLets your agent browse a library of ready-made stock factors and test how well a whole set of them predicts returns on a chosen market.
Similar skills
gitcrawl
394kLets your agent search a saved archive of GitHub issues and pull requests, group duplicates, and check their current status on GitHub.
slacrawl
394kLets your agent search and count messages in a local Slack archive, check how fresh that archive is, and refresh it when needed.
goplaces
394kHelps your agent search for places, get their details and reviews, and resolve place names using Google Places, with JSON output for scripts.