diff --git a/crates/fidc-core/src/platform_expr_strategy.rs b/crates/fidc-core/src/platform_expr_strategy.rs index 338535f..bfc2988 100644 --- a/crates/fidc-core/src/platform_expr_strategy.rs +++ b/crates/fidc-core/src/platform_expr_strategy.rs @@ -236,11 +236,7 @@ impl PlatformExprStrategy { engine.register_fn( "iff", |condition: bool, when_true: Dynamic, when_false: Dynamic| { - if condition { - when_true - } else { - when_false - } + if condition { when_true } else { when_false } }, ); engine.register_fn("contains", |value: &str, needle: &str| { @@ -404,11 +400,7 @@ impl PlatformExprStrategy { 0 } else { let next = quantity.saturating_sub(order_step_size.max(1)); - if next < minimum { - 0 - } else { - next - } + if next < minimum { 0 } else { next } } } @@ -971,9 +963,7 @@ impl PlatformExprStrategy { minimum_order_quantity: instrument .map(|item| item.minimum_order_quantity()) .unwrap_or(100) as i64, - order_step_size: instrument - .map(|item| item.order_step_size()) - .unwrap_or(100) as i64, + order_step_size: instrument.map(|item| item.order_step_size()).unwrap_or(100) as i64, paused: market.paused || candidate.is_paused, is_st: candidate.is_st || self.special_name(ctx, symbol), is_kcb: candidate.is_kcb, diff --git a/crates/fidc-core/src/strategy.rs b/crates/fidc-core/src/strategy.rs index af1236a..859e111 100644 --- a/crates/fidc-core/src/strategy.rs +++ b/crates/fidc-core/src/strategy.rs @@ -178,11 +178,7 @@ impl CnSmallCapRotationStrategy { let (sum, count) = window.fold((0.0, 0usize), |(sum, count), value| { (sum + value, count + 1) }); - if count == 0 { - 0.0 - } else { - sum / count as f64 - } + if count == 0 { 0.0 } else { sum / count as f64 } } fn gross_exposure(&self, closes: &[f64]) -> f64 { @@ -332,7 +328,7 @@ impl Strategy for CnSmallCapRotationStrategy { order_intents: Vec::new(), notes: vec![format!("warmup: {}", message)], diagnostics: vec![ - "insufficient history; skip trading on warmup dates".to_string() + "insufficient history; skip trading on warmup dates".to_string(), ], }); } @@ -628,11 +624,7 @@ impl JqMicroCapStrategy { 0 } else { let next = quantity.saturating_sub(order_step_size.max(1)); - if next < minimum { - 0 - } else { - next - } + if next < minimum { 0 } else { next } } } @@ -1538,7 +1530,7 @@ impl Strategy for JqMicroCapStrategy { order_intents: Vec::new(), notes: vec![format!("warmup: {}", message)], diagnostics: vec![ - "insufficient history; skip trading on warmup dates".to_string() + "insufficient history; skip trading on warmup dates".to_string(), ], }); } diff --git a/crates/fidc-core/tests/delisting.rs b/crates/fidc-core/tests/delisting.rs index 7f9de43..314512b 100644 --- a/crates/fidc-core/tests/delisting.rs +++ b/crates/fidc-core/tests/delisting.rs @@ -252,10 +252,12 @@ fn engine_settles_delisted_position_before_missing_market_snapshot_breaks_run() .any(|fill| fill.reason.contains("delisted_cash_settlement") && fill.symbol == "000001.SZ") ); - assert!(result - .holdings_summary - .iter() - .all(|holding| holding.symbol != "000001.SZ")); + assert!( + result + .holdings_summary + .iter() + .all(|holding| holding.symbol != "000001.SZ") + ); } #[test] @@ -477,9 +479,11 @@ fn engine_applies_successor_conversion_before_delisted_cash_settlement() { ); let result = engine.run().expect("backtest succeeds"); - assert!(result.equity_curve.iter().any(|point| point - .notes - .contains("successor_conversion 000001.SZ->000002.SZ"))); + assert!(result.equity_curve.iter().any(|point| { + point + .notes + .contains("successor_conversion 000001.SZ->000002.SZ") + })); assert!(result.fills.iter().all( |fill| !fill.reason.contains("delisted_cash_settlement") || fill.symbol != "000001.SZ" )); @@ -489,12 +493,16 @@ fn engine_applies_successor_conversion_before_delisted_cash_settlement() { .find(|holding| holding.symbol == "000002.SZ") .expect("successor holding exists"); assert_eq!(successor_holding.quantity, 500); - assert!(result - .holdings_summary - .iter() - .all(|holding| holding.symbol != "000001.SZ")); - assert!(result.account_events.iter().any(|event| event - .note - .contains("successor_conversion 000001.SZ->000002.SZ") - && event.note.contains("cash=1000.00"))); + assert!( + result + .holdings_summary + .iter() + .all(|holding| holding.symbol != "000001.SZ") + ); + assert!(result.account_events.iter().any(|event| { + event + .note + .contains("successor_conversion 000001.SZ->000002.SZ") + && event.note.contains("cash=1000.00") + })); } diff --git a/crates/fidc-core/tests/engine_hooks.rs b/crates/fidc-core/tests/engine_hooks.rs index a50f321..e4d525a 100644 --- a/crates/fidc-core/tests/engine_hooks.rs +++ b/crates/fidc-core/tests/engine_hooks.rs @@ -22,17 +22,17 @@ impl Strategy for HookProbeStrategy { "hook-probe" } - fn before_trading(&mut self, ctx: &StrategyContext<'_>) -> Result<(), fidc_core::BacktestError> { + fn before_trading( + &mut self, + ctx: &StrategyContext<'_>, + ) -> Result<(), fidc_core::BacktestError> { self.log .borrow_mut() .push(format!("before:{}", ctx.execution_date)); Ok(()) } - fn open_auction( - &mut self, - ctx: &StrategyContext<'_>, - ) -> Result<(), fidc_core::BacktestError> { + fn open_auction(&mut self, ctx: &StrategyContext<'_>) -> Result<(), fidc_core::BacktestError> { self.log .borrow_mut() .push(format!("auction:{}", ctx.execution_date));