From 43c234ee40becb7d5e4fa715ea4915a889bc96ae Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Sun, 22 Feb 2026 01:32:09 +0100 Subject: [PATCH] lint(adaptive-strategy): fix all 11 clippy deny violations - Replace .unwrap() on partial_cmp with .unwrap_or(Ordering::Equal) - Replace .unwrap() on Option with .ok_or_else()? for Kelly/PPO sizers - Convert empty-bracket structs to unit structs (ShortfallTracker, VPINCalculator) - Use fallback for chrono::Duration and serde_json::Number conversions Co-Authored-By: Claude Opus 4.6 --- adaptive-strategy/src/ensemble/weight_optimizer.rs | 9 +++++---- adaptive-strategy/src/execution/mod.rs | 4 ++-- adaptive-strategy/src/microstructure/mod.rs | 4 ++-- adaptive-strategy/src/models/deep_learning.rs | 7 +++++-- adaptive-strategy/src/models/mod.rs | 5 ++++- adaptive-strategy/src/risk/mod.rs | 6 +++--- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/adaptive-strategy/src/ensemble/weight_optimizer.rs b/adaptive-strategy/src/ensemble/weight_optimizer.rs index 863a241e4..2e580e929 100644 --- a/adaptive-strategy/src/ensemble/weight_optimizer.rs +++ b/adaptive-strategy/src/ensemble/weight_optimizer.rs @@ -279,8 +279,9 @@ impl WeightOptimizer { history.push(performance); // Maintain performance window - let cutoff_time = - chrono::Utc::now() - chrono::Duration::from_std(self.performance_window).unwrap(); + let cutoff_time = chrono::Utc::now() + - chrono::Duration::from_std(self.performance_window) + .unwrap_or_else(|_| chrono::Duration::seconds(3600)); history.retain(|p| p.timestamp > cutoff_time); debug!( @@ -694,7 +695,7 @@ impl WeightOptimizer { } let mut returns: Vec = history.iter().map(|p| p.return_value).collect(); - returns.sort_by(|a, b| a.partial_cmp(b).unwrap()); + returns.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)); let index = (returns.len() as f64 * 0.05).floor() as usize; returns.get(index).copied().unwrap_or(0.0) @@ -967,7 +968,7 @@ impl MetaOptimizer { pub fn get_best_algorithm(&self) -> WeightingAlgorithmType { self.algorithm_performance .iter() - .max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap()) + .max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)) .map(|(alg, _)| alg.clone()) .unwrap_or(WeightingAlgorithmType::BayesianModelAveraging) } diff --git a/adaptive-strategy/src/execution/mod.rs b/adaptive-strategy/src/execution/mod.rs index 812ee59c4..ab14fad9d 100644 --- a/adaptive-strategy/src/execution/mod.rs +++ b/adaptive-strategy/src/execution/mod.rs @@ -184,7 +184,7 @@ pub struct SlippageStatistics { /// Implementation shortfall tracking #[derive(Debug)] -pub struct ShortfallTracker {} +pub struct ShortfallTracker; /// Implementation shortfall measurement #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1000,7 +1000,7 @@ impl Default for ShortfallTracker { impl ShortfallTracker { /// Create a new shortfall tracker pub fn new() -> Self { - Self {} + Self } } diff --git a/adaptive-strategy/src/microstructure/mod.rs b/adaptive-strategy/src/microstructure/mod.rs index e62902af7..c2a5824be 100644 --- a/adaptive-strategy/src/microstructure/mod.rs +++ b/adaptive-strategy/src/microstructure/mod.rs @@ -28,7 +28,7 @@ use super::config::MicrostructureConfig; /// traders are present in the market. Higher VPIN values indicate higher /// probability of adverse selection for market makers. #[derive(Debug, Clone)] -pub struct VPINCalculator {} +pub struct VPINCalculator; impl VPINCalculator { /// Create a new VPIN calculator with the given configuration @@ -37,7 +37,7 @@ impl VPINCalculator { /// /// * `config` - VPIN calculation parameters pub fn new(_config: VPINConfig) -> Self { - Self {} + Self } /// Update VPIN calculation with new market data diff --git a/adaptive-strategy/src/models/deep_learning.rs b/adaptive-strategy/src/models/deep_learning.rs index 1474f52a7..82013e07c 100644 --- a/adaptive-strategy/src/models/deep_learning.rs +++ b/adaptive-strategy/src/models/deep_learning.rs @@ -640,7 +640,9 @@ impl Mamba2Model { // Use the latest features for single-step prediction // In a full implementation, we'd process the entire sequence - let latest_features = sequence.last().unwrap(); + let latest_features = sequence + .last() + .ok_or_else(|| anyhow::anyhow!("Sequence unexpectedly empty after non-empty check"))?; // Ensure features match model input dimension let input_features = if latest_features.len() != self.mamba_config.d_model { @@ -868,7 +870,8 @@ impl ModelTrait for Mamba2Model { parameters.insert( "compression_ratio".to_owned(), serde_json::Value::Number( - serde_json::Number::from_f64(self.compression_ratio).unwrap(), + serde_json::Number::from_f64(self.compression_ratio) + .unwrap_or_else(|| serde_json::Number::from(0)), ), ); diff --git a/adaptive-strategy/src/models/mod.rs b/adaptive-strategy/src/models/mod.rs index 7868762e0..e2c0bb847 100644 --- a/adaptive-strategy/src/models/mod.rs +++ b/adaptive-strategy/src/models/mod.rs @@ -308,7 +308,10 @@ impl ModelTrait for MockModel { ), ( "feature_sum".to_owned(), - serde_json::Value::Number(serde_json::Number::from_f64(feature_sum).unwrap()), + serde_json::Value::Number( + serde_json::Number::from_f64(feature_sum) + .unwrap_or_else(|| serde_json::Number::from(0)), + ), ), ])), }) diff --git a/adaptive-strategy/src/risk/mod.rs b/adaptive-strategy/src/risk/mod.rs index 28eb5e2f4..ef57ab06b 100644 --- a/adaptive-strategy/src/risk/mod.rs +++ b/adaptive-strategy/src/risk/mod.rs @@ -542,7 +542,7 @@ impl RiskManager { let kelly_recommendation = self .kelly_sizer .as_mut() - .unwrap() + .ok_or_else(|| anyhow::anyhow!("Kelly sizer not initialized"))? .calculate_position_size( symbol, expected_return, @@ -631,7 +631,7 @@ impl RiskManager { Some( self.kelly_sizer .as_mut() - .unwrap() + .ok_or_else(|| anyhow::anyhow!("Kelly sizer not initialized after is_some check"))? .calculate_position_size( symbol, expected_return, @@ -648,7 +648,7 @@ impl RiskManager { let ppo_recommendation = self .ppo_sizer .as_mut() - .unwrap() + .ok_or_else(|| anyhow::anyhow!("PPO sizer not initialized"))? .calculate_position_size( symbol, &market_data,