Technical Indicators (Rust)
A comprehensive Rust library for calculating financial technical indicators and building trading strategies, leveraging the Polars DataFrame library for high-performance data analysis.
Project Overview
Technical Indicators aims to provide 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 or strategies you need
- Extensibility: Add your own indicators or strategies 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
- Strategy modules: Combine indicators into rule-based trading strategies
- 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
Planned/Upcoming
- Average Directional Index (ADX)
- Rate of Change (ROC)
Installation
Add to your Cargo.toml
:
[]
= "*" # Or specify a version
= { = "1", = ["full"] } # If using async examples
= { = "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. Run a Strategy and Analyze Results
use *;
use ;
4. 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 or strategies ...
new
.finish?;
Advanced Examples
See the examples/
directory for:
- Basic indicator usage (SMA, EMA, RSI, MACD, Bollinger Bands, etc.)
- Strategy backtests (minute and daily)
- CSV workflows for real-world data
- 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.
Working with Multiple Stock Data Files
The examples directory contains sample code for running strategies on multiple stocks (AAPL, GOOGL, MSFT). You can use these as templates for your own multi-asset analysis.
Contributing
Contributions are welcome! Please:
- Open issues for bugs, questions, or feature requests
- Submit pull requests for new indicators, strategies, or improvements
- Follow Rust best practices and add tests/docs for new code
Links
License
MIT License. See LICENSE for details.