Technical Analysis Library in Python
The `ta` library (Technical Analysis Library in Python, also known as `python-ta`) is a Python library designed for feature engineering on financial time series datasets. It provides a comprehensive collection of over 150 technical indicators and candlestick pattern recognition functions, built entirely on the Pandas library. Version 0.11.0 is the current release, and the project maintains an active, albeit intermittent, release cadence with new features and bug fixes.
Warnings
- gotcha This library (`ta` by bukobasabino) is *not* the `TA-Lib` Python wrapper (which uses `import talib`). Despite similar names and functionality, they are distinct projects with different APIs and installation requirements. This `ta` library is pure Python and easier to install, while `TA-Lib` is a Cython wrapper around a C library.
- gotcha The library expects financial time series data with 'Open', 'High', 'Low', 'Close', and 'Volume' columns. Many indicators will produce NaN values for an initial 'lookback' period. It is crucial to handle or clean NaN values in your input DataFrame, either by using `ta.utils.dropna` or other Pandas methods, before applying indicators.
- gotcha While the `ta` library is robust, for extremely large datasets or highly performance-critical real-time applications, the `TA-Lib` Python wrapper (often imported as `talib`) may offer superior performance due to its C-compiled core. The `ta` library prioritizes ease of installation and pure Python implementation.
Install
-
pip install ta
Imports
- add_all_ta_features
from ta import add_all_ta_features
- dropna
from ta.utils import dropna
- RSIIndicator
from ta.momentum import RSIIndicator
Quickstart
import pandas as pd
from ta import add_all_ta_features
from ta.utils import dropna
# Example DataFrame (replace with your actual data)
data = {
'Open': [100, 102, 101, 105, 103, 106, 108, 107, 109, 110],
'High': [103, 104, 105, 106, 107, 108, 110, 110, 112, 113],
'Low': [98, 100, 99, 102, 100, 103, 105, 104, 106, 107],
'Close': [102, 101, 104, 103, 106, 107, 109, 108, 111, 112],
'Volume': [1000, 1200, 1100, 1500, 1300, 1400, 1600, 1550, 1700, 1800]
}
df = pd.DataFrame(data)
# Ensure data has required columns (Open, High, Low, Close, Volume)
# Clean NaN values (optional, but recommended if your data has them)
df_cleaned = dropna(df)
# Add all technical analysis features
df_features = add_all_ta_features(
df_cleaned,
open="Open", high="High", low="Low", close="Close", volume="Volume"
)
print(df_features.head())