pandas-ta Technical Analysis Library
pandas-ta is a comprehensive Python 3 library for technical analysis, extending Pandas Dataframes with a wide range of indicators. It's designed for quantitative researchers, traders, and investors, providing an easy-to-use API for applying financial indicators directly to Dataframes. The current version is 0.4.71b0 (beta), indicating active development and frequent updates.
Warnings
- breaking The default behavior of `append` for the `df.ta` accessor changed from `True` to `False` in version 0.4.0. Previously, applying `df.ta.indicator()` or `df.ta.strategy()` would directly add new columns to the original DataFrame. Now, you must explicitly pass `append=True` to modify the original DataFrame, or capture the output of individual indicator functions.
- breaking The `df.ta.strategy()` method underwent significant changes in 0.4.0. Its arguments and internal logic for applying multiple indicators were refactored. Older custom strategies or direct calls to `df.ta.strategy` might no longer work as expected without modification.
- gotcha The library is currently in a beta release series (e.g., `0.4.71b0`). While generally stable, this indicates ongoing development, and minor API adjustments or behavior changes might occur between beta versions or upon a full `0.4.x` stable release.
- gotcha Many technical indicators require specific columns (e.g., 'Open', 'High', 'Low', 'Close', 'Volume') to be present in the DataFrame. Missing or incorrectly named columns will raise `KeyError` or produce incorrect results/NaNs.
- gotcha Default parameters (e.g., `length`, `period`, `std_dev`) for indicators might not always align with your trading strategy or analysis needs. Relying solely on defaults can lead to unexpected results.
Install
-
pip install pandas_ta
Imports
- pandas_ta
import pandas_ta as ta
Quickstart
import pandas as pd
import pandas_ta as ta
import io
# Sample financial data (usually loaded from CSV, API, etc.)
data = """Open,High,Low,Close,Volume
100,105,99,103,1000
103,108,102,107,1200
107,112,106,110,1100
110,115,109,114,1300
114,119,113,117,1400
117,122,116,120,1500
120,125,119,123,1600
123,128,122,127,1700
127,132,126,130,1800
130,135,129,133,1900
"""
df = pd.read_csv(io.StringIO(data))
# Extend pandas with pandas-ta and apply a strategy
# By default, indicators are not appended to the original DataFrame in v0.4+
# Use append=True if you want to modify the original df, or reassign.
# For quickstart, we'll demonstrate adding to a new df to show the result clearly
# Apply a single indicator (e.g., Simple Moving Average)
df['SMA_10'] = ta.sma(df['Close'], length=3) # Example length
# Apply a full strategy (e.g., 'All' or a custom one)
# By default, 'append=False' in v0.4+ for df.ta accessor.
# Let's create a new DataFrame to show the strategy results cleanly.
strat_df = df.copy()
strat_df.ta.strategy("All") # Applies a set of common indicators
print("DataFrame with SMA:")
print(df.tail())
print("\nDataFrame with 'All' strategy indicators (new columns only):")
print(strat_df.tail())
# To see only the newly added columns for strategy:
# print(strat_df.drop(columns=['Open', 'High', 'Low', 'Close', 'Volume']).tail())