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


#[derive(Debug, Clone)]

pub struct NewsSentiment {
    sentiment_scores: VecDeque<f64>,
}

impl NewsSentiment {
    pub fn new() -> Self {
        Self {
            sentiment_scores: VecDeque::new(),
        }
    }

    pub fn update_sentiment(&mut self, sentiment_score: f64) {
        self.sentiment_scores.push_back(sentiment_score);
    }
}

impl Strategy for NewsSentiment {
    fn evaluate(&self, _price: &f64) -> f64 {
        let last_sentiment = self.sentiment_scores.back().unwrap();
        if *last_sentiment > 0.5 {
            1.0 // 买入信号
        } else if *last_sentiment < -0.5 {
            -1.0 // 卖出信号
        } else {
            0.0 // 无信号
        }
    }

    fn calculate_indicator(&self, _prices: &Vec<f64>) -> f64 {
        // 计算情绪得分平均值作为指标
        let mut total_score = 0.0;
        for score in &self.sentiment_scores {
            total_score += *score;
        }
        total_score / self.sentiment_scores.len() as f64
    }
}