Skip to main content

market_model/strategy/
buy_and_hold.rs

1use crate::strategy::PriceStrategy;
2use crate::types::Signal;
3
4/// Always long, used as a baseline strategy.
5pub struct BuyAndHold;
6
7impl PriceStrategy for BuyAndHold {
8    fn signal(&self, _history: &[f64]) -> Signal {
9        Signal::Long
10    }
11}
12
13/// Never trades, used as a neutral baseline.
14pub struct AlwaysFlat;
15
16impl PriceStrategy for AlwaysFlat {
17    fn signal(&self, _history: &[f64]) -> Signal {
18        Signal::Flat
19    }
20}
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25
26    #[test]
27    fn test_buy_and_hold() {
28        assert_eq!(BuyAndHold.signal(&[]), Signal::Long);
29        assert_eq!(BuyAndHold.signal(&[10.0, 11.0, 12.0]), Signal::Long);
30    }
31
32    #[test]
33    fn test_always_flat() {
34        assert_eq!(AlwaysFlat.signal(&[]), Signal::Flat);
35        assert_eq!(AlwaysFlat.signal(&[10.0, 11.0, 12.0]), Signal::Flat);
36    }
37}