Python wrapper for TA-Lib (https://ta-lib.org/).
This is a Python wrapper for TA-LIB based on Cythoninstead of SWIG. From the homepage:
TA-Lib is widely used by trading software developers requiring to performtechnical analysis of financial market data.
- Includes 150+ indicators such as ADX, MACD, RSI, Stochastic, BollingerBands, etc.
- Candlestick pattern recognition
- Open-source API for C/C++, Java, Perl, Python and 100% Managed .NET
The original Python bindings use SWIG which unfortunatelyare difficult to install and aren't as efficient as they could be. Thereforethis project uses Cython and Numpy to efficiently and cleanly bind to TA-Lib-- producing results 2-4 times faster than the SWIG interface.
Install TA-Lib or Read the Docs
Examples
Similar to TA-Lib, the function interface provides a lightweight wrapper ofthe exposed TA-Lib indicators.
Each function returns an output array and have default values for theirparameters, unless specified as keyword arguments. Typically, these functionswill have an initial "lookback" period (a required number of observationsbefore an output is generated) set to NaN
.
All of the following examples use the function API:
import numpyimport talibclose = numpy.random.random(100)
Calculate a simple moving average of the close prices:
output = talib.SMA(close)
Calculating bollinger bands, with triple exponential moving average:
from talib import MA_Typeupper, middle, lower = talib.BBANDS(close, matype=MA_Type.T3)
Calculating momentum of the close prices, with a time period of 5:
output = talib.MOM(close, timeperiod=5)
Abstract API Quick Start
If you're already familiar with using the function API, you should feel rightat home using the abstract API. Every function takes the same input, passedas a dictionary of Numpy arrays:
import numpy as np# note that all ndarrays must be the same length!inputs = { 'open': np.random.random(100), 'high': np.random.random(100), 'low': np.random.random(100), 'close': np.random.random(100), 'volume': np.random.random(100)}
Functions can either be imported directly or instantiated by name:
from talib import abstractsma = abstract.SMAsma = abstract.Function('sma')
From there, calling functions is basically the same as the function API:
from talib.abstract import *output = SMA(input_arrays, timeperiod=25) # calculate on close prices by defaultoutput = SMA(input_arrays, timeperiod=25, price='open') # calculate on opensupper, middle, lower = BBANDS(input_arrays, 20, 2, 2)slowk, slowd = STOCH(input_arrays, 5, 3, 0, 3, 0) # uses high, low, close by defaultslowk, slowd = STOCH(input_arrays, 5, 3, 0, 3, 0, prices=['high', 'low', 'open'])
Learn about more advanced usage of TA-Lib here.
Supported Indicators
We can show all the TA functions supported by TA-Lib, either as a list
oras a dict
sorted by group (e.g. "Overlap Studies", "Momentum Indicators",etc):
import talibprint talib.get_functions()print talib.get_function_groups()
Function Groups
- Overlap Studies
- Momentum Indicators
- Volume Indicators
- Volatility Indicators
- Price Transform
- Cycle Indicators
- Pattern Recognition
- Statistic Functions
- Math Transform
- Math Operators
Overlap Studies
BBANDS Bollinger BandsDEMA Double Exponential Moving AverageEMA Exponential Moving AverageHT_TRENDLINE Hilbert Transform - Instantaneous TrendlineKAMA Kaufman Adaptive Moving AverageMA Moving averageMAMA MESA Adaptive Moving AverageMAVP Moving average with variable periodMIDPOINT MidPoint over periodMIDPRICE Midpoint Price over periodSAR Parabolic SARSAREXT Parabolic SAR - ExtendedSMA Simple Moving AverageT3 Triple Exponential Moving Average (T3)TEMA Triple Exponential Moving AverageTRIMA Triangular Moving AverageWMA Weighted Moving Average
Momentum Indicators
ADX Average Directional Movement IndexADXR Average Directional Movement Index RatingAPO Absolute Price OscillatorAROON AroonAROONOSC Aroon OscillatorBOP Balance Of PowerCCI Commodity Channel IndexCMO Chande Momentum OscillatorDX Directional Movement IndexMACD Moving Average Convergence/DivergenceMACDEXT MACD with controllable MA typeMACDFIX Moving Average Convergence/Divergence Fix 12/26MFI Money Flow IndexMINUS_DI Minus Directional IndicatorMINUS_DM Minus Directional MovementMOM MomentumPLUS_DI Plus Directional IndicatorPLUS_DM Plus Directional MovementPPO Percentage Price OscillatorROC Rate of change : ((price/prevPrice)-1)*100ROCP Rate of change Percentage: (price-prevPrice)/prevPriceROCR Rate of change ratio: (price/prevPrice)ROCR100 Rate of change ratio 100 scale: (price/prevPrice)*100RSI Relative Strength IndexSTOCH StochasticSTOCHF Stochastic FastSTOCHRSI Stochastic Relative Strength IndexTRIX 1-day Rate-Of-Change (ROC) of a Triple Smooth EMAULTOSC Ultimate OscillatorWILLR Williams' %R
Volume Indicators
AD Chaikin A/D LineADOSC Chaikin A/D OscillatorOBV On Balance Volume
Volatility Indicators
ATR Average True RangeNATR Normalized Average True RangeTRANGE True Range
Price Transform
AVGPRICE Average PriceMEDPRICE Median PriceTYPPRICE Typical PriceWCLPRICE Weighted Close Price
Cycle Indicators
HT_DCPERIOD Hilbert Transform - Dominant Cycle PeriodHT_DCPHASE Hilbert Transform - Dominant Cycle PhaseHT_PHASOR Hilbert Transform - Phasor ComponentsHT_SINE Hilbert Transform - SineWaveHT_TRENDMODE Hilbert Transform - Trend vs Cycle Mode
Pattern Recognition
CDL2CROWS Two CrowsCDL3BLACKCROWS Three Black CrowsCDL3INSIDE Three Inside Up/DownCDL3LINESTRIKE Three-Line StrikeCDL3OUTSIDE Three Outside Up/DownCDL3STARSINSOUTH Three Stars In The SouthCDL3WHITESOLDIERS Three Advancing White SoldiersCDLABANDONEDBABY Abandoned BabyCDLADVANCEBLOCK Advance BlockCDLBELTHOLD Belt-holdCDLBREAKAWAY BreakawayCDLCLOSINGMARUBOZU Closing MarubozuCDLCONCEALBABYSWALL Concealing Baby SwallowCDLCOUNTERATTACK CounterattackCDLDARKCLOUDCOVER Dark Cloud CoverCDLDOJI DojiCDLDOJISTAR Doji StarCDLDRAGONFLYDOJI Dragonfly DojiCDLENGULFING Engulfing PatternCDLEVENINGDOJISTAR Evening Doji StarCDLEVENINGSTAR Evening StarCDLGAPSIDESIDEWHITE Up/Down-gap side-by-side white linesCDLGRAVESTONEDOJI Gravestone DojiCDLHAMMER HammerCDLHANGINGMAN Hanging ManCDLHARAMI Harami PatternCDLHARAMICROSS Harami Cross PatternCDLHIGHWAVE High-Wave CandleCDLHIKKAKE Hikkake PatternCDLHIKKAKEMOD Modified Hikkake PatternCDLHOMINGPIGEON Homing PigeonCDLIDENTICAL3CROWS Identical Three CrowsCDLINNECK In-Neck PatternCDLINVERTEDHAMMER Inverted HammerCDLKICKING KickingCDLKICKINGBYLENGTH Kicking - bull/bear determined by the longer marubozuCDLLADDERBOTTOM Ladder BottomCDLLONGLEGGEDDOJI Long Legged DojiCDLLONGLINE Long Line CandleCDLMARUBOZU MarubozuCDLMATCHINGLOW Matching LowCDLMATHOLD Mat HoldCDLMORNINGDOJISTAR Morning Doji StarCDLMORNINGSTAR Morning StarCDLONNECK On-Neck PatternCDLPIERCING Piercing PatternCDLRICKSHAWMAN Rickshaw ManCDLRISEFALL3METHODS Rising/Falling Three MethodsCDLSEPARATINGLINES Separating LinesCDLSHOOTINGSTAR Shooting StarCDLSHORTLINE Short Line CandleCDLSPINNINGTOP Spinning TopCDLSTALLEDPATTERN Stalled PatternCDLSTICKSANDWICH Stick SandwichCDLTAKURI Takuri (Dragonfly Doji with very long lower shadow)CDLTASUKIGAP Tasuki GapCDLTHRUSTING Thrusting PatternCDLTRISTAR Tristar PatternCDLUNIQUE3RIVER Unique 3 RiverCDLUPSIDEGAP2CROWS Upside Gap Two CrowsCDLXSIDEGAP3METHODS Upside/Downside Gap Three Methods
Statistic Functions
BETA BetaCORREL Pearson's Correlation Coefficient (r)LINEARREG Linear RegressionLINEARREG_ANGLE Linear Regression AngleLINEARREG_INTERCEPT Linear Regression InterceptLINEARREG_SLOPE Linear Regression SlopeSTDDEV Standard DeviationTSF Time Series ForecastVAR Variance