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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<f64> = 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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -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)),
|
||||
),
|
||||
),
|
||||
])),
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user