multi-factor

$npx mdskill add HKUDS/Vibe-Trading/multi-factor

Rank stocks by combining multiple factors into a top portfolio.

  • Builds diversified portfolios by selecting the highest ranked stocks.
  • Integrates momentum, value, quality, and volume indicators for analysis.
  • Standardizes inputs using Z-score normalization before combining scores.
  • Delivers a final list of top N stocks with equal weight allocation.

SKILL.md

.github/skills/multi-factorView on GitHub ↗
---
name: multi-factor
description: 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.
category: strategy
---
# 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

1. **Factor calculation**: calculate N factors for each stock (such as momentum, value, and quality)
2. **Cross-sectional standardization**: standardize each factor on the cross-section with Z-score normalization (subtract mean, divide by standard deviation)
3. **Composite scoring**: sum the factors with equal weights (or custom weights) to obtain a composite score
4. **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/PB
- `roe_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

```bash
pip install pandas numpy
```

## Signal Convention

- `1/N` = selected into TopN (equal-weight long), `0` = not selected

More from HKUDS/Vibe-Trading

SkillDescription
adr-hshareADR/H-share/A-share cross-listing premium analysis — track pricing gaps between US-listed ADRs, HK-listed H-shares, and A-shares for arbitrage signals, dual-listing valuation, and delisting risk assessment.
akshareAKShare financial data aggregator (18k+ stars). Free, no API key. Covers A-shares, US, HK, futures, macro, forex. Primary fallback for tushare and yfinance.
asset-allocationAsset allocation theory and optimizer usage — MPT / Black-Litterman / risk budgeting / all-weather strategy, including guides for 4 optimizers and rebalancing rules.
backtest-diagnoseDiagnose failed or underperforming backtests, locate the root cause, and fix the issue
behavioral-financeBehavioral finance applications: theories of overreaction and underreaction, behavioral explanations for momentum and reversal, investor sentiment cycles, cognitive-bias checklists, and debiasing quantitative strategies.
candlestickCandlestick pattern recognition engine, pure pandas vectorized implementation of 15 classic candlestick patterns (5 single-candle + 5 double-candle + 4 triple-candle + 1 trend confirmation), generating a composite signal from bullish/bearish pattern scores.
ccxtCCXT unified crypto exchange library (100+ exchanges). Free public market data. Fallback when OKX is unavailable.
chanlun基于缠论(缠中说禅)的形态识别引擎,使用czsc库自动检测K线分型、笔、中枢,并生成一买/一卖/二买/二卖/三买/三卖等买卖点信号。支持多周期分析和形态分类(3/5/7/9/11笔形态)。
commodity-analysisCommodity analysis (oil supply-demand balance / gold pricing / copper as an economic predictor / inventory cycles / futures premium-discount structure / seasonality), generating directional commodity signals.
convertible-bondA股可转债分析——转股/纯债/期权三维估值、下修/强赎/回售博弈、双低策略与转债轮动选债框架