RusTalib, the Crustacean Financial Analyst 🦀
Meet Rustalib, your steadfast crustacean companion for navigating the currents of financial markets! This comprehensive Rust library, rustalib, provides a powerful toolkit for calculating technical indicators, all powered by the high-performance Polars DataFrame library.
Whether you're charting, backtesting, or building live trading systems, Rustalib is here to help you process market data with speed and precision.
Project Overview
rustalib provides a robust, extensible, and efficient toolkit for quantitative finance, algorithmic trading, and data science in Rust. The library is designed for:
- Fast, vectorized computation using Polars DataFrames
- Easy integration with modern Rust data workflows
- Modular design: Use only the indicators you need
- Extensibility: Add your own indicators easily
Whether you are backtesting, researching, or building production trading systems, this crate offers a solid foundation for technical analysis in Rust.
Features
- Wide range of indicators: Moving averages, oscillators, volatility, volume, trend, momentum, and more
- Convenience functions: Add a suite of indicators to your DataFrame in one call
- CSV and DataFrame workflows: Read, process, and save data efficiently
- Well-documented and tested
Implemented Indicators
- Moving Averages: SMA, EMA, WMA
- Oscillators: RSI, MACD (line & signal)
- Volatility: Bollinger Bands, %B, ATR, Garman-Klass Volatility
- Volume: On-Balance Volume (OBV), Chaikin Money Flow (CMF)
- Other: Price returns, daily range, lagged prices, rolling returns/volatility, cyclical time features
Installation
Add to your Cargo.toml:
[]
= "*" # Or specify a version
= { = "0.46", = ["lazy", "dtype-full"] }
- Minimum Rust version: 1.70+
- Polars compatibility: 0.46+
Usage Examples
1. Calculate a Simple Moving Average (SMA)
use *;
use calculate_sma;
2. Combine Multiple Indicators
use *;
use ;
3. Reading Data from CSV and Saving Results
let df = default
.with_has_header
.try_into_reader_with_file_path?
.finish?;
// Important: Ensure column names are lowercase for compatibility with indicators
let mut df = df.lazy
.select
.collect?;
// ... apply indicators ...
new
.finish?;
Advanced Examples
See the examples/ directory for:
- Basic indicator usage (SMA, EMA, RSI, MACD, Bollinger Bands, etc.)
- CSV workflows for real-world data
- Multi-stock analysis with cross-asset comparisons
- Saving and analyzing results
Important Notes
Column Name Sensitivity
This library expects lowercase column names (open, high, low, close, volume) in DataFrames. When working with CSVs that might have different case formats (e.g., Open, High, etc.), make sure to rename the columns using Polars' selection and aliasing capabilities as shown in the examples above.
Contributing
Contributions are welcome! Please:
- Open issues for bugs, questions, or feature requests
- Submit pull requests for new indicators or improvements
- Follow Rust best practices and add tests/docs for new code
Links
License
MIT License. See LICENSE for details.