Technical Analysis (TA) is an easy to use library that is built upon Python's Pandas library with more than 60 Indicators. These indicators are comminly 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: Moving Average Convergence Divergence (MACD), Hull Exponential Moving Average (HMA), Bollinger Bands (BBANDS), On-Balance Volume (OBV), 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'].
import pandas as pd
import ta as ta
# Load data
df = pd.read_csv('symbol.csv', sep=',')
# Process and append your indicators to the 'df'
df.ta.ema(length=8, append=True)
df.ta.ema(length=21, append=True)
df.ta.sma(length=50, append=True)
df.ta.sma(length=200, append=True)
df.ta.kc(append=True)
df.ta.macd(fast=8, slow=21, signal=9, append=True)
df.ta.rsi(length=14, append=True)
df.ta.obv(append=True)
df.ta.log_return(cumulative=True, append=True)
# New Columns with results
df.columns
# Take a peek
df.tail()
# vv Continue Post Processing vv
- At 70+ indicators.
- Abbreviated Indicator names as listed below.
- Extended Pandas DataFrame as 'ta'. See examples below.
- Parameter names are more consistent.
- Former indicators still exist and are renamed with '_depreciated' append to it's name. For example, 'average_true_range' is now 'average_true_range_depreciated'.
- Refactoring indicators into categories similar to TA-lib.
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, inclusively, it can append the result to the existing DataFrame by including the parameter 'append=True' in the method call. See examples below.
- Awesome Oscillator: ao
- Absolute Price Oscillator: apo
- Balance of Power: bop
- Commodity Channel Index: cci
- Chande Momentum Oscillator: cmo
- Coppock Curve: copc
- KST Oscillator: kst
- Moving Average Convergence Divergence: macd
- Momentum: mom
- Percentage Price Oscillator: ppo
- Rate of Change: roc
- Relative Strength Index: rsi
- Stochastic Oscillator: stoch
- Trix: trix
- True strength index: tsi
- Ultimate Oscillator: uo
- Williams %R: willr
Moving Average Convergence Divergence (MACD) |
---|
- 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.
- Midpoint: midpoint
- Midprice: midprice
- Open-High-Low-Close Average: ohlc4
- Pascal's Weighted Moving Average: pwma
- William's Moving Average: rma
- Simple Moving Average: sma
- T3 Moving Average: t3
- Triple Exponential Moving Average: tema
- Triangular Moving Average: trima
- Volume Weighted Average Price: vwap
- Volume Weighted Moving Average: vwma
- Weighted Moving Average: wma
Simple Moving Averages (SMA) and Bollinger Bands (BBANDS) |
---|
Use parameter: cumulative=True for cumulative results.
- Log Return: log_return
- Percent Return: percent_return
Percent Return (Cumulative) with Simple Moving Average (SMA) |
---|
- Kurtosis: kurtosis
- Mean Absolute Deviation: mad
- Mean: mean
- Alias of sma
- Median: median
- Quantile: quantile
- Skew: skew
- Standard Deviation: stdev
- Variance: variance
- Z Score: zscore
Z Score |
---|
- Average Directional Movement Index: adx
- Aroon Oscillator: aroon
- Decreasing: decreasing
- Detrended Price Oscillator: dpo
- Increasing: increasing
- Vortex Indicator: vortex
Average Directional Movement Index (ADX) |
---|
- Acceleration Bands: accbands
- Average True Range: atr
- Bollinger Bands: bbands
- Donchian Channel: donchain
- Keltner Channel: kc
- Mass Index: massi
- Normalized Average True Range: natr
- True Range: true_range
Average True Range (ATR) |
---|
- Accumulation/Distribution Index: ad
- Accumulation/Distribution Oscillator: adosc
- Chaikin Money Flow: cmf
- Elder's Force Index: efi
- Ease of Movement: eom
- Money Flow Index: mfi
- Negative Volume Index: nvi
- On-Balance Volume: obv
- Price-Volume: pvol
- Price Volume Trend: pvt
On-Balance Volume (OBV) |
---|
https://technical-analysis-library-in-python.readthedocs.io/en/latest/
- English: https://towardsdatascience.com/technical-analysis-library-to-financial-datasets-with-pandas-python-4b2b390d3543
- Spanish: https://medium.com/datos-y-ciencia/biblioteca-de-an%C3%A1lisis-t%C3%A9cnico-sobre-series-temporales-financieras-para-machine-learning-con-cb28f9427d0
$ virtualenv -p python3 virtualenvironment
$ source virtualenvironment/bin/activate
$ pip install ta
To use this library you will need a financial time series dataset including “Open”, “High”, “Low”, “Close” and “Volume” columns. A “Timestamp” or "Date" column is not required, but is typically included anyhow. It is preferred that the original columns are lowercase, however it will do it's best to find the intended column. The majority of Technical Analysis Indicators use price or volume.
You should clean or fill NaN values in your dataset before adding technical analysis indicators.
You can get code examples in examples_to_use folder.
You can visualize the features in this notebook.
import pandas as pd
from ta import ta
# Help about this, 'ta', extension
help(pd.DataFrame().ta)
# List of all indicators
pd.DataFrame().ta.indicators()
# Help about the OBV indicator
help(ta.obv)
# Help about the OBV indicator as a DataFrame Extension
help(pd.DataFrame().ta.obv)
# Load data
spy = pd.read_csv('SPY.csv', sep=',')
# Typical Call
spy_ema50 = ta.ema(spy['close'], length=50)
# Extended Call
spy_ema50 = spy.ta.ema(length=50)
# Extended Call with appending to the 'spy' DataFrame and returning the result
# By default, appending is False
spy_ema50 = spy.ta.ema(length=50, append=True)
# Notice as 'spy_ema50' has been appended to 'spy' DataFrame
spy.columns
# You can also use the 'kind' parameter. Below are equivalent calls.
spy_ema50 = spy.ta(kind='ema', length=50)
spy_ema50 = spy.ta(kind='Ema', length=50)
# Using a non-default series as an input.
# For example instead of having 'ema' using the default 'close' column, have it use the 'open' column instead
spy_ema50_open = spy.ta.ema(close='open', length=50)
import pandas as pd
from ta import *
# Load data
df = pd.read_csv('your-file.csv', sep=',')
# Clean NaN values
df = utils.dropna(df)
# Add ta features filling NaN values
df = add_all_ta_features(df, "Open", "High", "Low", "Close", "Volume_BTC", fillna=True)
import pandas as pd
from ta import *
# Load datas
df = pd.read_csv('your-file.csv', sep=',')
# Clean NaN values
df = utils.dropna(df)
# Add bollinger band high indicator filling NaN values
df['bb_high_indicator'] = bollinger_hband_indicator_depreciated(df["Close"], n=20, ndev=2, fillna=True)
# Add bollinger band low indicator filling NaN values
df['bb_low_indicator'] = bollinger_lband_indicator_depreciated(df["Close"], n=20, ndev=2, fillna=True)
$ git clone https://github.com/bukosabino/ta.git
$ cd ta
$ pip install -r requirements.txt
$ cd dev
$ python bollinger_band_features_example.py
- https://en.wikipedia.org/wiki/Technical_analysis
- https://pandas.pydata.org
- https://github.com/FreddieWitherden/ta
- https://github.com/femtotrader/pandas_talib
- Add more technical analysis features.
- Incorporate dask library to parallelize
Developed by Bukosabino at Lecrin Technologies - http://lecrintech.com
Expanded and Extended (via Pandas) by Kevin Johnson - https://github.com/twopirllc
Please leave any comments, feedback, or suggestions.