Alpha158 and Alpha360 Factor Formula Reference¶
Overview¶
This document describes in detail the factor computation formulas of the Alpha158 and Alpha360 datasets in the Qlib quantitative investment platform. These factor sets are widely used for training and evaluating stock prediction models.
The Alpha158 Factor Set¶
Alpha158 contains 158 technical analysis indicators, grouped into four major categories: candlestick (K-line) features, price features, volume features, and rolling-window technical indicators.
1. Candlestick base features (9)¶
Candlestick features are computed from a single day's OHLC data and reflect price pattern characteristics:
| Factor | Formula | Meaning |
|---|---|---|
| KMID | ($close-$open)/$open |
Close-to-open difference ratio, i.e., the intraday return |
| KLEN | ($high-$low)/$open |
High-to-low range ratio, i.e., intraday volatility |
| KMID2 | ($close-$open)/($high-$low+1e-12) |
Body size relative to the full range |
| KUP | ($high-Greater($open, $close))/$open |
Upper-shadow ratio, reflecting overhead pressure |
| KUP2 | ($high-Greater($open, $close))/($high-$low+1e-12) |
Upper shadow as a share of the total range |
| KLOW | (Less($open, $close)-$low)/$open |
Lower-shadow ratio, reflecting downside support |
| KLOW2 | (Less($open, $close)-$low)/($high-$low+1e-12) |
Lower shadow as a share of the total range |
| KSFT | (2*$close-$high-$low)/$open |
Where the close sits relative to the midpoint |
| KSFT2 | (2*$close-$high-$low)/($high-$low+1e-12) |
Relative position of the close within the range |
2. Price features (4)¶
Base price features, standardized as ratios to the current closing price:
| Factor | Formula | Meaning |
|---|---|---|
| OPEN0 | $open/$close |
Today's open relative to the close |
| HIGH0 | $high/$close |
Today's high relative to the close |
| LOW0 | $low/$close |
Today's low relative to the close |
| VWAP0 | $vwap/$close |
Today's VWAP relative to the close |
3. Rolling-window technical indicators (145)¶
Technical indicators computed over 5/10/20/30/60-day rolling windows; each indicator yields 5 features, with 29 indicator types in total.
3.1 Price trend and momentum¶
| Factor | Formula | Meaning | Reference |
|---|---|---|---|
| ROC | Ref($close, d)/$close |
Rate of change over d days | Rate of Change |
| MA | Mean($close, d)/$close |
d-day simple moving average | Moving Average |
| STD | Std($close, d)/$close |
d-day price standard deviation (volatility) | - |
| BETA | Slope($close, d)/$close |
d-day price trend slope | - |
| RSQR | Rsquare($close, d) |
R² of the d-day linear regression, i.e., trend linearity | - |
| RESI | Resi($close, d)/$close |
Residual of the d-day linear regression | - |
3.2 Price position¶
| Factor | Formula | Meaning |
|---|---|---|
| MAX | Max($high, d)/$close |
Highest price within d days |
| MIN | Min($low, d)/$close |
Lowest price within d days |
| QTLU | Quantile($close, d, 0.8)/$close |
80th percentile over d days |
| QTLD | Quantile($close, d, 0.2)/$close |
20th percentile over d days |
| RANK | Rank($close, d) |
Percentile rank of the current price within d days |
| RSV | ($close-Min($low, d))/(Max($high, d)-Min($low, d)+1e-12) |
Relative strength value, the basis of the KDJ indicator |
3.3 Time-series position¶
| Factor | Formula | Meaning | Reference |
|---|---|---|---|
| IMAX | IdxMax($high, d)/d |
Relative position of the highest price | Aroon Indicator |
| IMIN | IdxMin($low, d)/d |
Relative position of the lowest price | Aroon Indicator |
| IMXD | (IdxMax($high, d)-IdxMin($low, d))/d |
Time gap between high and low, reflecting downward momentum | - |
3.4 Price-volume association¶
| Factor | Formula | Meaning |
|---|---|---|
| CORR | Corr($close, Log($volume+1), d) |
Correlation between price and volume |
| CORD | Corr($close/Ref($close,1), Log($volume/Ref($volume, 1)+1), d) |
Correlation between price changes and volume changes |
3.5 Up/down statistics¶
| Factor | Formula | Meaning |
|---|---|---|
| CNTP | Mean($close>Ref($close, 1), d) |
Fraction of up days within d days |
| CNTN | Mean($close<Ref($close, 1), d) |
Fraction of down days within d days |
| CNTD | CNTP - CNTN |
Difference between up-day and down-day counts |
3.6 RSI-style indicators¶
| Factor | Formula | Meaning | Reference |
|---|---|---|---|
| SUMP | Sum(Greater($close-Ref($close, 1), 0), d)/(Sum(Abs($close-Ref($close, 1)), d)+1e-12) |
Share of total gains in total movement | RSI Indicator |
| SUMN | Sum(Greater(Ref($close, 1)-$close, 0), d)/(Sum(Abs($close-Ref($close, 1)), d)+1e-12) |
Share of total losses in total movement | RSI Indicator |
| SUMD | SUMP - SUMN |
Gain/loss difference ratio, an RSI-like indicator | RSI Indicator |
3.7 Volume technical indicators¶
| Factor | Formula | Meaning | Reference |
|---|---|---|---|
| VMA | Mean($volume, d)/($volume+1e-12) |
Volume moving average | Volume Moving Average |
| VSTD | Std($volume, d)/($volume+1e-12) |
Volume standard deviation | - |
| WVMA | Std(Abs($close/Ref($close, 1)-1)*$volume, d)/(Mean(Abs($close/Ref($close, 1)-1)*$volume, d)+1e-12) |
Volume-weighted price-change volatility | - |
| VSUMP | Sum(Greater($volume-Ref($volume, 1), 0), d)/(Sum(Abs($volume-Ref($volume, 1)), d)+1e-12) |
Share of volume-increase days | - |
| VSUMN | Sum(Greater(Ref($volume, 1)-$volume, 0), d)/(Sum(Abs($volume-Ref($volume, 1)), d)+1e-12) |
Share of volume-decrease days | - |
| VSUMD | VSUMP - VSUMN |
Volume change difference ratio | - |
Rolling window notes¶
All rolling indicators use the following window sizes: [5, 10, 20, 30, 60] days
So each rolling indicator yields 5 features, for example: - ROC5, ROC10, ROC20, ROC30, ROC60 - MA5, MA10, MA20, MA30, MA60 - STD5, STD10, STD20, STD30, STD60 - ... and so on
The Alpha360 Factor Set¶
Alpha360 provides 360 raw price features, containing the complete OHLCV series over the past 60 days.
Design Philosophy¶
- Raw data preserved: provides raw prices rather than engineered features
- Unified normalization: all prices are normalized by the latest close; volume by the latest volume
- Time-series integrity: keeps the complete 60-day series, suited to deep learning models
Factor Composition¶
Alpha360 contains 6 factor families, each with 60 features, for a total of 360:
1. Closing price series (60)¶
CLOSE59, CLOSE58, CLOSE57, ..., CLOSE2, CLOSE1, CLOSE0
Formulas:
- CLOSE59: Ref($close, 59)/$close (close 59 days ago / current close)
- CLOSE58: Ref($close, 58)/$close (close 58 days ago / current close)
- ...
- CLOSE1: Ref($close, 1)/$close (close 1 day ago / current close)
- CLOSE0: $close/$close = 1 (current close, identically 1 after normalization)
2. Opening price series (60)¶
OPEN59, OPEN58, OPEN57, ..., OPEN2, OPEN1, OPEN0
Formula: Ref($open, i)/$close (i from 59 down to 0)
3. High price series (60)¶
HIGH59, HIGH58, HIGH57, ..., HIGH2, HIGH1, HIGH0
Formula: Ref($high, i)/$close (i from 59 down to 0)
4. Low price series (60)¶
LOW59, LOW58, LOW57, ..., LOW2, LOW1, LOW0
Formula: Ref($low, i)/$close (i from 59 down to 0)
5. VWAP series (60)¶
VWAP59, VWAP58, VWAP57, ..., VWAP2, VWAP1, VWAP0
Formula: Ref($vwap, i)/$close (i from 59 down to 0)
6. Volume series (60)¶
VOLUME59, VOLUME58, VOLUME57, ..., VOLUME2, VOLUME1, VOLUME0
Formula: Ref($volume, i)/($volume+1e-12) (i from 59 down to 0)
Normalization Notes¶
- Price normalization: all prices (close, open, high, low, VWAP) are divided by the current closing price
- Volume normalization: all volumes are divided by the current volume (with 1e-12 added to avoid division by zero)
- Normalized result: CLOSE0 is identically 1; VOLUME0 is identically 1 (and may be 0 after further normalization)
Label Definition¶
Both factor sets use the same label definition:
["Ref($close, -2)/Ref($close, -1) - 1"], ["LABEL0"]
Meaning: predicting the next day's return
- Numerator: Ref($close, -2) = the closing price at day t+2
- Denominator: Ref($close, -1) = the closing price at day t+1
- Label: (close at t+2 / close at t+1) − 1
Use-Case Comparison¶
When to use Alpha158¶
- Traditional machine learning models: LightGBM, XGBoost, linear regression, etc.
- Complete feature engineering: rich set of technical analysis indicators
- Interpretability: every feature has a clear financial meaning
- Computational efficiency: precomputed indicators make model training fast
When to use Alpha360¶
- Deep learning models: time-series models such as LSTM, GRU, and Transformer
- Sequence modeling: preserves complete time-series information
- Automatic feature extraction: the model learns price patterns on its own
- End-to-end learning: learns predictions directly from raw price data
Data Quality and Preprocessing¶
Missing values¶
- Alpha158 involves division; a
1e-12term is added to denominators to avoid division by zero - Volume-related computations use
($volume+1e-12)to handle zero-volume cases - Checking for and filling NaN values before training is recommended
Outliers¶
- Price gaps and trading suspensions can produce extremes; outlier detection is recommended
- Zero-volume cases are already handled via
1e-12 - Winsorizing features is recommended to curb the influence of extreme values
Normalization recommendations¶
- Alpha158: further Z-score standardization is recommended
- Alpha360: already relatively normalized, but further processing may be needed depending on the model
Source Code Locations¶
- Alpha158 implementation: qlib/contrib/data/loader.py (
Alpha158DL.get_feature_config()) - Alpha360 implementation: qlib/contrib/data/loader.py (
Alpha360DL.get_feature_config()) - Data handlers: qlib/contrib/data/handler.py (the
Alpha158andAlpha360classes)
References¶
- Qlib official documentation
- Rate of Change Indicator
- Moving Average
- RSI Indicator
- Aroon Indicator
- Volume Moving Average
This document was generated from an analysis of the Qlib source code; version details are subject to the actual code.