Skip to content

Momentum API Reference

Momentum Indicators Module

This module provides functions for calculating momentum-based indicators for financial time series analysis.

adx(data, period=14)

Calculate Average Directional Index (ADX).

ADX is a technical indicator used to determine the strength of a trend.

Parameters:

Name Type Description Default
data ndarray

Input time series data

required
period int

Number of periods for calculation

14

Returns:

Type Description
ndarray

ADX values

cci(close, period=20, constant=0.015)

Calculate Commodity Channel Index (CCI) using close prices.

CCI measures the current price level relative to an average price level over a given period. This version uses only close prices instead of typical prices for simplified calculation.

Parameters:

Name Type Description Default
close ndarray

Close prices

required
period int

Number of periods for calculation

20
constant float

Scaling constant

0.015

Returns:

Type Description
ndarray

CCI values

macd(data, fast_period=12, slow_period=26, signal_period=9)

Calculate Moving Average Convergence Divergence (MACD).

MACD is a trend-following momentum indicator that shows the relationship between two moving averages of a security's price.

Parameters:

Name Type Description Default
data ndarray

Input time series data

required
fast_period int

Period for the fast EMA

12
slow_period int

Period for the slow EMA

26
signal_period int

Period for the signal line (EMA of MACD line)

9

Returns:

Type Description
tuple of numpy.ndarray

Tuple containing (macd_line, signal_line, histogram)

momentum(data, period=14)

Calculate momentum over a specified period.

Momentum measures the amount that a price has changed over a given period.

Parameters:

Name Type Description Default
data ndarray

Input time series data

required
period int

Number of periods to calculate momentum

14

Returns:

Type Description
ndarray

Momentum values

percent_change(data, periods=1)

Calculate percentage change between consecutive periods.

Parameters:

Name Type Description Default
data ndarray

Input time series data

required
periods int

Number of periods to calculate change over

1

Returns:

Type Description
ndarray

Percentage change values

roc(data, period=14)

Calculate Rate of Change (ROC) over a specified period.

ROC measures the percentage change in price over a given period.

Parameters:

Name Type Description Default
data ndarray

Input time series data

required
period int

Number of periods to calculate ROC

14

Returns:

Type Description
ndarray

ROC values in percentage

rsi(data, period=14, smoothing_type='sma')

Calculate Relative Strength Index (RSI) over a specified period.

RSI measures the speed and change of price movements, indicating overbought (>70) or oversold (<30) conditions.

Parameters:

Name Type Description Default
data ndarray

Input time series data

required
period int

Number of periods to calculate RSI

14
smoothing_type str

Type of smoothing to use: 'sma' (Simple Moving Average) or 'ema' (Exponential Moving Average)

'sma'

Returns:

Type Description
ndarray

RSI values (0-100)

stochastic_oscillator(close, high, low, k_period=14, d_period=3)

Calculate Stochastic Oscillator.

The Stochastic Oscillator is a momentum indicator that shows the location of the close relative to the high-low range over a set number of periods.

Parameters:

Name Type Description Default
close ndarray

Close prices

required
high ndarray

High prices. If None, assumes close contains close prices and high=low=close

required
low ndarray

Low prices. If None, assumes close contains close prices and high=low=close

required
k_period int

Number of periods for %K

14
d_period int

Number of periods for %D (moving average of %K)

3

Returns:

Type Description
tuple of numpy.ndarray

Tuple containing (%K, %D)

tsi(data, long_period=25, short_period=13, signal_period=7)

Calculate True Strength Index (TSI).

TSI is a momentum oscillator that helps identify trends and reversals.

Parameters:

Name Type Description Default
data ndarray

Input time series data

required
long_period int

Long period for double smoothing

25
short_period int

Short period for double smoothing

13
signal_period int

Period for the signal line

7

Returns:

Type Description
tuple of numpy.ndarray

Tuple containing (tsi_line, signal_line)

williams_r(close, high=None, low=None, period=14)

Calculate Williams %R.

Williams %R is a momentum indicator that measures overbought and oversold levels.

Parameters:

Name Type Description Default
close ndarray

Close prices

required
high ndarray

High prices. If None, assumes close contains close prices and high=low=close

None
low ndarray

Low prices. If None, assumes close contains close prices and high=low=close

None
period int

Number of periods for calculation

14

Returns:

Type Description
ndarray

Williams %R values (-100 to 0)