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/data_config.rs
Line
Count
Source
1
//! Data configuration
2
3
use num_cpus;
4
use serde::{Deserialize, Serialize};
5
6
#[derive(Debug, Clone, Serialize, Deserialize)]
7
pub struct DataConfig {
8
    pub provider: String,
9
    pub symbols: Vec<String>,
10
    pub batch_size: usize,
11
    pub buffer_size: usize,
12
}
13
14
#[derive(Debug, Clone, Serialize, Deserialize)]
15
pub struct DataMicrostructureConfig {
16
    pub enable_bid_ask_spread: bool,
17
    pub enable_order_flow: bool,
18
    pub tick_size: f64,
19
    pub lot_size: f64,
20
    pub bid_ask_spread: bool,
21
    pub volume_imbalance: bool,
22
    pub price_impact: bool,
23
    pub kyle_lambda: bool,
24
    pub amihud_ratio: bool,
25
}
26
27
impl Default for DataMicrostructureConfig {
28
0
    fn default() -> Self {
29
0
        Self {
30
0
            enable_bid_ask_spread: true,
31
0
            enable_order_flow: true,
32
0
            tick_size: 0.01,
33
0
            lot_size: 100.0,
34
0
            bid_ask_spread: true,
35
0
            volume_imbalance: true,
36
0
            price_impact: false,
37
0
            kyle_lambda: false,
38
0
            amihud_ratio: false,
39
0
        }
40
0
    }
41
}
42
43
#[derive(Debug, Clone, Serialize, Deserialize)]
44
pub struct DataTLOBConfig {
45
    pub depth_levels: usize,
46
    pub enable_imbalance: bool,
47
    pub enable_pressure: bool,
48
    pub window_size: usize,
49
}
50
51
#[derive(Debug, Clone, Serialize, Deserialize)]
52
pub struct DataTechnicalIndicatorsConfig {
53
    pub enable_moving_averages: bool,
54
    pub enable_momentum: bool,
55
    pub enable_volatility: bool,
56
    pub window_sizes: Vec<usize>,
57
    pub ma_periods: Vec<usize>,
58
    pub rsi_periods: Vec<usize>,
59
    pub bollinger_periods: Vec<usize>,
60
    pub macd: DataMACDConfig,
61
}
62
63
impl Default for DataTechnicalIndicatorsConfig {
64
0
    fn default() -> Self {
65
0
        Self {
66
0
            enable_moving_averages: true,
67
0
            enable_momentum: true,
68
0
            enable_volatility: true,
69
0
            window_sizes: vec![10, 20, 50],
70
0
            ma_periods: vec![10, 20, 50, 200],
71
0
            rsi_periods: vec![14],
72
0
            bollinger_periods: vec![20],
73
0
            macd: DataMACDConfig::default(),
74
0
        }
75
0
    }
76
}
77
78
#[derive(Debug, Clone, Serialize, Deserialize)]
79
pub struct TrainingBenzingaConfig {
80
    pub api_key: String,
81
    pub api_key_env: String,
82
    pub symbols: Vec<String>,
83
    pub data_types: Vec<String>,
84
    pub timeout: u64,
85
    pub rate_limit: usize,
86
    pub batch_size: usize,
87
    pub enable_caching: bool,
88
}
89
90
impl Default for TrainingBenzingaConfig {
91
0
    fn default() -> Self {
92
0
        Self {
93
0
            api_key: String::new(),
94
0
            api_key_env: "BENZINGA_API_KEY".to_string(),
95
0
            symbols: vec!["SPY".to_string(), "AAPL".to_string()],
96
0
            data_types: vec![
97
0
                "news".to_string(),
98
0
                "sentiment".to_string(),
99
0
                "ratings".to_string(),
100
0
                "options".to_string(),
101
0
            ],
102
0
            timeout: 30,
103
0
            rate_limit: 60,
104
0
            batch_size: 1000,
105
0
            enable_caching: true,
106
0
        }
107
0
    }
108
}
109
110
#[derive(Debug, Clone, Serialize, Deserialize)]
111
pub enum DataCompressionAlgorithm {
112
    GZIP,
113
    ZSTD,
114
    LZ4,
115
    Snappy,
116
    None,
117
}
118
119
#[derive(Debug, Clone, Serialize, Deserialize)]
120
pub struct DataCompressionConfig {
121
    pub algorithm: DataCompressionAlgorithm,
122
    pub enabled: bool,
123
    pub level: Option<i32>,
124
}
125
126
impl Default for DataCompressionConfig {
127
0
    fn default() -> Self {
128
0
        Self {
129
0
            algorithm: DataCompressionAlgorithm::ZSTD,
130
0
            enabled: true,
131
0
            level: Some(3),
132
0
        }
133
0
    }
134
}
135
#[derive(Debug, Clone, Serialize, Deserialize)]
136
pub struct DataVersioningConfig {
137
    pub enabled: bool,
138
    pub version_format: String,
139
    pub keep_versions: usize,
140
}
141
142
impl Default for DataVersioningConfig {
143
0
    fn default() -> Self {
144
0
        Self {
145
0
            enabled: false,
146
0
            version_format: "v%Y%m%d_%H%M%S".to_string(),
147
0
            keep_versions: 5,
148
0
        }
149
0
    }
150
}
151
152
#[derive(Debug, Clone, Serialize, Deserialize)]
153
pub struct DataRetentionConfig {
154
    pub auto_cleanup: bool,
155
    pub retention_days: u32,
156
}
157
158
impl Default for DataRetentionConfig {
159
0
    fn default() -> Self {
160
0
        Self {
161
0
            auto_cleanup: false,
162
0
            retention_days: 30,
163
0
        }
164
0
    }
165
}
166
167
#[derive(Debug, Clone, Serialize, Deserialize)]
168
pub enum DataStorageFormat {
169
    Parquet,
170
    Arrow,
171
    Json,
172
    Csv,
173
    CSV,
174
    HDF5,
175
}
176
177
#[derive(Debug, Clone, Serialize, Deserialize)]
178
pub struct DataStorageConfig {
179
    pub format: DataStorageFormat,
180
    pub compression: DataCompressionConfig,
181
    pub path: String,
182
    pub base_directory: std::path::PathBuf,
183
    pub partition_by: Vec<String>,
184
    pub versioning: DataVersioningConfig,
185
    pub retention: DataRetentionConfig,
186
}
187
188
impl Default for DataStorageConfig {
189
0
    fn default() -> Self {
190
0
        Self {
191
0
            format: DataStorageFormat::Parquet,
192
0
            compression: DataCompressionConfig::default(),
193
0
            path: "./data".to_string(),
194
0
            base_directory: std::path::PathBuf::from("./data"),
195
0
            partition_by: vec!["symbol".to_string(), "date".to_string()],
196
0
            versioning: DataVersioningConfig::default(),
197
0
            retention: DataRetentionConfig::default(),
198
0
        }
199
0
    }
200
}
201
202
#[derive(Debug, Clone, Serialize, Deserialize)]
203
pub struct DataRegimeDetectionConfig {
204
    pub enable_hmm: bool,
205
    pub enable_clustering: bool,
206
    pub window_size: usize,
207
    pub n_states: usize,
208
    pub volatility_regime: bool,
209
    pub trend_regime: bool,
210
    pub volume_regime: bool,
211
    pub correlation_regime: bool,
212
    pub lookback_period: usize,
213
}
214
215
impl Default for DataRegimeDetectionConfig {
216
0
    fn default() -> Self {
217
0
        Self {
218
0
            enable_hmm: false,
219
0
            enable_clustering: false,
220
0
            window_size: 100,
221
0
            n_states: 3,
222
0
            volatility_regime: true,
223
0
            trend_regime: true,
224
0
            volume_regime: false,
225
0
            correlation_regime: false,
226
0
            lookback_period: 252,
227
0
        }
228
0
    }
229
}
230
231
#[derive(Debug, Clone, Serialize, Deserialize)]
232
pub struct DataProcessingConfig {
233
    pub worker_threads: usize,
234
    pub batch_size: usize,
235
    pub buffer_size: usize,
236
    pub timeout: u64,
237
    pub parallel_processing: bool,
238
}
239
240
impl Default for DataProcessingConfig {
241
0
    fn default() -> Self {
242
0
        Self {
243
0
            worker_threads: num_cpus::get(),
244
0
            batch_size: 1000,
245
0
            buffer_size: 10000,
246
0
            timeout: 300,
247
0
            parallel_processing: true,
248
0
        }
249
0
    }
250
}
251
252
#[derive(Debug, Clone, Serialize, Deserialize)]
253
pub struct DataTrainingConfig {
254
    pub batch_size: usize,
255
    pub sequence_length: usize,
256
    pub validation_split: f64,
257
    pub test_split: f64,
258
    pub sources: DataSourcesConfig,
259
    pub features: TrainingFeatureEngineeringConfig,
260
    pub validation: DataValidationConfig,
261
    pub storage: DataStorageConfig,
262
    pub processing: DataProcessingConfig,
263
    pub rate_limit: usize,
264
}
265
266
impl Default for DataTrainingConfig {
267
0
    fn default() -> Self {
268
0
        Self {
269
0
            batch_size: 32,
270
0
            sequence_length: 100,
271
0
            validation_split: 0.2,
272
0
            test_split: 0.1,
273
0
            sources: DataSourcesConfig::default(),
274
0
            features: TrainingFeatureEngineeringConfig::default(),
275
0
            validation: DataValidationConfig::default(),
276
0
            storage: DataStorageConfig::default(),
277
0
            processing: DataProcessingConfig::default(),
278
0
            rate_limit: 100,
279
0
        }
280
0
    }
281
}
282
283
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
284
pub struct DataSourcesConfig {
285
    pub databento: Option<DatabentoConfig>,
286
    pub benzinga: Option<TrainingBenzingaConfig>,
287
    #[serde(default)]
288
    pub enable_realtime: bool,
289
    pub interactive_brokers: Option<InteractiveBrokersConfig>,
290
    pub icmarkets: Option<ICMarketsConfig>,
291
    pub historical: Option<HistoricalDataConfig>,
292
}
293
294
#[derive(Debug, Clone, Serialize, Deserialize)]
295
pub struct InteractiveBrokersConfig {
296
    pub host: String,
297
    pub port: u16,
298
    pub client_id: i32,
299
    pub timeout_seconds: u64,
300
}
301
302
#[derive(Debug, Clone, Serialize, Deserialize)]
303
pub struct ICMarketsConfig {
304
    pub api_key: String,
305
    pub environment: String,
306
}
307
308
#[derive(Debug, Clone, Serialize, Deserialize)]
309
pub struct HistoricalDataConfig {
310
    pub enabled: bool,
311
    pub batch_size: usize,
312
    pub parallel_downloads: usize,
313
}
314
315
#[derive(Debug, Clone, Serialize, Deserialize)]
316
pub struct DatabentoConfig {
317
    pub api_key: String,
318
    pub dataset: String,
319
    pub symbols: Vec<String>,
320
    pub schema: String,
321
    pub stype_in: String,
322
}
323
324
#[derive(Debug, Clone, Serialize, Deserialize)]
325
pub struct DataValidationConfig {
326
    #[serde(default)]
327
    pub enable_price_validation: bool,
328
    #[serde(default)]
329
    pub enable_volume_validation: bool,
330
    #[serde(default)]
331
    pub price_threshold: f64,
332
    #[serde(default)]
333
    pub volume_threshold: f64,
334
    #[serde(default)]
335
    pub outlier_method: OutlierDetectionMethod,
336
    #[serde(default)]
337
    pub max_price_change: f64,
338
    #[serde(default)]
339
    pub max_volume_change: f64,
340
    #[serde(default)]
341
    pub max_timestamp_drift: i64,
342
    #[serde(default)]
343
    pub price_validation: bool,
344
    #[serde(default)]
345
    pub volume_validation: bool,
346
    #[serde(default)]
347
    pub timestamp_validation: bool,
348
    #[serde(default)]
349
    pub outlier_detection: bool,
350
    #[serde(default)]
351
    pub missing_data_handling: MissingDataHandling,
352
}
353
354
impl Default for DataValidationConfig {
355
0
    fn default() -> Self {
356
0
        Self {
357
0
            enable_price_validation: true,
358
0
            enable_volume_validation: true,
359
0
            price_threshold: 0.1,
360
0
            volume_threshold: 0.2,
361
0
            outlier_method: OutlierDetectionMethod::ZScore,
362
0
            max_price_change: 0.05,
363
0
            max_volume_change: 2.0,
364
0
            max_timestamp_drift: 1000,
365
0
            price_validation: true,
366
0
            volume_validation: true,
367
0
            timestamp_validation: true,
368
0
            outlier_detection: true,
369
0
            missing_data_handling: MissingDataHandling::Skip,
370
0
        }
371
0
    }
372
}
373
374
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
375
pub enum MissingDataHandling {
376
    #[default]
377
    Skip,
378
    Drop,
379
    Interpolate,
380
    ForwardFill,
381
    BackwardFill,
382
    FillForward,
383
    FillBackward,
384
    Mean,
385
    Median,
386
    Error,
387
}
388
389
#[derive(Debug, Clone, Serialize, Deserialize)]
390
pub struct TrainingFeatureEngineeringConfig {
391
    pub enable_normalization: bool,
392
    pub enable_scaling: bool,
393
    pub enable_log_returns: bool,
394
    pub lookback_window: usize,
395
    pub regime_detection: DataRegimeDetectionConfig,
396
    pub technical_indicators: DataTechnicalIndicatorsConfig,
397
    pub microstructure: DataMicrostructureConfig,
398
}
399
400
impl Default for TrainingFeatureEngineeringConfig {
401
0
    fn default() -> Self {
402
0
        Self {
403
0
            enable_normalization: true,
404
0
            enable_scaling: true,
405
0
            enable_log_returns: true,
406
0
            lookback_window: 100,
407
0
            regime_detection: DataRegimeDetectionConfig::default(),
408
0
            technical_indicators: DataTechnicalIndicatorsConfig::default(),
409
0
            microstructure: DataMicrostructureConfig::default(),
410
0
        }
411
0
    }
412
}
413
414
#[derive(Debug, Clone, Serialize, Deserialize)]
415
pub struct DataTemporalConfig {
416
    pub enable_time_features: bool,
417
    pub enable_seasonal: bool,
418
    pub timezone: String,
419
    pub business_hours_only: bool,
420
    pub market_session: bool,
421
    pub holiday_effects: bool,
422
    pub expiration_effects: bool,
423
}
424
425
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
426
pub enum OutlierDetectionMethod {
427
    #[default]
428
    ZScore,
429
    IQR,
430
    Isolation,
431
    IsolationForest,
432
    LocalOutlierFactor,
433
    None,
434
}
435
436
#[derive(Debug, Clone, Serialize, Deserialize)]
437
pub struct DataModuleConfig {
438
    pub data_path: String,
439
    pub batch_size: usize,
440
    pub num_workers: usize,
441
    pub cache_size: usize,
442
    pub settings: DataModuleSettings,
443
    pub interactive_brokers: Option<InteractiveBrokersConfig>,
444
}
445
446
#[derive(Debug, Clone, Serialize, Deserialize)]
447
pub struct DataModuleSettings {
448
    pub enable_preprocessing: bool,
449
    pub enable_validation: bool,
450
    pub max_memory_usage: usize,
451
    pub market_data_buffer_size: usize,
452
    pub order_event_buffer_size: usize,
453
}
454
455
#[derive(Debug, Clone, Serialize, Deserialize)]
456
pub struct DataMACDConfig {
457
    pub fast_period: usize,
458
    pub slow_period: usize,
459
    pub signal_period: usize,
460
    pub enabled: bool,
461
}
462
463
impl Default for DataMACDConfig {
464
0
    fn default() -> Self {
465
0
        Self {
466
0
            fast_period: 12,
467
0
            slow_period: 26,
468
0
            signal_period: 9,
469
0
            enabled: true,
470
0
        }
471
0
    }
472
}