TA-Lib (Python Wrapper)

0.6.8 · active · verified Mon Apr 13

TA-Lib is a Python wrapper for the widely-used TA-Lib C library, designed for technical analysis of financial market data. It provides over 150 indicators and candlestick pattern recognition functions, optimized for performance using Cython and NumPy. The current Python wrapper version is 0.6.8, and it maintains compatibility branches for different NumPy and underlying C TA-Lib versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates calculating common technical indicators like Simple Moving Average (SMA) and Relative Strength Index (RSI) using `ta-lib` with both NumPy arrays and Pandas Series as input. Note that `ta-lib` functions return `NaN` for the initial 'lookback' periods where insufficient data is available to compute the indicator.

import numpy as np
import talib
import pandas as pd

# Simulate some financial close prices
np.random.seed(42)
close_prices = np.random.rand(100) * 100 + 50

# Calculate Simple Moving Average (SMA)
sma = talib.SMA(close_prices, timeperiod=10)
print("SMA (first 15 values):", sma[:15])

# Calculate Relative Strength Index (RSI)
rsi = talib.RSI(close_prices, timeperiod=14)
print("RSI (first 15 values):", rsi[:15])

# TA-Lib functions return NaN for initial 'lookback' periods
# Example with Pandas Series input
df = pd.DataFrame({'Close': close_prices})
df['SMA'] = talib.SMA(df['Close'], timeperiod=10)
print("\nDataFrame with SMA (first 15 rows):\n", df.head(15))

view raw JSON →