Kand: Rust、Python 和 WASM 中的极其快速、现代化的技术分析。
Python | Repository: GitHub
Kand: A Modern, High-Performance Technical Analysis Library
[!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!
EMA calculation performance comparison across different implementations.
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, Kand achieves speeds rivaling or exceeding TA-Lib's peak performance, but with built-in memory safety that eliminates common vulnerabilities and reduces overhead in TA-Lib's C-based implementation.
** True Multithreading Capabilities**
Unlike TA-Lib, which is hindered by Python's GIL and single-threaded design, Kand enables seamless parallel processing across multiple cores, unlocking significant gains in multi-threaded environments for large-scale computations.
⚙️ Efficient Real-Time Incremental Updates
Kand introduces O(1) complexity for incremental calculations, ideal for streaming data and real-time applications—overcoming TA-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, Kand ensures lossless, high-speed data flow between Python and Rust, addressing TA-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 beyond TA-Lib's traditional scope.
** Streamlined Installation and Lightweight Design**
Install with a single pip install kand command, featuring precompiled wheels and no complex C dependencies—solving TA-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 than TA-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.
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:
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:
&mut Vec or &mut Array1) to store results, slashing memory allocations.Result or Result for reliable failure detection (e.g., invalid period, NaN inputs).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:
Get started with Kand in one command - no extra configuration needed:
pip install kandYou 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 kandRecommend Rust version >=1.80.
For web applications and Node.js projects, install Kand via npm:
npm i kandThe package provides WebAssembly bindings for high-performance technical analysis in JavaScript and TypeScript environments.
We are passionate about supporting contributors of all levels of experience and would love to see you get involved in the project. See the contributing guide to get started.
This project is licensed under either of the following licenses, at your option:
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in kand by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.
This project is provided "as is" without any warranties or guarantees of any kind, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, accuracy, or non-infringement. The authors and contributors of this project are not liable for any damages, losses, or liabilities resulting from the use of this project, including but not limited to financial losses, investment decisions, or trading outcomes.
Trading or investing in financial instruments involves high risks, including the potential loss of some or all of your investment amount, and may not be suitable for all users. Before using this project for any financial purposes, you should carefully consider your investment objectives, level of experience, and risk tolerance, and seek independent professional advice if needed.
The information, data, and calculations provided by this project are for informational purposes only and do not constitute financial, investment, or trading advice, recommendations, or solicitations to buy or sell an
暂无开放 Issues,或尚未同步最近议题。