Expand description
§Kand
A high-performance technical analysis library for Rust, inspired by TA-Lib.
§Overview
Kand provides a comprehensive suite of technical analysis tools for financial market data analysis. Built with Rust’s safety and performance in mind, it offers a modern alternative to traditional technical analysis libraries.
§Features
- High Performance: Written in pure Rust with zero dependencies on external C libraries
- Type Safety: Leverages Rust’s type system to prevent common errors at compile time
- Flexible Types: Supports both standard (32-bit) and extended (64-bit) precision modes
- Comprehensive Indicators: Implements popular technical indicators including:
- Moving Averages (SMA, EMA, WMA)
- Momentum Indicators (RSI, MACD)
- Volume Indicators (OBV)
- And more…
§Quick Start
use kand::ohlcv::sma;
// Input price data
let prices = vec![2.0, 4.0, 6.0, 8.0, 10.0];
let period = 3;
let mut sma_values = vec![0.0; prices.len()];
// Calculate SMA
sma::sma(&prices, period, &mut sma_values).unwrap();
// First (period-1) values will be NaN, then: [NaN, NaN, 4.0, 6.0, 8.0]
// Calculate next SMA value incrementally
let prev_sma = 8.0; // Last SMA value
let new_price = 12.0; // New price to include
let old_price = 6.0; // Oldest price to remove
let next_sma = sma::sma_inc(prev_sma, new_price, old_price, period).unwrap();
// next_sma = 10.0 ((8.0 + 10.0 + 12.0) / 3)§Feature Flags
Kand can be configured through feature flags:
§Precision Modes
default = ["extended", "check"]: 64-bit precision with basic validation checksstandard = ["f32", "i32"]: Standard precision mode using 32-bit typesextended = ["f64", "i64"]: Extended precision mode using 64-bit types
§Type Selection
f32: Use 32-bit floating point numbersf64: Use 64-bit floating point numbersi32: Use 32-bit integersi64: Use 64-bit integers
§Validation
check: Enable basic validation checksdeep-check = ["check"]: Enable extended validation (includes basic checks)
§Safety and Error Handling
All functions in Kand return a Result type, properly handling edge cases and
invalid inputs. Common error cases include:
InvalidParameter: Invalid input parameters (e.g., period < 2)InvalidData: Empty or invalid input dataLengthMismatch: Input and output slice lengths don’t matchInsufficientData: Not enough data points for calculationNaNDetected: NaN values in input data (withdeep-checkfeature)
§Performance Considerations
The library is optimized for both speed and memory usage:
- Incremental calculation support for real-time updates
- Configurable precision modes (standard/extended)
- In-place calculations to minimize memory allocations
- Optional validation checks that can be disabled for maximum performance
Re-exports§
Modules§
Constants§
- EPSILON
- Global EPSILON value used for floating-point comparisons to account for rounding errors in calculations.