Stock Indicators for Python provides financial market technical indicators from historical price quotes.
Advanced and specialized technical indicators including mathematical functions, candlestick pattern recognition, correlation analysis, and proprietary indicators for sophisticated market analysis.
Measures the correlation coefficient between two price series to identify relationships.
def get_correlation(quotes_a: Iterable[Quote], quotes_b: Iterable[Quote], lookback_periods: int = 20):
"""
Correlation - measures relationship between two price series.
Args:
quotes_a (Iterable[Quote]): First price series
quotes_b (Iterable[Quote]): Second price series
lookback_periods (int): Number of periods for calculation (defaults to 20)
Returns:
CorrelationResults[CorrelationResult]: Collection of Correlation results
"""Measures the volatility of a security relative to the overall market.
def get_beta(eval_quotes: Iterable[Quote], market_quotes: Iterable[Quote], lookback_periods: int,
beta_type: BetaType = BetaType.STANDARD):
"""
Beta - measures security volatility relative to market.
Args:
eval_quotes (Iterable[Quote]): Security quotes to evaluate
market_quotes (Iterable[Quote]): Market benchmark quotes
lookback_periods (int): Number of periods for calculation
beta_type (BetaType): Type of beta calculation (defaults to STANDARD)
Returns:
BetaResults[BetaResult]: Collection of Beta results
"""Measures the long-term memory and predictability of time series data.
def get_hurst(quotes: Iterable[Quote], lookback_periods: int = 100):
"""
Hurst Exponent - measures long-term memory of time series.
Args:
quotes (Iterable[Quote]): Historical price quotes
lookback_periods (int): Number of periods for calculation (defaults to 100)
Returns:
HurstResults[HurstResult]: Collection of Hurst results
"""Calculates slope and linear regression statistics for trend analysis.
def get_slope(quotes: Iterable[Quote], lookback_periods: int):
"""
Slope - linear regression slope and statistics.
Args:
quotes (Iterable[Quote]): Historical price quotes
lookback_periods (int): Number of periods for regression
Returns:
SlopeResults[SlopeResult]: Collection of Slope results
"""Identifies Doji candlestick patterns indicating market indecision.
def get_doji(quotes: Iterable[Quote]):
"""
Doji - identifies Doji candlestick patterns.
Args:
quotes (Iterable[Quote]): Historical price quotes
Returns:
CandleResults[CandleResult]: Collection of Doji pattern results
"""Identifies Marubozu candlestick patterns indicating strong directional movement.
def get_marubozu(quotes: Iterable[Quote]):
"""
Marubozu - identifies Marubozu candlestick patterns.
Args:
quotes (Iterable[Quote]): Historical price quotes
Returns:
CandleResults[CandleResult]: Collection of Marubozu pattern results
"""Transforms price data to approximate Gaussian normal distribution for better signal identification.
def get_fisher_transform(quotes: Iterable[Quote], lookback_periods: int = 10):
"""
Fisher Transform - transforms prices to Gaussian distribution.
Args:
quotes (Iterable[Quote]): Historical price quotes
lookback_periods (int): Number of periods for calculation (defaults to 10)
Returns:
FisherTransformResults[FisherTransformResult]: Collection of Fisher Transform results
"""Uses Hilbert Transform to identify the instantaneous trendline.
def get_ht_trendline(quotes: Iterable[Quote]):
"""
Hilbert Transform Instantaneous Trendline - identifies instantaneous trend.
Args:
quotes (Iterable[Quote]): Historical price quotes
Returns:
HtTrendlineResults[HtTrendlineResult]: Collection of HT Trendline results
"""Dr. Alexander Elder's indicator combining trend and momentum analysis.
def get_elder_ray(quotes: Iterable[Quote], lookback_periods: int = 13):
"""
Elder Ray Index - combines trend and momentum analysis.
Args:
quotes (Iterable[Quote]): Historical price quotes
lookback_periods (int): EMA periods for calculation (defaults to 13)
Returns:
ElderRayResults[ElderRayResult]: Collection of Elder Ray results
"""Compares the performance of one security relative to another.
def get_prs(eval_quotes: Iterable[Quote], base_quotes: Iterable[Quote], lookback_periods: Optional[int] = None,
sma_periods: Optional[int] = None):
"""
Price Relative Strength (PRS) - compares security performance.
Args:
eval_quotes (Iterable[Quote]): Security quotes to evaluate
base_quotes (Iterable[Quote]): Base security quotes for comparison
lookback_periods (Optional[int]): Periods for momentum calculation
sma_periods (Optional[int]): SMA periods for smoothing
Returns:
PRSResults[PRSResult]: Collection of PRS results
"""Measures the balance between buying and selling pressure.
def get_bop(quotes: Iterable[Quote]):
"""
Balance of Power (BOP) - measures buying vs selling pressure.
Args:
quotes (Iterable[Quote]): Historical price quotes
Returns:
BOPResults[BOPResult]: Collection of BOP results
"""Bill Williams' fractal-based support and resistance levels.
def get_fcb(quotes: Iterable[Quote], window_span: int = 2):
"""
Fractal Chaos Bands (FCB) - fractal-based support/resistance.
Args:
quotes (Iterable[Quote]): Historical price quotes
window_span (int): Window span for fractal identification (defaults to 2)
Returns:
FCBResults[FCBResult]: Collection of FCB results
"""Enhanced version of stochastic oscillator with additional smoothing.
def get_smi(quotes: Iterable[Quote], lookback_periods: int = 13, first_smooth_periods: int = 25,
second_smooth_periods: int = 2, signal_periods: int = 9):
"""
Stochastic Momentum Index (SMI) - enhanced stochastic with smoothing.
Args:
quotes (Iterable[Quote]): Historical price quotes
lookback_periods (int): Lookback periods for stochastic (defaults to 13)
first_smooth_periods (int): First smoothing periods (defaults to 25)
second_smooth_periods (int): Second smoothing periods (defaults to 2)
signal_periods (int): Signal line EMA periods (defaults to 9)
Returns:
SMIResults[SMIResult]: Collection of SMI results
"""Combines slow stochastic oscillator with MACD for enhanced trend detection.
def get_stc(quotes: Iterable[Quote], cycle_periods: int = 10, fast_periods: int = 23, slow_periods: int = 50):
"""
Schaff Trend Cycle (STC) - combines stochastic with MACD.
Args:
quotes (Iterable[Quote]): Historical price quotes
cycle_periods (int): Cycle periods for calculation (defaults to 10)
fast_periods (int): Fast periods for MACD (defaults to 23)
slow_periods (int): Slow periods for MACD (defaults to 50)
Returns:
STCResults[STCResult]: Collection of STC results
"""Filters out small price movements to identify significant trends and reversals.
def get_zig_zag(quotes: Iterable[Quote], percent_change: float = 5, end_type: EndType = EndType.CLOSE):
"""
Zig Zag - filters small movements to show significant trends.
Args:
quotes (Iterable[Quote]): Historical price quotes
percent_change (float): Minimum percentage change to identify pivot (defaults to 5)
end_type (EndType): Use CLOSE or HIGH_LOW prices (defaults to CLOSE)
Returns:
ZigZagResults[ZigZagResult]: Collection of Zig Zag results
"""Measures the relationship between closing prices and true range to identify trend changes.
def get_vortex(quotes: Iterable[Quote], lookback_periods: int = 14):
"""
Vortex Indicator - measures relationship between close and true range.
Args:
quotes (Iterable[Quote]): Historical price quotes
lookback_periods (int): Number of periods for calculation (defaults to 14)
Returns:
VortexResults[VortexResult]: Collection of Vortex results
"""Adaptive RSI that varies the lookback period based on market volatility.
def get_dynamic(quotes: Iterable[Quote], lookback_periods: int = 14, k_factor: float = 0.5):
"""
Dynamic Momentum Index - adaptive RSI with variable periods.
Args:
quotes (Iterable[Quote]): Historical price quotes
lookback_periods (int): Base lookback periods (defaults to 14)
k_factor (float): Volatility adjustment factor (defaults to 0.5)
Returns:
DynamicResults[DynamicResult]: Collection of Dynamic results
"""from stock_indicators.indicators import get_correlation
# Analyze correlation between two securities
correlation_results = get_correlation(spy_quotes, stock_quotes, lookback_periods=60)
# Identify periods of high/low correlation
for result in correlation_results:
if result.correlation is not None:
if abs(result.correlation) > 0.8:
print(f"{result.date}: High correlation: {result.correlation:.3f}")
elif abs(result.correlation) < 0.3:
print(f"{result.date}: Low correlation: {result.correlation:.3f}")from stock_indicators.indicators import get_doji, get_marubozu
from stock_indicators.indicators.common import Match
# Identify reversal patterns
doji_results = get_doji(quotes)
marubozu_results = get_marubozu(quotes)
# Look for strong pattern signals
for result in doji_results:
if result.match in [Match.BULL_CONFIRMED, Match.BEAR_CONFIRMED]:
print(f"{result.date}: Strong Doji signal: {result.match}")
for result in marubozu_results:
if result.match in [Match.BULL_CONFIRMED, Match.BEAR_CONFIRMED]:
print(f"{result.date}: Strong Marubozu signal: {result.match}")Retrospective price pattern that identifies central high or low points over a lookback window.
def get_fractal(quotes: Iterable[Quote], window_span: int = 2, end_type: EndType = EndType.HIGH_LOW):
"""
Williams Fractal - identifies high/low price patterns.
Args:
quotes (Iterable[Quote]): Historical price quotes
window_span (int): Number of periods to left and right of evaluation (defaults to 2)
end_type (EndType): High/Low pattern type (defaults to HIGH_LOW)
Returns:
FractalResults[FractalResult]: Collection of fractal results
"""Modified candlestick pattern that uses prior day data for smoothing.
def get_heikin_ashi(quotes: Iterable[Quote]):
"""
Heikin-Ashi - smoothed candlestick representation.
Args:
quotes (Iterable[Quote]): Historical price quotes
Returns:
HeikinAshiResults[HeikinAshiResult]: Collection of Heikin-Ashi results
"""Companion to the Alligator indicator showing convergence and divergence of the smoothed moving averages.
def get_gator(quotes: Iterable[Quote], jaw_periods: int = 13, teeth_periods: int = 8, lips_periods: int = 5):
"""
Gator Oscillator - shows Alligator jaw, teeth, and lips convergence/divergence.
Args:
quotes (Iterable[Quote]): Historical price quotes
jaw_periods (int): Jaw line periods (defaults to 13)
teeth_periods (int): Teeth line periods (defaults to 8)
lips_periods (int): Lips line periods (defaults to 5)
Returns:
GatorResults[GatorResult]: Collection of Gator oscillator results
"""Measures volatility capturing gaps and limits between periods.
def get_tr(quotes: Iterable[Quote]):
"""
True Range - measures period-to-period volatility.
Args:
quotes (Iterable[Quote]): Historical price quotes
Returns:
TrResults[TrResult]: Collection of True Range results
"""Price-based charting that filters time and focuses only on price movements.
def get_renko(quotes: Iterable[Quote], brick_size: float):
"""
Renko - price-based charting with fixed brick size.
Args:
quotes (Iterable[Quote]): Historical price quotes
brick_size (float): Fixed brick size for Renko chart
Returns:
RenkoResults[RenkoResult]: Collection of Renko results
"""
def get_renko_atr(quotes: Iterable[Quote], atr_periods: int = 14):
"""
Renko - price-based charting with ATR-based brick sizing.
Args:
quotes (Iterable[Quote]): Historical price quotes
atr_periods (int): Periods for ATR-based brick sizing (defaults to 14)
Returns:
RenkoResults[RenkoResult]: Collection of Renko results
"""Creates channels based on standard deviation from a linear regression line.
def get_stdev_channels(quotes: Iterable[Quote], lookback_periods: int = 20, standard_deviations: float = 2):
"""
Standard Deviation Channels - regression line with deviation bands.
Args:
quotes (Iterable[Quote]): Historical price quotes
lookback_periods (int): Number of periods for calculation (defaults to 20)
standard_deviations (float): Number of standard deviations for bands (defaults to 2)
Returns:
StdevChannelsResults[StdevChannelsResult]: Collection of channel results
"""def get_pivots(quotes: Iterable[Quote], left_span: int = 2, right_span: int = 2, max_trend_periods: int = 20):
"""
Pivots - identifies pivot points for support/resistance analysis.
Args:
quotes (Iterable[Quote]): Historical price quotes
left_span (int): Left span periods (defaults to 2)
right_span (int): Right span periods (defaults to 2)
max_trend_periods (int): Maximum trend periods (defaults to 20)
Returns:
PivotsResults[PivotsResult]: Collection of pivot results
"""
def get_rolling_pivots(quotes: Iterable[Quote], window_periods: int = 11, offset_periods: int = 9):
"""
Rolling Pivots - rolling window pivot analysis.
Args:
quotes (Iterable[Quote]): Historical price quotes
window_periods (int): Rolling window periods (defaults to 11)
offset_periods (int): Offset periods (defaults to 9)
Returns:
RollingPivotsResults[RollingPivotsResult]: Collection of rolling pivot results
"""Install with Tessl CLI
npx tessl i tessl/pypi-stock-indicators