algotrading

Crates.ioalgotrading
lib.rsalgotrading
version0.1.0-alpha.2
created_at2025-10-27 02:26:34.099465+00
updated_at2025-10-28 03:12:25.451343+00
descriptionA high-performance algorithmic trading toolkit written in Rust, with no dependencies.
homepage
repositoryhttps://github.com/ndavidson19/algotrading
max_upload_size
id1902146
size504,806
Nicholas Davidson (ndavidson19)

documentation

README

Algotrading

A high-performance algorithmic trading library for real-time market systems.

Algotrading provides low-latency statistical and econometric primitives optimized for quantitative trading strategies. It is:

  • Fast: SIMD-accelerated operations deliver nanosecond latencies with 4-8x speedups on modern hardware.

  • No Dependencies: Pure Rust implementation with zero external dependencies for easy integration into trading systems.

  • Zero-cost: Stack-allocated, const-generic data structures with no heap allocations in hot paths.

  • Flexible: Generic over scalar and SIMD types (f64, f64x4, f64x8) with a clean, unified API.

Crates.io MIT licensed Documentation Build Status

Documentation | API Reference | Examples | Performance Guide

Overview

Algotrading enables you to build high-frequency and medium-frequency trading strategies with:

  • Statistical functions — Mean, variance, correlation, skewness, kurtosis with SIMD
  • Probability distributions — Normal, Student-T, Log-Normal with fast parametric fitting
  • Rolling statistics — Constant-time O(1) updates with compile-time window sizes
  • Technical indicators — MACD, RSI, Bollinger Bands, EWMA, ATR
  • Options pricing — Black-Scholes, Greeks (Delta, Gamma, Vega, Theta), implied volatility
  • Risk metrics — VaR, Sharpe ratio, max drawdown, Kelly criterion
  • Matrix operations — Cholesky, eigenvalue decomposition, portfolio optimization
  • Regime detection — Markov switching models, Hidden Markov Models
  • Data quality — Real-time anomaly detection, staleness monitoring

Quick Start

Add this to your Cargo.toml:

[dependencies]
algotrading = "0.1.0-alpha.2"

Example: Building a Trading Signal

use algotrading::prelude::*;

fn main() {
    // Rolling statistics with 100-sample window
    let mut stats = RollingStats::<f64, 100>::new();

    // Technical indicators
    let mut rsi = RSI::standard();
    let mut macd = MACD::standard();

    // Regime detection
    let mut regime = MarkovSwitching::spy_default();

    for price in price_stream {
        // Update indicators
        let (mean, std) = stats.update(price);
        let rsi_val = rsi.update(price);
        let (macd_line, signal, _) = macd.update(price);

        // Calculate return and update regime
        let ret = (price - prev_price) / prev_price;
        regime.update(ret);

        // Generate signal
        if macd_line > signal && rsi_val < 70.0 && regime.current_state() == 1 {
            println!("BUY signal at {}", price);
        }
    }
}

SIMD Acceleration

Process multiple assets in parallel with 4-8x speedup:

use algotrading::prelude::*;
use algotrading::numeric::f64x8;

// Process 8 assets simultaneously
let mut stats = RollingStats::<f64x8, 100>::new();
let prices = f64x8::from_array([100.0, 101.0, 99.0, 102.0, 98.0, 103.0, 97.0, 104.0]);
let (means, stds) = stats.update(prices);

See examples/ for complete trading strategy implementations.

Features

Enable SIMD acceleration for 4-8x speedup on modern hardware:

[dependencies]
algotrading = { version = "0.1", features = ["simd"] }

Performance

Target latencies for trading operations:

Operation Latency Notes
Rolling stats update ~10ns O(1) constant time
Mean (10K samples, SIMD) ~8μs 5x faster than scalar
Distribution fitting (1K samples) ~2μs With SIMD acceleration
Cholesky decomposition 4×4 ~300ns Portfolio variance
Options Greeks ~50ns Delta, Gamma, Vega

See the Performance Guide for comprehensive benchmarks and optimization tips.

Documentation

Core Modules

Module Description
stats Core statistics (mean, variance, correlation) + rolling statistics with SIMD
probability Distributions (Normal, Student-T, Log-Normal), KDE, Monte Carlo
ta Technical indicators (MACD, RSI, Bollinger Bands, EWMA, ATR)
options Black-Scholes pricing, Greeks, implied volatility, local volatility
risk VaR, Sharpe ratio, max drawdown, Kelly criterion
matrix Cholesky, eigenvalue decomposition, portfolio optimization
regime Markov switching, Hidden Markov Models
filters Kalman filtering for state estimation
data Real-time data quality monitoring and anomaly detection

See the Module Documentation for detailed guides.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Before submitting a PR:

  • Run cargo test to ensure all tests pass
  • Run cargo clippy to check for common mistakes
  • Add benchmarks for performance-critical code
  • Update documentation as needed

Benchmarks

Run the benchmark suite:

cargo bench

Benchmark results are saved in target/criterion/ with detailed HTML reports.

License

This project is licensed under the MIT License.

Acknowledgments

Built by Nicholas Davidson for the quantitative trading community.

Special thanks to all contributors.

Commit count: 0

cargo fmt