Coverage Report

Created: 2025-10-06 12:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/home/jgrusewski/Work/foxhunt/config/src/ml_config.rs
Line
Count
Source
1
//! Machine learning configuration
2
3
use serde::{Deserialize, Serialize};
4
use std::collections::HashMap;
5
6
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7
pub struct MLConfig {
8
    pub model_config: ModelArchitectureConfig,
9
    pub training_config: TrainingConfig,
10
    pub simulation_config: SimulationConfig,
11
}
12
13
/// Configuration for market data simulation and stress testing
14
#[derive(Debug, Clone, Serialize, Deserialize)]
15
pub struct SimulationConfig {
16
    /// Initial market state with configurable symbol prices
17
    pub initial_market_state: MarketState,
18
    /// Simulation parameters
19
    pub parameters: SimulationParameters,
20
    /// Test symbol configuration for generic testing
21
    pub test_symbols: TestSymbolConfig,
22
}
23
24
/// Initial market state configuration
25
#[derive(Debug, Clone, Serialize, Deserialize)]
26
pub struct MarketState {
27
    /// Symbol-specific initial prices and configuration
28
    pub symbols: HashMap<String, SymbolConfig>,
29
    /// Default configuration for unlisted symbols
30
    pub default_symbol: SymbolConfig,
31
}
32
33
/// Configuration for individual symbols
34
#[derive(Debug, Clone, Serialize, Deserialize)]
35
pub struct SymbolConfig {
36
    /// Initial price for the symbol
37
    pub initial_price: f64,
38
    /// Base volatility for the symbol
39
    pub volatility: f64,
40
    /// Base trading volume
41
    pub base_volume: f64,
42
    /// Minimum spread in basis points
43
    pub min_spread_bps: f64,
44
    /// Maximum spread in basis points
45
    pub max_spread_bps: f64,
46
    /// Market capitalization tier (affects behavior)
47
    pub market_cap_tier: MarketCapTier,
48
}
49
50
/// Market capitalization tiers for different symbol behaviors
51
#[derive(Debug, Clone, Serialize, Deserialize)]
52
pub enum MarketCapTier {
53
    /// Large cap stocks (>$10B)
54
    LargeCap,
55
    /// Mid cap stocks ($2B-$10B)
56
    MidCap,
57
    /// Small cap stocks (<$2B)
58
    SmallCap,
59
    /// Generic test symbol
60
    Test,
61
}
62
63
/// Simulation parameters
64
#[derive(Debug, Clone, Serialize, Deserialize)]
65
pub struct SimulationParameters {
66
    /// Update rate in Hz
67
    pub update_rate_hz: u32,
68
    /// Base market volatility
69
    pub base_volatility: f64,
70
    /// Market trend direction (-1.0 to 1.0)
71
    pub trend: f64,
72
    /// Enable realistic market microstructure
73
    pub enable_microstructure: bool,
74
    /// Enable correlated movements between symbols
75
    pub enable_correlation: bool,
76
}
77
78
/// Test symbol configuration for generic testing
79
#[derive(Debug, Clone, Serialize, Deserialize)]
80
pub struct TestSymbolConfig {
81
    /// Prefix for test symbols (e.g., "TEST")
82
    pub symbol_prefix: String,
83
    /// Number of test symbols to generate
84
    pub count: usize,
85
    /// Price range for test symbols
86
    pub price_range: (f64, f64),
87
    /// Volume range for test symbols
88
    pub volume_range: (f64, f64),
89
}
90
91
/// Default simulation configuration
92
impl Default for SimulationConfig {
93
0
    fn default() -> Self {
94
0
        let mut symbols = HashMap::new();
95
96
        // Production-ready major symbols with realistic configurations
97
0
        symbols.insert(
98
0
            "AAPL".to_string(),
99
0
            SymbolConfig {
100
0
                initial_price: 150.0,
101
0
                volatility: 0.25,
102
0
                base_volume: 50000000.0,
103
0
                min_spread_bps: 1.0,
104
0
                max_spread_bps: 5.0,
105
0
                market_cap_tier: MarketCapTier::LargeCap,
106
0
            },
107
        );
108
109
0
        symbols.insert(
110
0
            "MSFT".to_string(),
111
0
            SymbolConfig {
112
0
                initial_price: 300.0,
113
0
                volatility: 0.22,
114
0
                base_volume: 30000000.0,
115
0
                min_spread_bps: 1.0,
116
0
                max_spread_bps: 5.0,
117
0
                market_cap_tier: MarketCapTier::LargeCap,
118
0
            },
119
        );
120
121
0
        symbols.insert(
122
0
            "GOOGL".to_string(),
123
0
            SymbolConfig {
124
0
                initial_price: 2500.0,
125
0
                volatility: 0.28,
126
0
                base_volume: 20000000.0,
127
0
                min_spread_bps: 2.0,
128
0
                max_spread_bps: 8.0,
129
0
                market_cap_tier: MarketCapTier::LargeCap,
130
0
            },
131
        );
132
133
0
        symbols.insert(
134
0
            "TSLA".to_string(),
135
0
            SymbolConfig {
136
0
                initial_price: 800.0,
137
0
                volatility: 0.45,
138
0
                base_volume: 80000000.0,
139
0
                min_spread_bps: 2.0,
140
0
                max_spread_bps: 10.0,
141
0
                market_cap_tier: MarketCapTier::LargeCap,
142
0
            },
143
        );
144
145
0
        symbols.insert(
146
0
            "AMZN".to_string(),
147
0
            SymbolConfig {
148
0
                initial_price: 3200.0,
149
0
                volatility: 0.30,
150
0
                base_volume: 25000000.0,
151
0
                min_spread_bps: 2.0,
152
0
                max_spread_bps: 8.0,
153
0
                market_cap_tier: MarketCapTier::LargeCap,
154
0
            },
155
        );
156
157
0
        symbols.insert(
158
0
            "NVDA".to_string(),
159
0
            SymbolConfig {
160
0
                initial_price: 500.0,
161
0
                volatility: 0.40,
162
0
                base_volume: 40000000.0,
163
0
                min_spread_bps: 2.0,
164
0
                max_spread_bps: 8.0,
165
0
                market_cap_tier: MarketCapTier::LargeCap,
166
0
            },
167
        );
168
169
0
        Self {
170
0
            initial_market_state: MarketState {
171
0
                symbols,
172
0
                default_symbol: SymbolConfig {
173
0
                    initial_price: 100.0,
174
0
                    volatility: 0.30,
175
0
                    base_volume: 1000000.0,
176
0
                    min_spread_bps: 5.0,
177
0
                    max_spread_bps: 20.0,
178
0
                    market_cap_tier: MarketCapTier::Test,
179
0
                },
180
0
            },
181
0
            parameters: SimulationParameters {
182
0
                update_rate_hz: 1000,
183
0
                base_volatility: 0.02,
184
0
                trend: 0.0,
185
0
                enable_microstructure: true,
186
0
                enable_correlation: false,
187
0
            },
188
0
            test_symbols: TestSymbolConfig {
189
0
                symbol_prefix: "TEST".to_string(),
190
0
                count: 10,
191
0
                price_range: (50.0, 500.0),
192
0
                volume_range: (100000.0, 10000000.0),
193
0
            },
194
0
        }
195
0
    }
196
}
197
198
#[derive(Debug, Clone, Serialize, Deserialize)]
199
pub struct ModelArchitectureConfig {
200
    pub model_type: String,
201
    pub hidden_dims: Vec<usize>,
202
    pub dropout_rate: f64,
203
    pub activation: String,
204
}
205
206
impl Default for ModelArchitectureConfig {
207
0
    fn default() -> Self {
208
0
        Self {
209
0
            model_type: "transformer".to_string(),
210
0
            hidden_dims: vec![256, 128, 64],
211
0
            dropout_rate: 0.1,
212
0
            activation: "relu".to_string(),
213
0
        }
214
0
    }
215
}
216
217
#[derive(Debug, Clone, Serialize, Deserialize)]
218
pub struct TrainingConfig {
219
    pub batch_size: usize,
220
    pub learning_rate: f64,
221
    pub epochs: u32,
222
    pub early_stopping_patience: u32,
223
}
224
225
impl Default for TrainingConfig {
226
0
    fn default() -> Self {
227
0
        Self {
228
0
            batch_size: 32,
229
0
            learning_rate: 0.001,
230
0
            epochs: 100,
231
0
            early_stopping_patience: 10,
232
0
        }
233
0
    }
234
}
235
236
#[derive(Debug, Clone, Serialize, Deserialize)]
237
pub struct Mamba2Config {
238
    pub d_model: usize,
239
    pub d_state: usize,
240
    pub d_conv: usize,
241
    pub expand: usize,
242
    pub dt_rank: Option<usize>,
243
    pub dt_min: f64,
244
    pub dt_max: f64,
245
    pub dt_init: String,
246
    pub dt_scale: f64,
247
    pub dt_init_floor: f64,
248
    pub conv_bias: bool,
249
    pub bias: bool,
250
    pub use_fast_path: bool,
251
    pub layer_idx: Option<usize>,
252
    pub device: Option<String>,
253
    pub dtype: Option<String>,
254
    pub d_head: usize,
255
    pub num_heads: usize,
256
    pub num_layers: usize,
257
    pub target_latency_us: u64,
258
    pub hardware_aware: bool,
259
    pub use_ssd: bool,
260
    pub use_selective_state: bool,
261
    pub max_seq_len: usize,
262
    pub batch_size: usize,
263
    pub seq_len: usize,
264
    pub dropout: f64,
265
}
266
267
impl Default for Mamba2Config {
268
0
    fn default() -> Self {
269
0
        Self {
270
0
            d_model: 768,
271
0
            d_state: 128,
272
0
            d_conv: 4,
273
0
            expand: 2,
274
0
            dt_rank: None, // Auto-calculated as ceil(d_model / 16)
275
0
            dt_min: 0.001,
276
0
            dt_max: 0.1,
277
0
            dt_init: "random".to_string(),
278
0
            dt_scale: 1.0,
279
0
            dt_init_floor: 1e-4,
280
0
            conv_bias: true,
281
0
            bias: false,
282
0
            use_fast_path: true,
283
0
            layer_idx: None,
284
0
            device: None,
285
0
            dtype: None,
286
0
            d_head: 32,
287
0
            num_heads: 8,
288
0
            num_layers: 4,
289
0
            target_latency_us: 3,
290
0
            hardware_aware: true,
291
0
            use_ssd: true,
292
0
            use_selective_state: true,
293
0
            max_seq_len: 1024,
294
0
            batch_size: 1,
295
0
            seq_len: 256,
296
0
            dropout: 0.0,
297
0
        }
298
0
    }
299
}