Convert Figma logo to code with AI

bukosabino logota

Technical Analysis Library using Pandas and Numpy

4,295
904
4,295
138

Top Related Projects

Python wrapper for TA-Lib (http://ta-lib.org/).

2,127

Common financial technical indicators implemented in Pandas.

Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators

17,609

Zipline, a Pythonic Algorithmic Trading Library

Quick Overview

The bukosabino/ta repository is a Python library for technical analysis of financial markets. It provides a comprehensive set of technical indicators and utility functions for analyzing stock market data, cryptocurrencies, and other financial instruments. The library is designed to be easy to use and integrate with popular data analysis tools like pandas.

Pros

  • Extensive collection of technical indicators and overlays
  • Built on top of pandas, allowing for easy integration with existing data analysis workflows
  • Well-documented with clear examples and explanations
  • Actively maintained and regularly updated

Cons

  • May have a steeper learning curve for users unfamiliar with technical analysis concepts
  • Performance can be slower for large datasets compared to some specialized libraries
  • Limited built-in visualization capabilities, requiring additional libraries for plotting
  • Some advanced or niche indicators may not be included

Code Examples

  1. Calculating Simple Moving Average (SMA):
import pandas as pd
import ta

# Assuming 'df' is a pandas DataFrame with 'close' price column
df['SMA_20'] = ta.trend.sma_indicator(df['close'], window=20)
  1. Computing Relative Strength Index (RSI):
# Calculate RSI with a 14-period window
df['RSI_14'] = ta.momentum.rsi(df['close'], window=14)
  1. Adding multiple indicators to a DataFrame:
# Add several indicators to the DataFrame
df = ta.add_all_ta_features(
    df, open="open", high="high", low="low", close="close", volume="volume"
)

Getting Started

To get started with the ta library, follow these steps:

  1. Install the library using pip:

    pip install ta
    
  2. Import the library and use it with your data:

    import pandas as pd
    import ta
    
    # Load your data into a pandas DataFrame
    df = pd.read_csv('your_data.csv')
    
    # Calculate a simple moving average
    df['SMA_20'] = ta.trend.sma_indicator(df['close'], window=20)
    
    # Add all available indicators
    df = ta.add_all_ta_features(
        df, open="open", high="high", low="low", close="close", volume="volume"
    )
    
    # Display the results
    print(df.head())
    

This will give you a basic setup to start using the ta library with your financial data.

Competitor Comparisons

Python wrapper for TA-Lib (http://ta-lib.org/).

Pros of ta-lib-python

  • Extensive library with over 150 technical indicators and functions
  • Highly optimized C implementation for faster performance
  • Well-established and widely used in the financial industry

Cons of ta-lib-python

  • Requires compilation and installation of C libraries, which can be complex
  • Less frequently updated compared to ta
  • Steeper learning curve for beginners

Code Comparison

ta-lib-python:

import talib
import numpy as np

close = np.random.random(100)
output = talib.SMA(close, timeperiod=10)

ta:

import pandas as pd
from ta import add_all_ta_features

df = pd.DataFrame()
df = add_all_ta_features(df, "open", "high", "low", "close", "volume")

Summary

ta-lib-python offers a comprehensive set of technical indicators with optimized performance, making it suitable for professional use. However, its installation process can be challenging, and updates are less frequent.

ta provides a more user-friendly approach with easier installation and regular updates. It's built on top of pandas, making it convenient for data manipulation. While it may not have as many indicators as ta-lib-python, it's more accessible for beginners and those who prefer a pure Python implementation.

The choice between the two depends on specific project requirements, performance needs, and user expertise.

2,127

Common financial technical indicators implemented in Pandas.

Pros of finta

  • Simpler API and easier to use for beginners
  • Faster execution speed for some indicators
  • More compact codebase, potentially easier to maintain

Cons of finta

  • Fewer technical indicators available compared to ta
  • Less active development and community support
  • Limited documentation and examples

Code Comparison

finta:

from finta import TA

close = df['close']
sma = TA.SMA(close, period=14)

ta:

from ta.trend import SMAIndicator

close = df['close']
sma_indicator = SMAIndicator(close=close, window=14)
sma = sma_indicator.sma_indicator()

Both libraries provide similar functionality for calculating technical indicators, but finta offers a more straightforward API. The ta library requires creating an indicator object before calling the method, while finta allows direct function calls.

finta is generally more concise and easier to use for simple calculations, making it a good choice for beginners or quick prototyping. However, ta offers a wider range of indicators and more customization options, which may be preferable for advanced users or complex analysis tasks.

The choice between these libraries depends on the specific requirements of your project, such as the need for particular indicators, performance considerations, and the level of community support desired.

Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators

Pros of pandas-ta

  • More extensive collection of technical indicators (130+ vs 32 in ta)
  • Better performance due to optimized Cython implementations
  • More active development and community support

Cons of pandas-ta

  • Steeper learning curve due to more complex API
  • Larger package size, which may impact installation and load times

Code Comparison

ta:

import ta

df['rsi'] = ta.momentum.rsi(df['close'])
df['macd'] = ta.trend.macd(df['close'])

pandas-ta:

import pandas_ta as ta

df.ta.rsi(close='close', append=True)
df.ta.macd(close='close', append=True)

Both libraries extend pandas DataFrame functionality, but pandas-ta offers a more concise syntax through the ta accessor. While ta requires separate function calls for each indicator, pandas-ta allows chaining multiple indicators in a single line:

df.ta.rsi(append=True).ta.macd(append=True)

This approach can lead to more readable and maintainable code, especially when working with multiple indicators. However, the simpler API of ta may be preferable for users who only need basic functionality or are new to technical analysis.

17,609

Zipline, a Pythonic Algorithmic Trading Library

Pros of Zipline

  • More comprehensive backtesting and live trading capabilities
  • Larger community and ecosystem of tools/integrations
  • Better documentation and learning resources

Cons of Zipline

  • Steeper learning curve for beginners
  • Heavier and more complex setup process
  • Less frequently updated (last commit over 2 years ago)

Code Comparison

Zipline example:

from zipline.api import order, record, symbol

def initialize(context):
    context.asset = symbol('AAPL')

def handle_data(context, data):
    order(context.asset, 10)
    record(AAPL=data.current(context.asset, 'price'))

TA example:

import pandas as pd
import ta

df = pd.read_csv('AAPL.csv', parse_dates=['Date'])
df['SMA'] = ta.trend.sma_indicator(df['Close'], window=14)
df['RSI'] = ta.momentum.rsi(df['Close'], window=14)

Zipline offers a more structured approach for building complete trading strategies, while TA focuses on providing technical analysis indicators that can be easily integrated into existing workflows.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CircleCI Documentation Status Coverage Status Code style: black Linter: Prospector PyPI PyPI - Downloads Donate PayPal

Technical Analysis Library in Python

It is a Technical Analysis library useful to do feature engineering from financial time series datasets (Open, Close, High, Low, Volume). It is built on Pandas and Numpy.

Bollinger Bands graph example

The library has implemented 43 indicators:

Volume

IDNameClassdefs
1Money Flow Index (MFI)MFIIndicatormoney_flow_index
2Accumulation/Distribution Index (ADI)AccDistIndexIndicatoracc_dist_index
3On-Balance Volume (OBV)OnBalanceVolumeIndicatoron_balance_volume
4Chaikin Money Flow (CMF)ChaikinMoneyFlowIndicatorchaikin_money_flow
5Force Index (FI)ForceIndexIndicatorforce_index
6Ease of Movement (EoM, EMV)EaseOfMovementIndicatorease_of_movement
sma_ease_of_movement
7Volume-price Trend (VPT)VolumePriceTrendIndicatorvolume_price_trend
8Negative Volume Index (NVI)NegativeVolumeIndexIndicatornegative_volume_index
9Volume Weighted Average Price (VWAP)VolumeWeightedAveragePricevolume_weighted_average_price

Volatility

IDNameClassdefs
10Average True Range (ATR)AverageTrueRangeaverage_true_range
11Bollinger Bands (BB)BollingerBandsbollinger_hband
bollinger_hband_indicator
bollinger_lband
bollinger_lband_indicator
bollinger_mavg
bollinger_pband
bollinger_wband
12Keltner Channel (KC)KeltnerChannelkeltner_channel_hband
keltner_channel_hband_indicator
keltner_channel_lband
keltner_channel_lband_indicator
keltner_channel_mband
keltner_channel_pband
keltner_channel_wband
13Donchian Channel (DC)DonchianChanneldonchian_channel_hband
donchian_channel_lband
donchian_channel_mban
donchian_channel_pband
donchian_channel_wband
14Ulcer Index (UI)UlcerIndexulcer_index

Trend

IDNameClassdefs
15Simple Moving Average (SMA)SMAIndicatorsma_indicator
16Exponential Moving Average (EMA)EMAIndicatorema_indicator
17Weighted Moving Average (WMA)WMAIndicatorwma_indicator
18Moving Average Convergence Divergence (MACD)MACDmacd
macd_diff
macd_signal
19Average Directional Movement Index (ADX)ADXIndicatoradx
adx_neg
adx_pos
20Vortex Indicator (VI)VortexIndicatorvortex_indicator_neg
vortex_indicator_pos
21Trix (TRIX)TRIXIndicatortrix
22Mass Index (MI)MassIndexmass_index
23Commodity Channel Index (CCI)CCIIndicatorcci
24Detrended Price Oscillator (DPO)DPOIndicatordpo
25KST Oscillator (KST)KSTIndicatorkst
kst_sig
26Ichimoku Kinkō Hyō (Ichimoku)IchimokuIndicatorichimoku_a
ichimoku_b
ichimoku_base_line
ichimoku_conversion_line
27Parabolic Stop And Reverse (Parabolic SAR)PSARIndicatorpsar_down
psar_down_indicator
psar_up
psar_up_indicator
28Schaff Trend Cycle (STC)STCIndicatorstc
29Aroon IndicatorAroonIndicatoraroon_down
aroon_up

Momentum

IDNameClassdefs
30Relative Strength Index (RSI)RSIIndicatorrsi
31Stochastic RSI (SRSI)StochRSIIndicatorstochrsi
stochrsi_d
stochrsi_k
32True strength index (TSI)TSIIndicatortsi
33Ultimate Oscillator (UO)UltimateOscillatorultimate_oscillator
34Stochastic Oscillator (SR)StochasticOscillatorstoch
stoch_signal
35Williams %R (WR)WilliamsRIndicatorwilliams_r
36Awesome Oscillator (AO)AwesomeOscillatorIndicatorawesome_oscillator
37Kaufman's Adaptive Moving Average (KAMA)KAMAIndicatorkama
38Rate of Change (ROC)ROCIndicatorroc
39Percentage Price Oscillator (PPO)PercentagePriceOscillatorppo
ppo_hist
ppo_signal
40Percentage Volume Oscillator (PVO)PercentageVolumeOscillatorpvo
pvo_hist
pvo_signal

Others

IDNameClassdefs
41Daily Return (DR)DailyReturnIndicatordaily_return
42Daily Log Return (DLR)DailyLogReturnIndicatordaily_log_return
43Cumulative Return (CR)CumulativeReturnIndicatorcumulative_return

Documentation

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

Motivation to use

How to use (Python 3)

$ pip install --upgrade ta

To use this library you should have a financial time series dataset including Timestamp, Open, High, Low, Close and Volume columns.

You should clean or fill NaN values in your dataset before add technical analysis features.

You can get code examples in examples_to_use folder.

You can visualize the features in this notebook.

Example adding all features

import pandas as pd
from ta import add_all_ta_features
from ta.utils import dropna


# Load datas
df = pd.read_csv('ta/tests/data/datas.csv', sep=',')

# Clean NaN values
df = dropna(df)

# Add all ta features
df = add_all_ta_features(
    df, open="Open", high="High", low="Low", close="Close", volume="Volume_BTC")

Example adding particular feature

import pandas as pd
from ta.utils import dropna
from ta.volatility import BollingerBands


# Load datas
df = pd.read_csv('ta/tests/data/datas.csv', sep=',')

# Clean NaN values
df = dropna(df)

# Initialize Bollinger Bands Indicator
indicator_bb = BollingerBands(close=df["Close"], window=20, window_dev=2)

# Add Bollinger Bands features
df['bb_bbm'] = indicator_bb.bollinger_mavg()
df['bb_bbh'] = indicator_bb.bollinger_hband()
df['bb_bbl'] = indicator_bb.bollinger_lband()

# Add Bollinger Band high indicator
df['bb_bbhi'] = indicator_bb.bollinger_hband_indicator()

# Add Bollinger Band low indicator
df['bb_bbli'] = indicator_bb.bollinger_lband_indicator()

# Add Width Size Bollinger Bands
df['bb_bbw'] = indicator_bb.bollinger_wband()

# Add Percentage Bollinger Bands
df['bb_bbp'] = indicator_bb.bollinger_pband()

Deploy and develop (for developers)

$ git clone https://github.com/bukosabino/ta.git
$ cd ta
$ pip install -r requirements-play.txt
$ make test

Sponsor

Logo OpenSistemas

Thank you to OpenSistemas! It is because of your contribution that I am able to continue the development of this open source library.

Based on

In Progress

  • Automated tests for all the indicators.

TODO

Changelog

Check the changelog of project.

Donation

If you think ta library help you, please consider buying me a coffee.

Credits

Developed by Darío López Padial (aka Bukosabino) and other contributors.

Please, let me know about any comment or feedback.

Also, I am a software engineer freelance focused on Data Science using Python tools such as Pandas, Scikit-Learn, Backtrader, Zipline or Catalyst. Don't hesitate to contact me if you need to develop something related with this library, Python, Technical Analysis, AlgoTrading, Machine Learning, etc.