v1.0.2

Math & Arrays

Kafal includes a full suite of math functions that seamlessly process both scalar numbers and vectorized Pandas Series.

Type-Aware Math Primitives

Every math helper checks its arguments dynamically. If passed a scalar, it returns a scalar float; if passed a time-series variable, it performs vectorized NumPy operations over the entire dataset.

// Math helpers automatically adapt to both scalar values and time-series arrays
abs_dev = math.abs(close - ta.sma(close, 20))
log_ret = math.log(close / close[1])

// Vectorized minimum and maximum
upper_bound = math.max(high, high[1])

// Price composites
typical = hlc3(high, low, close)     // (high + low + close) / 3

// Rolling statistics
highest_high = highest(high, 20)
volatility   = stdev(close, 20)

Array Buffer Operations

For strategies requiring dynamic memory buffers, Kafal provides explicit array manipulation functions.

// Mutable Array Buffer Operations
levels = array()
array_push(levels, 100.5)
array_push(levels, 105.0)

// Lookup and update array elements
val_first = array_get(levels, 0)
array_set(levels, 5, 120.0)