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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | required | |
volume | Volume data as a 1-D NumPy array of type | 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:
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:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | required | |
volume | Volume as a 1-D NumPy array of type | 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: | |
| |
| |
| |
| |
Each array has the same length as the input, with the first |
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:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | required | |
period | Period for ADX calculation (typically 14). Must be positive. | required |
Returns:
Type | Description |
---|---|
A tuple of four 1-D NumPy arrays containing: | |
| |
| |
| |
| |
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:
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: | |
| |
| |
| |
|
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | required | |
period | Period for ADX calculation (typically 14). | required |
Returns:
Type | Description |
---|---|
A tuple of 5 1-D NumPy arrays containing: | |
| |
| |
| |
| |
| |
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:
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: | |
| |
| |
| |
| |
|
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 | required | |
low | Input low prices as a 1-D NumPy array of type | required | |
period | The lookback period for calculations (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of 6 1-D NumPy arrays containing: | |
| |
| |
| |
| |
| |
| |
The first (period) elements of each array contain NaN values. |
Examples:
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: | |
| |
| |
| |
| |
| |
|
Examples:
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 | required | |
low | Input low prices as a 1-D NumPy array of type | required | |
period | The lookback period for calculations (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of 5 1-D NumPy arrays containing: | |
| |
| |
| |
| |
| |
The first (period) elements of each array contain NaN values. |
Examples:
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: | |
| |
| |
| |
| |
|
Examples:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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:
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 | 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: | |
| |
| |
| |
| |
| |
| |
| |
The first (period-1) elements of each array contain NaN values. |
Examples:
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: | |
| |
| |
| |
| |
| |
|
Examples:
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 | required | |
high | Input high prices as a 1-D NumPy array of type | required | |
low | Input low prices as a 1-D NumPy array of type | required | |
close | Input closing prices as a 1-D NumPy array of type | required |
Returns:
Type | Description |
---|---|
A 1-D NumPy array containing the BOP values. |
Examples:
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:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
| |
| |
| |
Each array has the same length as the input, with the first |
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 | 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 | required | |
high | High prices as a 1-D NumPy array of type | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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:
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:
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 | required | |
high | High prices as a 1-D NumPy array of type | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
|
Examples:
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: | |
| |
|
Examples:
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 | required | |
high | High prices as a 1-D NumPy array of type | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
|
Examples:
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: | |
| |
|
Examples:
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 | required | |
high | High prices as a 1-D NumPy array of type | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
|
Examples:
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: | |
| |
|
Examples:
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 | required | |
high | High prices as a 1-D NumPy array of type | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
|
Examples:
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: | |
| |
|
Examples:
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 | required | |
high | High prices as a 1-D NumPy array of type | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
|
Examples:
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: | |
| |
|
Examples:
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 | required | |
high | High prices as a 1-D NumPy array of type | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
|
Examples:
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: | |
| |
|
Examples:
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 | required | |
period | Smoothing period for EMA calculations. Must be >= 2. | required |
Returns:
Type | Description |
---|---|
A tuple of 1-D NumPy arrays containing: | |
| |
| |
| |
Each array has the same length as the input, with the first |
Examples:
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:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
| |
| |
| |
Each array has the same length as the input, with the first |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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 | required | |
low | Input low prices as a 1-D NumPy array of type | required | |
close | Input close prices as a 1-D NumPy array of type | 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:
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 | required | |
prev_low | Previous period's low price as | required | |
prev_close | Previous period's close price as | 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:
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 | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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 | required | |
prev_ema | Previous period's EMA value as | 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 |
Examples:
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 | 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: | |
| |
| |
| |
| |
| |
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:
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 | required | |
prev_fast_ema | Previous fast EMA value as | required | |
prev_slow_ema | Previous slow EMA value as | required | |
prev_signal | Previous signal line value as | 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: | |
| |
| |
|
Examples:
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 | 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:
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:
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 | required | |
low | Array of low prices as a 1-D NumPy array of type | required |
Returns:
Type | Description |
---|---|
A 1-D NumPy array containing the median price values. |
Examples:
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 | required | |
low | Current period's low price as | required |
Returns:
Type | Description |
---|---|
The calculated median price value. |
Examples:
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 | required | |
low | Array of low prices as a 1-D NumPy array of type | required | |
close | Array of close prices as a 1-D NumPy array of type | required | |
volume | Array of volume data as a 1-D NumPy array of type | required | |
period | The time period for MFI calculation (typically 14). | required |
Returns:
Type | Description |
---|---|
A tuple of five 1-D NumPy arrays containing: | |
| |
| |
| |
| |
|
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 | required | |
period | Time period for calculation (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of three 1-D NumPy arrays containing: | |
| |
| |
| |
Each array has the same length as the input, with initial elements containing NaN values. |
Examples:
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 | required | |
prev_highest | Previous highest value as | required | |
prev_lowest | Previous lowest value as | required | |
period | Time period for calculation (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple containing: | |
| |
| |
|
Examples:
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 | required | |
low | Input low price data as a 1-D NumPy array of type | required | |
period | Time period for calculation (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of three 1-D NumPy arrays containing: | |
| |
| |
| |
Each array has the same length as the input, with initial elements containing NaN values. |
Examples:
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 | required | |
low | Current low price value as | required | |
prev_highest | Previous highest high value as | required | |
prev_lowest | Previous lowest low value as | required | |
period | Time period for calculation (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple containing: | |
| |
| |
|
Examples:
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 | 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:
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:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
| |
| |
Each array has the same length as the input, with the first |
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 | required | |
low | Input low prices as a 1-D NumPy array of type | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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 | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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:
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 | required | |
volume | Volume data as a 1-D NumPy array of type | 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:
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 | required | |
prev_close | Previous closing price as | required | |
volume | Current volume as | required | |
prev_obv | Previous OBV value as | required |
Returns:
Type | Description |
---|---|
The calculated OBV value. |
Examples:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
| |
| |
Each array has the same length as the input, with the first |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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 | required | |
low | Current low price as | required | |
prev_high | Previous high price as | required | |
prev_low | Previous low price as | required | |
prev_close | Previous close price as | required | |
prev_smoothed_plus_dm | Previous smoothed +DM value as | required | |
prev_smoothed_tr | Previous smoothed TR value as | required | |
period | Smoothing period (>= 2). | required |
Returns:
Type | Description |
---|---|
A tuple containing (latest +DI, new smoothed +DM, new smoothed TR). |
Examples:
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 | required | |
low | Input low prices as a 1-D NumPy array of type | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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 | required | |
prev_high | Previous high price as | required | |
low | Current low price as | required | |
prev_low | Previous low price as | required | |
prev_plus_dm | Previous Plus DM value as | required | |
period | Smoothing period (>= 2). | required |
Returns:
Type | Description |
---|---|
The latest Plus DM value. |
Examples:
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 | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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:
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 | 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 |
Examples:
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:
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 | 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 |
Examples:
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:
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 | 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 |
Examples:
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 | 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 |
Examples:
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:
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:
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 | 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: | |
| |
| |
| |
Each array has the same length as the input, with the first |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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:
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 | required | |
low | Input low prices as a 1-D NumPy array of type | 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: | |
| |
| |
| |
| |
Each array has the same length as the input, with the first element containing NaN. |
Examples:
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:
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 | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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:
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 | required | |
period | Period for calculation (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of three 1-D NumPy arrays containing: | |
| |
| |
| |
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:
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: | |
| |
| |
|
Examples:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
| |
| |
Each array has the same length as the input, with initial values being NaN. |
Examples:
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 | 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:
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:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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: | |
| |
| |
| |
| |
| |
All arrays have the same length as the input, with the first |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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: | |
| |
| |
| |
| |
|
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 | 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: | |
| |
| |
| |
| |
| |
| |
| |
Each array has the same length as the input, with initial values being NaN. |
Examples:
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: | |
| |
| |
| |
| |
| |
| |
|
Examples:
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 | required | |
period | Smoothing period for calculations (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of 4 1-D NumPy arrays containing: | |
| |
| |
| |
| |
The first (3 * (period - 1)) elements of each array contain NaN values. |
Examples:
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: | |
| |
| |
| |
|
Examples:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | 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:
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:
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 | required | |
period | Smoothing period for calculations (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of 2 1-D NumPy arrays containing: | |
| |
| |
The first (period - 1) elements of each array contain NaN values. |
Examples:
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: | |
| |
|
Examples:
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 | required | |
period | Period for EMA calculations (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of 4 1-D NumPy arrays containing: | |
| |
| |
| |
| |
The first lookback elements of each array contain NaN values. |
Examples:
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: | |
| |
| |
| |
|
Examples:
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 | required | |
low | Input low prices as a 1-D NumPy array of type | required | |
close | Input close prices as a 1-D NumPy array of type | 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:
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:
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 | required | |
period | Period for Variance calculation (must be >= 2). | required |
Returns:
Type | Description |
---|---|
A tuple of three 1-D NumPy arrays containing: | |
| |
| |
| |
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:
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: | |
| |
| |
|
Examples:
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 | required |
Returns:
Type | Description |
---|---|
A tuple of four 1-D NumPy arrays containing: | |
| |
| |
| |
| |
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:
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: | |
| |
| |
| |
|
Examples:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | required | |
volume | Volume data as a 1-D NumPy array of type | required |
Returns:
Type | Description |
---|---|
A tuple of three 1-D NumPy arrays containing: | |
| |
| |
|
Examples:
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 | required | |
low | Latest low price value as | required | |
close | Latest close price value as | required | |
volume | Latest volume value as | required | |
prev_cum_pv | Previous cumulative price-volume product as | required | |
prev_cum_vol | Previous cumulative volume as | required |
Returns:
Type | Description |
---|---|
A tuple containing (new cumulative PV, new cumulative volume, new VWAP). |
Examples:
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 | required | |
low | Low prices as a 1-D NumPy array of type | required | |
close | Close prices as a 1-D NumPy array of type | required |
Returns:
Type | Description |
---|---|
A 1-D NumPy array containing the WCLPRICE values. |
Examples:
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 | required | |
low | Latest low price value as | required | |
close | Latest close price value as | required |
Returns:
Type | Description |
---|---|
The calculated WCLPRICE value. |
Examples:
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 | required | |
low | Input low prices as a 1-D NumPy array of type | required | |
close | Input closing prices as a 1-D NumPy array of type | required | |
period | Lookback period for calculations. Must be >= 2. | required |
Returns:
Type | Description |
---|---|
A tuple of three 1-D NumPy arrays containing: | |
| |
| |
| |
Each array has the same length as the input, with the first |
Examples:
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: | |
| |
| |
|
Examples:
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 | 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 |
Note
This function releases the Python GIL during computation using py.allow_threads()
to enable concurrent Python execution.
Examples:
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: