100% found this document useful (1 vote)
520 views38 pages

Python Technical Analysis Library Guide

This document provides documentation for a Technical Analysis library for Python that can be used to perform feature engineering on financial time series datasets. It describes momentum indicators included in the library such as Awesome Oscillator, Kaufman's Adaptive Moving Average, Money Flow Index, and Rate of Change. The library is built on Pandas and aims to help with technical analysis of financial datasets for tasks like identifying trends and turning points.

Uploaded by

James Liu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
520 views38 pages

Python Technical Analysis Library Guide

This document provides documentation for a Technical Analysis library for Python that can be used to perform feature engineering on financial time series datasets. It describes momentum indicators included in the library such as Awesome Oscillator, Kaufman's Adaptive Moving Average, Money Flow Index, and Rate of Change. The library is built on Pandas and aims to help with technical analysis of financial datasets for tasks like identifying trends and turning points.

Uploaded by

James Liu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Installation (python 3)
  • Examples
  • Motivation
  • Documentation
  • Indices and tables
  • Python Module Index
  • Index

Technical Analysis Library in Python

Documentation
Release 0.1.4

Dario Lopez Padial (Bukosabino)

Oct 22, 2019


Contents

1 Installation (python 3) 3

2 Examples 5

3 Motivation 7

4 Contents 9
4.1 Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5 Indices and tables 29

Python Module Index 31

Index 33

i
ii
Technical Analysis Library in Python Documentation, Release 0.1.4

It is a Technical Analysis library to financial time series datasets (open, close, high, low, volume). You can use it to do
feature engineering from financial datasets. It is builded on Python Pandas library.

Contents 1
Technical Analysis Library in Python Documentation, Release 0.1.4

2 Contents
CHAPTER 1

Installation (python 3)

> virtualenv -p python3 virtualenvironment


> source virtualenvironment/bin/activate
> pip install ta

3
Technical Analysis Library in Python Documentation, Release 0.1.4

4 Chapter 1. Installation (python 3)


CHAPTER 2

Examples

Adding all features:

import pandas as pd
from ta import *

# Load datas
df = pd.read_csv('[Link]', sep=',')

# Clean nan values


df = [Link](df)

# Add ta features filling Nans values


df = add_all_ta_features(df, "Open", "High", "Low", "Close", "Volume_BTC",
˓→fillna=True)

Adding individual features:

import pandas as pd
from ta import *

# Load datas
df = pd.read_csv('[Link]', sep=',')

# Clean nan values


df = [Link](df)

# Add bollinger band high indicator filling Nans values


df['bb_high_indicator'] = bollinger_hband_indicator(df["Close"], n=20, ndev=2,
˓→fillna=True)

# Add bollinger band low indicator filling Nans values


df['bb_low_indicator'] = bollinger_lband_indicator(df["Close"], n=20, ndev=2,
˓→fillna=True)

5
Technical Analysis Library in Python Documentation, Release 0.1.4

6 Chapter 2. Examples
CHAPTER 3

Motivation

• English: [Link]
• Spanish: [Link]
A9cnico-sobre-series-temporales-financieras-para-machine-learning-con-cb28f9427d0

7
Technical Analysis Library in Python Documentation, Release 0.1.4

8 Chapter 3. Motivation
CHAPTER 4

Contents

4.1 Documentation

It is a technical analysis library to financial time series datasets. You can use it to do feature engineering from financial
datasets. It is builded on pandas python library.

4.1.1 Momentum Indicators

Momentum Indicators.
[Link](high, low, s=5, len=34, fillna=False)
Awesome Oscillator
From: [Link]
The Awesome Oscillator is an indicator used to measure market momentum. AO calculates the difference of a
34 Period and 5 Period Simple Moving Averages. The Simple Moving Averages that are used are not calculated
using closing price but rather each bar’s midpoints. AO is generally used to affirm trends or to anticipate possible
reversals.
From: [Link]
Awesome Oscillator is a 34-period simple moving average, plotted through the central points of the bars
(H+L)/2, and subtracted from the 5-period simple moving average, graphed across the central points of the
bars (H+L)/2.
MEDIAN PRICE = (HIGH+LOW)/2
AO = SMA(MEDIAN PRICE, 5)-SMA(MEDIAN PRICE, 34)
where
SMA — Simple Moving Average.
Parameters
• high ([Link]) – dataset ‘High’ column.

9
Technical Analysis Library in Python Documentation, Release 0.1.4

• low ([Link]) – dataset ‘Low’ column.


• s (int) – short period
• len (int) – long period
• fillna (bool) – if True, fill nan values with -50.
Returns New feature generated.
Return type [Link]
[Link](close, n=10, pow1=2, pow2=30, fillna=False)
Kaufman’s Adaptive Moving Average (KAMA)
Moving average designed to account for market noise or volatility. KAMA will closely follow prices when the
price swings are relatively small and the noise is low. KAMA will adjust when the price swings widen and
follow prices from a greater distance. This trend-following indicator can be used to identify the overall trend,
time turning points and filter price movements.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column
• n (int) – n number of periods for the efficiency ratio
• pow1 (int) – number of periods for the fastest EMA constant
• pow2 (int) – number of periods for the slowest EMA constant
Returns New feature generated.
Return type [Link]
[Link].money_flow_index(high, low, close, volume, n=14, fillna=False)
Money Flow Index (MFI)
Uses both price and volume to measure buying and selling pressure. It is positive when the typical price rises
(buying pressure) and negative when the typical price declines (selling pressure). A ratio of positive and negative
money flow is then plugged into an RSI formula to create an oscillator that moves between zero and one hundred.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• volume ([Link]) – dataset ‘Volume’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link](close, n=12, fillna=False)
Rate of Change (ROC)
The Rate-of-Change (ROC) indicator, which is also referred to as simply Momentum, is a pure momentum
oscillator that measures the percent change in price from one period to the next. The ROC calculation compares

10 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

the current price with the price “n” periods ago. The plot forms an oscillator that fluctuates above and below
the zero line as the Rate-of-Change moves from positive to negative. As a momentum oscillator, ROC signals
include centerline crossovers, divergences and overbought-oversold readings. Divergences fail to foreshadow
reversals more often than not, so this article will forgo a detailed discussion on them. Even though centerline
crossovers are prone to whipsaw, especially short-term, these crossovers can be used to identify the overall trend.
Identifying overbought or oversold extremes comes naturally to the Rate-of-Change oscillator.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n periods.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link](close, n=14, fillna=False)
Relative Strength Index (RSI)
Compares the magnitude of recent gains and losses over a specified time period to measure speed and change of
price movements of a security. It is primarily used to attempt to identify overbought or oversold conditions in
the trading of an asset.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link](high, low, close, n=14, fillna=False)
Stochastic Oscillator
Developed in the late 1950s by George Lane. The stochastic oscillator presents the location of the closing price
of a stock in relation to the high and low range of the price of a stock over a period of time, typically a 14-day
period.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]

4.1. Documentation 11
Technical Analysis Library in Python Documentation, Release 0.1.4

[Link].stoch_signal(high, low, close, n=14, d_n=3, fillna=False)


Stochastic Oscillator Signal
Shows SMA of Stochastic Oscillator. Typically a 3 day SMA.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• d_n (int) – sma period over stoch_k
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link](close, r=25, s=13, fillna=False)
True strength index (TSI)
Shows both trend direction and overbought/oversold conditions.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• r (int) – high period.
• s (int) – low period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link](high, low, close, s=7, m=14, len=28, ws=4.0, wm=2.0, wl=1.0, fillna=False)
Ultimate Oscillator
Larry Williams’ (1976) signal, a momentum oscillator designed to capture momentum across three different
timeframes.
[Link]
BP = Close - Minimum(Low or Prior Close). TR = Maximum(High or Prior Close) - Minimum(Low or Prior
Close) Average7 = (7-period BP Sum) / (7-period TR Sum) Average14 = (14-period BP Sum) / (14-period TR
Sum) Average28 = (28-period BP Sum) / (28-period TR Sum)
UO = 100 x [(4 x Average7)+(2 x Average14)+Average28]/(4+2+1)
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• s (int) – short period

12 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

• m (int) – medium period


• len (int) – long period
• ws (float) – weight of short BP average for UO
• wm (float) – weight of medium BP average for UO
• wl (float) – weight of long BP average for UO
• fillna (bool) – if True, fill nan values with 50.
Returns New feature generated.
Return type [Link]
[Link](high, low, close, lbp=14, fillna=False)
Williams %R
From: [Link]
Developed by Larry Williams, Williams %R is a momentum indicator that is the inverse of the Fast Stochastic
Oscillator. Also referred to as %R, Williams %R reflects the level of the close relative to the highest high for the
look-back period. In contrast, the Stochastic Oscillator reflects the level of the close relative to the lowest low.
%R corrects for the inversion by multiplying the raw value by -100. As a result, the Fast Stochastic Oscillator
and Williams %R produce the exact same lines, only the scaling is different. Williams %R oscillates from 0 to
-100.
Readings from 0 to -20 are considered overbought. Readings from -80 to -100 are considered oversold.
Unsurprisingly, signals derived from the Stochastic Oscillator are also applicable to Williams %R.
%R = (Highest High - Close)/(Highest High - Lowest Low) * -100
Lowest Low = lowest low for the look-back period Highest High = highest high for the look-back period %R is
multiplied by -100 correct the inversion and move the decimal.
From: [Link] The Williams %R oscillates from 0 to -100. When
the indicator produces readings from 0 to -20, this indicates overbought market conditions. When readings are
-80 to -100, it indicates oversold market conditions.
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• lbp (int) – lookback period
• fillna (bool) – if True, fill nan values with -50.
Returns New feature generated.
Return type [Link]

4.1.2 Volume Indicators

Volume Indicators.
[Link].acc_dist_index(high, low, close, volume, fillna=False)
Accumulation/Distribution Index (ADI)
Acting as leading indicator of price movements.

4.1. Documentation 13
Technical Analysis Library in Python Documentation, Release 0.1.4

[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• volume ([Link]) – dataset ‘Volume’ column.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].chaikin_money_flow(high, low, close, volume, n=20, fillna=False)
Chaikin Money Flow (CMF)
It measures the amount of Money Flow Volume over a specific period.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• volume ([Link]) – dataset ‘Volume’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].ease_of_movement(high, low, close, volume, n=20, fillna=False)
Ease of movement (EoM, EMV)
It relate an asset’s price change to its volume and is particularly useful for assessing the strength of a trend.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• volume ([Link]) – dataset ‘Volume’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]

14 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

[Link].force_index(close, volume, n=2, fillna=False)


Force Index (FI)
It illustrates how strong the actual buying or selling pressure is. High positive values mean there is a strong
rising trend, and low values signify a strong downward trend.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• volume ([Link]) – dataset ‘Volume’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].negative_volume_index(close, volume, fillna=False)
Negative Volume Index (NVI)
[Link]
The Negative Volume Index (NVI) is a cumulative indicator that uses the change in volume to decide when
the smart money is active. Paul Dysart first developed this indicator in the 1930s. [. . . ] Dysart’s Negative
Volume Index works under the assumption that the smart money is active on days when volume decreases and
the not-so-smart money is active on days when volume increases.
The cumulative NVI line was unchanged when volume increased from one period to the other. In other words,
nothing was done. Norman Fosback, of Stock Market Logic, adjusted the indicator by substituting the percent-
age price change for Net Advances.
This implementation is the Fosback version.
If today’s volume is less than yesterday’s volume then: nvi(t) = nvi(t-1) * ( 1 + (close(t) - close(t-1)) / close(t-
1) )
Else nvi(t) = nvi(t-1)
Please note: the “[Link]” example calculation just adds the percentange change of price to previous
NVI when volumes decline; other sources indicate that the same percentage of the previous NVI value should
be added, which is what is implemented here.
Parameters
• close ([Link]) – dataset ‘Close’ column.
• volume ([Link]) – dataset ‘Volume’ column.
• fillna (bool) – if True, fill nan values with 1000.
Returns New feature generated.
Return type [Link]
See also: [Link]
[Link].on_balance_volume(close, volume, fillna=False)
On-balance volume (OBV)
It relates price and volume in the stock market. OBV is based on a cumulative total volume.
[Link]

4.1. Documentation 15
Technical Analysis Library in Python Documentation, Release 0.1.4

Parameters
• close ([Link]) – dataset ‘Close’ column.
• volume ([Link]) – dataset ‘Volume’ column.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].put_call_ratio()
Put/Call ratio (PCR) [Link]
[Link].volume_price_trend(close, volume, fillna=False)
Volume-price trend (VPT)
Is based on a running cumulative volume that adds or substracts a multiple of the percentage change in share
price trend and current volume, depending upon the investment’s upward or downward movements.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• volume ([Link]) – dataset ‘Volume’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]

4.1.3 Volatility Indicators

Volatility Indicators.
[Link].average_true_range(high, low, close, n=14, fillna=False)
Average True Range (ATR)
The indicator provide an indication of the degree of price volatility. Strong moves, in either direction, are often
accompanied by large ranges, or large True Ranges.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].bollinger_hband(close, n=20, ndev=2, fillna=False)
Bollinger Bands (BB)
Upper band at K times an N-period standard deviation above the moving average (MA + Kdeviation).

16 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• ndev (int) – n factor standard deviation
Returns New feature generated.
Return type [Link]
[Link].bollinger_hband_indicator(close, n=20, ndev=2, fillna=False)
Bollinger High Band Indicator
Returns 1, if close is higher than bollinger high band. Else, return 0.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• ndev (int) – n factor standard deviation
Returns New feature generated.
Return type [Link]
[Link].bollinger_lband(close, n=20, ndev=2, fillna=False)
Bollinger Bands (BB)
Lower band at K times an N-period standard deviation below the moving average (MA Kdeviation).
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• ndev (int) – n factor standard deviation
Returns New feature generated.
Return type [Link]
[Link].bollinger_lband_indicator(close, n=20, ndev=2, fillna=False)
Bollinger Low Band Indicator
Returns 1, if close is lower than bollinger low band. Else, return 0.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• ndev (int) – n factor standard deviation
Returns New feature generated.
Return type [Link]

4.1. Documentation 17
Technical Analysis Library in Python Documentation, Release 0.1.4

[Link].bollinger_mavg(close, n=20, fillna=False)


Bollinger Bands (BB)
N-period simple moving average (MA).
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].donchian_channel_hband(close, n=20, fillna=False)
Donchian channel (DC)
The upper band marks the highest price of an issue for n periods.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].donchian_channel_hband_indicator(close, n=20, fillna=False)
Donchian High Band Indicator
Returns 1, if close is higher than donchian high band channel. Else, return 0.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].donchian_channel_lband(close, n=20, fillna=False)
Donchian channel (DC)
The lower band marks the lowest price for n periods.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]

18 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

[Link].donchian_channel_lband_indicator(close, n=20, fillna=False)


Donchian Low Band Indicator
Returns 1, if close is lower than donchian low band channel. Else, return 0.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].keltner_channel_central(high, low, close, n=10, fillna=False)
Keltner channel (KC)
Showing a simple moving average line (central) of typical price.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].keltner_channel_hband(high, low, close, n=10, fillna=False)
Keltner channel (KC)
Showing a simple moving average line (high) of typical price.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].keltner_channel_hband_indicator(high, low, close, n=10, fillna=False)
Keltner Channel High Band Indicator (KC)
Returns 1, if close is higher than keltner high band channel. Else, return 0.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.

4.1. Documentation 19
Technical Analysis Library in Python Documentation, Release 0.1.4

• low ([Link]) – dataset ‘Low’ column.


• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].keltner_channel_lband(high, low, close, n=10, fillna=False)
Keltner channel (KC)
Showing a simple moving average line (low) of typical price.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]
[Link].keltner_channel_lband_indicator(high, low, close, n=10, fillna=False)
Keltner Channel Low Band Indicator (KC)
Returns 1, if close is lower than keltner low band channel. Else, return 0.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
Returns New feature generated.
Return type [Link]

4.1.4 Trend Indicators

Trend Indicators.
[Link](high, low, close, n=14, fillna=False)
Average Directional Movement Index (ADX)
The Plus Directional Indicator (+DI) and Minus Directional Indicator (-DI) are derived from smoothed aver-
ages of these differences, and measure trend direction over time. These two indicators are often referred to
collectively as the Directional Movement Indicator (DMI).
The Average Directional Index (ADX) is in turn derived from the smoothed averages of the difference between
+DI and -DI, and measures the strength of the trend (regardless of direction) over time.
Using these three indicators together, chartists can determine both the direction and strength of the trend.

20 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].adx_neg(high, low, close, n=14, fillna=False)
Average Directional Movement Index Negative (ADX)
The Plus Directional Indicator (+DI) and Minus Directional Indicator (-DI) are derived from smoothed aver-
ages of these differences, and measure trend direction over time. These two indicators are often referred to
collectively as the Directional Movement Indicator (DMI).
The Average Directional Index (ADX) is in turn derived from the smoothed averages of the difference between
+DI and -DI, and measures the strength of the trend (regardless of direction) over time.
Using these three indicators together, chartists can determine both the direction and strength of the trend.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].adx_pos(high, low, close, n=14, fillna=False)
Average Directional Movement Index Positive (ADX)
The Plus Directional Indicator (+DI) and Minus Directional Indicator (-DI) are derived from smoothed aver-
ages of these differences, and measure trend direction over time. These two indicators are often referred to
collectively as the Directional Movement Indicator (DMI).
The Average Directional Index (ADX) is in turn derived from the smoothed averages of the difference between
+DI and -DI, and measures the strength of the trend (regardless of direction) over time.
Using these three indicators together, chartists can determine both the direction and strength of the trend.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.

4.1. Documentation 21
Technical Analysis Library in Python Documentation, Release 0.1.4

• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].aroon_down(close, n=25, fillna=False)
Aroon Indicator (AI)
Identify when trends are likely to change direction (downtrend).
Aroon Down - ((N - Days Since N-day Low) / N) x 100
[Link] :Parameters: * close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.

Returns New feature generated.


Return type [Link]

[Link].aroon_up(close, n=25, fillna=False)


Aroon Indicator (AI)
Identify when trends are likely to change direction (uptrend).
Aroon Up - ((N - Days Since N-day High) / N) x 100
[Link] :Parameters: * close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.

Returns New feature generated.


Return type [Link]

[Link](high, low, close, n=20, c=0.015, fillna=False)


Commodity Channel Index (CCI)
CCI measures the difference between a security’s price change and its average price change. High positive
readings indicate that prices are well above their average, which is a show of strength. Low negative readings
indicate that prices are well below their average, which is a show of weakness.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n periods.
• c (int) – constant.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.

22 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

Return type [Link]


[Link](close, n=20, fillna=False)
Detrended Price Oscillator (DPO)
Is an indicator designed to remove trend from price and make it easier to identify cycles.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].ema_indicator(close, n=12, fillna=False)
EMA
Exponential Moving Average via Pandas
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n_fast (int) – n period short-term.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].ichimoku_a(high, low, n1=9, n2=26, visual=False, fillna=False)
Ichimoku Kinkō Hyō (Ichimoku)
It identifies the trend and look for potential signals within that trend.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• n1 (int) – n1 low period.
• n2 (int) – n2 medium period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].ichimoku_b(high, low, n2=26, n3=52, visual=False, fillna=False)
Ichimoku Kinkō Hyō (Ichimoku)
It identifies the trend and look for potential signals within that trend.
[Link]
Parameters

4.1. Documentation 23
Technical Analysis Library in Python Documentation, Release 0.1.4

• high ([Link]) – dataset ‘High’ column.


• low ([Link]) – dataset ‘Low’ column.
• n2 (int) – n2 medium period.
• n3 (int) – n3 high period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link](close, r1=10, r2=15, r3=20, r4=30, n1=10, n2=10, n3=10, n4=15, fillna=False)
KST Oscillator (KST)
It is useful to identify major stock market cycle junctures because its formula is weighed to be more greatly
influenced by the longer and more dominant time spans, in order to better reflect the primary swings of stock
market cycle.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• r1 (int) – r1 period.
• r2 (int) – r2 period.
• r3 (int) – r3 period.
• r4 (int) – r4 period.
• n1 (int) – n1 smoothed period.
• n2 (int) – n2 smoothed period.
• n3 (int) – n3 smoothed period.
• n4 (int) – n4 smoothed period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].kst_sig(close, r1=10, r2=15, r3=20, r4=30, n1=10, n2=10, n3=10, n4=15, nsig=9,
fillna=False)
KST Oscillator (KST Signal)
It is useful to identify major stock market cycle junctures because its formula is weighed to be more greatly
influenced by the longer and more dominant time spans, in order to better reflect the primary swings of stock
market cycle.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• r1 (int) – r1 period.
• r2 (int) – r2 period.
• r3 (int) – r3 period.
• r4 (int) – r4 period.

24 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

• n1 (int) – n1 smoothed period.


• n2 (int) – n2 smoothed period.
• n3 (int) – n3 smoothed period.
• n4 (int) – n4 smoothed period.
• nsig (int) – n period to signal.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link](close, n_fast=12, n_slow=26, fillna=False)
Moving Average Convergence Divergence (MACD)
Is a trend-following momentum indicator that shows the relationship between two moving averages of prices.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n_fast (int) – n period short-term.
• n_slow (int) – n period long-term.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].macd_diff(close, n_fast=12, n_slow=26, n_sign=9, fillna=False)
Moving Average Convergence Divergence (MACD Diff)
Shows the relationship between MACD and MACD Signal.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n_fast (int) – n period short-term.
• n_slow (int) – n period long-term.
• n_sign (int) – n period to signal.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].macd_signal(close, n_fast=12, n_slow=26, n_sign=9, fillna=False)
Moving Average Convergence Divergence (MACD Signal)
Shows EMA of MACD.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.

4.1. Documentation 25
Technical Analysis Library in Python Documentation, Release 0.1.4

• n_fast (int) – n period short-term.


• n_slow (int) – n period long-term.
• n_sign (int) – n period to signal.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].mass_index(high, low, n=9, n2=25, fillna=False)
Mass Index (MI)
It uses the high-low range to identify trend reversals based on range expansions. It identifies range bulges that
can foreshadow a reversal of the current trend.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• n (int) – n low period.
• n2 (int) – n high period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link](close, n=15, fillna=False)
Trix (TRIX)
Shows the percent rate of change of a triple exponentially smoothed moving average.
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].vortex_indicator_neg(high, low, close, n=14, fillna=False)
Vortex Indicator (VI)
It consists of two oscillators that capture positive and negative trend movement. A bearish signal triggers when
the negative trend indicator crosses above the positive trend indicator or a key level.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.

26 Chapter 4. Contents
Technical Analysis Library in Python Documentation, Release 0.1.4

• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].vortex_indicator_pos(high, low, close, n=14, fillna=False)
Vortex Indicator (VI)
It consists of two oscillators that capture positive and negative trend movement. A bullish signal triggers when
the positive trend indicator crosses above the negative trend indicator or a key level.
[Link]
Parameters
• high ([Link]) – dataset ‘High’ column.
• low ([Link]) – dataset ‘Low’ column.
• close ([Link]) – dataset ‘Close’ column.
• n (int) – n period.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]

4.1.5 Others Indicators

Others Indicators.
[Link].cumulative_return(close, fillna=False)
Cumulative Return (CR)
Parameters
• close ([Link]) – dataset ‘Close’ column.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].daily_log_return(close, fillna=False)
Daily Log Return (DLR)
[Link]
Parameters
• close ([Link]) – dataset ‘Close’ column.
• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]
[Link].daily_return(close, fillna=False)
Daily Return (DR)
Parameters

4.1. Documentation 27
Technical Analysis Library in Python Documentation, Release 0.1.4

• close ([Link]) – dataset ‘Close’ column.


• fillna (bool) – if True, fill nan values.
Returns New feature generated.
Return type [Link]

28 Chapter 4. Contents
CHAPTER 5

Indices and tables

• genindex
• modindex
• search

29
Technical Analysis Library in Python Documentation, Release 0.1.4

30 Chapter 5. Indices and tables


Python Module Index

m
momentum, 9

o
others, 27

t
ta, 9
[Link], 9
[Link], 27
[Link], 20
[Link], 16
[Link], 13
trend, 20

v
volatility, 16
volume, 13

31
Technical Analysis Library in Python Documentation, Release 0.1.4

32 Python Module Index


Index

A ema_indicator() (in module [Link]), 23


acc_dist_index() (in module [Link]), 13
adx() (in module [Link]), 20 F
adx_neg() (in module [Link]), 21 force_index() (in module [Link]), 14
adx_pos() (in module [Link]), 21
ao() (in module [Link]), 9 I
aroon_down() (in module [Link]), 22 ichimoku_a() (in module [Link]), 23
aroon_up() (in module [Link]), 22 ichimoku_b() (in module [Link]), 23
average_true_range() (in module [Link]),
16 K
kama() (in module [Link]), 10
B keltner_channel_central() (in module
bollinger_hband() (in module [Link]), 16 [Link]), 19
bollinger_hband_indicator() (in module keltner_channel_hband() (in module
[Link]), 17 [Link]), 19
bollinger_lband() (in module [Link]), 17 keltner_channel_hband_indicator() (in
bollinger_lband_indicator() (in module module [Link]), 19
[Link]), 17 keltner_channel_lband() (in module
bollinger_mavg() (in module [Link]), 17 [Link]), 20
keltner_channel_lband_indicator() (in
C module [Link]), 20
cci() (in module [Link]), 22 kst() (in module [Link]), 24
chaikin_money_flow() (in module [Link]), 14 kst_sig() (in module [Link]), 24
cumulative_return() (in module [Link]), 27

D M
macd() (in module [Link]), 25
daily_log_return() (in module [Link]), 27
macd_diff() (in module [Link]), 25
daily_return() (in module [Link]), 27
macd_signal() (in module [Link]), 25
donchian_channel_hband() (in module
mass_index() (in module [Link]), 26
[Link]), 18
momentum (module), 9
donchian_channel_hband_indicator() (in
money_flow_index() (in module [Link]), 10
module [Link]), 18
donchian_channel_lband() (in module
[Link]), 18
N
donchian_channel_lband_indicator() (in negative_volume_index() (in module [Link]),
module [Link]), 18 15
dpo() (in module [Link]), 23
O
E on_balance_volume() (in module [Link]), 15
ease_of_movement() (in module [Link]), 14 others (module), 27

33
Technical Analysis Library in Python Documentation, Release 0.1.4

P
put_call_ratio() (in module [Link]), 16

R
roc() (in module [Link]), 10
rsi() (in module [Link]), 11

S
stoch() (in module [Link]), 11
stoch_signal() (in module [Link]), 11

T
ta (module), 9
[Link] (module), 9
[Link] (module), 27
[Link] (module), 20
[Link] (module), 16
[Link] (module), 13
trend (module), 20
trix() (in module [Link]), 26
tsi() (in module [Link]), 12

U
uo() (in module [Link]), 12

V
volatility (module), 16
volume (module), 13
volume_price_trend() (in module [Link]), 16
vortex_indicator_neg() (in module [Link]), 26
vortex_indicator_pos() (in module [Link]), 27

W
wr() (in module [Link]), 13

34 Index

Technical Analysis Library in Python
Documentation
Release 0.1.4
Dario Lopez Padial (Bukosabino)
Oct 22, 2019
Contents
1
Installation (python 3)
3
2
Examples
5
3
Motivation
7
4
Contents
9
4.1
Documentation . . . . . . . . . . . . . . .
ii
Technical Analysis Library in Python Documentation, Release 0.1.4
It is a Technical Analysis library to financial time series
Technical Analysis Library in Python Documentation, Release 0.1.4
2
Contents
CHAPTER 1
Installation (python 3)
> virtualenv -p python3 virtualenvironment
> source virtualenvironment/bin/activate
> pip i
Technical Analysis Library in Python Documentation, Release 0.1.4
4
Chapter 1. Installation (python 3)
CHAPTER 2
Examples
Adding all features:
import pandas as pd
from ta import *
# Load datas
df = pd.read_csv('your-file.csv', s
Technical Analysis Library in Python Documentation, Release 0.1.4
6
Chapter 2. Examples

You might also like