Giter Site home page Giter Site logo

gp-slick-coder / ta Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bukosabino/ta

0.0 2.0 0.0 9.65 MB

Easy to use Technical Analysis Library in Python with 70+ Indicators

Home Page: https://technical-analysis-library-in-python.readthedocs.io/en/latest/

License: MIT License

Python 8.64% Jupyter Notebook 91.36%

ta's Introduction

Technical Analysis Library in Python

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'].

Quick Start using the DataFrame Extension

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

New Changes

  • 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.

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, inclusively, it can append the result to the existing DataFrame by including the parameter 'append=True' in the method call. See examples below.

Technical Analysis Indicators (by Category)

Momentum (17)

  • 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)
Example MACD

Overlap (19)

  • 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)
Example Chart

Performance (2)

Use parameter: cumulative=True for cumulative results.

  • Log Return: log_return
  • Percent Return: percent_return
Percent Return (Cumulative) with Simple Moving Average (SMA)
Example Cumulative Percent Return

Statistics (9)

  • 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
Example Z Score

Trend (6)

  • Average Directional Movement Index: adx
  • Aroon Oscillator: aroon
  • Decreasing: decreasing
  • Detrended Price Oscillator: dpo
  • Increasing: increasing
  • Vortex Indicator: vortex
Average Directional Movement Index (ADX)
Example ADX

Volatility (8)

  • 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)
Example ATR

Volume (10)

  • 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)
Example OBV

Documentation

https://technical-analysis-library-in-python.readthedocs.io/en/latest/

Motivation

Python 3 Installation

$ 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.

Getting Started and Examples

Module and Indicator Help

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)

Calling an Indicator

# 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

Additional ways of calling an Indicator

# 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)

Legacy Examples

Example adding all features

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)

Example adding individual features

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)

Developer Edition

$ git clone https://github.com/bukosabino/ta.git
$ cd ta
$ pip install -r requirements.txt
$ cd dev
$ python bollinger_band_features_example.py

Inspiration:

TODO:

Credits:

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.

ta's People

Contributors

twopirllc avatar bukosabino avatar christian-janiake-movile avatar coire avatar sam-kleiner avatar cjaniake avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.