Skip to content

Usage

Basic commands and recommended usage for custom and bulk processing.

General#

Version#

Prints out the version.

import pandas_ta as ta
print(ta.version)

Versions ≤ 0.3.14b

Bugs encountered in 0.3.14b (or earlier) are no longer being addressd. Before making a bug report, validate that the bug does not exist.


Help#

Ways to utilize Python's help() command for the library.

import pandas as pd
import pandas_ta as ta

# Create an empty DataFrame to access the "ta" extension.
df = pd.DataFrame()

# Indicator Help
help(ta.macd)

# Help about the DataFrame Extension "ta"
help(df.ta)


Indicators and Library Version#

Prints out the list of indicators.

1
2
3
4
5
6
7
import pandas as pd
import pandas_ta as ta

# Create an empty DataFrame to access the "ta" extension.
df = pd.DataFrame()

print(df.ta.indicators())


Programming Conventions#

This library supports three programming conventions: Standard "TA Lib" Convention, Pandas "ta" DataFrame Extension Convention and the Pandas "ta" study() Convention.

Best Practice

For maximum control and flexibility, it is recommended to use the study() method.

TA Lib

If TA Lib installed, TA Lib integrated indicators defaults to TA Lib, i.e. talib=True.

Each "Programming Convention" showcases:

  • The use of default and user specified parameters.
  • Enabling/disabling ta-lib.

    Standard OHLCV Source Indicators Examples

    • ema()
      • Default parameters
    • macd(fast=5, slow=20, talib=False)
      • Disable TA Lib computation
  • Indicator chaining/composition.

    Chained/Composed Indicators Examples

    • ohlc4()
      • Source
    • ema(close=ohlc4)
      • Use ohlc4 as input instead of close
    • macd(close=ohlc4, fast=5, slow=20, talib=False)
      • Disable TA Lib computation


NOTICE

Thanks to all those that have sponsored and dontated to the library in the past! Your support has been greatly appreciated! 🙏

However, future releases are on definite hold until 100+ donations of $150+ have been received via Buy Me a Coffee.

Help keep this library and application the best in it's class!


Example Setup Code#

Also examples assumes yfinance returns at least the following column names: "Open", "High", "Low", "Close", and "Volume"; additional columns are not needed for the library.

1
2
3
4
5
6
7
8
import pandas as pd
import pandas_ta as ta

_df = pd.DataFrame()

df = # df with ohlcv columns
# OR
df = _df.ta.ticker("spy", period="5y")

yfinance

yfinance must be installed to use df.ta.ticker() method.


Standard Convention#

With the above "Example Setup Code", Standard Convention is similar to TA Lib but with lowercase indicator names. The Standard Convention requires more explicit handling of indicator inputs and outputs as well as concatenating to the DataFrame (if needed).

Standard OHLCV Source Indicators Examples

1
2
3
4
5
6
# Since ema() returns a Series, it can immediately be concatenated to the df
df["EMA_10"] = ta.ema(df["Close"])

# Since macd() returns a DataFrame, it must be manually concatenated to the df
macddf = ta.macd(df["Close"], fast=5, slow=20, talib=False)
df = pd.concat([df, macddf])

Chained/Composed Indicators Examples

ohlc4 = ohlc4(df["Open"], df["High"], df["Low"], df["Close"])

# Since ema() returns a Series, it can immediately be concatenated to the df
df["EMAohlc4_10"] = ema(close=ohlc4)

# Since macd() returns a DataFrame, it must be manually concatenated to the df
macddf = macd(close=ohlc4, fast=5, slow=20, talib=False)
# Alternatively ...
# macddf = macd(close=df["EMAohlc4_10"], fast=5, slow=20, talib=False)
df = pd.concat([df, macddf])


DataFrame "ta" Extension Convention#

With the above "Example Setup Code", the DataFrame "ta" Extension Convention simplifies the number of steps to calculate and concatenate the indicators onto the df.

Pandas "ta" DataFrame Columns

The DataFrame "ta" Extension assumes the following columns: "Open", "High", "Low", "Close", and "Volume" exist; additional columns are not needed for the library.

DataFrame Concatenation

DataFrame Concatenation is not automatic. Use append=True, to concatenate the indicators to the df.

Standard OHLCV Source Indicators Examples

df.ta.ema(append=True)
df.ta.macd(fast=5, slow=20, talib=False, append=True)

Chained/Composed Indicators Examples

1
2
3
4
5
6
7
8
9
# One way ...
df.ta.ohlc4(append=True)
df.ta.ema(close=df["OHLC4"], append=True)
df.ta.macd(close=df["OHLC4"], fast=5, slow=20, talib=False, append=True)

# Alternatively ...
ohlc4 = df.ta.ohlc4(append=True)
df.ta.ema(close=ohlc4, append=True)
df.ta.macd(close=ohlc4, fast=5, slow=20, talib=False, append=True)


Pandas "ta" Study Convention#

With the above "Example Setup Code", the Pandas "ta" study() Convention also assumes the following columns: "Open", "High", "Low", "Close", and "Volume" exist in the df.

Standard OHLCV Source Indicators Examples

1
2
3
4
5
6
7
8
9
std_example = ta.Study(
    name="Standard OHLCV Example",
    cores=0,
    ta=[
        {"kind": "ema"},
        {"kind": "macd", "fast": 5, "slow": : 20, "talib": False}
    ]
)
df.ta.study(std_example, verbose=True)

Column Prefixes/Suffixes

The study() also accepts prefix and suffix parameters for additional or simplified naming options. This is useful for indicator chaining to avoid overwriting the results of another indicator with a different source.

Chained/Composed Indicators Examples

chained_example = ta.Study(
    name="Chained Example",
    cores=0,
    ta=[
        { "kind": "ohlc4" },
        { "kind": "ema", "close": "OHLC4", "prefix": "OHLC4" },
        {
            "kind": "macd", "close": "OHLC4",
            "fast": 5, "slow": 20,
            "talib": False, "prefix": "OHLC4"
        }
    ]
)
df.ta.study(chained_example, verbose=True)

Concatenating

The Pandas study() automatically concatenates to the DataFrame.

Multiprocessing

Multiprocessing is only available when using Pandas TA's df.ta.study() method.


"Buy Me A Coffee"

ko-fi