debot_db/
trading_strategy.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum TrendType {
    Up,
    Down,
    Any,
}

#[derive(Clone, Copy, Debug, Eq, Hash, Serialize, Deserialize)]
pub enum TradingStrategy {
    RandomWalk(TrendType),
    RandomForest(TrendType),
}

impl TradingStrategy {
    pub fn trend_type(&self) -> &TrendType {
        match self {
            TradingStrategy::RandomWalk(t) | TradingStrategy::RandomForest(t) => t,
        }
    }
}

impl PartialEq for TradingStrategy {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (
                TradingStrategy::RandomWalk(TrendType::Any),
                TradingStrategy::RandomWalk(TrendType::Up),
            ) => true,
            (
                TradingStrategy::RandomWalk(TrendType::Any),
                TradingStrategy::RandomWalk(TrendType::Down),
            ) => true,
            (
                TradingStrategy::RandomWalk(TrendType::Up),
                TradingStrategy::RandomWalk(TrendType::Any),
            ) => true,
            (
                TradingStrategy::RandomWalk(TrendType::Down),
                TradingStrategy::RandomWalk(TrendType::Any),
            ) => true,
            (TradingStrategy::RandomWalk(t1), TradingStrategy::RandomWalk(t2)) if t1 == t2 => true,

            (
                TradingStrategy::RandomForest(TrendType::Any),
                TradingStrategy::RandomForest(TrendType::Up),
            ) => true,
            (
                TradingStrategy::RandomForest(TrendType::Any),
                TradingStrategy::RandomForest(TrendType::Down),
            ) => true,
            (
                TradingStrategy::RandomForest(TrendType::Up),
                TradingStrategy::RandomForest(TrendType::Any),
            ) => true,
            (
                TradingStrategy::RandomForest(TrendType::Down),
                TradingStrategy::RandomForest(TrendType::Any),
            ) => true,
            (TradingStrategy::RandomForest(t1), TradingStrategy::RandomForest(t2)) if t1 == t2 => {
                true
            }

            _ => false,
        }
    }
}