Skip to content

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:

IndicatorFunctionFinancial Meaning
MACDtalib.MACD()Trend strength and reversal signal
RSItalib.RSI()Overbought/oversold strength
Bollinger Bandstalib.BBANDS()Price volatility range
ATRtalib.ATR()True range / stop-loss reference
ADXtalib.ADX()Trend strength filter
Stochastictalib.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 pattern
  • talib.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 ​

python
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 ​

bash
# 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

Official References ​

⚡ Real-time Data · 📊 Smart Analysis · 🎯 Backtesting