Pandas TA Logo

A Popular & Comprehensive Technical Analysis Library in Python 3

  Easy to Use

Conventional calling similar to TA Lib or simplified calling with a Pandas DataFrame.

  Large Library

Has more than 200 indicators with a flat library structure similar to TA Lib as well as few dependencies: Pandas and Numba.

  Accurate and Performant

Highly correlated to primarily TA Lib and secondarily to TradingView.

  Library Status

Features and Maintenance relies upon contributions, donations and sponsorships. As it stands, the library is in danger of archival if donations & sponsorships continue to remain at unsustainable levels. šŸ™

Description

Pandas TA is a Popular Comprehensive Technical Analysis Library in Python 3 leveraging numpy for accuracy, numba for performance, and pandas for brevity. The library contains more than 150 indicators and utilities and more than 60 Candelstick Patterns (when TA Lib is installed).

Features

With so many indicators, it can be difficult to keep track of all the different indicator arguments. For more details about an indicator, run help(ta.indicator_name) to get details on the indicator's arguments and return types before submitting an Issue.

Note: If TA Lib is installed, Pandas TA will automatically run the TA Lib version unless the keyword argument talib=False is used.

  • A large flat library structure similar to TA Lib and wraps TA Lib if installed.
  • Indicators are equivalent, if not highly correlated, to TA Lib first and secondly with Trading View
  • Performance improvements using numba
  • Store private indicators in a Custom Directory
        See:  help(ta.import_dir)
  • Data Leak Mitigation for indicators: dpo and ichimoku
        Include keyword argument: lookahead=False to disable look ahead bias.
  • Backtesting Support with the Signal and Trend indicators
        See: help(ta.tsignals) and help(ta.xsignals)
  • Performance Metrics | Beta

  • A Pandas DataFrame Extension named "ta" that simplifies development.
       The extension provides additional properties, methods, and indicators.
  • Create Custom Indicator Sets by creating a "Study" (fomerly "Strategy" in v0.3.14b).
  • Easily add prefixes or suffixes or both to indicator results.
       Useful for Studies and Chained/Composed indicators.
  • Bulk indicator processing support is enabled by default.
       Disable multiprocessing by using the keyword argument cores=0 in df.ta.study().
      Note Multiprocessing has it's own overhead. Test how many cpus, if needed, boost performance.
  • Data Acquisition using: df.ta.ticker(). Default: yfinance.
  • For a list of all DataFrame Extension indicators, run: df.ta.indicators()

Getting Started

Installation

Main

The last stable release, 0.3.14b, via pypi.

  Update to the development version if encountering many issues or running Python ≤ 3.10.

 pip install -U pandas-ta

Development

Most update to date version with the latest improvements including: indicators, features, speed, documentation, and bug fixes.

  pip install -U git+https://github.com/twopirllc/pandas-ta.git@development

Local (zip)

Installation issues? Download the preferred version, unzip in application directory and install.

Programming Conventions

The library provides three Programming Conventions: Standard, Pandas DataFrame Extension, and the Pandas TA Study to simplify the workflow. The following examples illustrate the different conventions.

Standard Convention

This convention is a common and familiar style among software libraries and was designed to be similar to TA Lib in form and function. As such, it is more verbose regarding and managing inputs and outputs.

import pandas as pd
import pandas_ta as ta

# Load Data
df = # 'ohlcv' data
# OR if 'yfinance' installed and Python 3.11 or 3.12
df = pd.DataFrame().ta.ticker("aapl", period="5y")

# -- Pre Process --

# If VWAP is needed, set the DataFrame index to a DatetimeIndex
# Replace "datetime" with appropriate column for your DataFrame
df.set_index(pd.DatetimeIndex(df["datetime"], inplace=True))

# Manually calculate indicators and append to the df
# For simplicity of example, assumes ohlcv names are lowercase
sma10 = ta.sma(df.close, length=10, talib=False)  # Returns a pd.Series
macddf = ta.macd(df.close, talib=False)            # Returns a pd.DataFrame
clogret = ta.log_return(df.close, cumulative=True)# Returns a pd.Series

# Manually append/concat columns to the DataFrame
df = pd.concat([df, sma10, macddf, clogret], axis=0)

# Verify columns were appended
print(", ".join(df.columns))

# Take a peek
df.tail()

# PTA Version info for Issues
print(df.ta.version)
# -- Post Process --

Pandas TA Study Convention

This Convention utilizes the DataFrame Extension method called study(), help(df.ta.study), to process "All", "Categories" or "Custom" groups of indicators with Python's multiprocessing, the default, or without mulitprocessing, when cores=0.

import pandas as pd
import pandas_ta as ta

# Load Data
df = # 'ohlcv' data
# OR if 'yfinance' installed and Python 3.11 or 3.12
df = pd.DataFrame().ta.ticker("aapl", period="5y")

# -- Pre Process --

# If VWAP is needed, set the DataFrame index to a DatetimeIndex
# Replace "datetime" with appropriate column for your DataFrame
df.set_index(pd.DatetimeIndex(df["datetime"], inplace=True))

# Create a Study DataClass... It takes an array of dicts/json
# Note: Multiprocessing is for indicator groups > 100
#       For smaller groups, < 100 or chaining indicators,
#       setting cores=0 will be much faster
demo = ta.Study(
  name="Demo Study",
  cores=0,
  ta=[
    {"kind": "sma", "length": 10, "talib": True},
    {"kind": "macd", "talib": False},
    {"kind": "log_return", "cumulative": True},
  ]
)
df.ta.study(demo)

# Verify columns were appended
print(", ".join(df.columns))

# Take a peek
df.tail()

# PTA Version info for Issues
print(df.ta.version)

# -- Post Process --