quant-indicators 0.7.0

Pure indicator math library for trading — MA, RSI, Bollinger, MACD, ATR, HRP
Documentation
//! Test helpers for indicator unit tests.

#[cfg(test)]
#[allow(clippy::expect_used)]
pub(crate) mod helpers {
    use chrono::{DateTime, TimeZone, Utc};
    use quant_primitives::Candle;
    use rust_decimal::Decimal;

    /// Create a flat candle (open = high = low = close) at the given timestamp.
    pub fn make_candle(close: Decimal, ts: DateTime<Utc>) -> Candle {
        Candle::new(close, close, close, close, Decimal::from(1000), ts)
            .expect("BUG in make_candle: flat candle with equal OHLC must always be valid")
    }

    /// Generate a timestamp offset by `idx` hours from 2024-01-01T00:00:00Z.
    pub fn ts(idx: i64) -> DateTime<Utc> {
        Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0)
            .single()
            .expect("BUG: hardcoded UTC datetime 2024-01-01T00:00:00 is always valid")
            + chrono::Duration::hours(idx)
    }
}