quant_indicators/
close.rs1use quant_primitives::Candle;
7
8use crate::error::IndicatorError;
9use crate::indicator::Indicator;
10use crate::series::Series;
11
12#[derive(Debug, Clone, Default)]
17pub struct Close;
18
19impl Close {
20 pub fn new() -> Self {
22 Self
23 }
24}
25
26impl Indicator for Close {
27 fn name(&self) -> &str {
28 "Close"
29 }
30
31 fn warmup_period(&self) -> usize {
32 1 }
34
35 fn compute(&self, candles: &[Candle]) -> Result<Series, IndicatorError> {
36 if candles.is_empty() {
37 return Err(IndicatorError::InsufficientData {
38 required: 1,
39 actual: 0,
40 });
41 }
42
43 let values: Vec<_> = candles.iter().map(|c| (c.timestamp(), c.close())).collect();
44
45 Ok(Series::new(values))
46 }
47}
48
49#[cfg(test)]
50#[path = "close_tests.rs"]
51mod tests;