RSTA - Rust Statistical Technical Analysis
A comprehensive Rust library for financial technical analysis indicators, providing efficient and type-safe implementations of popular indicators used in financial markets.
Overview
RSTA provides robust implementations of technical indicators used for analyzing financial markets and making trading decisions. The library is designed with a focus on performance, type safety, and ease of use.
Features
- Comprehensive Indicator Support: Includes trend, momentum, volume, and volatility indicators
- Type-Safe API: Leverages Rust's type system to provide a safe API
- Performance Optimized: Efficient algorithms suitable for large datasets
- Flexible Data Input: Works with both simple price data and OHLCV (Open, High, Low, Close, Volume) candles
- Real-time Updates: Support for both batch calculations and real-time updates
- Well Documented: Extensive documentation and examples
Installation
Add RSTA to your Cargo.toml:
[]
= "0.0.2"
API Reference
For complete API documentation, please visit docs.rs/rsta.
Key components:
-
Core Traits:
Indicator<T, O>: Common interface for all indicatorsPriceDataAccessor<T>: Uniform access to price data
-
Data Types:
Candle: OHLCV price data structureIndicatorError: Error types for indicator operations
-
Indicator Categories:
-
Trend Indicators:
- Simple Moving Average (SMA)
- Exponential Moving Average (EMA)
- Moving Average Convergence Divergence (MACD)
-
Momentum Indicators:
- Relative Strength Index (RSI)
- Stochastic Oscillator
- Williams %R
-
Volume Indicators:
- On Balance Volume (OBV)
- Chaikin Money Flow (CMF)
- Accumulation/Distribution Line (ADL)
- Volume Rate of Change (VROC)
-
Volatility Indicators:
- Standard Deviation (STD)
- Average True Range (ATR)
- Bollinger Bands (BB)
- Keltner Channels
-
Quick Start
Here's a simple example calculating a Simple Moving Average (SMA):
use Sma;
use Indicator;
Indicator Categories
RSTA organizes indicators into four main categories:
Trend Indicators
Track the direction of price movements over time.
use Sma;
use Indicator;
// Create a 14-period SMA
let mut sma = new?;
let prices = vec!;
let sma_values = sma.calculate?;
Available trend indicators:
- Simple Moving Average (SMA)
- Exponential Moving Average (EMA)
- Moving Average Convergence Divergence (MACD)
Momentum Indicators
Measure the rate of price changes to identify overbought or oversold conditions.
use Rsi;
use Indicator;
// Create a 14-period RSI
let mut rsi = new?;
let prices = vec!;
let rsi_values = rsi.calculate?;
Available momentum indicators:
- Relative Strength Index (RSI)
- Williams %R
- Stochastic Oscillator
Volume Indicators
Analyze trading volume to confirm price movements.
use Obv;
use Indicator;
use Candle;
// Create price data with OHLCV values
let candles = vec!;
// Create and calculate OBV
let mut obv = new?;
let obv_values = obv.calculate?;
Available volume indicators:
- On Balance Volume (OBV)
- Chaikin Money Flow (CMF)
- Accumulation/Distribution Line (ADL)
- Volume Rate of Change (VROC)
Volatility Indicators
Measure market volatility and price dispersion.
use Std;
use Indicator;
// Create a 20-period Standard Deviation indicator
let mut std_dev = new?;
let prices = vec!;
let std_values = std_dev.calculate?;
// Standard Deviation values
for value in std_values
Available volatility indicators:
- Standard Deviation (STD)
- Average True Range (ATR)
- Bollinger Bands (BB)
- Keltner Channels
Usage Patterns and Best Practices
Batch vs. Real-time Calculation
RSTA supports both batch calculation for historical data and real-time updates:
use Sma;
use Indicator;
// Create indicator
let mut sma = new?;
// Batch calculation
let historical_prices = vec!;
let historical_sma = sma.calculate?;
// Reset state for real-time updates
sma.reset;
// Real-time updates
let new_price = 105.0;
if let Some = sma.next?
Working with OHLCV Data
Some indicators require full OHLCV data using the Candle struct:
use Candle;
// Create a candle with OHLCV data
let candle = Candle ;
Combining Indicators for Trading Strategies
Many trading strategies use multiple indicators together. Once more indicators are implemented, you can combine them for complex trading strategies.
use Sma;
use Std;
use Indicator;
// Create indicators
let mut sma = new?;
let mut std_dev = new?;
// Calculate indicators
let prices = vec!;
let sma_values = sma.calculate?;
let std_values = std_dev.calculate?;
// Analyze results (simple example)
for i in 0..sma_values.len.min
Error Handling
All methods that might fail return a Result with detailed error information:
use Sma;
use IndicatorError;
// Handle errors explicitly
match new
Contributing
Contributions are welcome! Here's how you can help:
- Add New Indicators: Implement additional technical indicators
- Improve Performance: Optimize existing implementations
- Add Tests: Increase test coverage and add test cases
- Enhance Documentation: Improve examples and usage documentation
- Report Issues: Report bugs or suggest features
Please follow these steps to contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-new-indicator) - Commit your changes (
git commit -am 'Add a new indicator') - Push to the branch (
git push origin feature/my-new-indicator) - Create a new Pull Request
License
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.