ta Technical Analysis Library

repository·master·Indexed 26 days ago

https://github.com/bukosabino/ta

A Python technical analysis library built on Pandas and Numpy for feature engineering on financial time series data. It implements 43 indicators across Volume, Volatility, Trend, and Momentum categories, supporting standard data points such as Open, Close, High, Low, and Volume.

Tokens
3.4K
Snippets
10
Records
22
Agent score
90%

What's inside ta

  1. Overview of Technical Analysis Library

    master
    The ta library is a Python technical analysis library designed for feature engineering from financial time series datasets. It supports common data points such as Open, Close, High, Low, and Volume. The library is built on top of Pandas and Numpy and implements 43 different indicators across categories like Volume, Volatility, Trend, and Momentum.
  2. Prepare your dataset for technical analysis

    master

    To use the ta library, your financial time series dataset (typically a Pandas DataFrame) must include the following columns:

    • Timestamp
    • Open
    • High
    • Low
    • Close
    • Volume

    Important: You must clean or fill NaN values in your dataset before adding technical analysis features. You can use ta.utils.dropna to handle missing values.

  3. Add all technical analysis features to a DataFrame

    master

    You can use add_all_ta_features to perform feature engineering on a financial dataset by adding all available technical analysis indicators at once. You can specify the column names for open, high, low, close, and volume. Setting fillna=True will automatically fill the resulting NaN values.

    Note: It is recommended to clean your data using ta.utils.dropna before adding 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 ta features filling NaN values
    df = add_all_ta_features(
        df, open="Open", high="High", low="Low", close="Close", volume="Volume_BTC", fillna=True)
  4. Use the BollingerBands indicator

    master

    To add specific Bollinger Bands features to a DataFrame, initialize the BollingerBands class from ta.volatility with the close price series, a window size, and window_dev (standard deviation).

    Available methods for the indicator instance:

    • bollinger_mavg(): Returns the moving average.
    • bollinger_hband(): Returns the upper band.
    • bollinger_lband(): Returns the lower band.
    • bollinger_hband_indicator(): Returns the high indicator.
    • bollinger_lband_indicator(): Returns the low indicator.
    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()
  5. Momentum indicators in ta

    master

    The ta.momentum module provides indicators to measure the speed of price movements. Indicators are available as classes and functional definitions.

    Available Momentum indicators:

    • Relative Strength Index (RSI): RSIIndicator, rsi
    • Stochastic RSI (SRSI): StochRSIIndicator, stochrsi, stochrsi_d, stochrsi_k
    • True strength index (TSI): TSIIndicator, tsi
    • Ultimate Oscillator (UO): UltimateOscillator, ultimate_oscillator
    • Stochastic Oscillator (SR): StochasticOscillator, stoch, stoch_signal
    • Williams %R (WR): WilliamsRIndicator, williams_r
    • Awesome Oscillator (AO): AwesomeOscillatorIndicator, awesome_oscillator
    • Kaufman's Adaptive Moving Average (KAMA): KAMAIndicator, kama
    • Rate of Change (ROC): ROCIndicator, roc
    • Percentage Price Oscillator (PPO): PercentagePriceOscillator, ppo, ppo_hist, ppo_signal
    • Percentage Volume Oscillator (PVO): PercentageVolumeOscillator, pvo, pvo_hist, pvo_signal
  6. Other indicators in ta

    master

    The ta.others module provides general return-based indicators.

    Available indicators:

    • Daily Return (DR): DailyReturnIndicator, daily_return
    • Daily Log Return (DLR): DailyLogReturnIndicator, daily_log_return
    • Cumulative Return (CR): CumulativeReturnIndicator, cumulative_return