TA-Lib — Technical Analysis Library
TA-Lib is the most authoritative open-source technical analysis library, providing 200+ standard indicators with a C/C++ core for maximum performance. It is the de facto standard for indicator-based feature engineering in A-Share quantitative strategies.
Overview
TA-Lib was first released in 2001 under the BSD License, led by Mario Fortier. Its C core ensures high computational performance, while the Python binding integrates seamlessly into pandas/numpy workflows.
Built-in indicators span multiple groups: Overlap Studies (Trend), Momentum, Volume, Volatility, Price Transform, Pattern Recognition, Cycle Indicators, and Statistic Functions (10 official groups in total).
Official site: TA-Lib GitHub: TA-Lib/ta-lib
Applications in A-Share Quantitative Strategies
1. Machine Learning Feature Engineering
Use TA-Lib indicators as input features for XGBoost/LightGBM models. Commonly used factors:
| Indicator | Function | Financial Meaning |
|---|---|---|
| MACD | talib.MACD() | Trend strength and reversal signal |
| RSI | talib.RSI() | Overbought/oversold strength |
| Bollinger Bands | talib.BBANDS() | Price volatility range |
| ATR | talib.ATR() | True range / stop-loss reference |
| ADX | talib.ADX() | Trend strength filter |
| Stochastic | talib.STOCH() | K/D stochastic oscillator |
2. Candlestick Pattern Recognition
TA-Lib includes 60+ candlestick pattern recognition functions:
talib.CDLHAMMER()— Hammer (bullish reversal at bottom)talib.CDLENGULFING()— Engulfing patterntalib.CDL3BLACKCROWS()— Three Black Crows (bearish top signal)
Returns 100 (bullish), -100 (bearish), or 0 (no signal) — usable as binary classification features.
3. Rule-Based Strategy Signals
Directly use indicators to build rule-based strategies: MACD golden/death cross, RSI threshold breakouts, Bollinger Band range breakouts — forming the signal layer of quantitative strategies.
Quick Reference
import talib
close = df['close'].values
high = df['high'].values
low = df['low'].values
volume = df['volume'].values
# Trend
macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
ma20 = talib.SMA(close, timeperiod=20)
# Momentum
rsi = talib.RSI(close, timeperiod=14)
k, d = talib.STOCH(high, low, close)
# Volatility
upper, mid, lower = talib.BBANDS(close, timeperiod=20)
atr = talib.ATR(high, low, close, timeperiod=14)
# Volume
obv = talib.OBV(close, volume)Installation
# macOS
brew install ta-lib && pip install TA-Lib
# Ubuntu/Debian: libta-lib-dev is NOT in the official apt repos — build from source
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz && cd ta-lib
./configure --prefix=/usr && make && sudo make install
pip install TA-Lib
# conda (recommended — pre-built package on conda-forge)
conda install -c conda-forge ta-lib