Crate rangebar

Crate rangebar 

Source
Expand description

§Rangebar

High-performance non-lookahead bias range bar construction for Binance UM Futures data.

§Quick Start

use rangebar::{RangeBarProcessor, AggTrade, FixedPoint};

// Create processor with 0.8% threshold (8000 basis points)
let mut processor = RangeBarProcessor::new(8000);

// Create sample trade data
let trade = AggTrade {
    agg_trade_id: 123456789,
    price: FixedPoint::from_str("50000.12345").unwrap(),
    volume: FixedPoint::from_str("1.50000000").unwrap(),
    first_trade_id: 100,
    last_trade_id: 105,
    timestamp: 1609459200000,
    is_buyer_maker: false,
};

// Process trades into range bars
let trades = vec![trade];
let bars = processor.process_trades(&trades).unwrap();

for bar in bars {
    println!("Bar: O={} H={} L={} C={} V={}",
             bar.open, bar.high, bar.low, bar.close, bar.volume);
}

§Algorithm

Range bars close when price moves ±threshold% from the bar’s opening price:

  1. Non-lookahead bias: Thresholds computed only from bar open price
  2. Breach inclusion: Breaching trade included in closing bar
  3. Fixed thresholds: Never recalculated during bar lifetime

§Features

  • 137M+ trades/second processing (2025 benchmarks)
  • Fixed-point arithmetic (no floating-point errors)
  • Memory efficient streaming processing
  • Comprehensive statistics via Polars (when statistics feature enabled)
  • Data integrity validation and checksums (when data-integrity feature enabled)

Re-exports§

pub use fixed_point::FixedPoint;
pub use range_bars::ProcessingError;
pub use range_bars::RangeBarProcessor;
pub use types::AggTrade;
pub use types::RangeBar;
pub use statistics::AlgorithmConfig;
pub use statistics::DatasetInfo;
pub use statistics::FormatMetadata;
pub use statistics::PerformanceMetrics;
pub use statistics::QualityMetrics;
pub use statistics::RangeBarMetadata;
pub use statistics::StatisticalConfig;
pub use statistics::StatisticalEngine;
pub use statistics::Statistics;

Modules§

fixed_point
Fixed-point arithmetic for precise decimal calculations without floating point errors
range_bars
Core range bar processing algorithm
statistics
Comprehensive financial statistics and market microstructure analysis
types
Type definitions for range bar processing

Constants§

DESCRIPTION
NAME
VERSION
Version information

Functions§

init
Library initialization and configuration