TA-Lib is a very famous technical analysis library for financial market data. It provides 200 technical indicators such as MACD, RSI, Stochastic, Bollinger Bands, etc. It also includes candlestick pattern recognition functions.
Installation
Do the followings to install the Python wrapper of TA-Lib:
# Install TA-Lib: https://www.ta-lib.org wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz tar -xvzf ta-lib-0.4.0-src.tar.gz cd ta-lib ./configure --prefix=/usr make make install # Install Python wrapper. pip install TA-Lib
Usage
All function API supports both numpy.ndarray
and pandas.Series
as input.
#!/usr/bin/python3 import numpy as np import talib # Display all functions. #~ print(talib.get_functions()) # Display list of functions of group. print(talib.get_function_groups()['Overlap Studies']) #~ print(talib.get_function_groups()['Momentum Indicators']) #~ print(talib.get_function_groups()['Volume Indicators']) #~ print(talib.get_function_groups()['Volatility Indicators']) #~ print(talib.get_function_groups()['Pattern Recognition']) #~ print(talib.get_function_groups()['Cycle Indicators']) #~ print(talib.get_function_groups()['Statistic Functions']) #~ print(talib.get_function_groups()['Price Transform']) #~ print(talib.get_function_groups()['Math Transform']) #~ print(talib.get_function_groups()['Math Operators']) # Display information about SMA, Simple Moving Average # and how to call it. help(talib.SMA) # Calculate Simple Moving Average. ############################### sma_data = np.array([ 81.59, 81.06, 82.87, 83, 83.61, 83.15, 82.84, 83.99, 84.55, 84.36, 85.53, 86.54, 86.89, 87.77, 87.29]) sma_results = talib.SMA(sma_data, timeperiod=5) print(sma_results)
Output
['BBANDS', 'DEMA', 'EMA', 'HT_TRENDLINE', 'KAMA', 'MA', 'MAMA', 'MAVP', 'MIDPOINT', 'MIDPRICE', 'SAR', 'SAREXT', 'SMA', 'T3', 'TEMA', 'TRIMA', 'WMA'] Help on function SMA in module talib._ta_lib: SMA(...) SMA(real[, timeperiod=?]) Simple Moving Average (Overlap Studies) Inputs: real: (any ndarray) Parameters: timeperiod: 30 Outputs: real [ nan nan nan nan 82.426 82.738 83.094 83.318 83.628 83.778 84.254 84.994 85.574 86.218 86.804]
Documentation of all functions
- Overlap Studies
- Momentum Indicators
- Volume Indicators
- Volatility Indicators
- Pattern Recognition
- Cycle Indicators
- Statistic Functions
- Price Transform
- Math Transform
- Math Operators
Reference
- https://www.ta-lib.org/function.html
- https://sourceforge.net/p/ta-lib/code/HEAD/tree/trunk/ta-lib/c/src/ta_func/
- https://zorro-trader.com/manual/en/candle.htm