Skip to main content

quantwave_core/features/
trendflex.rs

1//! Trendflex feature extractor wrapper.
2//!
3//! Simple wrapper around existing Trendflex for ML use.
4//! Returns the zero-lag trend component value.
5//!
6//! Source: quantwave-core/src/indicators/trendflex.rs
7
8use crate::indicators::trendflex::Trendflex;
9use crate::traits::Next;
10
11#[derive(Debug, Clone, Copy, PartialEq)]
12pub struct TrendflexFeatures {
13    pub trendflex: f64,
14}
15
16#[derive(Debug, Clone)]
17pub struct TrendflexFeatureExtractor {
18    inner: Trendflex,
19}
20
21impl TrendflexFeatureExtractor {
22    pub fn new(length: usize) -> Self {
23        Self {
24            inner: Trendflex::new(length),
25        }
26    }
27}
28
29impl Next<f64> for TrendflexFeatureExtractor {
30    type Output = TrendflexFeatures;
31
32    fn next(&mut self, input: f64) -> Self::Output {
33        let val = self.inner.next(input);
34        TrendflexFeatures { trendflex: val }
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn test_trendflex_wrapper_basic() {
44        let mut ext = TrendflexFeatureExtractor::new(20);
45        for i in 0..50 {
46            let val = 100.0 + (i as f64) * 0.1;
47            let f = ext.next(val);
48            // After warmup it should be non-zero in trending data
49        }
50    }
51}