Technical Analysis Library in Python for financial time series datasets with 43 indicators across Volume, Volatility, Trend, Momentum, and Others categories
Momentum-based technical indicators that measure the rate of price change and identify overbought/oversold conditions, momentum shifts, and potential reversal points. These indicators help traders assess the strength of price movements and timing of entries/exits.
Compares the magnitude of recent gains and losses over a specified period to measure the speed and magnitude of price changes.
class RSIIndicator:
def __init__(self, close, window=14, fillna=False):
"""
Relative Strength Index (RSI).
Parameters:
- close (Series): Dataset 'Close' column
- window (int): Period for calculation (default: 14)
- fillna (bool): If True, fill NaN values (default: False)
"""
def rsi(self):
"""Returns: Series with RSI values (0-100 scale)"""
def rsi(close, window=14, fillna=False):
"""Functional interface for RSI"""Shows both trend direction and overbought/oversold conditions by using double-smoothed momentum.
class TSIIndicator:
def __init__(self, close, window_slow=25, window_fast=13, fillna=False):
"""
True strength index (TSI).
Parameters:
- close (Series): Dataset 'Close' column
- window_slow (int): Slow period (default: 25)
- window_fast (int): Fast period (default: 13)
- fillna (bool): If True, fill NaN values (default: False)
"""
def tsi(self):
"""Returns: Series with TSI values"""
def tsi(close, window_slow=25, window_fast=13, fillna=False):
"""Functional interface for TSI"""Larry Williams' momentum oscillator designed to capture momentum across three different timeframes.
class UltimateOscillator:
def __init__(self, high, low, close, window1=7, window2=14, window3=28,
weight1=4.0, weight2=2.0, weight3=1.0, fillna=False):
"""
Ultimate Oscillator.
Parameters:
- high (Series): Dataset 'High' column
- low (Series): Dataset 'Low' column
- close (Series): Dataset 'Close' column
- window1 (int): Short period (default: 7)
- window2 (int): Medium period (default: 14)
- window3 (int): Long period (default: 28)
- weight1 (float): Weight of short BP average (default: 4.0)
- weight2 (float): Weight of medium BP average (default: 2.0)
- weight3 (float): Weight of long BP average (default: 1.0)
- fillna (bool): If True, fill NaN values (default: False)
"""
def ultimate_oscillator(self):
"""Returns: Series with Ultimate Oscillator values (0-100 scale)"""
def ultimate_oscillator(high, low, close, window1=7, window2=14, window3=28,
weight1=4.0, weight2=2.0, weight3=1.0, fillna=False):
"""Functional interface for Ultimate Oscillator"""Developed by George Lane, presents the location of the closing price relative to the high-low range over a given period.
class StochasticOscillator:
def __init__(self, high, low, close, window=14, smooth_window=3, fillna=False):
"""
Stochastic Oscillator.
Parameters:
- high (Series): Dataset 'High' column
- low (Series): Dataset 'Low' column
- close (Series): Dataset 'Close' column
- window (int): Period for calculation (default: 14)
- smooth_window (int): SMA period over %K (default: 3)
- fillna (bool): If True, fill NaN values (default: False)
"""
def stoch(self):
"""Returns: Series with Stochastic %K values (0-100 scale)"""
def stoch_signal(self):
"""Returns: Series with Stochastic %D (signal) values (0-100 scale)"""
def stoch(high, low, close, window=14, smooth_window=3, fillna=False):
"""Functional interface for Stochastic %K"""
def stoch_signal(high, low, close, window=14, smooth_window=3, fillna=False):
"""Functional interface for Stochastic %D"""Moving average designed to account for market noise or volatility by adjusting its smoothing constant.
class KAMAIndicator:
def __init__(self, close, window=10, pow1=2, pow2=30, fillna=False):
"""
Kaufman's Adaptive Moving Average (KAMA).
Parameters:
- close (Series): Dataset 'Close' column
- window (int): Period for efficiency ratio (default: 10)
- pow1 (int): Fastest EMA constant periods (default: 2)
- pow2 (int): Slowest EMA constant periods (default: 30)
- fillna (bool): If True, fill NaN values (default: False)
"""
def kama(self):
"""Returns: Series with KAMA values"""
def kama(close, window=10, pow1=2, pow2=30, fillna=False):
"""Functional interface for KAMA"""Pure momentum oscillator that measures the percent change in price from one period to the next.
class ROCIndicator:
def __init__(self, close, window=12, fillna=False):
"""
Rate of Change (ROC).
Parameters:
- close (Series): Dataset 'Close' column
- window (int): Period for calculation (default: 12)
- fillna (bool): If True, fill NaN values (default: False)
"""
def roc(self):
"""Returns: Series with ROC values (percentage)"""
def roc(close, window=12, fillna=False):
"""Functional interface for ROC"""Indicator used to measure market momentum by comparing recent market momentum to historic market momentum.
class AwesomeOscillatorIndicator:
def __init__(self, high, low, window1=5, window2=34, fillna=False):
"""
Awesome Oscillator.
Parameters:
- high (Series): Dataset 'High' column
- low (Series): Dataset 'Low' column
- window1 (int): Short period (default: 5)
- window2 (int): Long period (default: 34)
- fillna (bool): If True, fill NaN values (default: False)
"""
def awesome_oscillator(self):
"""Returns: Series with Awesome Oscillator values"""
def awesome_oscillator(high, low, window1=5, window2=34, fillna=False):
"""Functional interface for Awesome Oscillator"""Momentum indicator that is the inverse of the Fast Stochastic Oscillator, measuring overbought/oversold levels.
class WilliamsRIndicator:
def __init__(self, high, low, close, lbp=14, fillna=False):
"""
Williams %R.
Parameters:
- high (Series): Dataset 'High' column
- low (Series): Dataset 'Low' column
- close (Series): Dataset 'Close' column
- lbp (int): Lookback period (default: 14)
- fillna (bool): If True, fill NaN values (default: False)
"""
def williams_r(self):
"""Returns: Series with Williams %R values (-100 to 0 scale)"""
def williams_r(high, low, close, lbp=14, fillna=False):
"""Functional interface for Williams %R"""Takes advantage of both momentum indicators to create a more sensitive indicator that ranges between 0 and 1.
class StochRSIIndicator:
def __init__(self, close, window=14, smooth1=3, smooth2=3, fillna=False):
"""
Stochastic RSI.
Parameters:
- close (Series): Dataset 'Close' column
- window (int): RSI period (default: 14)
- smooth1 (int): Moving average of Stochastic RSI (default: 3)
- smooth2 (int): Moving average of %K (default: 3)
- fillna (bool): If True, fill NaN values (default: False)
"""
def stochrsi(self):
"""Returns: Series with Stochastic RSI values (0-1 scale)"""
def stochrsi_k(self):
"""Returns: Series with Stochastic RSI %K values (0-100 scale)"""
def stochrsi_d(self):
"""Returns: Series with Stochastic RSI %D values (0-100 scale)"""
def stochrsi(close, window=14, smooth1=3, smooth2=3, fillna=False):
"""Functional interface for Stochastic RSI"""
def stochrsi_k(close, window=14, smooth1=3, smooth2=3, fillna=False):
"""Functional interface for Stochastic RSI %K"""
def stochrsi_d(close, window=14, smooth1=3, smooth2=3, fillna=False):
"""Functional interface for Stochastic RSI %D"""Momentum oscillator that measures the difference between two moving averages as a percentage of the larger moving average.
class PercentagePriceOscillator:
def __init__(self, close, window_slow=26, window_fast=12, window_sign=9, fillna=False):
"""
Percentage Price Oscillator (PPO).
Parameters:
- close (Series): Dataset 'Close' column
- window_slow (int): Long-term period (default: 26)
- window_fast (int): Short-term period (default: 12)
- window_sign (int): Signal period (default: 9)
- fillna (bool): If True, fill NaN values (default: False)
"""
def ppo(self):
"""Returns: Series with PPO Line values (percentage)"""
def ppo_signal(self):
"""Returns: Series with PPO Signal Line values (percentage)"""
def ppo_hist(self):
"""Returns: Series with PPO Histogram values (percentage)"""
def ppo(close, window_slow=26, window_fast=12, window_sign=9, fillna=False):
"""Functional interface for PPO Line"""
def ppo_signal(close, window_slow=26, window_fast=12, window_sign=9, fillna=False):
"""Functional interface for PPO Signal Line"""
def ppo_hist(close, window_slow=26, window_fast=12, window_sign=9, fillna=False):
"""Functional interface for PPO Histogram"""Momentum oscillator for volume that measures the difference between two volume-based moving averages.
class PercentageVolumeOscillator:
def __init__(self, volume, window_slow=26, window_fast=12, window_sign=9, fillna=False):
"""
Percentage Volume Oscillator (PVO).
Parameters:
- volume (Series): Dataset 'Volume' column
- window_slow (int): Long-term period (default: 26)
- window_fast (int): Short-term period (default: 12)
- window_sign (int): Signal period (default: 9)
- fillna (bool): If True, fill NaN values (default: False)
"""
def pvo(self):
"""Returns: Series with PVO Line values (percentage)"""
def pvo_signal(self):
"""Returns: Series with PVO Signal Line values (percentage)"""
def pvo_hist(self):
"""Returns: Series with PVO Histogram values (percentage)"""
def pvo(volume, window_slow=26, window_fast=12, window_sign=9, fillna=False):
"""Functional interface for PVO Line"""
def pvo_signal(volume, window_slow=26, window_fast=12, window_sign=9, fillna=False):
"""Functional interface for PVO Signal Line"""
def pvo_hist(volume, window_slow=26, window_fast=12, window_sign=9, fillna=False):
"""Functional interface for PVO Histogram"""from ta.momentum import *
import pandas as pd
def analyze_momentum(df):
# Primary momentum indicators
df['RSI'] = rsi(df['Close'], window=14)
df['Stoch_K'] = stoch(df['High'], df['Low'], df['Close'])
df['Stoch_D'] = stoch_signal(df['High'], df['Low'], df['Close'])
# Advanced momentum indicators
df['Williams_R'] = williams_r(df['High'], df['Low'], df['Close'])
df['Ultimate_Osc'] = ultimate_oscillator(df['High'], df['Low'], df['Close'])
# Rate of change indicators
df['ROC'] = roc(df['Close'], window=12)
df['Awesome_Osc'] = awesome_oscillator(df['High'], df['Low'])
return df
# Apply momentum analysis
df_momentum = analyze_momentum(df)from ta.momentum import RSIIndicator, StochasticOscillator
# Create momentum indicators for signal generation
rsi_indicator = RSIIndicator(close=df['Close'], window=14)
stoch_indicator = StochasticOscillator(
high=df['High'],
low=df['Low'],
close=df['Close'],
window=14
)
# Calculate values
df['RSI'] = rsi_indicator.rsi()
df['Stoch_K'] = stoch_indicator.stoch()
# Generate signals
df['RSI_Overbought'] = df['RSI'] > 70
df['RSI_Oversold'] = df['RSI'] < 30
df['Stoch_Overbought'] = df['Stoch_K'] > 80
df['Stoch_Oversold'] = df['Stoch_K'] < 20
# Combined momentum signal
df['Momentum_Signal'] = (
(df['RSI_Oversold'] & df['Stoch_Oversold']).astype(int) * 1 + # Buy signal
(df['RSI_Overbought'] & df['Stoch_Overbought']).astype(int) * -1 # Sell signal
)from ta.momentum import TSIIndicator, KAMAIndicator
# Multi-timeframe momentum analysis
def multi_timeframe_momentum(df):
# Short-term momentum (fast settings)
df['RSI_Fast'] = rsi(df['Close'], window=7)
df['TSI_Fast'] = tsi(df['Close'], window_slow=15, window_fast=7)
# Medium-term momentum (standard settings)
df['RSI_Medium'] = rsi(df['Close'], window=14)
df['KAMA'] = kama(df['Close'], window=10)
# Long-term momentum (slow settings)
df['RSI_Slow'] = rsi(df['Close'], window=21)
df['TSI_Slow'] = tsi(df['Close'], window_slow=35, window_fast=15)
return df
df_multi_tf = multi_timeframe_momentum(df)Install with Tessl CLI
npx tessl i tessl/pypi-ta