quant-indicators 0.7.0

Pure indicator math library for trading — MA, RSI, Bollinger, MACD, ATR, HRP
Documentation
//! Close price passthrough indicator.
//!
//! Simply returns close prices with timestamps. Useful for signal generators
//! that don't need technical indicators but still need access to timestamps.

use quant_primitives::Candle;

use crate::error::IndicatorError;
use crate::indicator::Indicator;
use crate::series::Series;

/// Passthrough indicator that returns close prices.
///
/// This is useful for signal generators that don't use technical indicators
/// but still need timestamps (like BuyAndHoldSignal).
#[derive(Debug, Clone, Default)]
pub struct Close;

impl Close {
    /// Create a new Close indicator.
    pub fn new() -> Self {
        Self
    }
}

impl Indicator for Close {
    fn name(&self) -> &str {
        "Close"
    }

    fn warmup_period(&self) -> usize {
        1 // Just need one candle
    }

    fn compute(&self, candles: &[Candle]) -> Result<Series, IndicatorError> {
        if candles.is_empty() {
            return Err(IndicatorError::InsufficientData {
                required: 1,
                actual: 0,
            });
        }

        let values: Vec<_> = candles.iter().map(|c| (c.timestamp(), c.close())).collect();

        Ok(Series::new(values))
    }
}

#[cfg(test)]
#[path = "close_tests.rs"]
mod tests;