Skip to content

API

kand

ad(high, low, close, volume) builtin

Computes the Accumulation/Distribution (A/D) indicator over NumPy arrays.

The A/D indicator measures the cumulative flow of money into and out of a security by combining price and volume data. It helps identify whether buying or selling pressure is dominant.

Parameters:

Name Type Description Default
high

High prices as a 1-D NumPy array of type f64.

required
low

Low prices as a 1-D NumPy array of type f64.

required
close

Close prices as a 1-D NumPy array of type f64.

required
volume

Volume data as a 1-D NumPy array of type f64.

required

Returns:

Type Description

A new 1-D NumPy array containing the A/D values. The array has the same length as the inputs.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0])
>>> low = np.array([8.0, 9.0, 11.0])
>>> close = np.array([9.0, 11.0, 13.0])
>>> volume = np.array([100.0, 150.0, 200.0])
>>> result = kand.ad(high, low, close, volume)
>>> print(result)
[-50.0, 25.0, 125.0]

ad_incremental(high, low, close, volume, prev_ad) builtin

Computes the latest Accumulation/Distribution (A/D) value incrementally.

This function calculates only the latest A/D value using the previous A/D value, avoiding recalculation of the entire series.

Parameters:

Name Type Description Default
high

Latest high price.

required
low

Latest low price.

required
close

Latest closing price.

required
volume

Latest volume.

required
prev_ad

Previous A/D value.

required

Returns:

Type Description

The latest A/D value.

Examples:

>>> import kand
>>> high = 15.0
>>> low = 11.0
>>> close = 13.0
>>> volume = 200.0
>>> prev_ad = 25.0
>>> result = kand.ad_incremental(high, low, close, volume, prev_ad)
>>> print(result)
125.0

add_demo(a, b)

Add two numbers together.

Parameters:

Name Type Description Default
a int

First number.

required
b int

Second number.

required

Returns:

Type Description
int

The sum of a and b.

adosc(high, low, close, volume, fast_period, slow_period) builtin

Calculate Accumulation/Distribution Oscillator (A/D Oscillator or ADOSC)

The A/D Oscillator is a momentum indicator that measures the difference between a fast and slow EMA of the Accumulation/Distribution Line. It helps identify trend strength and potential reversals.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
volume

Volume as a 1-D NumPy array of type f32.

required
fast_period

Fast period for A/D Oscillator calculation.

required
slow_period

Slow period for A/D Oscillator calculation.

required

Returns:

Type Description

A tuple of 4 1-D NumPy arrays containing:

  • ADOSC values
  • A/D Line values
  • Fast EMA values
  • Slow EMA values

Each array has the same length as the input, with the first slow_period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 11.0, 12.0, 11.5, 10.5])
>>> low = np.array([8.0, 9.0, 10.0, 9.5, 8.5])
>>> close = np.array([9.0, 10.0, 11.0, 10.0, 9.0])
>>> volume = np.array([100.0, 150.0, 200.0, 150.0, 100.0])
>>> adosc, ad, fast_ema, slow_ema = kand.adosc(high, low, close, volume, 3, 5)

adosc_incremental(high, low, close, volume, prev_ad, prev_fast_ema, prev_slow_ema, fast_period, slow_period) builtin

Calculate latest A/D Oscillator value incrementally

Provides optimized calculation of the latest ADOSC value when new data arrives, without recalculating the entire series.

Parameters:

Name Type Description Default
high

Latest high price.

required
low

Latest low price.

required
close

Latest closing price.

required
volume

Latest volume.

required
prev_ad

Previous A/D value.

required
prev_fast_ema

Previous fast EMA value.

required
prev_slow_ema

Previous slow EMA value.

required
fast_period

Fast EMA period.

required
slow_period

Slow EMA period.

required

Returns:

Type Description

A tuple containing (ADOSC, AD, Fast EMA, Slow EMA) values.

Examples:

>>> import kand
>>> adosc, ad, fast_ema, slow_ema = kand.adosc_incremental(
...     10.5,  # high
...     9.5,   # low
...     10.0,  # close
...     150.0, # volume
...     100.0, # prev_ad
...     95.0,  # prev_fast_ema
...     90.0,  # prev_slow_ema
...     3,     # fast_period
...     10,    # slow_period
... )

adx(high, low, close, period) builtin

Calculate Average Directional Index (ADX) for a NumPy array

The ADX (Average Directional Index) measures the strength of a trend, regardless of whether it's up or down. Values range from 0 to 100, with higher values indicating stronger trends.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f64.

required
low

Low prices as a 1-D NumPy array of type f64.

required
close

Close prices as a 1-D NumPy array of type f64.

required
period

Period for ADX calculation (typically 14). Must be positive.

required

Returns:

Type Description

A tuple of four 1-D NumPy arrays containing:

  • ADX values
  • Smoothed +DM values
  • Smoothed -DM values
  • Smoothed TR values

Each array has the same length as the input, with the first (2*period-1) elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([24.20, 24.07, 24.04, 23.87, 23.67])
>>> low = np.array([23.85, 23.72, 23.64, 23.37, 23.46])
>>> close = np.array([23.89, 23.95, 23.67, 23.78, 23.50])
>>> adx, plus_dm, minus_dm, tr = kand.adx(high, low, close, 2)

adx_incremental(high, low, prev_high, prev_low, prev_close, prev_adx, prev_smoothed_plus_dm, prev_smoothed_minus_dm, prev_smoothed_tr, period) builtin

Calculate the latest ADX value incrementally

Parameters:

Name Type Description Default
py

Python interpreter token

required
high

Current period's high price

required
low

Current period's low price

required
prev_high

Previous period's high price

required
prev_low

Previous period's low price

required
prev_close

Previous period's close price

required
prev_adx

Previous period's ADX value

required
prev_smoothed_plus_dm

Previous period's smoothed +DM

required
prev_smoothed_minus_dm

Previous period's smoothed -DM

required
prev_smoothed_tr

Previous period's smoothed TR

required
period

Period for ADX calculation (typically 14)

required

Returns:

Type Description

A tuple containing:

  • Latest ADX value
  • New smoothed +DM
  • New smoothed -DM
  • New smoothed TR

Examples:

>>> import kand
>>> adx, plus_dm, minus_dm, tr = kand.adx_incremental(
...     24.20,  # current high
...     23.85,  # current low
...     24.07,  # previous high
...     23.72,  # previous low
...     23.95,  # previous close
...     25.0,   # previous ADX
...     0.5,    # previous smoothed +DM
...     0.3,    # previous smoothed -DM
...     1.2,    # previous smoothed TR
...     14      # period
... )

adxr(high, low, close, period) builtin

Calculate Average Directional Index Rating (ADXR) for a NumPy array.

ADXR is a momentum indicator that measures the strength of a trend by comparing the current ADX value with the ADX value from period days ago.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f64.

required
low

Low prices as a 1-D NumPy array of type f64.

required
close

Close prices as a 1-D NumPy array of type f64.

required
period

Period for ADX calculation (typically 14).

required

Returns:

Type Description

A tuple of 5 1-D NumPy arrays containing:

  • ADXR values
  • ADX values
  • Smoothed +DM values
  • Smoothed -DM values
  • Smoothed TR values

The first (3*period-2) elements of each array contain NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([24.20, 24.07, 24.04, 23.87, 23.67])
>>> low = np.array([23.85, 23.72, 23.64, 23.37, 23.46])
>>> close = np.array([23.89, 23.95, 23.67, 23.78, 23.50])
>>> adxr, adx, plus_dm, minus_dm, tr = kand.adxr(high, low, close, 2)

adxr_incremental(high, low, prev_high, prev_low, prev_close, prev_adx, prev_adx_period_ago, prev_smoothed_plus_dm, prev_smoothed_minus_dm, prev_smoothed_tr, period) builtin

Calculate the latest ADXR value incrementally

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Current high price as f64.

required
low

Current low price as f64.

required
prev_high

Previous high price as f64.

required
prev_low

Previous low price as f64.

required
prev_close

Previous close price as f64.

required
prev_adx

Previous ADX value as f64.

required
prev_adx_period_ago

ADX value from period days ago as f64.

required
prev_smoothed_plus_dm

Previous smoothed +DM value as f64.

required
prev_smoothed_minus_dm

Previous smoothed -DM value as f64.

required
prev_smoothed_tr

Previous smoothed TR value as f64.

required
period

Period for ADX calculation (typically 14).

required

Returns:

Type Description

A tuple of 5 values:

  • Latest ADXR value
  • Latest ADX value
  • New smoothed +DM value
  • New smoothed -DM value
  • New smoothed TR value

Examples:

>>> import kand
>>> adxr, adx, plus_dm, minus_dm, tr = kand.adxr_incremental(
...     24.20,  # high
...     23.85,  # low
...     24.07,  # prev_high
...     23.72,  # prev_low
...     23.95,  # prev_close
...     25.0,   # prev_adx
...     20.0,   # prev_adx_period_ago
...     0.5,    # prev_smoothed_plus_dm
...     0.3,    # prev_smoothed_minus_dm
...     1.2,    # prev_smoothed_tr
...     14      # period
... )

aroon(high, low, period) builtin

Calculate Aroon indicator for a NumPy array.

The Aroon indicator consists of two lines that measure the time since the last high/low relative to a lookback period. It helps identify the start of new trends and trend reversals.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high prices as a 1-D NumPy array of type f32.

required
low

Input low prices as a 1-D NumPy array of type f32.

required
period

The lookback period for calculations (must be >= 2).

required

Returns:

Type Description

A tuple of 6 1-D NumPy arrays containing:

  • Aroon Up values
  • Aroon Down values
  • Previous high values
  • Previous low values
  • Days since high values
  • Days since low values

The first (period) elements of each array contain NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> aroon_up, aroon_down, prev_high, prev_low, days_high, days_low = kand.aroon(high, low, 3)

aroon_incremental(high, low, prev_high, prev_low, days_since_high, days_since_low, period) builtin

Calculate the next Aroon values incrementally.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Current period's high price.

required
low

Current period's low price.

required
prev_high

Previous highest price in period.

required
prev_low

Previous lowest price in period.

required
days_since_high

Days since previous highest price.

required
days_since_low

Days since previous lowest price.

required
period

The lookback period (must be >= 2).

required

Returns:

Type Description

A tuple containing:

  • Aroon Up value
  • Aroon Down value
  • New highest price
  • New lowest price
  • Updated days since high
  • Updated days since low

Examples:

>>> import kand
>>> aroon_up, aroon_down, new_high, new_low, days_high, days_low = kand.aroon_incremental(
...     15.0,  # high
...     12.0,  # low
...     14.0,  # prev_high
...     11.0,  # prev_low
...     2,     # days_since_high
...     1,     # days_since_low
...     14     # period
... )

aroonosc(high, low, period) builtin

Calculate Aroon Oscillator for a NumPy array.

The Aroon Oscillator measures the strength of a trend by comparing the time since the last high and low. It oscillates between -100 and +100, with positive values indicating an uptrend and negative values a downtrend.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high prices as a 1-D NumPy array of type f64.

required
low

Input low prices as a 1-D NumPy array of type f64.

required
period

The lookback period for calculations (must be >= 2).

required

Returns:

Type Description

A tuple of 5 1-D NumPy arrays containing:

  • Aroon Oscillator values
  • Previous high values
  • Previous low values
  • Days since high values
  • Days since low values

The first (period) elements of each array contain NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> osc, prev_high, prev_low, days_high, days_low = kand.aroonosc(high, low, 3)

aroonosc_incremental(high, low, prev_high, prev_low, days_since_high, days_since_low, period) builtin

Calculate the next Aroon Oscillator value incrementally.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Current period's high price.

required
low

Current period's low price.

required
prev_high

Previous highest price within the period.

required
prev_low

Previous lowest price within the period.

required
days_since_high

Days since previous highest price.

required
days_since_low

Days since previous lowest price.

required
period

The lookback period for calculations (must be >= 2).

required

Returns:

Type Description

A tuple containing:

  • Aroon Oscillator value
  • New highest price
  • New lowest price
  • Updated days since high
  • Updated days since low

Examples:

>>> import kand
>>> osc, high, low, days_high, days_low = kand.aroonosc_incremental(
...     15.0,  # high
...     12.0,  # low
...     14.0,  # prev_high
...     11.0,  # prev_low
...     2,     # days_since_high
...     1,     # days_since_low
...     14     # period
... )

atr(high, low, close, period) builtin

Computes the Average True Range (ATR) over NumPy arrays.

The Average True Range (ATR) is a technical analysis indicator that measures market volatility by decomposing the entire range of an asset price for a given period.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Window size for ATR calculation. Must be greater than 1.

required

Returns:

Type Description

A new 1-D NumPy array containing the ATR values. The array has the same length as the input,

with the first period elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> close = np.array([9.0, 11.0, 14.0, 12.0, 11.0])
>>> result = kand.atr(high, low, close, 3)

atr_incremental(high, low, prev_close, prev_atr, period) builtin

Calculate the next ATR value incrementally.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Current period's high price.

required
low

Current period's low price.

required
prev_close

Previous period's close price.

required
prev_atr

Previous period's ATR value.

required
period

The time period for ATR calculation (must be >= 2).

required

Returns:

Type Description

The calculated ATR value.

Examples:

>>> import kand
>>> atr = kand.atr_incremental(
...     15.0,  # high
...     11.0,  # low
...     12.0,  # prev_close
...     3.0,   # prev_atr
...     14     # period
... )

bbands(price, period, dev_up, dev_down) builtin

Calculate Bollinger Bands for a NumPy array.

Bollinger Bands consist of: - A middle band (N-period simple moving average) - An upper band (K standard deviations above middle band) - A lower band (K standard deviations below middle band)

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
price

Input price values as a 1-D NumPy array of type f32.

required
period

The time period for calculations (must be >= 2).

required
dev_up

Number of standard deviations for upper band.

required
dev_down

Number of standard deviations for lower band.

required

Returns:

Type Description

A tuple of 7 1-D NumPy arrays containing:

  • Upper band values
  • Middle band values
  • Lower band values
  • SMA values
  • Variance values
  • Sum values
  • Sum of squares values

The first (period-1) elements of each array contain NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> price = np.array([10.0, 11.0, 12.0, 13.0, 14.0])
>>> upper, middle, lower, sma, var, sum, sum_sq = kand.bbands(price, 3, 2.0, 2.0)

bbands_incremental(price, prev_sma, prev_sum, prev_sum_sq, old_price, period, dev_up, dev_down) builtin

Calculate the next Bollinger Bands values incrementally.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
price

The current price value.

required
prev_sma

The previous SMA value.

required
prev_sum

The previous sum for variance calculation.

required
prev_sum_sq

The previous sum of squares for variance calculation.

required
old_price

The oldest price value to be removed from the period.

required
period

The time period for calculations (must be >= 2).

required
dev_up

Number of standard deviations for upper band.

required
dev_down

Number of standard deviations for lower band.

required

Returns:

Type Description

A tuple containing:

  • Upper Band value
  • Middle Band value
  • Lower Band value
  • New SMA value
  • New Sum value
  • New Sum of Squares value

Examples:

>>> import kand
>>> upper, middle, lower, sma, sum, sum_sq = kand.bbands_incremental(
...     10.0,   # price
...     9.5,    # prev_sma
...     28.5,   # prev_sum
...     272.25, # prev_sum_sq
...     9.0,    # old_price
...     3,      # period
...     2.0,    # dev_up
...     2.0     # dev_down
... )

bop(open, high, low, close) builtin

Calculate Balance of Power (BOP) indicator for NumPy arrays.

The Balance of Power (BOP) is a momentum oscillator that measures the relative strength between buyers and sellers by comparing the closing price to the opening price and normalizing it by the trading range (high - low).

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Input opening prices as a 1-D NumPy array of type f64.

required
high

Input high prices as a 1-D NumPy array of type f64.

required
low

Input low prices as a 1-D NumPy array of type f64.

required
close

Input closing prices as a 1-D NumPy array of type f64.

required

Returns:

Type Description

A 1-D NumPy array containing the BOP values.

Examples:

>>> import numpy as np
>>> import kand
>>> open = np.array([10.0, 11.0, 12.0, 13.0])
>>> high = np.array([12.0, 13.0, 14.0, 15.0])
>>> low = np.array([8.0, 9.0, 10.0, 11.0])
>>> close = np.array([11.0, 12.0, 13.0, 14.0])
>>> bop = kand.bop(open, high, low, close)

bop_incremental(open, high, low, close) builtin

Calculate a single Balance of Power (BOP) value for the latest price data.

Parameters:

Name Type Description Default
open

Current period's opening price

required
high

Current period's high price

required
low

Current period's low price

required
close

Current period's closing price

required

Returns:

Type Description

The calculated BOP value

Examples:

>>> import kand
>>> bop = kand.bop_incremental(10.0, 12.0, 8.0, 11.0)

cci(high, low, close, period) builtin

Computes the Commodity Channel Index (CCI) over NumPy arrays.

The CCI is a momentum-based oscillator used to help determine when an investment vehicle is reaching a condition of being overbought or oversold.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Window size for CCI calculation. Must be positive and less than input length.

required

Returns:

Type Description

A tuple of 1-D NumPy arrays containing:

  • CCI values
  • Typical prices
  • SMA of typical prices
  • Mean deviation values

Each array has the same length as the input, with the first period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([24.20, 24.07, 24.04, 23.87, 23.67])
>>> low = np.array([23.85, 23.72, 23.64, 23.37, 23.46])
>>> close = np.array([23.89, 23.95, 23.67, 23.78, 23.50])
>>> cci, tp, sma_tp, mean_dev = kand.cci(high, low, close, 3)
>>> print(cci)
[nan, nan, -100.0, 66.67, -133.33]

cci_incremental(prev_sma_tp, new_high, new_low, new_close, old_high, old_low, old_close, period, tp_buffer) builtin

Calculates the next CCI value incrementally.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prev_sma_tp

Previous SMA value of typical prices.

required
new_high

New high price.

required
new_low

New low price.

required
new_close

New close price.

required
old_high

Old high price to be removed.

required
old_low

Old low price to be removed.

required
old_close

Old close price to be removed.

required
period

Window size for CCI calculation.

required
tp_buffer

List containing the last period typical prices.

required

Returns:

Type Description

The next CCI value.

Examples:

>>> import kand
>>> prev_sma_tp = 100.0
>>> new_high = 105.0
>>> new_low = 95.0
>>> new_close = 100.0
>>> old_high = 102.0
>>> old_low = 98.0
>>> old_close = 100.0
>>> period = 14
>>> tp_buffer = [100.0] * period
>>> next_cci = kand.cci_incremental(prev_sma_tp, new_high, new_low, new_close,
...                                  old_high, old_low, old_close, period, tp_buffer)

cdl_doji(open, high, low, close, body_percent, shadow_equal_percent) builtin

Detects Doji candlestick patterns in price data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening prices as a 1-D NumPy array of type f64.

required
high

High prices as a 1-D NumPy array of type f64.

required
low

Low prices as a 1-D NumPy array of type f64.

required
close

Close prices as a 1-D NumPy array of type f64.

required
body_percent

Maximum body size as percentage of range (e.g. 5.0 for 5%).

required
shadow_equal_percent

Maximum shadow length difference percentage (e.g. 100.0).

required

Returns:

Type Description

A 1-D NumPy array containing pattern signals (1.0 = pattern, 0.0 = no pattern).

Examples:

>>> import numpy as np
>>> import kand
>>> open = np.array([10.0, 10.5, 10.2])
>>> high = np.array([11.0, 11.2, 10.8])
>>> low = np.array([9.8, 10.1, 9.9])
>>> close = np.array([10.3, 10.4, 10.25])
>>> signals = kand.cdl_doji(open, high, low, close, 5.0, 100.0)

cdl_doji_incremental(open, high, low, close, body_percent, shadow_equal_percent) builtin

Detects a Doji pattern in a single candlestick.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening price.

required
high

High price.

required
low

Low price.

required
close

Close price.

required
body_percent

Maximum body size as percentage of range.

required
shadow_equal_percent

Maximum shadow length difference percentage.

required

Returns:

Type Description

Signal value (1.0 for Doji pattern, 0.0 for no pattern).

Examples:

>>> import kand
>>> signal = kand.cdl_doji_incremental(10.0, 11.0, 9.8, 10.3, 5.0, 100.0)

cdl_dragonfly_doji(open, high, low, close, body_percent) builtin

Detects Dragonfly Doji candlestick patterns in price data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening prices as a 1-D NumPy array of type f32.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
body_percent

Maximum body size as percentage of total range (typically 5%).

required

Returns:

Type Description

A 1-D NumPy array containing pattern signals:

  • 100: Bullish Dragonfly Doji pattern detected
  • 0: No pattern detected

Examples:

>>> import numpy as np
>>> import kand
>>> open = np.array([100.0, 101.0, 102.0])
>>> high = np.array([102.0, 103.0, 104.0])
>>> low = np.array([98.0, 99.0, 100.0])
>>> close = np.array([101.0, 102.0, 103.0])
>>> signals = kand.cdl_dragonfly_doji(open, high, low, close, 5.0)

cdl_dragonfly_doji_incremental(open, high, low, close, body_percent) builtin

Detects a Dragonfly Doji pattern in a single candlestick.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening price.

required
high

High price.

required
low

Low price.

required
close

Close price.

required
body_percent

Maximum body size as percentage of total range.

required

Returns:

Type Description

Signal value:

  • 100: Bullish Dragonfly Doji pattern detected
  • 0: No pattern detected

Examples:

>>> import kand
>>> signal = kand.cdl_dragonfly_doji_incremental(100.0, 102.0, 98.0, 100.1, 5.0)

cdl_gravestone_doji(open, high, low, close, body_percent) builtin

Detects Gravestone Doji candlestick patterns in price data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening prices as a 1-D NumPy array of type f64.

required
high

High prices as a 1-D NumPy array of type f64.

required
low

Low prices as a 1-D NumPy array of type f64.

required
close

Close prices as a 1-D NumPy array of type f64.

required
body_percent

Maximum body size as percentage of total range (typically 5%).

required

Returns:

Type Description

A 1-D NumPy array containing pattern signals:

  • -100: Bearish Gravestone Doji pattern detected
  • 0: No pattern detected

Examples:

>>> import numpy as np
>>> import kand
>>> open = np.array([100.0, 101.0, 102.0])
>>> high = np.array([102.0, 103.0, 104.0])
>>> low = np.array([98.0, 99.0, 100.0])
>>> close = np.array([101.0, 102.0, 103.0])
>>> signals = kand.cdl_gravestone_doji(open, high, low, close, 5.0)

cdl_gravestone_doji_incremental(open, high, low, close, body_percent) builtin

Detects a Gravestone Doji pattern in a single candlestick.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening price.

required
high

High price.

required
low

Low price.

required
close

Close price.

required
body_percent

Maximum body size as percentage of total range.

required

Returns:

Type Description

Signal value:

  • -100: Bearish Gravestone Doji pattern detected
  • 0: No pattern detected

Examples:

>>> import kand
>>> signal = kand.cdl_gravestone_doji_incremental(100.0, 102.0, 98.0, 100.1, 5.0)

cdl_hammer(open, high, low, close, period, factor) builtin

Detects Hammer candlestick patterns in price data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening prices as a 1-D NumPy array of type f64.

required
high

High prices as a 1-D NumPy array of type f64.

required
low

Low prices as a 1-D NumPy array of type f64.

required
close

Close prices as a 1-D NumPy array of type f64.

required
period

Period for EMA calculation of body sizes.

required
factor

Minimum ratio of lower shadow to body length.

required

Returns:

Type Description

A tuple of two 1-D NumPy arrays containing:

  • Pattern signals:
  • 100: Bullish Hammer pattern detected
  • 0: No pattern detected
  • EMA values of candle body sizes

Examples:

>>> import numpy as np
>>> import kand
>>> open = np.array([100.0, 101.0, 102.0])
>>> high = np.array([102.0, 103.0, 104.0])
>>> low = np.array([98.0, 99.0, 100.0])
>>> close = np.array([101.0, 102.0, 103.0])
>>> signals, body_avg = kand.cdl_hammer(open, high, low, close, 14, 2.0)

cdl_hammer_incremental(open, high, low, close, prev_body_avg, period, factor) builtin

Detects a Hammer pattern in a single candlestick.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening price.

required
high

High price.

required
low

Low price.

required
close

Close price.

required
prev_body_avg

Previous EMA value of body sizes.

required
period

Period for EMA calculation.

required
factor

Minimum ratio of lower shadow to body length.

required

Returns:

Type Description

A tuple containing:

  • Signal value:
  • 100: Bullish Hammer pattern detected
  • 0: No pattern detected
  • Updated EMA value of body sizes

Examples:

>>> import kand
>>> signal, body_avg = kand.cdl_hammer_incremental(100.0, 102.0, 98.0, 100.1, 0.5, 14, 2.0)

cdl_inverted_hammer(open, high, low, close, period, factor) builtin

Detects Inverted Hammer candlestick patterns in price data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening prices as a 1-D NumPy array of type f32.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Period for EMA calculation of body sizes.

required
factor

Minimum ratio of upper shadow to body length.

required

Returns:

Type Description

A tuple of two 1-D NumPy arrays containing:

  • Pattern signals:
  • 100: Bullish Inverted Hammer pattern detected
  • 0: No pattern detected
  • EMA values of candle body sizes

Examples:

>>> import numpy as np
>>> import kand
>>> open = np.array([100.0, 101.0, 102.0])
>>> high = np.array([102.0, 103.0, 104.0])
>>> low = np.array([98.0, 99.0, 100.0])
>>> close = np.array([101.0, 102.0, 103.0])
>>> signals, body_avg = kand.cdl_inverted_hammer(open, high, low, close, 14, 2.0)

cdl_inverted_hammer_incremental(open, high, low, close, prev_body_avg, period, factor) builtin

Detects an Inverted Hammer pattern in a single candlestick.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening price.

required
high

High price.

required
low

Low price.

required
close

Close price.

required
prev_body_avg

Previous EMA value of body sizes.

required
period

Period for EMA calculation.

required
factor

Minimum ratio of upper shadow to body length.

required

Returns:

Type Description

A tuple containing:

  • Signal value:
  • 100: Bullish Inverted Hammer pattern detected
  • 0: No pattern detected
  • Updated EMA value of body sizes

Examples:

>>> import kand
>>> signal, body_avg = kand.cdl_inverted_hammer_incremental(100.0, 102.0, 98.0, 100.1, 0.5, 14, 2.0)

cdl_long_shadow(open, high, low, close, period, shadow_factor) builtin

Detects Long Shadow candlestick patterns in price data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening prices as a 1-D NumPy array of type f32.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Period for EMA calculation of body sizes.

required
shadow_factor

Minimum percentage of total range that shadow must be.

required

Returns:

Type Description

A tuple of two 1-D NumPy arrays containing:

  • Pattern signals:
  • 100: Bullish Long Lower Shadow pattern detected
  • -100: Bearish Long Upper Shadow pattern detected
  • 0: No pattern detected
  • EMA values of candle body sizes

Examples:

>>> import numpy as np
>>> import kand
>>> open = np.array([100.0, 101.0, 102.0])
>>> high = np.array([102.0, 103.0, 104.0])
>>> low = np.array([98.0, 99.0, 100.0])
>>> close = np.array([101.0, 102.0, 103.0])
>>> signals, body_avg = kand.cdl_long_shadow(open, high, low, close, 14, 75.0)

cdl_long_shadow_incremental(open, high, low, close, prev_body_avg, period, shadow_factor) builtin

Detects a Long Shadow pattern in a single candlestick.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening price.

required
high

High price.

required
low

Low price.

required
close

Close price.

required
prev_body_avg

Previous EMA value of body sizes.

required
period

Period for EMA calculation.

required
shadow_factor

Minimum percentage of total range that shadow must be.

required

Returns:

Type Description

A tuple containing:

  • Signal value:
  • 100: Bullish Long Lower Shadow pattern detected
  • -100: Bearish Long Upper Shadow pattern detected
  • 0: No pattern detected
  • Updated EMA value of body sizes

Examples:

>>> import kand
>>> signal, body_avg = kand.cdl_long_shadow_incremental(100.0, 102.0, 98.0, 100.1, 0.5, 14, 75.0)

cdl_marubozu(open, high, low, close, period, shadow_percent) builtin

Detects Marubozu candlestick patterns in price data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening prices as a 1-D NumPy array of type f32.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Period for EMA calculation of body sizes.

required
shadow_percent

Maximum shadow size as percentage of body.

required

Returns:

Type Description

A tuple of two 1-D NumPy arrays containing:

  • Pattern signals:
  • 1.0: Bullish Marubozu pattern detected
  • -1.0: Bearish Marubozu pattern detected
  • 0.0: No pattern detected
  • EMA values of candle body sizes

Examples:

>>> import numpy as np
>>> import kand
>>> open = np.array([100.0, 101.0, 102.0])
>>> high = np.array([102.0, 103.0, 104.0])
>>> low = np.array([98.0, 99.0, 100.0])
>>> close = np.array([101.0, 102.0, 103.0])
>>> signals, body_avg = kand.cdl_marubozu(open, high, low, close, 14, 5.0)

cdl_marubozu_incremental(open, high, low, close, prev_body_avg, period, shadow_percent) builtin

Detects a Marubozu pattern in a single candlestick.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
open

Opening price.

required
high

High price.

required
low

Low price.

required
close

Close price.

required
prev_body_avg

Previous EMA value of body sizes.

required
period

Period for EMA calculation.

required
shadow_percent

Maximum shadow size as percentage of body.

required

Returns:

Type Description

A tuple containing:

  • Signal value:
  • 1.0: Bullish Marubozu pattern detected
  • -1.0: Bearish Marubozu pattern detected
  • 0.0: No pattern detected
  • Updated EMA value of body sizes

Examples:

>>> import kand
>>> signal, body_avg = kand.cdl_marubozu_incremental(100.0, 102.0, 98.0, 100.1, 0.5, 14, 5.0)

dema(input_price, period) builtin

Calculates Double Exponential Moving Average (DEMA) over NumPy arrays.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
input_price

Price values as a 1-D NumPy array of type f32.

required
period

Smoothing period for EMA calculations. Must be >= 2.

required

Returns:

Type Description

A tuple of 1-D NumPy arrays containing:

  • DEMA values
  • First EMA values
  • Second EMA values

Each array has the same length as the input, with the first 2*(period-1) elements containing NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0])
>>> dema, ema1, ema2 = kand.dema(prices, 3)

dema_incremental(price, prev_ema1, prev_ema2, period) builtin

Calculates the next DEMA value incrementally.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
price

Current price value.

required
prev_ema1

Previous value of first EMA.

required
prev_ema2

Previous value of second EMA.

required
period

Smoothing period. Must be >= 2.

required

Returns:

Type Description

A tuple containing (DEMA, new_ema1, new_ema2).

Examples:

>>> import kand
>>> dema, ema1, ema2 = kand.dema_incremental(10.0, 9.5, 9.0, 3)

dx(high, low, close, period) builtin

Computes the Directional Movement Index (DX) over NumPy arrays.

The DX indicator measures the strength of a trend by comparing positive and negative directional movements.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Window size for DX calculation. Must be positive and less than input length.

required

Returns:

Type Description

A tuple of four 1-D NumPy arrays containing:

  • DX values
  • Smoothed +DM values
  • Smoothed -DM values
  • Smoothed TR values

Each array has the same length as the input, with the first period elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([24.20, 24.07, 24.04, 23.87, 23.67])
>>> low = np.array([23.85, 23.72, 23.64, 23.37, 23.46])
>>> close = np.array([23.89, 23.95, 23.67, 23.78, 23.50])
>>> dx, plus_dm, minus_dm, tr = kand.dx(high, low, close, 3)

dx_incremental(input_high, input_low, input_prev_high, input_prev_low, input_prev_close, input_prev_smoothed_plus_dm, input_prev_smoothed_minus_dm, input_prev_smoothed_tr, param_period) builtin

Calculates the latest DX value incrementally.

Computes only the most recent DX value using previous smoothed values. Optimized for real-time calculations where only the latest value is needed.

For the formula, refer to the [dx] function documentation.

Parameters:

Name Type Description Default
input_high float

Current high price.

required
input_low float

Current low price.

required
input_prev_high float

Previous period's high price.

required
input_prev_low float

Previous period's low price.

required
input_prev_close float

Previous period's close price.

required
input_prev_smoothed_plus_dm float

Previous smoothed +DM value.

required
input_prev_smoothed_minus_dm float

Previous smoothed -DM value.

required
input_prev_smoothed_tr float

Previous smoothed TR value.

required
param_period int

Period for DX calculation (typically 14).

required

Returns:

Name Type Description
tuple

A tuple containing: - Latest DX value (float) - New smoothed +DM (float) - New smoothed -DM (float) - New smoothed TR (float)

Example

import kand high, low = 24.20, 23.85 prev_high, prev_low, prev_close = 24.07, 23.72, 23.95 prev_smoothed_plus_dm = 0.5 prev_smoothed_minus_dm = 0.3 prev_smoothed_tr = 1.2 period = 14 dx, plus_dm, minus_dm, tr = kand.dx_incremental( ... high, low, prev_high, prev_low, prev_close, ... prev_smoothed_plus_dm, prev_smoothed_minus_dm, ... prev_smoothed_tr, period)

ecl(high, low, close) builtin

Computes the Expanded Camarilla Levels (ECL) over NumPy arrays.

The ECL indicator calculates multiple support and resistance levels based on the previous period's high, low and close prices.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high prices as a 1-D NumPy array of type f32.

required
low

Input low prices as a 1-D NumPy array of type f32.

required
close

Input close prices as a 1-D NumPy array of type f32.

required

Returns:

Type Description

A tuple of ten 1-D NumPy arrays containing the ECL values (H5,H4,H3,H2,H1,L1,L2,L3,L4,L5).

Each array has the same length as the input, with the first element containing NaN value.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([24.20, 24.07, 24.04, 23.87, 23.67])
>>> low = np.array([23.85, 23.72, 23.64, 23.37, 23.46])
>>> close = np.array([23.89, 23.95, 23.67, 23.78, 23.50])
>>> h5,h4,h3,h2,h1,l1,l2,l3,l4,l5 = kand.ecl(high, low, close)

ecl_incremental(prev_high, prev_low, prev_close) builtin

Computes the latest Expanded Camarilla Levels (ECL) values incrementally.

This function provides an efficient way to calculate ECL values for new data without reprocessing the entire dataset.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prev_high

Previous period's high price as f32.

required
prev_low

Previous period's low price as f32.

required
prev_close

Previous period's close price as f32.

required

Returns:

Type Description

A tuple of ten values (H5,H4,H3,H2,H1,L1,L2,L3,L4,L5) containing the latest ECL levels.

Examples:

>>> import kand
>>> h5,h4,h3,h2,h1,l1,l2,l3,l4,l5 = kand.ecl_incremental(24.20, 23.85, 23.89)

ema(data, period, k=None) builtin

Computes the Exponential Moving Average (EMA) over a NumPy array.

The Exponential Moving Average is calculated by applying more weight to recent prices via a smoothing factor k. Each value is calculated as: EMA = Price * k + EMA(previous) * (1 - k) where k is typically 2/(period+1).

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input data as a 1-D NumPy array of type f32.

required
period

Window size for EMA calculation. Must be positive and less than input length.

required
k

Optional custom smoothing factor. If None, uses default k = 2/(period+1).

None

Returns:

Type Description

A new 1-D NumPy array containing the EMA values. The array has the same length as the input,

with the first period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> result = kand.ema(data, 3)
>>> print(result)
[nan, nan, 2.0, 3.0, 4.2]

ema_incremental(price, prev_ema, period, k=None) builtin

Computes the latest EMA value incrementally.

This function provides an efficient way to calculate EMA values for new data without reprocessing the entire dataset.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
price

Current period's price value as f32.

required
prev_ema

Previous period's EMA value as f32.

required
period

Window size for EMA calculation. Must be >= 2.

required
k

Optional custom smoothing factor. If None, uses default k = 2/(period+1).

None

Returns:

Type Description

The new EMA value as f32.

Examples:

>>> import kand
>>> current_price = 15.0
>>> prev_ema = 14.5
>>> period = 14
>>> new_ema = kand.ema_incremental(current_price, prev_ema, period)

macd(data, fast_period, slow_period, signal_period) builtin

Computes the Moving Average Convergence Divergence (MACD) over a NumPy array.

MACD is a trend-following momentum indicator that shows the relationship between two moving averages of an asset's price. It consists of three components: - MACD Line: Difference between fast and slow EMAs - Signal Line: EMA of the MACD line - Histogram: Difference between MACD line and signal line

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input price data as a 1-D NumPy array of type f64.

required
fast_period

Period for fast EMA calculation (typically 12).

required
slow_period

Period for slow EMA calculation (typically 26).

required
signal_period

Period for signal line calculation (typically 9).

required

Returns:

Type Description

A tuple of five 1-D NumPy arrays containing:

  • MACD line values
  • Signal line values
  • MACD histogram values
  • Fast EMA values
  • Slow EMA values

Each array has the same length as the input, with initial elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> macd_line, signal_line, histogram, fast_ema, slow_ema = kand.macd(data, 2, 3, 2)

macd_incremental(price, prev_fast_ema, prev_slow_ema, prev_signal, fast_period, slow_period, signal_period) builtin

Computes the latest MACD values incrementally from previous state.

This function provides an efficient way to calculate MACD for streaming data by using previous EMA values instead of recalculating the entire series.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
price

Current price value as f64.

required
prev_fast_ema

Previous fast EMA value as f64.

required
prev_slow_ema

Previous slow EMA value as f64.

required
prev_signal

Previous signal line value as f64.

required
fast_period

Period for fast EMA calculation (typically 12).

required
slow_period

Period for slow EMA calculation (typically 26).

required
signal_period

Period for signal line calculation (typically 9).

required

Returns:

Type Description

A tuple of three values:

  • MACD line value
  • Signal line value
  • MACD histogram value

Examples:

>>> import kand
>>> macd_line, signal_line, histogram = kand.macd_incremental(
...     100.0,  # current price
...     95.0,   # previous fast EMA
...     98.0,   # previous slow EMA
...     -2.5,   # previous signal
...     12,     # fast period
...     26,     # slow period
...     9       # signal period
... )

max(prices, period) builtin

Calculate Maximum Value for a NumPy array

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prices

Input prices as a 1-D NumPy array of type f64.

required
period

Period for MAX calculation (must be >= 2).

required

Returns:

Type Description

A 1-D NumPy array containing MAX values. The first (period-1) elements contain NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([1.0, 2.0, 3.0, 2.5, 4.0])
>>> max_values = kand.max(prices, 3)

max_incremental(price, prev_max, old_price, period) builtin

Calculate the latest Maximum Value incrementally

Parameters:

Name Type Description Default
py

Python interpreter token

required
price

Current period's price

required
prev_max

Previous period's MAX value

required
old_price

Price being removed from the period

required
period

Period for MAX calculation (must be >= 2)

required

Returns:

Type Description

The new MAX value

Examples:

>>> import kand
>>> new_max = kand.max_incremental(10.5, 11.0, 9.0, 14)

medprice(high, low) builtin

Calculates the Median Price (MEDPRICE) for a NumPy array.

The Median Price is a technical analysis indicator that represents the middle point between high and low prices for each period.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Array of high prices as a 1-D NumPy array of type f64.

required
low

Array of low prices as a 1-D NumPy array of type f64.

required

Returns:

Type Description

A 1-D NumPy array containing the median price values.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 11.0, 12.0])
>>> low = np.array([8.0, 9.0, 10.0])
>>> result = kand.medprice(high, low)
>>> print(result)
[9.0, 10.0, 11.0]

medprice_incremental(high, low) builtin

Calculates a single Median Price value incrementally.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Current period's high price as f64.

required
low

Current period's low price as f64.

required

Returns:

Type Description

The calculated median price value.

Examples:

>>> import kand
>>> result = kand.medprice_incremental(10.0, 8.0)
>>> print(result)
9.0

mfi(high, low, close, volume, period) builtin

Calculates the Money Flow Index (MFI) for a NumPy array.

The Money Flow Index (MFI) is a technical oscillator that uses price and volume data to identify overbought or oversold conditions in an asset.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Array of high prices as a 1-D NumPy array of type f32.

required
low

Array of low prices as a 1-D NumPy array of type f32.

required
close

Array of close prices as a 1-D NumPy array of type f32.

required
volume

Array of volume data as a 1-D NumPy array of type f32.

required
period

The time period for MFI calculation (typically 14).

required

Returns:

Type Description

A tuple of five 1-D NumPy arrays containing:

  • MFI values (0-100)
  • Typical prices
  • Money flows
  • Positive money flows
  • Negative money flows

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 11.0, 12.0, 11.0])
>>> low = np.array([8.0, 9.0, 10.0, 9.0])
>>> close = np.array([9.0, 10.0, 11.0, 10.0])
>>> volume = np.array([100.0, 150.0, 200.0, 150.0])
>>> mfi, typ_prices, money_flows, pos_flows, neg_flows = kand.mfi(high, low, close, volume, 2)

midpoint(data, period) builtin

Calculates Midpoint values for a NumPy array.

The Midpoint is a technical indicator that represents the arithmetic mean of the highest and lowest prices over a specified period.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input price data as a 1-D NumPy array of type f64.

required
period

Time period for calculation (must be >= 2).

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • Midpoint values
  • Highest values for each period
  • Lowest values for each period

Each array has the same length as the input, with initial elements containing NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> midpoint, highest, lowest = kand.midpoint(data, 3)

midpoint_incremental(price, prev_highest, prev_lowest, period) builtin

Calculates the next Midpoint value incrementally.

Provides an optimized way to calculate the next Midpoint value when new data arrives, without recalculating the entire series.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
price

Current price value as f64.

required
prev_highest

Previous highest value as f64.

required
prev_lowest

Previous lowest value as f64.

required
period

Time period for calculation (must be >= 2).

required

Returns:

Type Description

A tuple containing:

  • Midpoint value
  • New highest value
  • New lowest value

Examples:

>>> import kand
>>> midpoint, new_highest, new_lowest = kand.midpoint_incremental(
...     15.0,  # current price
...     16.0,  # previous highest
...     14.0,  # previous lowest
...     14     # period
... )

midprice(high, low, period) builtin

Calculates Midpoint Price values for a NumPy array.

The Midpoint Price is a technical indicator that represents the mean value between the highest high and lowest low prices over a specified period.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high price data as a 1-D NumPy array of type f32.

required
low

Input low price data as a 1-D NumPy array of type f32.

required
period

Time period for calculation (must be >= 2).

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • Midpoint Price values
  • Highest high values for each period
  • Lowest low values for each period

Each array has the same length as the input, with initial elements containing NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> midprice, highest, lowest = kand.midprice(high, low, 3)

midprice_incremental(high, low, prev_highest, prev_lowest, period) builtin

Calculates the next Midpoint Price value incrementally.

Provides an optimized way to calculate the next Midpoint Price value when new data arrives, without recalculating the entire series.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Current high price value as f32.

required
low

Current low price value as f32.

required
prev_highest

Previous highest high value as f32.

required
prev_lowest

Previous lowest low value as f32.

required
period

Time period for calculation (must be >= 2).

required

Returns:

Type Description

A tuple containing:

  • Midpoint Price value
  • New highest high value
  • New lowest low value

Examples:

>>> import kand
>>> midprice, new_highest, new_lowest = kand.midprice_incremental(
...     10.5,  # current high
...     9.8,   # current low
...     10.2,  # previous highest high
...     9.5,   # previous lowest low
...     14     # period
... )

min(prices, period) builtin

Calculate Minimum Value (MIN) for a NumPy array

The MIN indicator finds the lowest price value within a given time period.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prices

Input prices as a 1-D NumPy array of type f64.

required
period

Period for MIN calculation (must be >= 2).

required

Returns:

Type Description

A 1-D NumPy array containing MIN values. First (period-1) elements contain NaN.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([10.0, 8.0, 6.0, 7.0, 9.0])
>>> min_values = kand.min(prices, 3)

min_incremental(price, prev_min, prev_price, period) builtin

Calculate the latest MIN value incrementally

Parameters:

Name Type Description Default
py

Python interpreter token

required
price

Current period's price

required
prev_min

Previous period's MIN value

required
prev_price

Price value being removed from the period

required
period

Period for MIN calculation (must be >= 2)

required

Returns:

Type Description

The new MIN value

Examples:

>>> import kand
>>> new_min = kand.min_incremental(15.0, 12.0, 14.0, 14)

minus_di(high, low, close, period) builtin

Computes the Minus Directional Indicator (-DI) over NumPy arrays.

The -DI measures the presence and strength of a downward price trend. It is one component used in calculating the Average Directional Index (ADX), which helps determine trend strength.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Window size for -DI calculation. Must be positive and less than input length.

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • The -DI values
  • The smoothed -DM values
  • The smoothed TR values

Each array has the same length as the input, with the first period elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([35.0, 36.0, 35.5, 35.8, 36.2])
>>> low = np.array([34.0, 35.0, 34.5, 34.8, 35.2])
>>> close = np.array([34.5, 35.5, 35.0, 35.3, 35.7])
>>> minus_di, smoothed_minus_dm, smoothed_tr = kand.minus_di(high, low, close, 3)
>>> print(minus_di)
[nan, nan, nan, 25.3, 24.1]

minus_dm(high, low, period) builtin

Computes the Minus Directional Movement (-DM) over NumPy arrays.

Minus Directional Movement (-DM) measures downward price movement and is used as part of the Directional Movement System developed by J. Welles Wilder.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high prices as a 1-D NumPy array of type f32.

required
low

Input low prices as a 1-D NumPy array of type f32.

required
period

Window size for -DM calculation. Must be positive and less than input length.

required

Returns:

Type Description

A new 1-D NumPy array containing the -DM values. The array has the same length as the input,

with the first period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([35266.0, 35247.5, 35235.7, 35190.8, 35182.0])
>>> low = np.array([35216.1, 35206.5, 35180.0, 35130.7, 35153.6])
>>> result = kand.minus_dm(high, low, 3)

mom(data, period) builtin

Computes the Momentum (MOM) over a NumPy array.

Momentum measures the change in price between the current price and the price n periods ago.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input data as a 1-D NumPy array of type f32.

required
period

Window size for momentum calculation. Must be positive and less than input length.

required

Returns:

Type Description

A new 1-D NumPy array containing the momentum values. The array has the same length as the input,

with the first period elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([2.0, 4.0, 6.0, 8.0, 10.0])
>>> result = kand.mom(data, 2)
>>> print(result)
[nan, nan, 4.0, 4.0, 4.0]

mom_incremental(current_price, old_price) builtin

Calculates the next Momentum (MOM) value incrementally.

This function provides an optimized way to calculate the latest momentum value when streaming data is available, without needing the full price history.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
current_price

The current period's price value.

required
old_price

The price value from n periods ago.

required

Returns:

Type Description

The calculated momentum value.

Examples:

>>> import kand
>>> momentum = kand.mom_incremental(10.0, 6.0)
>>> print(momentum)
4.0

natr(high, low, close, period) builtin

Computes the Normalized Average True Range (NATR) over NumPy arrays.

The NATR is a measure of volatility that accounts for the price level of the instrument. It expresses the ATR as a percentage of the closing price.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Window size for NATR calculation. Must be positive and less than input length.

required

Returns:

Type Description

A new 1-D NumPy array containing the NATR values. The array has the same length as the input,

with the first period elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> close = np.array([9.0, 11.0, 14.0, 12.0, 11.0])
>>> result = kand.natr(high, low, close, 3)

natr_incremental(high, low, close, prev_close, prev_atr, period) builtin

Calculates the next NATR value incrementally.

This function provides an optimized way to calculate a single new NATR value using the previous ATR value and current price data, without recalculating the entire series.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Current period's high price.

required
low

Current period's low price.

required
close

Current period's closing price.

required
prev_close

Previous period's closing price.

required
prev_atr

Previous period's ATR value.

required
period

Period for NATR calculation (must be >= 2).

required

Returns:

Type Description

The calculated NATR value.

Examples:

>>> import kand
>>> natr = kand.natr_incremental(
...     15.0,  # high
...     11.0,  # low
...     14.0,  # close
...     12.0,  # prev_close
...     3.0,   # prev_atr
...     3      # period
... )

obv(close, volume) builtin

Computes the On Balance Volume (OBV) over NumPy arrays.

On Balance Volume (OBV) is a momentum indicator that uses volume flow to predict changes in stock price. When volume increases without a significant price change, the price will eventually jump upward. When volume decreases without a significant price change, the price will eventually jump downward.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
close

Close prices as a 1-D NumPy array of type f64.

required
volume

Volume data as a 1-D NumPy array of type f64.

required

Returns:

Type Description

A new 1-D NumPy array containing the OBV values. The array has the same length as the input.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> close = np.array([10.0, 12.0, 11.0, 13.0])
>>> volume = np.array([100.0, 150.0, 120.0, 200.0])
>>> result = kand.obv(close, volume)
>>> print(result)
[100.0, 250.0, 130.0, 330.0]

obv_incremental(curr_close, prev_close, volume, prev_obv) builtin

Calculates the next OBV value incrementally.

This function provides an optimized way to calculate a single new OBV value using the previous OBV value and current price/volume data.

Parameters:

Name Type Description Default
curr_close

Current closing price as f64.

required
prev_close

Previous closing price as f64.

required
volume

Current volume as f64.

required
prev_obv

Previous OBV value as f64.

required

Returns:

Type Description

The calculated OBV value.

Examples:

>>> import kand
>>> curr_close = 12.0
>>> prev_close = 10.0
>>> volume = 150.0
>>> prev_obv = 100.0
>>> result = kand.obv_incremental(curr_close, prev_close, volume, prev_obv)
>>> print(result)
250.0

plus_di(high, low, close, period) builtin

Computes the Plus Directional Indicator (+DI) over NumPy arrays.

+DI measures the presence and strength of an upward price trend. It is one component used in calculating the Average Directional Index (ADX), which helps determine trend strength.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
period

Window size for +DI calculation. Must be positive and less than input length.

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • +DI values
  • Smoothed +DM values
  • Smoothed TR values

Each array has the same length as the input, with the first period elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 11.5, 11.0])
>>> low = np.array([9.0, 10.0, 10.0, 9.5])
>>> close = np.array([9.5, 11.0, 10.5, 10.0])
>>> plus_di, smoothed_plus_dm, smoothed_tr = kand.plus_di(high, low, close, 2)

plus_di_incremental(high, low, prev_high, prev_low, prev_close, prev_smoothed_plus_dm, prev_smoothed_tr, period) builtin

Calculates the next +DI value incrementally using previous smoothed values.

This function enables real-time calculation of +DI by using the previous smoothed values and current price data, avoiding the need to recalculate the entire series.

Parameters:

Name Type Description Default
high

Current high price as f32.

required
low

Current low price as f32.

required
prev_high

Previous high price as f32.

required
prev_low

Previous low price as f32.

required
prev_close

Previous close price as f32.

required
prev_smoothed_plus_dm

Previous smoothed +DM value as f32.

required
prev_smoothed_tr

Previous smoothed TR value as f32.

required
period

Smoothing period (>= 2).

required

Returns:

Type Description

A tuple containing (latest +DI, new smoothed +DM, new smoothed TR).

Examples:

>>> import kand
>>> plus_di, smoothed_plus_dm, smoothed_tr = kand.plus_di_incremental(
...     10.5,  # high
...     9.5,   # low
...     10.0,  # prev_high
...     9.0,   # prev_low
...     9.5,   # prev_close
...     15.0,  # prev_smoothed_plus_dm
...     20.0,  # prev_smoothed_tr
...     14     # period
... )

plus_dm(high, low, period) builtin

Computes the Plus Directional Movement (+DM) over NumPy arrays.

Plus Directional Movement (+DM) measures upward price movement and is used as part of the Directional Movement System developed by J. Welles Wilder.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high prices as a 1-D NumPy array of type f32.

required
low

Input low prices as a 1-D NumPy array of type f32.

required
period

Window size for +DM calculation. Must be positive and less than input length.

required

Returns:

Type Description

A new 1-D NumPy array containing the +DM values. The array has the same length as the input,

with the first period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([35266.0, 35247.5, 35235.7, 35190.8, 35182.0])
>>> low = np.array([35216.1, 35206.5, 35180.0, 35130.7, 35153.6])
>>> result = kand.plus_dm(high, low, 3)

plus_dm_incremental(high, prev_high, low, prev_low, prev_plus_dm, period) builtin

Calculates the next Plus DM value incrementally using previous values.

This function enables real-time calculation of Plus DM by using the previous Plus DM value and current price data, avoiding the need to recalculate the entire series.

Parameters:

Name Type Description Default
high

Current high price as f32.

required
prev_high

Previous high price as f32.

required
low

Current low price as f32.

required
prev_low

Previous low price as f32.

required
prev_plus_dm

Previous Plus DM value as f32.

required
period

Smoothing period (>= 2).

required

Returns:

Type Description

The latest Plus DM value.

Examples:

>>> import kand
>>> new_plus_dm = kand.plus_dm_incremental(
...     10.5,  # high
...     10.0,  # prev_high
...     9.8,   # low
...     9.5,   # prev_low
...     0.45,  # prev_plus_dm
...     14     # period
... )

rma(data, period) builtin

Computes the Running Moving Average (RMA) over a NumPy array.

The Running Moving Average is similar to an Exponential Moving Average (EMA) but uses a different smoothing factor. It is calculated using a weighted sum of the current value and previous RMA value, with weights determined by the period size.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input data as a 1-D NumPy array of type f64.

required
period

Window size for RMA calculation. Must be positive and less than input length.

required

Returns:

Type Description

A new 1-D NumPy array containing the RMA values. The array has the same length as the input,

with the first period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> result = kand.rma(data, 3)
>>> print(result)
[nan, nan, 2.0, 2.67, 3.44]

rma_incremental(current_price, prev_rma, period) builtin

Calculates the next RMA value incrementally.

This function provides an optimized way to calculate the latest RMA value when streaming data is available, without needing the full price history.

Parameters:

Name Type Description Default
current_price

The current period's price value.

required
prev_rma

The previous period's RMA value.

required
period

The smoothing period (must be >= 2).

required

Returns:

Type Description

The calculated RMA value.

Examples:

>>> import kand
>>> new_rma = kand.rma_incremental(10.0, 9.5, 14)

roc(data, period) builtin

Computes the Rate of Change (ROC) over a NumPy array.

The Rate of Change (ROC) is a momentum oscillator that measures the percentage change in price between the current price and the price n periods ago.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input price data as a 1-D NumPy array of type f64.

required
period

Number of periods to look back. Must be positive.

required

Returns:

Type Description

A new 1-D NumPy array containing the ROC values. The array has the same length as the input,

with the first period elements containing NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([10.0, 10.5, 11.2, 10.8, 11.5])
>>> result = kand.roc(data, 2)
>>> print(result)
[nan, nan, 12.0, 2.86, 6.48]

roc_incremental(current_price, prev_price) builtin

Calculates a single ROC value incrementally.

This function provides an optimized way to calculate the latest ROC value when streaming data is available, without needing the full price history.

Parameters:

Name Type Description Default
current_price

The current period's price value.

required
prev_price

The price from n periods ago.

required

Returns:

Type Description

The calculated ROC value.

Examples:

>>> import kand
>>> roc = kand.roc_incremental(11.5, 10.0)
>>> print(roc)
15.0

rocp(data, period) builtin

Computes the Rate of Change Percentage (ROCP) over a NumPy array.

The Rate of Change Percentage (ROCP) is a momentum indicator that measures the percentage change between the current price and the price n periods ago.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input price data as a 1-D NumPy array of type f64.

required
period

Number of periods to look back. Must be positive.

required

Returns:

Type Description

A new 1-D NumPy array containing the ROCP values. The array has the same length as the input,

with the first period elements containing NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([10.0, 10.5, 11.2, 10.8, 11.5])
>>> result = kand.rocp(data, 2)
>>> print(result)
[nan, nan, 0.12, 0.0286, 0.0648]

rocp_incremental(current_price, prev_price) builtin

Calculates a single ROCP value incrementally.

This function provides an optimized way to calculate the latest ROCP value when streaming data is available, without needing the full price history.

Parameters:

Name Type Description Default
current_price

The current period's price value.

required
prev_price

The price from n periods ago.

required

Returns:

Type Description

The calculated ROCP value.

Examples:

>>> import kand
>>> rocp = kand.rocp_incremental(11.5, 10.0)
>>> print(rocp)
0.15

rocr(data, period) builtin

Computes the Rate of Change Ratio (ROCR) over a NumPy array.

The Rate of Change Ratio (ROCR) is a momentum indicator that measures the ratio between the current price and the price n periods ago.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input price data as a 1-D NumPy array of type f64.

required
period

Number of periods to look back. Must be >= 2.

required

Returns:

Type Description

A new 1-D NumPy array containing the ROCR values. The array has the same length as the input,

with the first period elements containing NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([10.0, 10.5, 11.2, 10.8, 11.5])
>>> result = kand.rocr(data, 2)
>>> print(result)
[nan, nan, 1.12, 1.0286, 1.0648]

rocr100(data, period) builtin

Computes the Rate of Change Ratio * 100 (ROCR100) over a NumPy array.

ROCR100 is a momentum indicator that measures the percentage change in price over a specified period. It compares the current price to a past price and expresses the ratio as a percentage. Values above 100 indicate price increases, while values below 100 indicate price decreases.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input price data as a 1-D NumPy array of type f64.

required
period

Number of periods to look back. Must be >= 2.

required

Returns:

Type Description

A new 1-D NumPy array containing the ROCR100 values. The array has the same length as the input,

with the first period elements containing NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([10.0, 10.5, 11.2, 10.8, 11.5])
>>> result = kand.rocr100(data, 2)
>>> print(result)
[nan, nan, 106.67, 102.86, 106.48]

rocr100_incremental(current_price, prev_price) builtin

Calculates a single ROCR100 value incrementally.

This function provides an optimized way to calculate the latest ROCR100 value when streaming data is available, without needing the full price history.

Parameters:

Name Type Description Default
current_price

The current period's price value.

required
prev_price

The price from n periods ago.

required

Returns:

Type Description

The calculated ROCR100 value.

Examples:

>>> import kand
>>> rocr100 = kand.rocr100_incremental(11.5, 10.0)
>>> print(rocr100)
115.0

rocr_incremental(current_price, prev_price) builtin

Calculates a single ROCR value incrementally.

This function provides an optimized way to calculate the latest ROCR value when streaming data is available, without needing the full price history.

Parameters:

Name Type Description Default
current_price

The current period's price value.

required
prev_price

The price from n periods ago.

required

Returns:

Type Description

The calculated ROCR value.

Examples:

>>> import kand
>>> rocr = kand.rocr_incremental(11.5, 10.0)
>>> print(rocr)
1.15

rsi(prices, period) builtin

Computes the Relative Strength Index (RSI) over NumPy arrays.

The RSI is a momentum oscillator that measures the speed and magnitude of recent price changes to evaluate overbought or oversold conditions.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prices

Input prices as a 1-D NumPy array of type f64.

required
period

Window size for RSI calculation. Must be positive and less than input length.

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • RSI values
  • Average gain values
  • Average loss values

Each array has the same length as the input, with the first period elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.42])
>>> rsi, avg_gain, avg_loss = kand.rsi(prices, 5)

rsi_incremental(current_price, prev_price, prev_avg_gain, prev_avg_loss, period) builtin

Calculates a single RSI value incrementally.

This function provides an optimized way to calculate the latest RSI value when streaming data is available, without needing the full price history.

Parameters:

Name Type Description Default
current_price

The current period's price value.

required
prev_price

The previous period's price value.

required
prev_avg_gain

The previous period's average gain.

required
prev_avg_loss

The previous period's average loss.

required
period

The time period for RSI calculation.

required

Returns:

Type Description

A tuple containing (RSI value, new average gain, new average loss).

Examples:

>>> import kand
>>> rsi, avg_gain, avg_loss = kand.rsi_incremental(45.42, 45.10, 0.24, 0.14, 14)

sar(high, low, acceleration, maximum) builtin

Calculates the Parabolic SAR (Stop And Reverse) indicator over NumPy arrays.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high prices as a 1-D NumPy array of type f32.

required
low

Input low prices as a 1-D NumPy array of type f32.

required
acceleration

Initial acceleration factor (e.g. 0.02).

required
maximum

Maximum acceleration factor (e.g. 0.2).

required

Returns:

Type Description

A tuple of four 1-D NumPy arrays containing:

  • SAR values
  • Trend direction (true=long, false=short)
  • Acceleration factors
  • Extreme points

Each array has the same length as the input, with the first element containing NaN.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> sar, is_long, af, ep = kand.sar(high, low, 0.02, 0.2)

sar_incremental(high, low, prev_high, prev_low, prev_sar, is_long, af, ep, acceleration, maximum) builtin

Incrementally updates the Parabolic SAR with new price data.

Parameters:

Name Type Description Default
high

Current period's high price.

required
low

Current period's low price.

required
prev_high

Previous period's high price.

required
prev_low

Previous period's low price.

required
prev_sar

Previous period's SAR value.

required
is_long

Current trend direction (true=long, false=short).

required
af

Current acceleration factor.

required
ep

Current extreme point.

required
acceleration

Acceleration factor increment.

required
maximum

Maximum acceleration factor.

required

Returns:

Type Description

A tuple containing (SAR value, trend direction, acceleration factor, extreme point).

Examples:

>>> import kand
>>> sar, is_long, af, ep = kand.sar_incremental(
...     15.0, 14.0, 14.5, 13.5, 13.0, True, 0.02, 14.5, 0.02, 0.2
... )

sma(data, period) builtin

Computes the Simple Moving Average (SMA) over a NumPy array.

The Simple Moving Average is calculated by taking the arithmetic mean of a window of values that moves across the input array. For each position, it sums the previous period values and divides by the period size.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input data as a 1-D NumPy array of type f64.

required
period

Window size for SMA calculation. Must be positive and less than input length.

required

Returns:

Type Description

A new 1-D NumPy array containing the SMA values. The array has the same length as the input,

with the first period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> result = kand.sma(data, 3)
>>> print(result)
[nan, nan, 2.0, 3.0, 4.0]

sma_incremental(prev_sma, new_price, old_price, period) builtin

Incrementally calculates the next SMA value.

This function provides an optimized way to update an existing SMA value when new data arrives, without recalculating the entire series.

Parameters:

Name Type Description Default
prev_sma

Previous SMA value.

required
new_price

New price to include in calculation.

required
old_price

Oldest price to remove from calculation.

required
period

The time period for SMA calculation (must be >= 2).

required

Returns:

Type Description

The next SMA value.

Examples:

>>> import kand
>>> prev_sma = 4.0
>>> new_price = 10.0
>>> old_price = 2.0
>>> period = 3
>>> next_sma = kand.sma_incremental(prev_sma, new_price, old_price, period)
>>> print(next_sma)
6.666666666666666

stddev(input, period) builtin

Calculate Standard Deviation for a NumPy array

Standard Deviation measures the dispersion of values from their mean over a specified period. It is calculated by taking the square root of the variance.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
input

Input values as a 1-D NumPy array of type f64.

required
period

Period for calculation (must be >= 2).

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • Standard Deviation values
  • Running sum values
  • Running sum of squares values

Each array has the same length as the input, with the first (period-1) elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> stddev, sum, sum_sq = kand.stddev(prices, 3)

stddev_incremental(price, prev_sum, prev_sum_sq, old_price, period) builtin

Calculate the latest Standard Deviation value incrementally

Parameters:

Name Type Description Default
py

Python interpreter token

required
price

Current period's price

required
prev_sum

Previous period's sum

required
prev_sum_sq

Previous period's sum of squares

required
old_price

Price being removed from the period

required
period

Period for calculation (must be >= 2)

required

Returns:

Type Description

A tuple containing:

  • Latest Standard Deviation value
  • New sum
  • New sum of squares

Examples:

>>> import kand
>>> stddev, sum, sum_sq = kand.stddev_incremental(
...     10.0,   # current price
...     100.0,  # previous sum
...     1050.0, # previous sum of squares
...     8.0,    # old price
...     14      # period
... )

stoch(high, low, close, k_period, k_slow_period, d_period) builtin

Computes the Stochastic Oscillator indicator over NumPy arrays.

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. The indicator consists of two lines: %K (the fast line) and %D (the slow line).

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
k_period

Period for %K calculation. Must be >= 2.

required
k_slow_period

Smoothing period for slow %K. Must be >= 2.

required
d_period

Period for %D calculation. Must be >= 2.

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • Fast %K values
  • Slow %K values
  • %D values

Each array has the same length as the input, with initial values being NaN.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> close = np.array([9.0, 11.0, 14.0, 12.0, 11.0])
>>> fast_k, k, d = kand.stoch(high, low, close, 3, 2, 2)

sum(input, period) builtin

Calculate Sum for a NumPy array

Calculates the rolling sum of values over a specified period.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
input

Input values as a 1-D NumPy array of type f64.

required
period

Period for sum calculation (must be >= 2).

required

Returns:

Type Description

A 1-D NumPy array containing the sum values.

The first (period-1) elements contain NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> sums = kand.sum(data, 3)

sum_incremental(new_price, old_price, prev_sum) builtin

Calculate the latest sum value incrementally

Parameters:

Name Type Description Default
py

Python interpreter token

required
new_price

The newest price value to add

required
old_price

The oldest price value to remove

required
prev_sum

The previous sum value

required

Returns:

Type Description

The new sum value

Examples:

>>> import kand
>>> new_sum = kand.sum_incremental(
...     5.0,    # new price
...     3.0,    # old price
...     10.0,   # previous sum
... )

supertrend(high, low, close, period, multiplier) builtin

Computes the Supertrend indicator over NumPy arrays.

The Supertrend indicator is a trend-following indicator that combines Average True Range (ATR) with basic upper and lower bands to identify trend direction and potential reversal points.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f64.

required
low

Low prices as a 1-D NumPy array of type f64.

required
close

Close prices as a 1-D NumPy array of type f64.

required
period

Period for ATR calculation (typically 7-14). Must be positive.

required
multiplier

ATR multiplier (typically 2-4).

required

Returns:

Type Description

A tuple of five 1-D NumPy arrays:

  • trend: Array containing trend direction (1.0 for uptrend, -1.0 for downtrend)
  • supertrend: Array containing Supertrend values
  • atr: Array containing ATR values
  • upper: Array containing upper band values
  • lower: Array containing lower band values

All arrays have the same length as the input, with the first period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> close = np.array([9.0, 11.0, 14.0, 12.0, 11.0])
>>> trend, supertrend, atr, upper, lower = kand.supertrend(high, low, close, 3, 3.0)

supertrend_incremental(high, low, close, prev_close, prev_atr, prev_trend, prev_upper, prev_lower, period, multiplier) builtin

Calculates a single Supertrend value incrementally.

This function provides an optimized way to calculate the latest Supertrend value using previous values, making it ideal for real-time calculations.

Parameters:

Name Type Description Default
high

Current period's high price

required
low

Current period's low price

required
close

Current period's close price

required
prev_close

Previous period's close price

required
prev_atr

Previous period's ATR value

required
prev_trend

Previous period's trend direction (1 for uptrend, -1 for downtrend)

required
prev_upper

Previous period's upper band

required
prev_lower

Previous period's lower band

required
period

ATR calculation period (typically 7-14)

required
multiplier

ATR multiplier (typically 2-4)

required

Returns:

Type Description

A tuple containing:

  • trend: Current trend direction (1 for uptrend, -1 for downtrend)
  • supertrend: Current Supertrend value
  • atr: Current ATR value
  • upper: Current upper band
  • lower: Current lower band

Examples:

>>> import kand
>>> trend, supertrend, atr, upper, lower = kand.supertrend_incremental(
...     15.0,   # Current high
...     11.0,   # Current low
...     14.0,   # Current close
...     11.0,   # Previous close
...     2.0,    # Previous ATR
...     1,      # Previous trend
...     16.0,   # Previous upper band
...     10.0,   # Previous lower band
...     7,      # ATR period
...     3.0,    # Multiplier
... )

t3(data, period, vfactor) builtin

Computes the T3 (Triple Exponential Moving Average) indicator over a NumPy array.

T3 is a sophisticated moving average developed by Tim Tillson that reduces lag while maintaining smoothness. It combines six EMAs with optimized weightings to produce a responsive yet smooth indicator.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input data as a 1-D NumPy array of type f32.

required
period

Smoothing period for EMAs (must be >= 2).

required
vfactor

Volume factor controlling smoothing (typically 0-1).

required

Returns:

Type Description

A tuple of seven 1-D NumPy arrays containing:

  • T3 values
  • EMA1 values
  • EMA2 values
  • EMA3 values
  • EMA4 values
  • EMA5 values
  • EMA6 values

Each array has the same length as the input, with initial values being NaN.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> t3, e1, e2, e3, e4, e5, e6 = kand.t3(data, 2, 0.7)

t3_incremental(price, prev_ema1, prev_ema2, prev_ema3, prev_ema4, prev_ema5, prev_ema6, period, vfactor) builtin

Incrementally calculates the next T3 value.

This function provides an optimized way to update T3 values in real-time by using previously calculated EMA values.

Parameters:

Name Type Description Default
price

Latest price value to calculate T3 from.

required
prev_ema1

Previous EMA1 value.

required
prev_ema2

Previous EMA2 value.

required
prev_ema3

Previous EMA3 value.

required
prev_ema4

Previous EMA4 value.

required
prev_ema5

Previous EMA5 value.

required
prev_ema6

Previous EMA6 value.

required
period

Smoothing period for EMAs (must be >= 2).

required
vfactor

Volume factor (typically 0-1).

required

Returns:

Type Description

A tuple containing:

  • Latest T3 value
  • Updated EMA1 value
  • Updated EMA2 value
  • Updated EMA3 value
  • Updated EMA4 value
  • Updated EMA5 value
  • Updated EMA6 value

Examples:

>>> import kand
>>> t3, e1, e2, e3, e4, e5, e6 = kand.t3_incremental(
...     100.0,  # New price
...     95.0,   # Previous EMA1
...     94.0,   # Previous EMA2
...     93.0,   # Previous EMA3
...     92.0,   # Previous EMA4
...     91.0,   # Previous EMA5
...     90.0,   # Previous EMA6
...     5,      # Period
...     0.7,    # Volume factor
... )

tema(prices, period) builtin

Calculate Triple Exponential Moving Average (TEMA) for a NumPy array.

TEMA is an enhanced moving average designed to reduce lag while maintaining smoothing properties. It applies triple exponential smoothing to put more weight on recent data and less on older data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prices

Input prices as a 1-D NumPy array of type f64.

required
period

Smoothing period for calculations (must be >= 2).

required

Returns:

Type Description

A tuple of 4 1-D NumPy arrays containing:

  • TEMA values
  • First EMA values
  • Second EMA values
  • Third EMA values

The first (3 * (period - 1)) elements of each array contain NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0])
>>> tema, ema1, ema2, ema3 = kand.tema(prices, 3)

tema_incremental(new_price, prev_ema1, prev_ema2, prev_ema3, period) builtin

Calculate the next TEMA value incrementally.

Parameters:

Name Type Description Default
new_price

Latest price value to process.

required
prev_ema1

Previous value of first EMA.

required
prev_ema2

Previous value of second EMA.

required
prev_ema3

Previous value of third EMA.

required
period

Smoothing period for calculations (must be >= 2).

required

Returns:

Type Description

A tuple containing:

  • Current TEMA value
  • Updated first EMA
  • Updated second EMA
  • Updated third EMA

Examples:

>>> import kand
>>> tema, ema1, ema2, ema3 = kand.tema_incremental(
...     10.0,  # new_price
...     9.0,   # prev_ema1
...     8.0,   # prev_ema2
...     7.0,   # prev_ema3
...     3      # period
... )

trange(high, low, close) builtin

Computes the True Range (TR) over NumPy arrays.

True Range measures the market's volatility by considering the current high-low range and the previous close price.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required

Returns:

Type Description

A new 1-D NumPy array containing the TR values. The array has the same length as the input,

with the first element containing NaN value.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0])
>>> low = np.array([8.0, 9.0, 11.0])
>>> close = np.array([9.0, 11.0, 14.0])
>>> result = kand.trange(high, low, close)
>>> print(result)
[nan, 3.0, 4.0]

trange_incremental(high, low, prev_close) builtin

Calculates a single True Range value for the most recent period.

Parameters:

Name Type Description Default
high

Current period's high price.

required
low

Current period's low price.

required
prev_close

Previous period's closing price.

required

Returns:

Type Description

The calculated True Range value.

Examples:

>>> import kand
>>> tr = kand.trange_incremental(12.0, 9.0, 11.0)
>>> print(tr)
3.0  # max(3, 1, 2)

trima(prices, period) builtin

Calculate Triangular Moving Average (TRIMA) for a NumPy array.

TRIMA is a double-smoothed moving average that places more weight on the middle portion of the price series and less weight on the first and last portions. This results in a smoother moving average compared to a Simple Moving Average (SMA).

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prices

Input prices as a 1-D NumPy array of type f64.

required
period

Smoothing period for calculations (must be >= 2).

required

Returns:

Type Description

A tuple of 2 1-D NumPy arrays containing:

  • First SMA values
  • Final TRIMA values

The first (period - 1) elements of each array contain NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> sma1, trima = kand.trima(prices, 3)

trima_incremental(prev_sma1, prev_sma2, new_price, old_price, old_sma1, period) builtin

Calculate the next TRIMA value incrementally.

Parameters:

Name Type Description Default
prev_sma1

Previous first SMA value.

required
prev_sma2

Previous TRIMA value.

required
new_price

Latest price to include in calculation.

required
old_price

Price dropping out of first window.

required
old_sma1

SMA1 value dropping out of second window.

required
period

Smoothing period for calculations (must be >= 2).

required

Returns:

Type Description

A tuple containing:

  • Updated first SMA value
  • Updated TRIMA value

Examples:

>>> import kand
>>> trima, sma1 = kand.trima_incremental(
...     35.5,  # prev_sma1
...     35.2,  # prev_sma2
...     36.0,  # new_price
...     35.0,  # old_price
...     35.1,  # old_sma1
...     5      # period
... )

trix(prices, period) builtin

Calculates the Triple Exponential Moving Average Oscillator (TRIX) over a NumPy array.

TRIX is a momentum oscillator that measures the rate of change of a triple exponentially smoothed moving average. It helps identify oversold and overbought conditions and potential trend reversals through divergences.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prices

Input prices as a 1-D NumPy array of type f64.

required
period

Period for EMA calculations (must be >= 2).

required

Returns:

Type Description

A tuple of 4 1-D NumPy arrays containing:

  • TRIX values
  • First EMA values
  • Second EMA values
  • Third EMA values

The first lookback elements of each array contain NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> trix, ema1, ema2, ema3 = kand.trix(prices, 2)

trix_incremental(price, prev_ema1, prev_ema2, prev_ema3, period) builtin

Calculates a single new TRIX value incrementally.

Parameters:

Name Type Description Default
price

Current price value.

required
prev_ema1

Previous first EMA value.

required
prev_ema2

Previous second EMA value.

required
prev_ema3

Previous third EMA value.

required
period

Period for EMA calculations (must be >= 2).

required

Returns:

Type Description

A tuple containing:

  • TRIX value
  • Updated first EMA value
  • Updated second EMA value
  • Updated third EMA value

Examples:

>>> import kand
>>> trix, ema1, ema2, ema3 = kand.trix_incremental(
...     100.0,  # price
...     98.0,   # prev_ema1
...     97.0,   # prev_ema2
...     96.0,   # prev_ema3
...     14      # period
... )

typprice(high, low, close) builtin

Computes the Typical Price over NumPy arrays.

The Typical Price is calculated by taking the arithmetic mean of the high, low and close prices for each period.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high prices as a 1-D NumPy array of type f32.

required
low

Input low prices as a 1-D NumPy array of type f32.

required
close

Input close prices as a 1-D NumPy array of type f32.

required

Returns:

Type Description

A new 1-D NumPy array containing the Typical Price values. The array has the same length as the inputs.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([24.20, 24.07, 24.04])
>>> low = np.array([23.85, 23.72, 23.64])
>>> close = np.array([23.89, 23.95, 23.67])
>>> result = kand.typprice(high, low, close)
>>> print(result)
[23.98, 23.91, 23.78]

typprice_incremental(high, low, close) builtin

Calculates a single Typical Price value incrementally.

Parameters:

Name Type Description Default
high

Current period's high price.

required
low

Current period's low price.

required
close

Current period's close price.

required

Returns:

Type Description

The calculated Typical Price value.

Examples:

>>> import kand
>>> typ_price = kand.typprice_incremental(24.20, 23.85, 23.89)
>>> print(typ_price)
23.98  # (24.20 + 23.85 + 23.89) / 3

var(prices, period) builtin

Calculate Variance (VAR) for a NumPy array

Variance measures the average squared deviation of data points from their mean over a specified period.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prices

Input prices as a 1-D NumPy array of type f64.

required
period

Period for Variance calculation (must be >= 2).

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • Variance values
  • Running sum values
  • Running sum of squares values

Each array has the same length as the input, with the first (period-1) elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([2.0, 4.0, 6.0, 8.0, 10.0])
>>> var, sum, sum_sq = kand.var(prices, 3)

var_incremental(price, prev_sum, prev_sum_sq, old_price, period) builtin

Calculate the latest Variance value incrementally

Parameters:

Name Type Description Default
py

Python interpreter token

required
price

Current period's price

required
prev_sum

Previous period's sum

required
prev_sum_sq

Previous period's sum of squares

required
old_price

Price being removed from the period

required
period

Period for Variance calculation (must be >= 2)

required

Returns:

Type Description

A tuple containing:

  • Latest Variance value
  • New sum
  • New sum of squares

Examples:

>>> import kand
>>> var, sum, sum_sq = kand.var_incremental(
...     10.0,  # current price
...     25.0,  # previous sum
...     220.0, # previous sum of squares
...     5.0,   # price to remove
...     3      # period
... )

vegas(prices) builtin

Computes the VEGAS (Volume and EMA Guided Adaptive Scaling) indicator over NumPy arrays.

VEGAS is a trend following indicator that uses multiple EMAs to define channels and boundaries.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
prices

Input prices as a 1-D NumPy array of type f64.

required

Returns:

Type Description

A tuple of four 1-D NumPy arrays containing:

  • Channel Upper (EMA 144)
  • Channel Lower (EMA 169)
  • Boundary Upper (EMA 576)
  • Boundary Lower (EMA 676)

Each array has the same length as the input, with the first 675 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> prices = np.array([44.34, 44.09, 44.15, 43.61, 44.33])
>>> ch_upper, ch_lower, b_upper, b_lower = kand.vegas(prices)

vegas_incremental(price, prev_channel_upper, prev_channel_lower, prev_boundary_upper, prev_boundary_lower) builtin

Incrementally calculates the next VEGAS values.

Parameters:

Name Type Description Default
price

Current price value.

required
prev_channel_upper

Previous EMA(144) value.

required
prev_channel_lower

Previous EMA(169) value.

required
prev_boundary_upper

Previous EMA(576) value.

required
prev_boundary_lower

Previous EMA(676) value.

required

Returns:

Type Description

A tuple containing:

  • Updated Channel Upper value
  • Updated Channel Lower value
  • Updated Boundary Upper value
  • Updated Boundary Lower value

Examples:

>>> import kand
>>> price = 100.0
>>> prev_values = (98.0, 97.5, 96.0, 95.5)
>>> ch_upper, ch_lower, b_upper, b_lower = kand.vegas_incremental(
...     price,
...     prev_values[0],
...     prev_values[1],
...     prev_values[2],
...     prev_values[3]
... )

vwap(high, low, close, volume) builtin

Calculates Volume Weighted Average Price (VWAP) for a series of price data.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required
volume

Volume data as a 1-D NumPy array of type f32.

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • VWAP values
  • Cumulative price-volume products
  • Cumulative volumes

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0])
>>> low = np.array([8.0, 9.0, 11.0])
>>> close = np.array([9.0, 10.0, 12.0])
>>> volume = np.array([100.0, 150.0, 200.0])
>>> vwap, cum_pv, cum_vol = kand.vwap(high, low, close, volume)

vwap_incremental(high, low, close, volume, prev_cum_pv, prev_cum_vol) builtin

Calculates a single VWAP value from the latest price and volume data.

Parameters:

Name Type Description Default
high

Latest high price value as f32.

required
low

Latest low price value as f32.

required
close

Latest close price value as f32.

required
volume

Latest volume value as f32.

required
prev_cum_pv

Previous cumulative price-volume product as f32.

required
prev_cum_vol

Previous cumulative volume as f32.

required

Returns:

Type Description

A tuple containing (new cumulative PV, new cumulative volume, new VWAP).

Examples:

>>> import kand
>>> new_cum_pv, new_cum_vol, vwap = kand.vwap_incremental(15.0, 11.0, 14.0, 200.0, 1000.0, 150.0)

wclprice(high, low, close) builtin

Calculates the Weighted Close Price (WCLPRICE) for a series of price data.

The Weighted Close Price is a price indicator that assigns more weight to the closing price compared to high and low prices. It provides a single value that reflects price action with emphasis on the closing price.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

High prices as a 1-D NumPy array of type f32.

required
low

Low prices as a 1-D NumPy array of type f32.

required
close

Close prices as a 1-D NumPy array of type f32.

required

Returns:

Type Description

A 1-D NumPy array containing the WCLPRICE values.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0])
>>> low = np.array([8.0, 9.0, 11.0])
>>> close = np.array([9.0, 11.0, 14.0])
>>> wclprice = kand.wclprice(high, low, close)

wclprice_incremental(high, low, close) builtin

Calculates a single Weighted Close Price (WCLPRICE) value from the latest price data.

Parameters:

Name Type Description Default
high

Latest high price value as f32.

required
low

Latest low price value as f32.

required
close

Latest close price value as f32.

required

Returns:

Type Description

The calculated WCLPRICE value.

Examples:

>>> import kand
>>> wclprice = kand.wclprice_incremental(15.0, 11.0, 14.0)

willr(high, low, close, period) builtin

Calculates Williams %R (Williams Percent Range) for a series of prices.

Williams %R is a momentum indicator that measures overbought and oversold levels by comparing the closing price to the high-low range over a specified period. The indicator oscillates between 0 and -100.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
high

Input high prices as a 1-D NumPy array of type f64.

required
low

Input low prices as a 1-D NumPy array of type f64.

required
close

Input closing prices as a 1-D NumPy array of type f64.

required
period

Lookback period for calculations. Must be >= 2.

required

Returns:

Type Description

A tuple of three 1-D NumPy arrays containing:

  • Williams %R values
  • Highest high values for each period
  • Lowest low values for each period

Each array has the same length as the input, with the first period-1 elements containing NaN values.

Examples:

>>> import numpy as np
>>> import kand
>>> high = np.array([10.0, 12.0, 15.0, 14.0, 13.0])
>>> low = np.array([8.0, 9.0, 11.0, 10.0, 9.0])
>>> close = np.array([9.0, 11.0, 14.0, 12.0, 11.0])
>>> willr, highest, lowest = kand.willr(high, low, close, 3)

willr_incremental(prev_highest_high, prev_lowest_low, prev_high, prev_low, close, high, low) builtin

Incrementally calculates Williams %R for the latest data point.

This function provides an optimized way to calculate the latest Williams %R value by using previously calculated highest high and lowest low values.

Parameters:

Name Type Description Default
prev_highest_high

Previous period's highest high value.

required
prev_lowest_low

Previous period's lowest low value.

required
prev_high

Previous period's high price.

required
prev_low

Previous period's low price.

required
close

Current period's closing price.

required
high

Current period's high price.

required
low

Current period's low price.

required

Returns:

Type Description

A tuple containing:

  • Current Williams %R value
  • New highest high
  • New lowest low

Examples:

>>> import kand
>>> willr, high, low = kand.willr_incremental(15.0, 10.0, 14.0, 11.0, 12.0, 13.0, 11.0)

wma(data, period) builtin

Computes the Weighted Moving Average (WMA) over a NumPy array.

The Weighted Moving Average assigns linearly decreasing weights to each price in the period, giving more importance to recent prices and less to older ones.

Parameters:

Name Type Description Default
py

Python interpreter token required for GIL management.

required
data

Input data as a 1-D NumPy array of type f32.

required
period

Window size for WMA calculation. Must be >= 2.

required

Returns:

Type Description

A new 1-D NumPy array containing the WMA values. The array has the same length as the input,

with the first period-1 elements containing NaN values.

Note

This function releases the Python GIL during computation using py.allow_threads() to enable concurrent Python execution.

Examples:

>>> import numpy as np
>>> import kand
>>> data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> result = kand.wma(data, 3)
>>> print(result)
[nan, nan, 2.0, 3.0, 4.0]

wma_incremental(input_window, period) builtin

Incrementally calculates the next WMA value.

This function provides an optimized way to calculate the latest WMA value by using a window of the most recent prices.

Parameters:

Name Type Description Default
input_window

Array of price values ordered from newest to oldest.

required
period

The time period for WMA calculation (must be >= 2).

required

Returns:

Type Description

The next WMA value.

Examples:

>>> import kand
>>> window = [5.0, 4.0, 3.0]  # newest to oldest
>>> wma = kand.wma_incremental(window, 3)
>>> print(wma)
4.333333333333333