Documentation
use std::collections::VecDeque;
use crate::strategy_engine::Strategy;


#[derive(Debug, Clone)]
pub struct DayTrading {
    prices: VecDeque<f64>,
}

impl DayTrading {
    pub fn new() -> Self {
        Self {
            prices: VecDeque::new(),
        }
    }

    pub fn update_price(&mut self, price: f64) {
        self.prices.push_back(price);
    }
}

impl Strategy for DayTrading {
    fn evaluate(&self, price: &f64) -> f64 {
        if self.prices.len() < 2 {
            return 0.0;
        }

        let last_price = self.prices[self.prices.len() - 2];
        if *price > last_price {
            1.0 // 买入信号
        } else if *price < last_price {
            -1.0 // 卖出信号
        } else {
            0.0 // 无信号
        }
    }

    fn calculate_indicator(&self, prices: &Vec<f64>) -> f64 {
        // 计算胜率作为指标
        let mut wins = 0;
        let mut total_trades = 0;

        for price in prices {
            let signal = self.evaluate(price);
            if signal > 0.0 {
                total_trades += 1;
                if *price > prices[0] {
                    wins += 1;
                }
            } else if signal < 0.0 {
                total_trades += 1;
                if *price < prices[0] {
                    wins += 1;
                }
            }
        }

        if total_trades == 0 {
            0.0
        } else {
            wins as f64 / total_trades as f64
        }
    }
}