CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ta-lib

Python wrapper for TA-LIB providing 175+ technical analysis indicators for financial market data

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

cycle-indicators.mddocs/

Cycle Indicators

Hilbert Transform-based indicators for cycle analysis and trend vs cycle mode determination. These advanced indicators use mathematical transformations to identify market cycles, dominant periods, and phase relationships in price data.

Capabilities

Hilbert Transform - Dominant Cycle Period

Determines the dominant cycle period in the price data, helping identify the primary cyclical component.

def HT_DCPERIOD(real):
    """
    Hilbert Transform - Dominant Cycle Period
    
    Identifies the dominant cycle period in price data using Hilbert Transform analysis.
    
    Parameters:
    - real: array-like, input price data (typically close prices)
    
    Returns:
    numpy.ndarray: Dominant cycle period values (in periods)
    """

Hilbert Transform - Dominant Cycle Phase

Calculates the phase of the dominant cycle, indicating where the current price is within the cycle.

def HT_DCPHASE(real):
    """
    Hilbert Transform - Dominant Cycle Phase
    
    Determines the phase angle of the dominant cycle (0 to 360 degrees).
    
    Parameters:
    - real: array-like, input price data
    
    Returns:
    numpy.ndarray: Dominant cycle phase values (degrees)
    """

Hilbert Transform - Phasor Components

Provides the in-phase and quadrature components of the dominant cycle, representing the cycle as a rotating vector.

def HT_PHASOR(real):
    """
    Hilbert Transform - Phasor Components
    
    Returns the in-phase and quadrature components of the dominant cycle.
    
    Parameters:
    - real: array-like, input price data
    
    Returns:
    tuple: (inphase, quadrature) - Phasor component values
    """

Hilbert Transform - SineWave

Generates sine and lead sine waves based on the dominant cycle, useful for cycle timing and trend prediction.

def HT_SINE(real):
    """
    Hilbert Transform - SineWave
    
    Generates sine and lead sine waves from the dominant cycle analysis.
    
    Parameters:
    - real: array-like, input price data
    
    Returns:
    tuple: (sine, leadsine) - Sine wave and lead sine wave values
    """

Hilbert Transform - Trend vs Cycle Mode

Determines whether the market is in a trending mode or cycling mode, helping choose appropriate indicators and strategies.

def HT_TRENDMODE(real):
    """
    Hilbert Transform - Trend vs Cycle Mode
    
    Identifies whether the market is trending or cycling.
    
    Parameters:
    - real: array-like, input price data
    
    Returns:
    tuple: (integer, trendmode) - Integer component and trend mode indicator arrays
    - integer: array of integer values (first component)
    - trendmode: array with 1 = trending, 0 = cycling (second component)
    """

Usage Examples

import talib
import numpy as np

# Sample price data (needs sufficient length for Hilbert Transform)
np.random.seed(42)
price_trend = np.linspace(100, 120, 100)
price_cycle = 5 * np.sin(np.linspace(0, 8*np.pi, 100))
price_data = price_trend + price_cycle + np.random.normal(0, 0.5, 100)

# Calculate Hilbert Transform indicators
dc_period = talib.HT_DCPERIOD(price_data)
dc_phase = talib.HT_DCPHASE(price_data)
inphase, quadrature = talib.HT_PHASOR(price_data)
sine, leadsine = talib.HT_SINE(price_data)
trendmode, _ = talib.HT_TRENDMODE(price_data)

# Analyze results
print(f"Dominant Cycle Period: {dc_period[-1]:.2f} periods")
print(f"Current Phase: {dc_phase[-1]:.1f} degrees")
print(f"Market Mode: {'Trending' if trendmode[-1] else 'Cycling'}")

# Trading applications:
# - Use sine/leadsine crossovers for cycle timing
# - Apply trend-following indicators when trendmode = 1
# - Apply oscillators when trendmode = 0
# - Use dominant cycle period to optimize indicator parameters

# Sine wave trading signals
if sine[-1] > leadsine[-1] and sine[-2] <= leadsine[-2]:
    print("Potential bullish cycle signal")
elif sine[-1] < leadsine[-1] and sine[-2] >= leadsine[-2]:
    print("Potential bearish cycle signal")

Understanding Hilbert Transform Indicators

Theory

The Hilbert Transform is a mathematical operation that creates a 90-degree phase shift in a signal, allowing for the analysis of instantaneous amplitude, phase, and frequency. In financial markets, this helps identify:

  • Cycle Components: Separate trending from cyclical price movements
  • Phase Relationships: Determine where price is within a cycle
  • Dominant Periods: Identify the most significant cycle length

Practical Applications

  1. Adaptive Indicators: Use dominant cycle period to dynamically adjust indicator periods
  2. Market Mode Detection: Switch between trend-following and mean-reversion strategies
  3. Cycle Timing: Use phase information to time entries and exits
  4. Signal Filtering: Apply different signal processing based on trend vs cycle mode

Limitations

  • Require substantial historical data (typically 50+ periods)
  • May produce unstable results in choppy markets
  • Best suited for markets with clear cyclical components
  • Should be combined with other analysis methods for robust trading decisions

Install with Tessl CLI

npx tessl i tessl/pypi-ta-lib

docs

abstract-streaming.md

cycle-indicators.md

index.md

math-operations.md

momentum-indicators.md

overlap-studies.md

pattern-recognition.md

price-transform.md

statistical-functions.md

volatility-indicators.md

volume-indicators.md

tile.json