Stock Indicators for Python provides financial market technical indicators from historical price quotes.
npx @tessl/cli install tessl/pypi-stock-indicators@1.3.0Stock Indicators for Python provides financial market technical indicators from historical price quotes. Send in historical price data and get back desired indicators such as moving averages, Relative Strength Index, Stochastic Oscillator, Parabolic SAR, and more. Nothing more.
The library supports over 130 different technical indicators including trend, momentum, volatility, volume, and specialized indicators. It can be used in any market analysis software using standard OHLCV price quotes for equities, commodities, forex, cryptocurrencies, and others.
pip install stock-indicatorsfrom stock_indicators import indicators
from stock_indicators.indicators.common import Quote, BetaType, CandlePart, MAType, PeriodSizeCommon import pattern for all indicators:
from stock_indicators.indicators import get_sma, get_rsi, get_bollinger_bandsfrom datetime import datetime
from stock_indicators.indicators.common import Quote
from stock_indicators.indicators import get_sma
# Create historical price quotes
quotes = [
Quote(date=datetime(2023, 1, 1), open=100.0, high=102.0, low=99.0, close=101.0, volume=10000),
Quote(date=datetime(2023, 1, 2), open=101.0, high=103.0, low=100.0, close=102.0, volume=12000),
Quote(date=datetime(2023, 1, 3), open=102.0, high=104.0, low=101.0, close=103.0, volume=11000),
# ... more quotes
]
# Calculate Simple Moving Average with 10-period lookback
sma_results = get_sma(quotes, lookback_periods=10)
# Access results
for result in sma_results:
if result.sma is not None:
print(f"Date: {result.date}, SMA: {result.sma}")The Stock Indicators library is built around a simple but powerful architecture:
All indicators follow consistent patterns:
Iterable[Quote] as the primary input{IndicatorName}Results[{IndicatorName}Result] collectionsEssential data structures and enumerations used throughout the library. Includes the Quote class for price data input, result base classes, and configuration enums for indicator parameters.
class Quote:
def __init__(self, date: datetime, open: Optional[Any] = None,
high: Optional[Any] = None, low: Optional[Any] = None,
close: Optional[Any] = None, volume: Optional[Any] = None): ...
class ResultBase:
@property
def date(self) -> datetime: ...
class IndicatorResults[T]:
def remove_warmup_periods(self, periods: int): ...
def find(self, lookup_date: datetime): ...
def condense(self): ...Moving averages and trend-following indicators that smooth price data to identify market direction. Includes Simple Moving Average (SMA), Exponential Moving Average (EMA), Hull Moving Average (HMA), and adaptive moving averages.
def get_sma(quotes: Iterable[Quote], lookback_periods: int,
candle_part: CandlePart = CandlePart.CLOSE): ...
def get_ema(quotes: Iterable[Quote], lookback_periods: int): ...
def get_hma(quotes: Iterable[Quote], lookback_periods: int): ...
def get_kama(quotes: Iterable[Quote], er_periods: int = 10, fast_periods: int = 2, slow_periods: int = 30): ...Oscillators that measure the rate of price change and momentum to identify overbought/oversold conditions. Includes RSI, Stochastic, MACD, and various momentum oscillators.
def get_rsi(quotes: Iterable[Quote], lookback_periods: int = 14): ...
def get_stoch(quotes: Iterable[Quote], lookback_periods: int = 14,
signal_periods: int = 3, smooth_periods: int = 3): ...
def get_macd(quotes: Iterable[Quote], fast_periods: int = 12, slow_periods: int = 26, signal_periods: int = 9): ...
def get_stoch_rsi(quotes: Iterable[Quote], rsi_periods: int = 14, stoch_periods: int = 14,
signal_periods: int = 3, smooth_periods: int = 1): ...Measures of price volatility and range-based indicators. Includes Bollinger Bands, Average True Range (ATR), Keltner Channels, and volatility-based overlays.
def get_bollinger_bands(quotes: Iterable[Quote], lookback_periods: int = 20, standard_deviations: float = 2): ...
def get_atr(quotes: Iterable[Quote], lookback_periods: int = 14): ...
def get_keltner(quotes: Iterable[Quote], ema_periods: int = 20, multiplier: float = 2.0, atr_periods: int = 10): ...
def get_donchian(quotes: Iterable[Quote], lookback_periods: int = 20): ...Volume-based indicators that analyze trading volume patterns and price-volume relationships. Includes On-Balance Volume (OBV), Money Flow Index (MFI), and volume oscillators.
def get_obv(quotes: Iterable[Quote]): ...
def get_mfi(quotes: Iterable[Quote], lookback_periods: int = 14): ...
def get_cmf(quotes: Iterable[Quote], lookback_periods: int = 20): ...
def get_vwap(quotes: Iterable[Quote]): ...Price overlays and support/resistance indicators that are plotted directly on price charts. Includes Parabolic SAR, SuperTrend, Ichimoku Cloud, and pivot point systems.
def get_parabolic_sar(quotes: Iterable[Quote], acceleration_factor: float = 0.02, max_acceleration_factor: float = 0.2): ...
def get_super_trend(quotes: Iterable[Quote], lookback_periods: int = 10, multiplier: float = 3.0): ...
def get_ichimoku(quotes: Iterable[Quote], tenkan_periods: int = 9, kijun_periods: int = 26, senkou_b_periods: int = 52, senkou_offset: int = None, chikou_offset: int = None): ...
def get_pivot_points(quotes: Iterable[Quote], window_periods: int = 1, point_type: PivotPointType = PivotPointType.STANDARD): ...Advanced and specialized technical indicators including mathematical functions, candlestick pattern recognition, and proprietary indicators.
def get_correlation(quotes_a: Iterable[Quote], quotes_b: Iterable[Quote], lookback_periods: int = 20): ...
def get_beta(eval_quotes: Iterable[Quote], market_quotes: Iterable[Quote], lookback_periods: int, beta_type: BetaType = BetaType.STANDARD): ...
def get_hurst(quotes: Iterable[Quote], lookback_periods: int = 100): ...
def get_doji(quotes: Iterable[Quote]): ...class CandlePart(Enum):
OPEN = ...
HIGH = ...
LOW = ...
CLOSE = ...
VOLUME = ...
HL2 = ... # (High + Low) / 2
HLC3 = ... # (High + Low + Close) / 3
OC2 = ... # (Open + Close) / 2
OHL3 = ... # (Open + High + Low) / 3
OHLC4 = ... # (Open + High + Low + Close) / 4
class MAType(Enum):
ALMA = ...
DEMA = ...
EPMA = ...
EMA = ...
HMA = ...
KAMA = ...
MAMA = ...
SMA = ...
SMMA = ...
TEMA = ...
WMA = ...
class BetaType(Enum):
STANDARD = ...
UP = ...
DOWN = ...
ALL = ...
class PivotPointType(Enum):
STANDARD = ...
CAMARILLA = ...
DEMARK = ...
FIBONACCI = ...
WOODIE = ...