Kand
Kand: Blazing-Fast, Modern Technical Analysis in Rust, Python, and WASM.
Install / Use
npx skills add kand-ta/kandInstalls into whichever agent you are using.
README
<p align="center"> <picture align="center"> <img alt="EMA Performance Comparison" src="docs/assets/bench_ema.png" width="600"> </picture> </p> <p align="center"> <i>EMA calculation performance comparison across different implementations.</i> </p>[!WARNING] This project is under active development. APIs may change, and some features might not be fully implemented or tested yet. Contributions and feedback are welcome!
Why Kand?
Kand is engineered as a modern replacement for TA-Lib, addressing its core limitations—such as single-threaded execution, Python GIL constraints, memory overhead, and inefficient real-time processing—while preserving its strengths in comprehensive indicator support and ease of integration. Built in Rust, Kand delivers superior performance, safety, and flexibility for quantitative trading, data science, and financial analysis.
-
⚡ Superior Performance with Memory Safety Leveraging Rust's efficiency,
Kandachieves speeds rivaling or exceedingTA-Lib's peak performance, but with built-in memory safety that eliminates common vulnerabilities and reduces overhead inTA-Lib's C-based implementation. -
🔓 True Multithreading Capabilities Unlike
TA-Lib, which is hindered by Python's GIL and single-threaded design,Kandenables seamless parallel processing across multiple cores, unlocking significant gains in multi-threaded environments for large-scale computations. -
⚙️ Efficient Real-Time Incremental Updates
Kandintroduces O(1) complexity for incremental calculations, ideal for streaming data and real-time applications—overcomingTA-Lib's reliance on batch processing, which introduces latency and inefficiency in dynamic scenarios. -
🚀 Zero-Copy NumPy Integration With native, zero-copy data sharing via Rust-NumPy bindings,
Kandensures lossless, high-speed data flow between Python and Rust, addressingTA-Lib's memory copying overhead and enabling ultra-low latency (~7ns) operations. -
📊 Expanded Indicator Suite Kand supports a wide array of standard indicators (e.g., EMA, RSI, MACD) like
TA-Lib, while pioneering advanced ones such as Vegas, VWAP, and Supertrend, extending analytical capabilities beyondTA-Lib's traditional scope. -
📦 Streamlined Installation and Lightweight Design Install with a single
pip install kandcommand, featuring precompiled wheels and no complex C dependencies—solvingTA-Lib's notoriously cumbersome setup and reducing package bloat for effortless deployment. -
💻 Broad Cross-Platform Compatibility Seamlessly runs on macOS, Linux, and Windows, with additional support for JavaScript/TypeScript via
WebAssembly, providing greater universality thanTA-Lib's platform-specific challenges.
If you truly understand
TA-Lib's limitations, you'll appreciate Kand's innovations.Kandisn't just about fixing what's broken—it's about enabling what's possible. Dive deeper at whykand.
Python API
The Python interface of kand leverages PyO3 for ultra-low latency bindings to the Rust core, seamlessly integrating with NumPy for zero-copy operations and true thread-safe calculations. Below are examples for batch and incremental usage.
import numpy as np
from kand import ema
# Batch EMA computation with zero-copy NumPy integration
prices = np.array([10.0, 11.0, 12.0, 13.0, 14.0], dtype=np.float64)
ema_values = ema(prices, period=3)
# Incremental EMA update for streaming data
prev_ema = 13.5
new_price = 15.0
new_ema = ema_inc(new_price, prev_ema, period=3)
Key Features:
- Zero-Copy: Operates directly on NumPy arrays, avoiding memory duplication.
- GIL-Free: Rust backend releases the Python GIL, enabling parallel execution.
- Incremental Updates: O(1) complexity for real-time applications.
Rust API
The Rust interface in kand provides a high-performance, type-safe implementation of EMA with flexible parameter control. It supports both Vec and ndarray inputs for batch and incremental calculations, as shown below.
use kand::ohlcv::ema;
use ndarray::Array1;
// Batch EMA calculation over a price series
let prices = vec![10.0, 11.0, 12.0, 13.0, 14.0];
let mut ema_values = vec![0.0; prices.len()];
ema::ema(&prices, 3, None, &mut ema_values)?;
// Batch EMA with ndarray for scientific workflows
let prices = Array1::from_vec(vec![10.0, 11.0, 12.0, 13.0, 14.0]);
let mut ema_values = Array1::zeros(prices.len());
ema::ema(&prices, 3, None, &mut ema_values)?;
// Constant-time incremental EMA update
let prev_ema = 13.5;
let new_price = 15.0;
let new_ema = ema::ema_inc(new_price, prev_ema, 3, None)?;
Key Features:
- Memory Efficiency: Leverages mutable buffers (
&mut Vec<f64>or&mut Array1<f64>) to store results, slashing memory allocations. - Error Handling: Returns
Result<(), KandError>orResult<f64, KandError>for reliable failure detection (e.g., invalid period, NaN inputs). - Incremental Design: O(1) updates tailored for real-time systems.
JavaScript/TypeScript API
The JavaScript/TypeScript interface provides WebAssembly bindings for high-performance technical analysis in web applications and Node.js projects. It delivers near-native performance with a clean, synchronous API.
import { ema, emaInc } from 'kand';
// Batch EMA computation for price series
const prices = new Float64Array([10.0, 11.0, 12.0, 13.0, 14.0]);
const emaValues = ema(prices, 3, null);
console.log(emaValues);
// Incremental EMA update for streaming data
const prevEma = 13.5;
const newPrice = 15.0;
const newEma = emaInc(newPrice, prevEma, 3, null);
console.log(newEma);
// Custom smoothing factor
const customK = 0.5;
const customEma = emaInc(newPrice, prevEma, 3, customK);
Key Features:
- WebAssembly Performance: Near-native speed through optimized WASM bindings.
- Type Safety: Full TypeScript definitions with comprehensive JSDoc documentation.
- ES Module Standard: Adheres to the ES module standard for native integration with modern JavaScript environments.
Setup
Python
Get started with Kand in one command - no extra configuration needed:
pip install kand
Rust
You can take latest release from crates.io, or if you want to use the latest features / performance improvements point to the main branch of this repo.
cargo add kand
Recommend Rust version >=1.80.
JavaScript/TypeScript
For web applications and Node.js projects, install Kand via npm:
npm i kand
The package provides WebAssembly bindings for high-performance technical analysis in JavaScript and TypeScript environments.
Functions List
OHLCV Based
- [x] AD - Chaikin A/D Line
- [x] ADOSC - Chaikin A/D Oscillator
- [x] ADR - Average Daily Range
- [x] ADX - Average Directional Movement Index
- [x] ADXR - Average Directional Movement Index Rating
- [x] AROON - Aroon
- [x] AROONOSC - Aroon Oscillator
- [x] ATR - Average True Range
- [x] BBANDS - Bollinger Bands
- [x] BOP - Balance Of Power
- [x] CCI - Commodity Channel Index
- [x] CDL_DOJI - Doji
- [x] CDL_DRAGONFLY_DOJI - Dragonfly Doji
- [x] CDL_GRAVESTONE_DOJI - Gravestone Doji
- [x] CDL_HAMMER - Hammer
- [x] CDL_INVERTED_HAMMER - Inverted Hammer
- [x] CDL_LONG_LOWER_SHADOW - Long Lower Shadow
- [x] CDL_LONG_UPPER_SHADOW - Long Upper Shadow
- [x] CDL_MARUBOZU - Marubozu
- [x] DEMA - Double Exponential Moving Average
- [x] DX - Directional Movement Index
- [x] EMA - Exponential Moving Average
- [x] ECL - Expanded Camarilla Levels [Untested]
- [x] HA - Heikin Ashi Chart
- [x] MACD - Moving Average Convergence/Divergence [Unstable]
- [x] MEDPRICE - Median Price
- [x] MFI - Money Flow Index [No Incremental]
- [x] MIDPOINT - MidPoint over period
- [x] MIDPRICE - Midpoint Price over period
- [x] MINUS_DI - Minus Directional Indicator
- [x] MINUS_DM - Minus Directional Movement
- [x] MOM - Momentum
- [x] NATR - Normalized Average True Range
- [x] OBV - On Balance Volume
- [x] PLUS_DI - Plus Directional Indicator
- [x] PLUS_DM - Plus Directional Movement
- [x] RMA - Rolling Moving Average
- [x] ROC - Rate of change : ((price/prevPrice)-1)*100
- [x] ROCP - Rate of change Percentage: (price-prevPrice)/prevPrice
- [x] ROCR - Rate of change ratio: (price/prevPrice)
- [x] ROCR100 - Rate of change ratio 100 scal
Related Skills
valuecell
11.0kValueCell is a community-driven, multi-agent platform for financial applications.
QuantDinger
10.4kAI quantitative trading platform for crypto, stocks, and forex with backtesting, live trading, market data, and multi-agent research.vibe-trading ,trading-agents,ai-trader,ai-trading
beanquery-mcp
50Beancount MCP Server is an experimental implementation that utilizes the Model Context Protocol (MCP) to enable AI assistants to query and analyze Beancount ledger files using Beancount Query Language (BQL) and the beanquery tool.
finance-skills
3.1kA collection of skills for AI financial analysis.
