Pandas Technical Analysis (Pandas TA) is an easy to use library that is built upon Python's Pandas library with more than 100 Indicators. These indicators are commonly used for financial time series datasets with columns or labels similar to: datetime, open, high, low, close, volume, et al. Many commonly used indicators are included, such as: Simple Moving Average (SMA) Moving Average Convergence Divergence (MACD), Hull Exponential Moving Average (HMA), Bollinger Bands (BBANDS), On-Balance Volume (OBV), Aroon & Aroon Oscillator (AROON) and more.
This version contains both the orignal code branch as well as a newly refactored branch with the option to use Pandas DataFrame Extension mode.
All the indicators return a named Series or a DataFrame in uppercase underscore parameter format. For example, MACD(fast=12, slow=26, signal=9) will return a DataFrame with columns: ['MACD_12_26_9', 'MACDh_12_26_9', 'MACDs_12_26_9'].
Features
Has 100+ indicators and utility functions.
Option to use multiprocessing when using df.ta.strategy(). See below.
Example Jupyter Notebook under the examples directory.
A new 'ta' method called 'strategy' that be default, runs all the indicators.
Abbreviated Indicator names as listed below.
Extended Pandas DataFrame as 'ta'.
Easily add prefixes or suffixes or both to columns names.
Above (above)
Above Value (above_value)
Below (below)
Below Value (below_value)
Cross Value (cross_value)
User Added Indicators:
Aberration (aberration)
BRAR (brar)
Corrected Indicators:
Absolute Price Oscillator (apo)
Aroon & Aroon Oscillator (aroon)
* Fixed indicator and included oscillator in returned dataframe
Bollinger Bands (bbands)
Commodity Channel Index (cci)
Chande Momentum Oscillator (cmo)
Relative Vigor Index (rvgi)
Symmetric Weighted Moving Average (swma)
What is a Pandas DataFrame Extension?
A Pandas DataFrame Extension, extends a DataFrame allowing one to add more functionality and features to Pandas to suit your needs. As such, it is now easier to run Technical Analysis on existing Financial Time Series without leaving the current DataFrame. This extension by default returns the Indicator result or it can append the result to the existing DataFrame by including the parameter 'append=True' in the method call. Examples below.
importpandasaspdimportpandas_taasta# Load datadf=pd.read_csv('symbol.csv', sep=',')
# Calculate Returns and append to the df DataFramedf.ta.log_return(cumulative=True, append=True)
df.ta.percent_return(cumulative=True, append=True)
# New Columns with resultsdf.columns# Take a peekdf.tail()
# vv Continue Post Processing vv
Module and Indicator Help
importpandasaspdimportpandas_taasta# Help about this, 'ta', extensionhelp(pd.DataFrame().ta)
# List of all indicatorspd.DataFrame().ta.indicators()
# Help about the log_return indicatorhelp(ta.log_return)
New DataFrame Method: strategy with Multiprocessing
Strategy is a new Pandas (TA) method to facilitate bulk indicator processing. By default, running df.ta.strategy() will append all
applicable indicators to DataFrame df. Utility methods like above, below et al are not included.
The ta.strategy() method is still under development. Future iterations will allow you to load a ta.json config file with your specific strategy name and parameters to automatically run you bulk indicators.
# This property only effects df.ta.strategy(). When set to True,# it enables multiprocessing when processing "ALL" the indicators.# Default is Falsedf.ta.mp=True# Runs and appends all indicators to the current DataFrame by default# The resultant DataFrame will be large.df.ta.strategy()
# Or equivalently use name='all'df.ta.strategy(name='all')
# Use verbose if you want to make sure it is running.df.ta.strategy(verbose=True)
# Use timed if you want to see how long it takes to run.df.ta.strategy(timed=True)
# You can change the number of cores to use. Though the# default will usually be bestdf.ta.strategy(cores=4)
# Maybe you do not want certain indicators.# Just exclude (a list of) them.df.ta.strategy(exclude=['bop', 'mom', 'percent_return', 'wcp', 'pvi'], verbose=True)
# Perhaps you want to use different values for indicators.# This will run ALL indicators that have fast or slow as parameters.# Check your results and exclude as necessary.df.ta.strategy(fast=10, slow=50, verbose=True)
# Sanity check. Make sure all the columns are theredf.columns
New DataFrame Properties: reverse & datetime_ordered
# The 'reverse' is a helper property that returns the DataFrame# in reverse orderdf=df.ta.reverse# The 'datetime_ordered' property returns True if the DataFrame# index is of Pandas datetime64 and df.index[0] < df.index[-1]# Otherwise it return Falsetime_series_in_order=df.ta.datetime_ordered
DataFrame Property: adjusted
# Set ta to default to an adjusted column, 'adj_close', overriding default 'close'df.ta.adjusted='adj_close'df.ta.sma(length=10, append=True)
# To reset back to 'close', set adjusted back to Nonedf.ta.adjusted=None
Technical Analysis Indicators (by Category)
Candles (2)
Doji: cdl_doji
Heikin-Ashi: ha
Momentum (27)
Awesome Oscillator: ao
Absolute Price Oscillator: apo
Bias: bias
Balance of Power: bop
BRAR: brar
Commodity Channel Index: cci
Center of Gravity: cg
Chande Momentum Oscillator: cmo
Coppock Curve: coppock
Fisher Transform: fisher
Inertia: inertia
KDJ: kdj
KST Oscillator: kst
Moving Average Convergence Divergence: macd
Momentum: mom
Percentage Price Oscillator: ppo
Psychological Line: psl
Percentage Volume Oscillator: pvo
Rate of Change: roc
Relative Strength Index: rsi
Relative Vigor Index: rvgi
Slope: *slope
Stochastic Oscillator: stoch
Trix: trix
True strength index: tsi
Ultimate Oscillator: uo
Williams %R: willr
Moving Average Convergence Divergence (MACD)
Overlap (26)
Double Exponential Moving Average: dema
Exponential Moving Average: ema
Fibonacci's Weighted Moving Average: fwma
High-Low Average: hl2
High-Low-Close Average: hlc3
Commonly known as 'Typical Price' in Technical Analysis literature
Hull Exponential Moving Average: hma
Ichimoku Kinkō Hyō: ichimoku
Use: help(ta.ichimoku). Returns two DataFrames.
Kaufman's Adaptive Moving Average: kama
Linear Regression: linreg
Midpoint: midpoint
Midprice: midprice
Open-High-Low-Close Average: ohlc4
Pascal's Weighted Moving Average: pwma
William's Moving Average: rma
Sine Weighted Moving Average: sinwma
Simple Moving Average: sma
Supertrend: supertrend
Symmetric Weighted Moving Average: swma
T3 Moving Average: t3
Triple Exponential Moving Average: tema
Triangular Moving Average: trima
Volume Weighted Average Price: vwap
Volume Weighted Moving Average: vwma
Weighted Closing Price: wcp
Weighted Moving Average: wma
Zero Lag Moving Average: zlma
Simple Moving Averages (SMA) and Bollinger Bands (BBANDS)
Performance (3)
Use parameter: cumulative=True for cumulative results.
Log Return: log_return
Percent Return: percent_return
Trend Return: trend_return
Percent Return (Cumulative) with Simple Moving Average (SMA)