Format related strategy and test files

This commit is contained in:
boris
2026-04-22 23:36:56 -07:00
parent ea2871a0f2
commit c4967c3711
4 changed files with 35 additions and 45 deletions

View File

@@ -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,

View File

@@ -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(),
],
});
}

View File

@@ -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
assert!(
result
.holdings_summary
.iter()
.all(|holding| holding.symbol != "000001.SZ"));
.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
assert!(result.equity_curve.iter().any(|point| {
point
.notes
.contains("successor_conversion 000001.SZ->000002.SZ")));
.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
assert!(
result
.holdings_summary
.iter()
.all(|holding| holding.symbol != "000001.SZ"));
assert!(result.account_events.iter().any(|event| event
.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")));
&& event.note.contains("cash=1000.00")
}));
}

View File

@@ -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));