View on GitHub

TA-Lib

Python wrapper for TA-Lib (https://ta-lib.org/).

Download this project as a .zip file Download this project as a tar.gz file

Function API Examples

Similar to TA-Lib, the function interface provides a lightweight wrapper of the exposed TA-Lib indicators.

Each function returns an output array and have default values for their parameters, unless specified as keyword arguments. Typically, these functions will have an initial "lookback" period (a required number of observations before an output is generated) set to NaN.

The lookback is function-specific and may be larger than the timeperiod parameter. For example, RSI(timeperiod=14) needs 15 price observations, because the first RSI value is derived from 14 consecutive price changes.

All of the following examples use the function API:

import numpy
import talib

close = 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_Type

upper, 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)

Functions documented as having an unstable period start with that extra unstable-period setting at 0. get_unstable_period() only returns a non-zero value after you set one explicitly with set_unstable_period().

Documentation for all functions:

Documentation Index Next: Using the Abstract API